diff options
author | Aleksey Kladov <[email protected]> | 2019-11-26 18:18:26 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-26 18:32:39 +0000 |
commit | 882fe0a47ee6f60928395326d1f194eec521ce2e (patch) | |
tree | ce9e253bb9555e5cb68ba6004b710018c7ef5571 /crates/ra_ide_api/src | |
parent | 141fca60061d85494fcb719a4c8237eaf6c7c134 (diff) |
More precise NameKind::Self
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 23 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 95 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/classify.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/name_definition.rs | 6 |
5 files changed, 62 insertions, 70 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index b6c72efdf..c10a6c844 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -71,10 +71,11 @@ pub(crate) fn reference_definition( | |||
71 | Some(nav) => return Exact(nav), | 71 | Some(nav) => return Exact(nav), |
72 | None => return Approximate(vec![]), | 72 | None => return Approximate(vec![]), |
73 | }, | 73 | }, |
74 | Some(SelfType(ty)) => { | 74 | Some(SelfType(imp)) => { |
75 | if let Some((adt, _)) = ty.as_adt() { | 75 | // FIXME: ideally, this should point to the type in the impl, and |
76 | return Exact(adt.to_nav(db)); | 76 | // not at the whole impl. And goto **type** definition should bring |
77 | } | 77 | // us to the actual type |
78 | return Exact(imp.to_nav(db)); | ||
78 | } | 79 | } |
79 | Some(Local(local)) => return Exact(local.to_nav(db)), | 80 | Some(Local(local)) => return Exact(local.to_nav(db)), |
80 | Some(GenericParam(_)) => { | 81 | Some(GenericParam(_)) => { |
@@ -503,7 +504,7 @@ mod tests { | |||
503 | } | 504 | } |
504 | } | 505 | } |
505 | ", | 506 | ", |
506 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | 507 | "impl IMPL_BLOCK FileId(1) [12; 73)", |
507 | ); | 508 | ); |
508 | 509 | ||
509 | check_goto( | 510 | check_goto( |
@@ -516,7 +517,7 @@ mod tests { | |||
516 | } | 517 | } |
517 | } | 518 | } |
518 | ", | 519 | ", |
519 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | 520 | "impl IMPL_BLOCK FileId(1) [12; 73)", |
520 | ); | 521 | ); |
521 | 522 | ||
522 | check_goto( | 523 | check_goto( |
@@ -529,7 +530,7 @@ mod tests { | |||
529 | } | 530 | } |
530 | } | 531 | } |
531 | ", | 532 | ", |
532 | "Foo ENUM_DEF FileId(1) [0; 14) [5; 8)", | 533 | "impl IMPL_BLOCK FileId(1) [15; 75)", |
533 | ); | 534 | ); |
534 | 535 | ||
535 | check_goto( | 536 | check_goto( |
@@ -541,7 +542,7 @@ mod tests { | |||
541 | } | 542 | } |
542 | } | 543 | } |
543 | ", | 544 | ", |
544 | "Foo ENUM_DEF FileId(1) [0; 14) [5; 8)", | 545 | "impl IMPL_BLOCK FileId(1) [15; 62)", |
545 | ); | 546 | ); |
546 | } | 547 | } |
547 | 548 | ||
@@ -560,7 +561,7 @@ mod tests { | |||
560 | } | 561 | } |
561 | } | 562 | } |
562 | ", | 563 | ", |
563 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | 564 | "impl IMPL_BLOCK FileId(1) [49; 115)", |
564 | ); | 565 | ); |
565 | 566 | ||
566 | check_goto( | 567 | check_goto( |
@@ -572,11 +573,11 @@ mod tests { | |||
572 | } | 573 | } |
573 | impl Make for Foo { | 574 | impl Make for Foo { |
574 | fn new() -> Self<|> { | 575 | fn new() -> Self<|> { |
575 | Self{} | 576 | Self {} |
576 | } | 577 | } |
577 | } | 578 | } |
578 | ", | 579 | ", |
579 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", | 580 | "impl IMPL_BLOCK FileId(1) [49; 115)", |
580 | ); | 581 | ); |
581 | } | 582 | } |
582 | 583 | ||
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 9839be985..260a7b869 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -133,20 +133,12 @@ fn hover_text_from_name_kind( | |||
133 | hir::ModuleDef::TypeAlias(it) => from_def_source(db, it), | 133 | hir::ModuleDef::TypeAlias(it) => from_def_source(db, it), |
134 | hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), | 134 | hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), |
135 | }, | 135 | }, |
136 | SelfType(ty) => match ty.as_adt() { | ||
137 | Some((adt_def, _)) => match adt_def { | ||
138 | hir::Adt::Struct(it) => from_def_source(db, it), | ||
139 | hir::Adt::Union(it) => from_def_source(db, it), | ||
140 | hir::Adt::Enum(it) => from_def_source(db, it), | ||
141 | }, | ||
142 | _ => None, | ||
143 | }, | ||
144 | Local(_) => { | 136 | Local(_) => { |
145 | // Hover for these shows type names | 137 | // Hover for these shows type names |
146 | *no_fallback = true; | 138 | *no_fallback = true; |
147 | None | 139 | None |
148 | } | 140 | } |
149 | GenericParam(_) => { | 141 | GenericParam(_) | SelfType(_) => { |
150 | // FIXME: Hover for generic param | 142 | // FIXME: Hover for generic param |
151 | None | 143 | None |
152 | } | 144 | } |
@@ -622,49 +614,52 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
622 | ", | 614 | ", |
623 | ); | 615 | ); |
624 | let hover = analysis.hover(position).unwrap().unwrap(); | 616 | let hover = analysis.hover(position).unwrap().unwrap(); |
625 | assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing")); | 617 | assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); |
626 | assert_eq!(hover.info.is_exact(), true); | ||
627 | |||
628 | let (analysis, position) = single_file_with_position( | ||
629 | " | ||
630 | struct Thing { x: u32 } | ||
631 | impl Thing { | ||
632 | fn new() -> Self<|> { | ||
633 | Self { x: 0 } | ||
634 | } | ||
635 | } | ||
636 | ", | ||
637 | ); | ||
638 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
639 | assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing")); | ||
640 | assert_eq!(hover.info.is_exact(), true); | ||
641 | |||
642 | let (analysis, position) = single_file_with_position( | ||
643 | " | ||
644 | enum Thing { A } | ||
645 | impl Thing { | ||
646 | pub fn new() -> Self<|> { | ||
647 | Thing::A | ||
648 | } | ||
649 | } | ||
650 | ", | ||
651 | ); | ||
652 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
653 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); | ||
654 | assert_eq!(hover.info.is_exact(), true); | 618 | assert_eq!(hover.info.is_exact(), true); |
655 | 619 | ||
656 | let (analysis, position) = single_file_with_position( | 620 | /* FIXME: revive these tests |
657 | " | 621 | let (analysis, position) = single_file_with_position( |
658 | enum Thing { A } | 622 | " |
659 | impl Thing { | 623 | struct Thing { x: u32 } |
660 | pub fn thing(a: Self<|>) { | 624 | impl Thing { |
661 | } | 625 | fn new() -> Self<|> { |
662 | } | 626 | Self { x: 0 } |
663 | ", | 627 | } |
664 | ); | 628 | } |
665 | let hover = analysis.hover(position).unwrap().unwrap(); | 629 | ", |
666 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); | 630 | ); |
667 | assert_eq!(hover.info.is_exact(), true); | 631 | |
632 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
633 | assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); | ||
634 | assert_eq!(hover.info.is_exact(), true); | ||
635 | |||
636 | let (analysis, position) = single_file_with_position( | ||
637 | " | ||
638 | enum Thing { A } | ||
639 | impl Thing { | ||
640 | pub fn new() -> Self<|> { | ||
641 | Thing::A | ||
642 | } | ||
643 | } | ||
644 | ", | ||
645 | ); | ||
646 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
647 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); | ||
648 | assert_eq!(hover.info.is_exact(), true); | ||
649 | |||
650 | let (analysis, position) = single_file_with_position( | ||
651 | " | ||
652 | enum Thing { A } | ||
653 | impl Thing { | ||
654 | pub fn thing(a: Self<|>) { | ||
655 | } | ||
656 | } | ||
657 | ", | ||
658 | ); | ||
659 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
660 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); | ||
661 | assert_eq!(hover.info.is_exact(), true); | ||
662 | */ | ||
668 | } | 663 | } |
669 | 664 | ||
670 | #[test] | 665 | #[test] |
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index cb343e59a..21a1ea69e 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs | |||
@@ -83,10 +83,7 @@ pub(crate) fn find_all_refs( | |||
83 | NameKind::Field(field) => field.to_nav(db), | 83 | NameKind::Field(field) => field.to_nav(db), |
84 | NameKind::AssocItem(assoc) => assoc.to_nav(db), | 84 | NameKind::AssocItem(assoc) => assoc.to_nav(db), |
85 | NameKind::Def(def) => NavigationTarget::from_def(db, def)?, | 85 | NameKind::Def(def) => NavigationTarget::from_def(db, def)?, |
86 | NameKind::SelfType(ref ty) => match ty.as_adt() { | 86 | NameKind::SelfType(imp) => imp.to_nav(db), |
87 | Some((adt, _)) => adt.to_nav(db), | ||
88 | None => return None, | ||
89 | }, | ||
90 | NameKind::Local(local) => local.to_nav(db), | 87 | NameKind::Local(local) => local.to_nav(db), |
91 | NameKind::GenericParam(_) => return None, | 88 | NameKind::GenericParam(_) => return None, |
92 | }; | 89 | }; |
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index 227737ad2..5cea805ec 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs | |||
@@ -178,8 +178,7 @@ pub(crate) fn classify_name_ref( | |||
178 | Some(NameDefinition { kind, container, visibility }) | 178 | Some(NameDefinition { kind, container, visibility }) |
179 | } | 179 | } |
180 | PathResolution::SelfType(impl_block) => { | 180 | PathResolution::SelfType(impl_block) => { |
181 | let ty = impl_block.target_ty(db); | 181 | let kind = NameKind::SelfType(impl_block); |
182 | let kind = NameKind::SelfType(ty); | ||
183 | let container = impl_block.module(db); | 182 | let container = impl_block.module(db); |
184 | Some(NameDefinition { kind, container, visibility }) | 183 | Some(NameDefinition { kind, container, visibility }) |
185 | } | 184 | } |
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index cf12db066..10d3a2364 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs | |||
@@ -4,8 +4,8 @@ | |||
4 | //! Note that the reference search is possible for not all of the classified items. | 4 | //! Note that the reference search is possible for not all of the classified items. |
5 | 5 | ||
6 | use hir::{ | 6 | use hir::{ |
7 | Adt, AssocItem, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, | 7 | Adt, AssocItem, GenericParam, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, |
8 | VariantDef, | 8 | StructField, VariantDef, |
9 | }; | 9 | }; |
10 | use ra_syntax::{ast, ast::VisibilityOwner}; | 10 | use ra_syntax::{ast, ast::VisibilityOwner}; |
11 | 11 | ||
@@ -17,7 +17,7 @@ pub enum NameKind { | |||
17 | Field(StructField), | 17 | Field(StructField), |
18 | AssocItem(AssocItem), | 18 | AssocItem(AssocItem), |
19 | Def(ModuleDef), | 19 | Def(ModuleDef), |
20 | SelfType(Ty), | 20 | SelfType(ImplBlock), |
21 | Local(Local), | 21 | Local(Local), |
22 | GenericParam(GenericParam), | 22 | GenericParam(GenericParam), |
23 | } | 23 | } |