]> git.lizzy.rs Git - rust.git/commitdiff
Merge #2588
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Wed, 18 Dec 2019 15:47:58 +0000 (15:47 +0000)
committerGitHub <noreply@github.com>
Wed, 18 Dec 2019 15:47:58 +0000 (15:47 +0000)
2588: Don't bother with focus range for navigation to locals r=matklad a=matklad

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
crates/ra_ide/src/display/navigation_target.rs
crates/ra_ide/src/goto_definition.rs

index 6a6b49afdf141a6fd4f3adf9cf8959028f80272e..b9ae67828481943903eb794fc799f35b830b430d 100644 (file)
@@ -328,22 +328,23 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
 impl ToNav for hir::Local {
     fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
         let src = self.source(db);
-        let (full_range, focus_range) = match src.value {
-            Either::Left(it) => {
-                (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range()))
+        let node = match &src.value {
+            Either::Left(bind_pat) => {
+                bind_pat.name().map_or_else(|| bind_pat.syntax().clone(), |it| it.syntax().clone())
             }
-            Either::Right(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())),
+            Either::Right(it) => it.syntax().clone(),
         };
+        let full_range = original_range(db, src.with_value(&node));
         let name = match self.name(db) {
             Some(it) => it.to_string().into(),
             None => "".into(),
         };
         NavigationTarget {
-            file_id: src.file_id.original_file(db),
+            file_id: full_range.file_id,
             name,
             kind: BIND_PAT,
-            full_range,
-            focus_range,
+            full_range: full_range.range,
+            focus_range: None,
             container_name: None,
             description: None,
             docs: None,
index 48757f17069c759e0407db2b78c8ab91addbe5aa..184555792cea7ce49e8f07eabd9e82d35d4f636a 100644 (file)
@@ -817,4 +817,45 @@ struct Foo<T> {
             "T",
         );
     }
+
+    #[test]
+    fn goto_within_macro() {
+        check_goto(
+            "
+            //- /lib.rs
+            macro_rules! id {
+                ($($tt:tt)*) => ($($tt)*)
+            }
+
+            fn foo() {
+                let x = 1;
+                id!({
+                    let y = <|>x;
+                    let z = y;
+                });
+            }
+            ",
+            "x BIND_PAT FileId(1) [69; 70)",
+            "x",
+        );
+
+        check_goto(
+            "
+            //- /lib.rs
+            macro_rules! id {
+                ($($tt:tt)*) => ($($tt)*)
+            }
+
+            fn foo() {
+                let x = 1;
+                id!({
+                    let y = x;
+                    let z = <|>y;
+                });
+            }
+            ",
+            "y BIND_PAT FileId(1) [98; 99)",
+            "y",
+        );
+    }
 }