diff options
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 29 | ||||
-rw-r--r-- | docs/dev/architecture.md | 8 |
2 files changed, 27 insertions, 10 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index ad00abe49..df877c324 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -95,6 +95,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
95 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { | 95 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { |
96 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); | 96 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); |
97 | 97 | ||
98 | let mut no_fallback = false; | ||
99 | |||
98 | match classify_name_ref(db, &analyzer, name_ref) { | 100 | match classify_name_ref(db, &analyzer, name_ref) { |
99 | Some(Method(it)) => res.extend(from_def_source(db, it)), | 101 | Some(Method(it)) => res.extend(from_def_source(db, it)), |
100 | Some(Macro(it)) => { | 102 | Some(Macro(it)) => { |
@@ -142,11 +144,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
142 | }) | 144 | }) |
143 | } | 145 | } |
144 | } | 146 | } |
145 | Some(Pat(_)) => { | 147 | Some(Pat(_)) | Some(SelfParam(_)) => { |
146 | res.extend(None); | 148 | // Hover for these shows type names |
147 | } | 149 | no_fallback = true; |
148 | Some(SelfParam(_)) => { | ||
149 | res.extend(None); | ||
150 | } | 150 | } |
151 | Some(GenericParam(_)) => { | 151 | Some(GenericParam(_)) => { |
152 | // FIXME: Hover for generic param | 152 | // FIXME: Hover for generic param |
@@ -154,7 +154,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
154 | None => {} | 154 | None => {} |
155 | } | 155 | } |
156 | 156 | ||
157 | if res.is_empty() { | 157 | if res.is_empty() && !no_fallback { |
158 | // Fallback index based approach: | 158 | // Fallback index based approach: |
159 | let symbols = crate::symbol_index::index_resolve(db, name_ref); | 159 | let symbols = crate::symbol_index::index_resolve(db, name_ref); |
160 | for sym in symbols { | 160 | for sym in symbols { |
@@ -675,4 +675,21 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
675 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); | 675 | assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); |
676 | assert_eq!(hover.info.is_exact(), true); | 676 | assert_eq!(hover.info.is_exact(), true); |
677 | } | 677 | } |
678 | |||
679 | #[test] | ||
680 | fn test_hover_shadowing_pat() { | ||
681 | let (analysis, position) = single_file_with_position( | ||
682 | " | ||
683 | fn x() {} | ||
684 | |||
685 | fn y() { | ||
686 | let x = 0i32; | ||
687 | x<|>; | ||
688 | } | ||
689 | ", | ||
690 | ); | ||
691 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
692 | assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); | ||
693 | assert_eq!(hover.info.is_exact(), true); | ||
694 | } | ||
678 | } | 695 | } |
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md index 1cf498094..cf714d659 100644 --- a/docs/dev/architecture.md +++ b/docs/dev/architecture.md | |||
@@ -50,15 +50,15 @@ processes. These are outlined below: | |||
50 | the grammar described in [grammar.ron]: | 50 | the grammar described in [grammar.ron]: |
51 | - [ast/generated.rs][ast generated] in `ra_syntax` based on | 51 | - [ast/generated.rs][ast generated] in `ra_syntax` based on |
52 | [ast/generated.tera.rs][ast source] | 52 | [ast/generated.tera.rs][ast source] |
53 | - [syntax_kinds/generated.rs][syntax_kinds generated] in `ra_syntax` based on | 53 | - [syntax_kind/generated.rs][syntax_kind generated] in `ra_syntax` based on |
54 | [syntax_kinds/generated.tera.rs][syntax_kinds source] | 54 | [syntax_kind/generated.tera.rs][syntax_kind source] |
55 | 55 | ||
56 | [tera]: https://tera.netlify.com/ | 56 | [tera]: https://tera.netlify.com/ |
57 | [grammar.ron]: ../../crates/ra_syntax/src/grammar.ron | 57 | [grammar.ron]: ../../crates/ra_syntax/src/grammar.ron |
58 | [ast generated]: ../../crates/ra_syntax/src/ast/generated.rs | 58 | [ast generated]: ../../crates/ra_syntax/src/ast/generated.rs |
59 | [ast source]: ../../crates/ra_syntax/src/ast/generated.rs.tera | 59 | [ast source]: ../../crates/ra_syntax/src/ast/generated.rs.tera |
60 | [syntax_kinds generated]: ../../crates/ra_syntax/src/syntax_kinds/generated.rs | 60 | [syntax_kind generated]: ../../crates/ra_parser/src/syntax_kind/generated.rs |
61 | [syntax_kinds source]: ../../crates/ra_syntax/src/syntax_kinds/generated.rs.tera | 61 | [syntax_kind source]: ../../crates/ra_parser/src/syntax_kind/generated.rs.tera |
62 | 62 | ||
63 | 63 | ||
64 | ## Code Walk-Through | 64 | ## Code Walk-Through |