mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Implement Find All References for local variables
This commit is contained in:
parent
2a704035f4
commit
3746689e9d
8 changed files with 96 additions and 3 deletions
|
@ -257,6 +257,38 @@ impl AnalysisImpl {
|
|||
vec![]
|
||||
}
|
||||
|
||||
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, _token: &JobToken) -> Vec<(FileId, TextRange)> {
|
||||
let root = self.root(file_id);
|
||||
let file = root.syntax(file_id);
|
||||
let syntax = file.syntax();
|
||||
|
||||
let mut ret = vec![];
|
||||
|
||||
// Find the symbol we are looking for
|
||||
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
|
||||
|
||||
// We are only handing local references for now
|
||||
if let Some(resolved) = resolve_local_name(&file, offset, name_ref) {
|
||||
|
||||
ret.push((file_id, resolved.1));
|
||||
|
||||
if let Some(fn_def) = find_node_at_offset::<ast::FnDef>(syntax, offset) {
|
||||
|
||||
let refs : Vec<_> = fn_def.syntax().descendants()
|
||||
.filter_map(ast::NameRef::cast)
|
||||
.filter(|n: &ast::NameRef| resolve_local_name(&file, n.syntax().range().start(), *n) == Some(resolved.clone()))
|
||||
.collect();
|
||||
|
||||
for r in refs {
|
||||
ret.push((file_id, r.syntax().range()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
|
||||
let root = self.root(file_id);
|
||||
let module_tree = root.module_tree();
|
||||
|
|
|
@ -217,6 +217,9 @@ impl Analysis {
|
|||
self.imp
|
||||
.approximately_resolve_symbol(file_id, offset, token)
|
||||
}
|
||||
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, TextRange)> {
|
||||
self.imp.find_all_refs(file_id, offset, token)
|
||||
}
|
||||
pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> {
|
||||
self.imp.parent_module(file_id)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue