aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-02-23 11:05:45 +0000
committerVille Penttinen <[email protected]>2019-02-23 11:05:45 +0000
commitc565ec2d6e736c90b8c5a6b89795022d1cc1c1a3 (patch)
tree929e56ebef10379842a9cf223d237c94ddc70ea6 /crates
parent7046b162756b0fa1b6e6e2223ffbfdf6f41ca6bc (diff)
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.
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs2
-rw-r--r--crates/ra_ide_api/src/symbol_index.rs22
2 files changed, 17 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 2c9ec970a..ce5ae0363 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -67,7 +67,7 @@ impl NavigationTarget {
67 name: symbol.name.clone(), 67 name: symbol.name.clone(),
68 kind: symbol.ptr.kind(), 68 kind: symbol.ptr.kind(),
69 full_range: symbol.ptr.range(), 69 full_range: symbol.ptr.range(),
70 focus_range: None, 70 focus_range: symbol.name_range,
71 container_name: symbol.container_name.clone(), 71 container_name: symbol.container_name.clone(),
72 } 72 }
73 } 73 }
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs
index afb10fa92..93bdf05d8 100644
--- a/crates/ra_ide_api/src/symbol_index.rs
+++ b/crates/ra_ide_api/src/symbol_index.rs
@@ -33,6 +33,7 @@ use ra_syntax::{
33 SyntaxKind::{self, *}, 33 SyntaxKind::{self, *},
34 ast::{self, NameOwner}, 34 ast::{self, NameOwner},
35 WalkEvent, 35 WalkEvent,
36 TextRange,
36}; 37};
37use ra_db::{ 38use ra_db::{
38 SourceRootId, SourceDatabase, 39 SourceRootId, SourceDatabase,
@@ -70,7 +71,7 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex>
70 let node = find_covering_node(source_file.syntax(), text_range); 71 let node = find_covering_node(source_file.syntax(), text_range);
71 let ptr = SyntaxNodePtr::new(node); 72 let ptr = SyntaxNodePtr::new(node);
72 // TODO: Should we get container name for macro symbols? 73 // TODO: Should we get container name for macro symbols?
73 symbols.push(FileSymbol { file_id, name, ptr, container_name: None }) 74 symbols.push(FileSymbol { file_id, name, ptr, name_range: None, container_name: None })
74 } 75 }
75 76
76 Arc::new(SymbolIndex::new(symbols)) 77 Arc::new(SymbolIndex::new(symbols))
@@ -207,6 +208,7 @@ pub(crate) struct FileSymbol {
207 pub(crate) file_id: FileId, 208 pub(crate) file_id: FileId,
208 pub(crate) name: SmolStr, 209 pub(crate) name: SmolStr,
209 pub(crate) ptr: SyntaxNodePtr, 210 pub(crate) ptr: SyntaxNodePtr,
211 pub(crate) name_range: Option<TextRange>,
210 pub(crate) container_name: Option<SmolStr>, 212 pub(crate) container_name: Option<SmolStr>,
211} 213}
212 214
@@ -236,12 +238,14 @@ fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec
236 symbols 238 symbols
237} 239}
238 240
239fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr)> { 241fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
240 fn decl<N: NameOwner>(node: &N) -> Option<(SmolStr, SyntaxNodePtr)> { 242 fn decl<N: NameOwner>(node: &N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
241 let name = node.name()?.text().clone(); 243 let name = node.name()?;
244 let name_range = name.syntax().range();
245 let name = name.text().clone();
242 let ptr = SyntaxNodePtr::new(node.syntax()); 246 let ptr = SyntaxNodePtr::new(node.syntax());
243 247
244 Some((name, ptr)) 248 Some((name, ptr, name_range))
245 } 249 }
246 visitor() 250 visitor()
247 .visit(decl::<ast::FnDef>) 251 .visit(decl::<ast::FnDef>)
@@ -256,5 +260,11 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr)> {
256} 260}
257 261
258fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> { 262fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
259 to_symbol(node).map(move |(name, ptr)| FileSymbol { name, ptr, file_id, container_name: None }) 263 to_symbol(node).map(move |(name, ptr, name_range)| FileSymbol {
264 name,
265 ptr,
266 file_id,
267 name_range: Some(name_range),
268 container_name: None,
269 })
260} 270}