aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/navigation_target.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-23 12:17:53 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-23 12:17:53 +0000
commite5fb33a94618d45051192d99e859bdd44c3daa36 (patch)
treeb77da2812c973e2270d7abf808634cb9655e2c68 /crates/ra_ide_api/src/navigation_target.rs
parent38add103c3f30493e336a37827a76f48a6e7c584 (diff)
parent40e6cb196b3e4fdb580812a418edfb8df08cf423 (diff)
Merge #879
879: Fixes to goto definition r=vipentti a=vipentti Previously goto definition would fail when the cursor was over the name of the definition. Now we should properly resolve to a `NavigationTarget` when on top of the name of a definition. In addition this adds `name_range` field to `FileSymbol`, this further fixes goto_definition and symbol based navigation by allowing the `NavigationTarget` to actually have a `focus_range`, meaning instead of focusing on the start of the `full_range`, we can have the cursor focus on the name. e.g. goto definition ```rust fn bar() { fn foo() { } foo<|>(); } ``` Previously this would put the cursor at the start of the FN_DEF: ```rust fn bar() { <|>fn foo() { } foo(); } ``` Now when using the symbol based resolving, we'll have a proper focus range and instead put the cursor at the start of the name. ```rust fn bar() { fn <|>foo() { } foo(); } ``` This fixes #877 but doesn't contain the refactoring of the return type for `goto_definition` Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/navigation_target.rs')
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index fd001179a..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 }
@@ -193,12 +193,13 @@ impl NavigationTarget {
193 buf.push_str(&format!(" {:?}", focus_range)) 193 buf.push_str(&format!(" {:?}", focus_range))
194 } 194 }
195 if let Some(container_name) = self.container_name() { 195 if let Some(container_name) = self.container_name() {
196 buf.push_str(&format!(" {:?}", container_name)) 196 buf.push_str(&format!(" {}", container_name))
197 } 197 }
198 buf 198 buf
199 } 199 }
200 200
201 fn from_named(file_id: FileId, node: &impl ast::NameOwner) -> NavigationTarget { 201 /// Allows `NavigationTarget` to be created from a `NameOwner`
202 pub(crate) fn from_named(file_id: FileId, node: &impl ast::NameOwner) -> NavigationTarget {
202 let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); 203 let name = node.name().map(|it| it.text().clone()).unwrap_or_default();
203 let focus_range = node.name().map(|it| it.syntax().range()); 204 let focus_range = node.name().map(|it| it.syntax().range());
204 NavigationTarget::from_syntax(file_id, name, focus_range, node.syntax()) 205 NavigationTarget::from_syntax(file_id, name, focus_range, node.syntax())