rust-lang / rust-lang/rust-analyzer
`scope_for_offset` does not make sense
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
We have scope_for_offset function, which finds expression's scope based on offset. It is used primaraly for completion, where offset is the postion of the cursor.
Currently, ExprScopes is implmented by maintaining a tree of scopes (= sets of names) and a mapping from expressions to scopes. At the moment, scope_for_offset works by, roughly, finding the nearest expression to the offset and using it's scope. The problem with this approach is that it doesn't work. here's fun example
fn main() {
let x;
let y;
/* caret here */
let z;
}
Here, we obviously want to see x and y in scope, but not z. The problem is, there are no expressions in the snippet at all, so the "find nearest expression" plan fails.
Proposed solution is to store scope origin along with each scope, and, instead of finding closest expression, look for "closest scope", where "closes scope" is actually a bunch of hand-written heuristics for various edge cases, plus the base rule about enclosing expression.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the scope_for_offset function and the ExprScopes implementation described in the issue. Reproduce the completion case with the cursor before let z, then determine the scope-origin and closest-scope behavior needed so x and y are visible while z is not.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100