aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/defs.rs23
-rw-r--r--crates/ide_db/src/imports_locator.rs2
-rw-r--r--crates/ide_db/src/search.rs2
3 files changed, 18 insertions, 9 deletions
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs
index 3cef0baf7..201a3d6fa 100644
--- a/crates/ide_db/src/defs.rs
+++ b/crates/ide_db/src/defs.rs
@@ -91,7 +91,8 @@ pub enum NameClass {
91} 91}
92 92
93impl NameClass { 93impl NameClass {
94 pub fn definition(self, db: &dyn HirDatabase) -> Option<Definition> { 94 /// `Definition` defined by this name.
95 pub fn defined(self, db: &dyn HirDatabase) -> Option<Definition> {
95 let res = match self { 96 let res = match self {
96 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), 97 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
97 NameClass::Definition(it) => it, 98 NameClass::Definition(it) => it,
@@ -103,7 +104,8 @@ impl NameClass {
103 Some(res) 104 Some(res)
104 } 105 }
105 106
106 pub fn reference_or_definition(self, db: &dyn HirDatabase) -> Definition { 107 /// `Definition` referenced or defined by this name.
108 pub fn referenced_or_defined(self, db: &dyn HirDatabase) -> Definition {
107 match self { 109 match self {
108 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), 110 NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
109 NameClass::Definition(it) | NameClass::ConstReference(it) => it, 111 NameClass::Definition(it) | NameClass::ConstReference(it) => it,
@@ -150,7 +152,7 @@ impl NameClass {
150 }) 152 })
151 .and_then(|name_ref| NameRefClass::classify(sema, &name_ref))?; 153 .and_then(|name_ref| NameRefClass::classify(sema, &name_ref))?;
152 154
153 Some(NameClass::Definition(name_ref_class.definition(sema.db))) 155 Some(NameClass::Definition(name_ref_class.referenced(sema.db)))
154 } else { 156 } else {
155 let extern_crate = it.syntax().parent().and_then(ast::ExternCrate::cast)?; 157 let extern_crate = it.syntax().parent().and_then(ast::ExternCrate::cast)?;
156 let resolved = sema.resolve_extern_crate(&extern_crate)?; 158 let resolved = sema.resolve_extern_crate(&extern_crate)?;
@@ -233,15 +235,20 @@ impl NameClass {
233pub enum NameRefClass { 235pub enum NameRefClass {
234 ExternCrate(Crate), 236 ExternCrate(Crate),
235 Definition(Definition), 237 Definition(Definition),
236 FieldShorthand { local: Local, field: Definition }, 238 FieldShorthand { local_ref: Local, field_ref: Definition },
237} 239}
238 240
239impl NameRefClass { 241impl NameRefClass {
240 pub fn definition(self, db: &dyn HirDatabase) -> Definition { 242 /// `Definition`, which this name refers to.
243 pub fn referenced(self, db: &dyn HirDatabase) -> Definition {
241 match self { 244 match self {
242 NameRefClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), 245 NameRefClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
243 NameRefClass::Definition(def) => def, 246 NameRefClass::Definition(def) => def,
244 NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local), 247 NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
248 // FIXME: this is inherently ambiguous -- this name refers to
249 // two different defs....
250 Definition::Local(local_ref)
251 }
245 } 252 }
246 } 253 }
247 254
@@ -272,7 +279,9 @@ impl NameRefClass {
272 let field = Definition::Field(field); 279 let field = Definition::Field(field);
273 let res = match local { 280 let res = match local {
274 None => NameRefClass::Definition(field), 281 None => NameRefClass::Definition(field),
275 Some(local) => NameRefClass::FieldShorthand { field, local }, 282 Some(local) => {
283 NameRefClass::FieldShorthand { field_ref: field, local_ref: local }
284 }
276 }; 285 };
277 return Some(res); 286 return Some(res);
278 } 287 }
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs
index 8c925fbdc..df74be00b 100644
--- a/crates/ide_db/src/imports_locator.rs
+++ b/crates/ide_db/src/imports_locator.rs
@@ -60,5 +60,5 @@ fn get_name_definition<'a>(
60 candidate_node 60 candidate_node
61 }; 61 };
62 let name = ast::Name::cast(candidate_name_node)?; 62 let name = ast::Name::cast(candidate_name_node)?;
63 NameClass::classify(sema, &name)?.definition(sema.db) 63 NameClass::classify(sema, &name)?.defined(sema.db)
64} 64}
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 3af52ec5e..a24335240 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -292,7 +292,7 @@ impl<'a> FindUsages<'a> {
292 }; 292 };
293 sink(reference) 293 sink(reference)
294 } 294 }
295 Some(NameRefClass::FieldShorthand { local, field }) => { 295 Some(NameRefClass::FieldShorthand { local_ref: local, field_ref: field }) => {
296 let reference = match self.def { 296 let reference = match self.def {
297 Definition::Field(_) if &field == self.def => Reference { 297 Definition::Field(_) if &field == self.def => Reference {
298 file_range: self.sema.original_range(name_ref.syntax()), 298 file_range: self.sema.original_range(name_ref.syntax()),