aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/defs.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-01-15 17:57:32 +0000
committerLukas Wirth <[email protected]>2021-01-15 18:21:23 +0000
commitcb863390f23bc2eac6561d55def9bd3ba54605fc (patch)
treeb19b39d9b6231e8857a4096cc803cf35e2ddbe81 /crates/ide_db/src/defs.rs
parent0c58aa9dc0e24f0fa6a6ee7eb0c35041dedddb0a (diff)
Handle self/super/crate in PathSegment as NameRef
Diffstat (limited to 'crates/ide_db/src/defs.rs')
-rw-r--r--crates/ide_db/src/defs.rs45
1 files changed, 27 insertions, 18 deletions
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs
index d68fe42b0..231e886a9 100644
--- a/crates/ide_db/src/defs.rs
+++ b/crates/ide_db/src/defs.rs
@@ -10,7 +10,7 @@ use hir::{
10 Module, ModuleDef, Name, PathResolution, Semantics, Visibility, 10 Module, ModuleDef, Name, PathResolution, Semantics, Visibility,
11}; 11};
12use syntax::{ 12use syntax::{
13 ast::{self, AstNode}, 13 ast::{self, AstNode, PathSegmentKind},
14 match_ast, SyntaxKind, SyntaxNode, 14 match_ast, SyntaxKind, SyntaxNode,
15}; 15};
16 16
@@ -117,6 +117,13 @@ impl NameClass {
117 } 117 }
118 } 118 }
119 119
120 pub fn classify_self_param(
121 sema: &Semantics<RootDatabase>,
122 self_param: &ast::SelfParam,
123 ) -> Option<NameClass> {
124 sema.to_def(self_param).map(Definition::Local).map(NameClass::Definition)
125 }
126
120 pub fn classify(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<NameClass> { 127 pub fn classify(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<NameClass> {
121 let _p = profile::span("classify_name"); 128 let _p = profile::span("classify_name");
122 129
@@ -135,24 +142,26 @@ impl NameClass {
135 let path = use_tree.path()?; 142 let path = use_tree.path()?;
136 let path_segment = path.segment()?; 143 let path_segment = path.segment()?;
137 let name_ref_class = path_segment 144 let name_ref_class = path_segment
138 .name_ref() 145 .kind()
139 // The rename might be from a `self` token, so fallback to the name higher 146 .and_then(|kind| {
140 // in the use tree. 147 match kind {
141 .or_else(||{ 148 // The rename might be from a `self` token, so fallback to the name higher
142 if path_segment.self_token().is_none() { 149 // in the use tree.
143 return None; 150 PathSegmentKind::SelfKw => {
151 let use_tree = use_tree
152 .syntax()
153 .parent()
154 .as_ref()
155 // Skip over UseTreeList
156 .and_then(SyntaxNode::parent)
157 .and_then(ast::UseTree::cast)?;
158 let path = use_tree.path()?;
159 let path_segment = path.segment()?;
160 path_segment.name_ref()
161 },
162 PathSegmentKind::Name(name_ref) => Some(name_ref),
163 _ => return None,
144 } 164 }
145
146 let use_tree = use_tree
147 .syntax()
148 .parent()
149 .as_ref()
150 // Skip over UseTreeList
151 .and_then(SyntaxNode::parent)
152 .and_then(ast::UseTree::cast)?;
153 let path = use_tree.path()?;
154 let path_segment = path.segment()?;
155 path_segment.name_ref()
156 }) 165 })
157 .and_then(|name_ref| NameRefClass::classify(sema, &name_ref))?; 166 .and_then(|name_ref| NameRefClass::classify(sema, &name_ref))?;
158 167