diff options
author | Aleksey Kladov <[email protected]> | 2020-02-28 14:27:52 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-28 14:27:52 +0000 |
commit | 209eb32796c6fd56d1b378690c807cf73ce54235 (patch) | |
tree | a7bc47a44969c8c236289bb3750c819a510dc5c4 /crates/ra_ide/src | |
parent | 9ef6359950fa2f3ecb9a7d4120f01e4baeaad978 (diff) |
Classify name takes const patterns into account
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 13 | ||||
-rw-r--r-- | crates/ra_ide/src/hover.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 16 |
4 files changed, 16 insertions, 21 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 6053c1bb6..621ab982c 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -30,7 +30,9 @@ pub(crate) fn goto_definition( | |||
30 | reference_definition(&sema, &name_ref).to_vec() | 30 | reference_definition(&sema, &name_ref).to_vec() |
31 | }, | 31 | }, |
32 | ast::Name(name) => { | 32 | ast::Name(name) => { |
33 | name_definition(&sema, &name)? | 33 | let def = classify_name(&sema, &name)?.definition(); |
34 | let nav = def.try_to_nav(sema.db)?; | ||
35 | vec![nav] | ||
34 | }, | 36 | }, |
35 | _ => return None, | 37 | _ => return None, |
36 | } | 38 | } |
@@ -88,15 +90,6 @@ pub(crate) fn reference_definition( | |||
88 | Approximate(navs) | 90 | Approximate(navs) |
89 | } | 91 | } |
90 | 92 | ||
91 | fn name_definition( | ||
92 | sema: &Semantics<RootDatabase>, | ||
93 | name: &ast::Name, | ||
94 | ) -> Option<Vec<NavigationTarget>> { | ||
95 | let def = classify_name(sema, name)?; | ||
96 | let nav = def.try_to_nav(sema.db)?; | ||
97 | Some(vec![nav]) | ||
98 | } | ||
99 | |||
100 | #[cfg(test)] | 93 | #[cfg(test)] |
101 | mod tests { | 94 | mod tests { |
102 | use test_utils::{assert_eq_text, covers}; | 95 | use test_utils::{assert_eq_text, covers}; |
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 7ba4bfcac..1e4fcdefb 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -156,7 +156,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
156 | classify_name_ref(&sema, &name_ref).map(|d| (name_ref.syntax().clone(), d)) | 156 | classify_name_ref(&sema, &name_ref).map(|d| (name_ref.syntax().clone(), d)) |
157 | }, | 157 | }, |
158 | ast::Name(name) => { | 158 | ast::Name(name) => { |
159 | classify_name(&sema, &name).map(|d| (name.syntax().clone(), d)) | 159 | classify_name(&sema, &name).map(|d| (name.syntax().clone(), d.definition())) |
160 | }, | 160 | }, |
161 | _ => None, | 161 | _ => None, |
162 | } | 162 | } |
@@ -761,13 +761,13 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
761 | fn test_hover_through_literal_string_in_builtin_macro() { | 761 | fn test_hover_through_literal_string_in_builtin_macro() { |
762 | check_hover_no_result( | 762 | check_hover_no_result( |
763 | r#" | 763 | r#" |
764 | //- /lib.rs | 764 | //- /lib.rs |
765 | #[rustc_builtin_macro] | 765 | #[rustc_builtin_macro] |
766 | macro_rules! assert { | 766 | macro_rules! assert { |
767 | ($cond:expr) => {{ /* compiler built-in */ }}; | 767 | ($cond:expr) => {{ /* compiler built-in */ }}; |
768 | ($cond:expr,) => {{ /* compiler built-in */ }}; | 768 | ($cond:expr,) => {{ /* compiler built-in */ }}; |
769 | ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }}; | 769 | ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }}; |
770 | } | 770 | } |
771 | 771 | ||
772 | fn foo() { | 772 | fn foo() { |
773 | assert!("hel<|>lo"); | 773 | assert!("hel<|>lo"); |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index baa8a4d29..f763013ae 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -155,7 +155,7 @@ fn find_name( | |||
155 | opt_name: Option<ast::Name>, | 155 | opt_name: Option<ast::Name>, |
156 | ) -> Option<RangeInfo<(String, NameDefinition)>> { | 156 | ) -> Option<RangeInfo<(String, NameDefinition)>> { |
157 | if let Some(name) = opt_name { | 157 | if let Some(name) = opt_name { |
158 | let def = classify_name(sema, &name)?; | 158 | let def = classify_name(sema, &name)?.definition(); |
159 | let range = name.syntax().text_range(); | 159 | let range = name.syntax().text_range(); |
160 | return Some(RangeInfo::new(range, (name.text().to_string(), def))); | 160 | return Some(RangeInfo::new(range, (name.text().to_string(), def))); |
161 | } | 161 | } |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index c0f7c1c9f..6312bcb83 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -7,7 +7,7 @@ mod tests; | |||
7 | 7 | ||
8 | use hir::{Name, Semantics}; | 8 | use hir::{Name, Semantics}; |
9 | use ra_ide_db::{ | 9 | use ra_ide_db::{ |
10 | defs::{classify_name, NameDefinition}, | 10 | defs::{classify_name, NameClass, NameDefinition}, |
11 | RootDatabase, | 11 | RootDatabase, |
12 | }; | 12 | }; |
13 | use ra_prof::profile; | 13 | use ra_prof::profile; |
@@ -169,7 +169,7 @@ fn highlight_element( | |||
169 | let name = element.into_node().and_then(ast::Name::cast).unwrap(); | 169 | let name = element.into_node().and_then(ast::Name::cast).unwrap(); |
170 | let name_kind = classify_name(sema, &name); | 170 | let name_kind = classify_name(sema, &name); |
171 | 171 | ||
172 | if let Some(NameDefinition::Local(local)) = &name_kind { | 172 | if let Some(NameClass::NameDefinition(NameDefinition::Local(local))) = &name_kind { |
173 | if let Some(name) = local.name(db) { | 173 | if let Some(name) = local.name(db) { |
174 | let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); | 174 | let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); |
175 | *shadow_count += 1; | 175 | *shadow_count += 1; |
@@ -177,11 +177,13 @@ fn highlight_element( | |||
177 | } | 177 | } |
178 | }; | 178 | }; |
179 | 179 | ||
180 | let h = match name_kind { | 180 | match name_kind { |
181 | Some(name_kind) => highlight_name(db, name_kind), | 181 | Some(NameClass::NameDefinition(def)) => { |
182 | None => highlight_name_by_syntax(name), | 182 | highlight_name(db, def) | HighlightModifier::Definition |
183 | }; | 183 | } |
184 | h | HighlightModifier::Definition | 184 | Some(NameClass::ConstReference(def)) => highlight_name(db, def), |
185 | None => highlight_name_by_syntax(name) | HighlightModifier::Definition, | ||
186 | } | ||
185 | } | 187 | } |
186 | 188 | ||
187 | // Highlight references like the definitions they resolve to | 189 | // Highlight references like the definitions they resolve to |