mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Add name_range field to FileSymbol
This contains the syntax range of the name itself, allowing NavigationTarget to properly set the focus_range. This should make it so that when using symbol based navigation, we should always focus on the name, instead of the full range.
This commit is contained in:
parent
7046b16275
commit
c565ec2d6e
2 changed files with 17 additions and 7 deletions
|
@ -67,7 +67,7 @@ impl NavigationTarget {
|
||||||
name: symbol.name.clone(),
|
name: symbol.name.clone(),
|
||||||
kind: symbol.ptr.kind(),
|
kind: symbol.ptr.kind(),
|
||||||
full_range: symbol.ptr.range(),
|
full_range: symbol.ptr.range(),
|
||||||
focus_range: None,
|
focus_range: symbol.name_range,
|
||||||
container_name: symbol.container_name.clone(),
|
container_name: symbol.container_name.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ use ra_syntax::{
|
||||||
SyntaxKind::{self, *},
|
SyntaxKind::{self, *},
|
||||||
ast::{self, NameOwner},
|
ast::{self, NameOwner},
|
||||||
WalkEvent,
|
WalkEvent,
|
||||||
|
TextRange,
|
||||||
};
|
};
|
||||||
use ra_db::{
|
use ra_db::{
|
||||||
SourceRootId, SourceDatabase,
|
SourceRootId, SourceDatabase,
|
||||||
|
@ -70,7 +71,7 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex>
|
||||||
let node = find_covering_node(source_file.syntax(), text_range);
|
let node = find_covering_node(source_file.syntax(), text_range);
|
||||||
let ptr = SyntaxNodePtr::new(node);
|
let ptr = SyntaxNodePtr::new(node);
|
||||||
// TODO: Should we get container name for macro symbols?
|
// TODO: Should we get container name for macro symbols?
|
||||||
symbols.push(FileSymbol { file_id, name, ptr, container_name: None })
|
symbols.push(FileSymbol { file_id, name, ptr, name_range: None, container_name: None })
|
||||||
}
|
}
|
||||||
|
|
||||||
Arc::new(SymbolIndex::new(symbols))
|
Arc::new(SymbolIndex::new(symbols))
|
||||||
|
@ -207,6 +208,7 @@ pub(crate) struct FileSymbol {
|
||||||
pub(crate) file_id: FileId,
|
pub(crate) file_id: FileId,
|
||||||
pub(crate) name: SmolStr,
|
pub(crate) name: SmolStr,
|
||||||
pub(crate) ptr: SyntaxNodePtr,
|
pub(crate) ptr: SyntaxNodePtr,
|
||||||
|
pub(crate) name_range: Option<TextRange>,
|
||||||
pub(crate) container_name: Option<SmolStr>,
|
pub(crate) container_name: Option<SmolStr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,12 +238,14 @@ fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec
|
||||||
symbols
|
symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr)> {
|
fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
|
||||||
fn decl<N: NameOwner>(node: &N) -> Option<(SmolStr, SyntaxNodePtr)> {
|
fn decl<N: NameOwner>(node: &N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
|
||||||
let name = node.name()?.text().clone();
|
let name = node.name()?;
|
||||||
|
let name_range = name.syntax().range();
|
||||||
|
let name = name.text().clone();
|
||||||
let ptr = SyntaxNodePtr::new(node.syntax());
|
let ptr = SyntaxNodePtr::new(node.syntax());
|
||||||
|
|
||||||
Some((name, ptr))
|
Some((name, ptr, name_range))
|
||||||
}
|
}
|
||||||
visitor()
|
visitor()
|
||||||
.visit(decl::<ast::FnDef>)
|
.visit(decl::<ast::FnDef>)
|
||||||
|
@ -256,5 +260,11 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
|
fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
|
||||||
to_symbol(node).map(move |(name, ptr)| FileSymbol { name, ptr, file_id, container_name: None })
|
to_symbol(node).map(move |(name, ptr, name_range)| FileSymbol {
|
||||||
|
name,
|
||||||
|
ptr,
|
||||||
|
file_id,
|
||||||
|
name_range: Some(name_range),
|
||||||
|
container_name: None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue