diff options
Diffstat (limited to 'crates/ide_db/src/defs.rs')
-rw-r--r-- | crates/ide_db/src/defs.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index d33a6cb86..d68fe42b0 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -6,8 +6,8 @@ | |||
6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). | 6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). |
7 | 7 | ||
8 | use hir::{ | 8 | use hir::{ |
9 | db::HirDatabase, Crate, Field, HasVisibility, Impl, Label, LifetimeParam, Local, MacroDef, | 9 | db::HirDatabase, Crate, Field, GenericParam, HasVisibility, Impl, Label, Local, MacroDef, |
10 | Module, ModuleDef, Name, PathResolution, Semantics, TypeParam, Visibility, | 10 | Module, ModuleDef, Name, PathResolution, Semantics, Visibility, |
11 | }; | 11 | }; |
12 | use syntax::{ | 12 | use syntax::{ |
13 | ast::{self, AstNode}, | 13 | ast::{self, AstNode}, |
@@ -24,8 +24,7 @@ pub enum Definition { | |||
24 | ModuleDef(ModuleDef), | 24 | ModuleDef(ModuleDef), |
25 | SelfType(Impl), | 25 | SelfType(Impl), |
26 | Local(Local), | 26 | Local(Local), |
27 | TypeParam(TypeParam), | 27 | GenericParam(GenericParam), |
28 | LifetimeParam(LifetimeParam), | ||
29 | Label(Label), | 28 | Label(Label), |
30 | } | 29 | } |
31 | 30 | ||
@@ -37,8 +36,7 @@ impl Definition { | |||
37 | Definition::ModuleDef(it) => it.module(db), | 36 | Definition::ModuleDef(it) => it.module(db), |
38 | Definition::SelfType(it) => Some(it.module(db)), | 37 | Definition::SelfType(it) => Some(it.module(db)), |
39 | Definition::Local(it) => Some(it.module(db)), | 38 | Definition::Local(it) => Some(it.module(db)), |
40 | Definition::TypeParam(it) => Some(it.module(db)), | 39 | Definition::GenericParam(it) => Some(it.module(db)), |
41 | Definition::LifetimeParam(it) => Some(it.module(db)), | ||
42 | Definition::Label(it) => Some(it.module(db)), | 40 | Definition::Label(it) => Some(it.module(db)), |
43 | } | 41 | } |
44 | } | 42 | } |
@@ -50,8 +48,7 @@ impl Definition { | |||
50 | Definition::ModuleDef(def) => def.definition_visibility(db), | 48 | Definition::ModuleDef(def) => def.definition_visibility(db), |
51 | Definition::SelfType(_) => None, | 49 | Definition::SelfType(_) => None, |
52 | Definition::Local(_) => None, | 50 | Definition::Local(_) => None, |
53 | Definition::TypeParam(_) => None, | 51 | Definition::GenericParam(_) => None, |
54 | Definition::LifetimeParam(_) => None, | ||
55 | Definition::Label(_) => None, | 52 | Definition::Label(_) => None, |
56 | } | 53 | } |
57 | } | 54 | } |
@@ -77,8 +74,7 @@ impl Definition { | |||
77 | }, | 74 | }, |
78 | Definition::SelfType(_) => return None, | 75 | Definition::SelfType(_) => return None, |
79 | Definition::Local(it) => it.name(db)?, | 76 | Definition::Local(it) => it.name(db)?, |
80 | Definition::TypeParam(it) => it.name(db), | 77 | Definition::GenericParam(it) => it.name(db), |
81 | Definition::LifetimeParam(it) => it.name(db), | ||
82 | Definition::Label(it) => it.name(db), | 78 | Definition::Label(it) => it.name(db), |
83 | }; | 79 | }; |
84 | Some(name) | 80 | Some(name) |
@@ -231,7 +227,11 @@ impl NameClass { | |||
231 | }, | 227 | }, |
232 | ast::TypeParam(it) => { | 228 | ast::TypeParam(it) => { |
233 | let def = sema.to_def(&it)?; | 229 | let def = sema.to_def(&it)?; |
234 | Some(NameClass::Definition(Definition::TypeParam(def))) | 230 | Some(NameClass::Definition(Definition::GenericParam(def.into()))) |
231 | }, | ||
232 | ast::ConstParam(it) => { | ||
233 | let def = sema.to_def(&it)?; | ||
234 | Some(NameClass::Definition(Definition::GenericParam(def.into()))) | ||
235 | }, | 235 | }, |
236 | _ => None, | 236 | _ => None, |
237 | } | 237 | } |
@@ -249,7 +249,7 @@ impl NameClass { | |||
249 | match parent { | 249 | match parent { |
250 | ast::LifetimeParam(it) => { | 250 | ast::LifetimeParam(it) => { |
251 | let def = sema.to_def(&it)?; | 251 | let def = sema.to_def(&it)?; |
252 | Some(NameClass::Definition(Definition::LifetimeParam(def))) | 252 | Some(NameClass::Definition(Definition::GenericParam(def.into()))) |
253 | }, | 253 | }, |
254 | ast::Label(it) => { | 254 | ast::Label(it) => { |
255 | let def = sema.to_def(&it)?; | 255 | let def = sema.to_def(&it)?; |
@@ -350,7 +350,7 @@ impl NameRefClass { | |||
350 | if let Some(path) = macro_call.path() { | 350 | if let Some(path) = macro_call.path() { |
351 | if path.qualifier().is_none() { | 351 | if path.qualifier().is_none() { |
352 | // Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment | 352 | // Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment |
353 | // paths are handled below (allowing `log<|>::info!` to resolve to the log crate). | 353 | // paths are handled below (allowing `log$0::info!` to resolve to the log crate). |
354 | if let Some(macro_def) = sema.resolve_macro_call(¯o_call) { | 354 | if let Some(macro_def) = sema.resolve_macro_call(¯o_call) { |
355 | return Some(NameRefClass::Definition(Definition::Macro(macro_def))); | 355 | return Some(NameRefClass::Definition(Definition::Macro(macro_def))); |
356 | } | 356 | } |
@@ -385,7 +385,8 @@ impl NameRefClass { | |||
385 | | SyntaxKind::WHERE_PRED | 385 | | SyntaxKind::WHERE_PRED |
386 | | SyntaxKind::REF_TYPE => sema | 386 | | SyntaxKind::REF_TYPE => sema |
387 | .resolve_lifetime_param(lifetime) | 387 | .resolve_lifetime_param(lifetime) |
388 | .map(Definition::LifetimeParam) | 388 | .map(GenericParam::LifetimeParam) |
389 | .map(Definition::GenericParam) | ||
389 | .map(NameRefClass::Definition), | 390 | .map(NameRefClass::Definition), |
390 | // lifetime bounds, as in the 'b in 'a: 'b aren't wrapped in TypeBound nodes so we gotta check | 391 | // lifetime bounds, as in the 'b in 'a: 'b aren't wrapped in TypeBound nodes so we gotta check |
391 | // if our lifetime is in a LifetimeParam without being the constrained lifetime | 392 | // if our lifetime is in a LifetimeParam without being the constrained lifetime |
@@ -393,7 +394,8 @@ impl NameRefClass { | |||
393 | != Some(lifetime) => | 394 | != Some(lifetime) => |
394 | { | 395 | { |
395 | sema.resolve_lifetime_param(lifetime) | 396 | sema.resolve_lifetime_param(lifetime) |
396 | .map(Definition::LifetimeParam) | 397 | .map(GenericParam::LifetimeParam) |
398 | .map(Definition::GenericParam) | ||
397 | .map(NameRefClass::Definition) | 399 | .map(NameRefClass::Definition) |
398 | } | 400 | } |
399 | _ => None, | 401 | _ => None, |
@@ -414,9 +416,10 @@ impl From<PathResolution> for Definition { | |||
414 | Definition::ModuleDef(def) | 416 | Definition::ModuleDef(def) |
415 | } | 417 | } |
416 | PathResolution::Local(local) => Definition::Local(local), | 418 | PathResolution::Local(local) => Definition::Local(local), |
417 | PathResolution::TypeParam(par) => Definition::TypeParam(par), | 419 | PathResolution::TypeParam(par) => Definition::GenericParam(par.into()), |
418 | PathResolution::Macro(def) => Definition::Macro(def), | 420 | PathResolution::Macro(def) => Definition::Macro(def), |
419 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), | 421 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), |
422 | PathResolution::ConstParam(par) => Definition::GenericParam(par.into()), | ||
420 | } | 423 | } |
421 | } | 424 | } |
422 | } | 425 | } |