mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
WIP: This doesn't currently work but I also don't think it's the right abstraction
This commit is contained in:
parent
91312a9ff9
commit
1d4c767879
3 changed files with 25 additions and 3 deletions
|
@ -9,7 +9,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use relative_path::RelativePath;
|
use relative_path::RelativePath;
|
||||||
use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit};
|
use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
TextUnit, TextRange, SmolStr, File, AstNode,
|
TextUnit, TextRange, SmolStr, File, AstNode,
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
|
@ -197,8 +197,22 @@ impl AnalysisImpl {
|
||||||
let file = root.syntax(file_id);
|
let file = root.syntax(file_id);
|
||||||
let syntax = file.syntax();
|
let syntax = file.syntax();
|
||||||
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
|
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
|
||||||
|
|
||||||
|
// First try to resolve the symbol locally
|
||||||
|
if let Some(name) = resolve_local_name(&file, offset, name_ref) {
|
||||||
|
let vec: Vec<(FileId, FileSymbol)>::new();
|
||||||
|
vec.push((file_id, FileSymbol {
|
||||||
|
name: name.text(),
|
||||||
|
node_range: name.syntax().range(),
|
||||||
|
kind : NAME
|
||||||
|
}));
|
||||||
|
|
||||||
|
return vec;
|
||||||
|
} else {
|
||||||
|
// If that fails try the index based approach.
|
||||||
return self.index_resolve(name_ref, token);
|
return self.index_resolve(name_ref, token);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) {
|
if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) {
|
||||||
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
||||||
if module.has_semi() {
|
if module.has_semi() {
|
||||||
|
|
|
@ -164,6 +164,14 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>(
|
||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolve_local_name<'a>(file: &'a File, offset: TextUnit, name_ref: ast::NameRef) -> Option<ast::Name<'a>> {
|
||||||
|
let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), offset)?;
|
||||||
|
let scopes = scope::FnScopes::new(fn_def);
|
||||||
|
|
||||||
|
// TODO: This doesn't work because of scopes lifetime
|
||||||
|
scope::resolve_local_name(name_ref, &scopes)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -2,7 +2,7 @@ mod fn_scope;
|
||||||
mod mod_scope;
|
mod mod_scope;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
fn_scope::FnScopes,
|
fn_scope::{FnScopes, resolve_local_name},
|
||||||
mod_scope::ModuleScope,
|
mod_scope::ModuleScope,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue