From cc3eb8531177940ad34ff505f0426151b985daf3 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Tue, 4 Aug 2020 09:23:23 -0400 Subject: Add test showing unresolved module rename --- crates/ra_ide/src/syntax_highlighting/tests.rs | 3 +++ crates/ra_ide/test_data/highlighting.html | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 87a6e2523..2deee404c 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -9,6 +9,9 @@ use crate::{mock_analysis::single_file, FileRange, TextRange}; fn test_highlighting() { check_highlighting( r#" +use inner::{self as inner_mod}; +mod inner {} + #[derive(Clone, Debug)] struct Foo { pub x: i32, diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html index 345a2f023..efd725bcc 100644 --- a/crates/ra_ide/test_data/highlighting.html +++ b/crates/ra_ide/test_data/highlighting.html @@ -35,7 +35,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
#[derive(Clone, Debug)]
+
use inner::{self as inner_mod};
+mod inner {}
+
+#[derive(Clone, Debug)]
 struct Foo {
     pub x: i32,
     pub y: i32,
-- 
cgit v1.2.3


From 4e2e3543c72b5963eb91b94b8180fecf268930e3 Mon Sep 17 00:00:00 2001
From: Paul Daniel Faria 
Date: Tue, 4 Aug 2020 09:28:40 -0400
Subject: When resolving a rename, fallback to the name higher in the use tree
 if the path segment is `self`

---
 crates/ra_ide/test_data/highlighting.html |  2 +-
 crates/ra_ide_db/src/defs.rs              | 25 ++++++++++++++++++++++---
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html
index efd725bcc..23c25ad8c 100644
--- a/crates/ra_ide/test_data/highlighting.html
+++ b/crates/ra_ide/test_data/highlighting.html
@@ -35,7 +35,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 
 .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
 
-
use inner::{self as inner_mod};
+
use inner::{self as inner_mod};
 mod inner {}
 
 #[derive(Clone, Debug)]
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index 66c048714..b51000b03 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -12,7 +12,7 @@ use hir::{
 use ra_prof::profile;
 use ra_syntax::{
     ast::{self, AstNode},
-    match_ast,
+    match_ast, SyntaxNode,
 };
 
 use crate::RootDatabase;
@@ -123,8 +123,27 @@ pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option
                 let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?;
                 let path = use_tree.path()?;
                 let path_segment = path.segment()?;
-                let name_ref = path_segment.name_ref()?;
-                let name_ref_class = classify_name_ref(sema, &name_ref)?;
+                let name_ref_class = path_segment
+                    .name_ref()
+                    // The rename might be from a `self` token, so fallback to the name higher
+                    // in the use tree.
+                    .or_else(||{
+                        if path_segment.self_token().is_none() {
+                            return None;
+                        }
+
+                        let use_tree = use_tree
+                            .syntax()
+                            .parent()
+                            .as_ref()
+                            // Skip over UseTreeList
+                            .and_then(SyntaxNode::parent)
+                            .and_then(ast::UseTree::cast)?;
+                        let path = use_tree.path()?;
+                        let path_segment = path.segment()?;
+                        path_segment.name_ref()
+                    })
+                    .and_then(|name_ref| classify_name_ref(sema, &name_ref))?;
 
                 Some(NameClass::Definition(name_ref_class.definition()))
             },
-- 
cgit v1.2.3