Skip to content

Commit 32246b9

Browse files
Merge #5664
5664: Fix renamed self module. r=jonas-schievink a=Nashenas88 Fixes #5663 Now `inner_mod` below is properly marked as a `module`. ```rust use crate::inner::{self as inner_mod}; mod inner {} ``` Co-authored-by: Paul Daniel Faria <[email protected]>
2 parents dab810b + 4e2e354 commit 32246b9

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

crates/ra_ide/src/syntax_highlighting/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use crate::{mock_analysis::single_file, FileRange, TextRange};
99
fn test_highlighting() {
1010
check_highlighting(
1111
r#"
12+
use inner::{self as inner_mod};
13+
mod inner {}
14+
1215
#[derive(Clone, Debug)]
1316
struct Foo {
1417
pub x: i32,

crates/ra_ide/test_data/highlighting.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535

3636
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
3737
</style>
38-
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">derive</span><span class="punctuation">(</span><span class="attribute">Clone</span><span class="punctuation">,</span><span class="attribute"> Debug</span><span class="punctuation">)</span><span class="attribute">]</span>
38+
<pre><code><span class="keyword">use</span> <span class="module">inner</span><span class="operator">::</span><span class="punctuation">{</span><span class="self_keyword">self</span> <span class="keyword">as</span> <span class="module declaration">inner_mod</span><span class="punctuation">}</span><span class="punctuation">;</span>
39+
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="punctuation">{</span><span class="punctuation">}</span>
40+
41+
<span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">derive</span><span class="punctuation">(</span><span class="attribute">Clone</span><span class="punctuation">,</span><span class="attribute"> Debug</span><span class="punctuation">)</span><span class="attribute">]</span>
3942
<span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span>
4043
<span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span>
4144
<span class="keyword">pub</span> <span class="field declaration">y</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span>

crates/ra_ide_db/src/defs.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hir::{
1212
use ra_prof::profile;
1313
use ra_syntax::{
1414
ast::{self, AstNode},
15-
match_ast,
15+
match_ast, SyntaxNode,
1616
};
1717

1818
use crate::RootDatabase;
@@ -123,8 +123,27 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
123123
let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?;
124124
let path = use_tree.path()?;
125125
let path_segment = path.segment()?;
126-
let name_ref = path_segment.name_ref()?;
127-
let name_ref_class = classify_name_ref(sema, &name_ref)?;
126+
let name_ref_class = path_segment
127+
.name_ref()
128+
// The rename might be from a `self` token, so fallback to the name higher
129+
// in the use tree.
130+
.or_else(||{
131+
if path_segment.self_token().is_none() {
132+
return None;
133+
}
134+
135+
let use_tree = use_tree
136+
.syntax()
137+
.parent()
138+
.as_ref()
139+
// Skip over UseTreeList
140+
.and_then(SyntaxNode::parent)
141+
.and_then(ast::UseTree::cast)?;
142+
let path = use_tree.path()?;
143+
let path_segment = path.segment()?;
144+
path_segment.name_ref()
145+
})
146+
.and_then(|name_ref| classify_name_ref(sema, &name_ref))?;
128147

129148
Some(NameClass::Definition(name_ref_class.definition()))
130149
},

0 commit comments

Comments
 (0)