diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/display/navigation_target.rs | 22 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 55 | ||||
-rw-r--r-- | crates/ra_ide/src/hover.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 31 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/references/classify.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide/src/references/name_definition.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/highlighting.html | 9 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/rainbow_highlighting.html | 1 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 12 |
10 files changed, 120 insertions, 34 deletions
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index add11fbc3..6a6b49afd 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs | |||
@@ -6,7 +6,7 @@ use ra_db::{FileId, SourceDatabase}; | |||
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | ast::{self, DocCommentsOwner, NameOwner}, | 7 | ast::{self, DocCommentsOwner, NameOwner}, |
8 | match_ast, AstNode, SmolStr, | 8 | match_ast, AstNode, SmolStr, |
9 | SyntaxKind::{self, BIND_PAT}, | 9 | SyntaxKind::{self, BIND_PAT, TYPE_PARAM}, |
10 | TextRange, | 10 | TextRange, |
11 | }; | 11 | }; |
12 | 12 | ||
@@ -351,6 +351,26 @@ impl ToNav for hir::Local { | |||
351 | } | 351 | } |
352 | } | 352 | } |
353 | 353 | ||
354 | impl ToNav for hir::TypeParam { | ||
355 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | ||
356 | let src = self.source(db); | ||
357 | let range = match src.value { | ||
358 | Either::Left(it) => it.syntax().text_range(), | ||
359 | Either::Right(it) => it.syntax().text_range(), | ||
360 | }; | ||
361 | NavigationTarget { | ||
362 | file_id: src.file_id.original_file(db), | ||
363 | name: self.name(db).to_string().into(), | ||
364 | kind: TYPE_PARAM, | ||
365 | full_range: range, | ||
366 | focus_range: None, | ||
367 | container_name: None, | ||
368 | description: None, | ||
369 | docs: None, | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | |||
354 | pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { | 374 | pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { |
355 | let parse = db.parse(symbol.file_id); | 375 | let parse = db.parse(symbol.file_id); |
356 | let node = symbol.ptr.to_node(parse.tree().syntax()); | 376 | let node = symbol.ptr.to_node(parse.tree().syntax()); |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 76a741207..1b968134d 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -64,9 +64,11 @@ pub(crate) fn reference_definition( | |||
64 | 64 | ||
65 | let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); | 65 | let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); |
66 | match name_kind { | 66 | match name_kind { |
67 | Some(Macro(mac)) => return Exact(mac.to_nav(db)), | 67 | Some(Macro(it)) => return Exact(it.to_nav(db)), |
68 | Some(Field(field)) => return Exact(field.to_nav(db)), | 68 | Some(Field(it)) => return Exact(it.to_nav(db)), |
69 | Some(AssocItem(assoc)) => return Exact(assoc.to_nav(db)), | 69 | Some(TypeParam(it)) => return Exact(it.to_nav(db)), |
70 | Some(AssocItem(it)) => return Exact(it.to_nav(db)), | ||
71 | Some(Local(it)) => return Exact(it.to_nav(db)), | ||
70 | Some(Def(def)) => match NavigationTarget::from_def(db, def) { | 72 | Some(Def(def)) => match NavigationTarget::from_def(db, def) { |
71 | Some(nav) => return Exact(nav), | 73 | Some(nav) => return Exact(nav), |
72 | None => return Approximate(vec![]), | 74 | None => return Approximate(vec![]), |
@@ -77,10 +79,6 @@ pub(crate) fn reference_definition( | |||
77 | // us to the actual type | 79 | // us to the actual type |
78 | return Exact(imp.to_nav(db)); | 80 | return Exact(imp.to_nav(db)); |
79 | } | 81 | } |
80 | Some(Local(local)) => return Exact(local.to_nav(db)), | ||
81 | Some(GenericParam(_)) => { | ||
82 | // FIXME: go to the generic param def | ||
83 | } | ||
84 | None => {} | 82 | None => {} |
85 | }; | 83 | }; |
86 | 84 | ||
@@ -689,8 +687,51 @@ mod tests { | |||
689 | fo<|>o(); | 687 | fo<|>o(); |
690 | } | 688 | } |
691 | } | 689 | } |
690 | mod confuse_index { fn foo(); } | ||
692 | ", | 691 | ", |
693 | "foo FN_DEF FileId(1) [52; 63) [55; 58)", | 692 | "foo FN_DEF FileId(1) [52; 63) [55; 58)", |
694 | ); | 693 | ); |
695 | } | 694 | } |
695 | |||
696 | #[should_panic] // currently failing because of expr mapping problems | ||
697 | #[test] | ||
698 | fn goto_through_format() { | ||
699 | check_goto( | ||
700 | " | ||
701 | //- /lib.rs | ||
702 | #[macro_export] | ||
703 | macro_rules! format { | ||
704 | ($($arg:tt)*) => ($crate::fmt::format($crate::__export::format_args!($($arg)*))) | ||
705 | } | ||
706 | #[rustc_builtin_macro] | ||
707 | #[macro_export] | ||
708 | macro_rules! format_args { | ||
709 | ($fmt:expr) => ({ /* compiler built-in */ }); | ||
710 | ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }) | ||
711 | } | ||
712 | pub mod __export { | ||
713 | pub use crate::format_args; | ||
714 | fn foo() {} // for index confusion | ||
715 | } | ||
716 | fn foo() -> i8 {} | ||
717 | fn test() { | ||
718 | format!(\"{}\", fo<|>o()) | ||
719 | } | ||
720 | ", | ||
721 | "foo FN_DEF FileId(1) [359; 376) [362; 365)", | ||
722 | ); | ||
723 | } | ||
724 | |||
725 | #[test] | ||
726 | fn goto_for_type_param() { | ||
727 | check_goto( | ||
728 | " | ||
729 | //- /lib.rs | ||
730 | struct Foo<T> { | ||
731 | t: <|>T, | ||
732 | } | ||
733 | ", | ||
734 | "T TYPE_PARAM FileId(1) [11; 12)", | ||
735 | ); | ||
736 | } | ||
696 | } | 737 | } |
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index d8185c688..d372ca758 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -138,7 +138,7 @@ fn hover_text_from_name_kind( | |||
138 | *no_fallback = true; | 138 | *no_fallback = true; |
139 | None | 139 | None |
140 | } | 140 | } |
141 | GenericParam(_) | SelfType(_) => { | 141 | TypeParam(_) | SelfType(_) => { |
142 | // FIXME: Hover for generic param | 142 | // FIXME: Hover for generic param |
143 | None | 143 | None |
144 | } | 144 | } |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 59eced9d7..3730121af 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -122,18 +122,11 @@ fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> { | |||
122 | 122 | ||
123 | while let Some(maybe_leaf_pat) = pats_to_process.pop_front() { | 123 | while let Some(maybe_leaf_pat) = pats_to_process.pop_front() { |
124 | match &maybe_leaf_pat { | 124 | match &maybe_leaf_pat { |
125 | ast::Pat::BindPat(bind_pat) => { | 125 | ast::Pat::BindPat(bind_pat) => match bind_pat.pat() { |
126 | if let Some(pat) = bind_pat.pat() { | 126 | Some(pat) => pats_to_process.push_back(pat), |
127 | pats_to_process.push_back(pat); | 127 | _ => leaf_pats.push(maybe_leaf_pat), |
128 | } else { | 128 | }, |
129 | leaf_pats.push(maybe_leaf_pat); | 129 | ast::Pat::TuplePat(tuple_pat) => pats_to_process.extend(tuple_pat.args()), |
130 | } | ||
131 | } | ||
132 | ast::Pat::TuplePat(tuple_pat) => { | ||
133 | for arg_pat in tuple_pat.args() { | ||
134 | pats_to_process.push_back(arg_pat); | ||
135 | } | ||
136 | } | ||
137 | ast::Pat::RecordPat(record_pat) => { | 130 | ast::Pat::RecordPat(record_pat) => { |
138 | if let Some(pat_list) = record_pat.record_field_pat_list() { | 131 | if let Some(pat_list) = record_pat.record_field_pat_list() { |
139 | pats_to_process.extend( | 132 | pats_to_process.extend( |
@@ -151,10 +144,9 @@ fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> { | |||
151 | } | 144 | } |
152 | } | 145 | } |
153 | ast::Pat::TupleStructPat(tuple_struct_pat) => { | 146 | ast::Pat::TupleStructPat(tuple_struct_pat) => { |
154 | for arg_pat in tuple_struct_pat.args() { | 147 | pats_to_process.extend(tuple_struct_pat.args()) |
155 | pats_to_process.push_back(arg_pat); | ||
156 | } | ||
157 | } | 148 | } |
149 | ast::Pat::RefPat(ref_pat) => pats_to_process.extend(ref_pat.pat()), | ||
158 | _ => (), | 150 | _ => (), |
159 | } | 151 | } |
160 | } | 152 | } |
@@ -163,9 +155,10 @@ fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> { | |||
163 | 155 | ||
164 | #[cfg(test)] | 156 | #[cfg(test)] |
165 | mod tests { | 157 | mod tests { |
166 | use crate::mock_analysis::single_file; | ||
167 | use insta::assert_debug_snapshot; | 158 | use insta::assert_debug_snapshot; |
168 | 159 | ||
160 | use crate::mock_analysis::single_file; | ||
161 | |||
169 | #[test] | 162 | #[test] |
170 | fn let_statement() { | 163 | fn let_statement() { |
171 | let (analysis, file_id) = single_file( | 164 | let (analysis, file_id) = single_file( |
@@ -202,6 +195,7 @@ fn main() { | |||
202 | 195 | ||
203 | let test = (42, 'a'); | 196 | let test = (42, 'a'); |
204 | let (a, (b, c, (d, e), f)) = (2, (3, 4, (6.6, 7.7), 5)); | 197 | let (a, (b, c, (d, e), f)) = (2, (3, 4, (6.6, 7.7), 5)); |
198 | let &x = &92; | ||
205 | }"#, | 199 | }"#, |
206 | ); | 200 | ); |
207 | 201 | ||
@@ -257,6 +251,11 @@ fn main() { | |||
257 | kind: TypeHint, | 251 | kind: TypeHint, |
258 | label: "f64", | 252 | label: "f64", |
259 | }, | 253 | }, |
254 | InlayHint { | ||
255 | range: [627; 628), | ||
256 | kind: TypeHint, | ||
257 | label: "i32", | ||
258 | }, | ||
260 | ] | 259 | ] |
261 | "### | 260 | "### |
262 | ); | 261 | ); |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 3e7bfd872..e3ecde50d 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -85,7 +85,7 @@ pub(crate) fn find_all_refs( | |||
85 | NameKind::Def(def) => NavigationTarget::from_def(db, def)?, | 85 | NameKind::Def(def) => NavigationTarget::from_def(db, def)?, |
86 | NameKind::SelfType(imp) => imp.to_nav(db), | 86 | NameKind::SelfType(imp) => imp.to_nav(db), |
87 | NameKind::Local(local) => local.to_nav(db), | 87 | NameKind::Local(local) => local.to_nav(db), |
88 | NameKind::GenericParam(_) => return None, | 88 | NameKind::TypeParam(_) => return None, |
89 | }; | 89 | }; |
90 | 90 | ||
91 | let search_scope = { | 91 | let search_scope = { |
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index b716d32e5..c1f091ec0 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs | |||
@@ -110,6 +110,15 @@ pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Opti | |||
110 | kind: NameKind::Macro(def), | 110 | kind: NameKind::Macro(def), |
111 | }) | 111 | }) |
112 | }, | 112 | }, |
113 | ast::TypeParam(it) => { | ||
114 | let src = name.with_value(it); | ||
115 | let def = hir::TypeParam::from_source(db, src)?; | ||
116 | Some(NameDefinition { | ||
117 | visibility: None, | ||
118 | container: def.module(db), | ||
119 | kind: NameKind::TypeParam(def), | ||
120 | }) | ||
121 | }, | ||
113 | _ => None, | 122 | _ => None, |
114 | } | 123 | } |
115 | } | 124 | } |
@@ -168,9 +177,8 @@ pub(crate) fn classify_name_ref( | |||
168 | let kind = NameKind::Local(local); | 177 | let kind = NameKind::Local(local); |
169 | Some(NameDefinition { kind, container, visibility: None }) | 178 | Some(NameDefinition { kind, container, visibility: None }) |
170 | } | 179 | } |
171 | PathResolution::GenericParam(par) => { | 180 | PathResolution::TypeParam(par) => { |
172 | // FIXME: get generic param def | 181 | let kind = NameKind::TypeParam(par); |
173 | let kind = NameKind::GenericParam(par); | ||
174 | Some(NameDefinition { kind, container, visibility }) | 182 | Some(NameDefinition { kind, container, visibility }) |
175 | } | 183 | } |
176 | PathResolution::Macro(def) => { | 184 | PathResolution::Macro(def) => { |
diff --git a/crates/ra_ide/src/references/name_definition.rs b/crates/ra_ide/src/references/name_definition.rs index 10d3a2364..8c67c8863 100644 --- a/crates/ra_ide/src/references/name_definition.rs +++ b/crates/ra_ide/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, ImplBlock, Local, MacroDef, Module, ModuleDef, | 7 | Adt, AssocItem, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, StructField, |
8 | StructField, VariantDef, | 8 | TypeParam, VariantDef, |
9 | }; | 9 | }; |
10 | use ra_syntax::{ast, ast::VisibilityOwner}; | 10 | use ra_syntax::{ast, ast::VisibilityOwner}; |
11 | 11 | ||
@@ -19,7 +19,7 @@ pub enum NameKind { | |||
19 | Def(ModuleDef), | 19 | Def(ModuleDef), |
20 | SelfType(ImplBlock), | 20 | SelfType(ImplBlock), |
21 | Local(Local), | 21 | Local(Local), |
22 | GenericParam(GenericParam), | 22 | TypeParam(TypeParam), |
23 | } | 23 | } |
24 | 24 | ||
25 | #[derive(PartialEq, Eq)] | 25 | #[derive(PartialEq, Eq)] |
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index b39c4d371..4166a8f90 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html | |||
@@ -9,6 +9,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
9 | .parameter { color: #94BFF3; } | 9 | .parameter { color: #94BFF3; } |
10 | .builtin { color: #DD6718; } | 10 | .builtin { color: #DD6718; } |
11 | .text { color: #DCDCCC; } | 11 | .text { color: #DCDCCC; } |
12 | .type { color: #7CB8BB; } | ||
12 | .attribute { color: #94BFF3; } | 13 | .attribute { color: #94BFF3; } |
13 | .literal { color: #BFEBBF; } | 14 | .literal { color: #BFEBBF; } |
14 | .macro { color: #94BFF3; } | 15 | .macro { color: #94BFF3; } |
@@ -45,4 +46,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
45 | <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>; | 46 | <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>; |
46 | 47 | ||
47 | <span class="variable.mut">y</span>; | 48 | <span class="variable.mut">y</span>; |
49 | } | ||
50 | |||
51 | <span class="keyword">enum</span> <span class="type">E</span><<span class="type">X</span>> { | ||
52 | <span class="constant">V</span>(<span class="type">X</span>) | ||
53 | } | ||
54 | |||
55 | <span class="keyword">impl</span><<span class="type">X</span>> <span class="type">E</span><<span class="type">X</span>> { | ||
56 | <span class="keyword">fn</span> <span class="function">new</span><<span class="type">T</span>>() -> <span class="type">E</span><<span class="type">T</span>> {} | ||
48 | }</code></pre> \ No newline at end of file | 57 | }</code></pre> \ No newline at end of file |
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html index 79f11ea80..9dfbc8047 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html | |||
@@ -9,6 +9,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
9 | .parameter { color: #94BFF3; } | 9 | .parameter { color: #94BFF3; } |
10 | .builtin { color: #DD6718; } | 10 | .builtin { color: #DD6718; } |
11 | .text { color: #DCDCCC; } | 11 | .text { color: #DCDCCC; } |
12 | .type { color: #7CB8BB; } | ||
12 | .attribute { color: #94BFF3; } | 13 | .attribute { color: #94BFF3; } |
13 | .literal { color: #BFEBBF; } | 14 | .literal { color: #BFEBBF; } |
14 | .macro { color: #94BFF3; } | 15 | .macro { color: #94BFF3; } |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index e6a79541f..7ecb1a027 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -225,8 +225,7 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { | |||
225 | Def(hir::ModuleDef::Trait(_)) => "type", | 225 | Def(hir::ModuleDef::Trait(_)) => "type", |
226 | Def(hir::ModuleDef::TypeAlias(_)) => "type", | 226 | Def(hir::ModuleDef::TypeAlias(_)) => "type", |
227 | Def(hir::ModuleDef::BuiltinType(_)) => "type", | 227 | Def(hir::ModuleDef::BuiltinType(_)) => "type", |
228 | SelfType(_) => "type", | 228 | SelfType(_) | TypeParam(_) => "type", |
229 | GenericParam(_) => "type", | ||
230 | Local(local) => { | 229 | Local(local) => { |
231 | if local.is_mut(db) { | 230 | if local.is_mut(db) { |
232 | "variable.mut" | 231 | "variable.mut" |
@@ -255,6 +254,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
255 | .parameter { color: #94BFF3; } | 254 | .parameter { color: #94BFF3; } |
256 | .builtin { color: #DD6718; } | 255 | .builtin { color: #DD6718; } |
257 | .text { color: #DCDCCC; } | 256 | .text { color: #DCDCCC; } |
257 | .type { color: #7CB8BB; } | ||
258 | .attribute { color: #94BFF3; } | 258 | .attribute { color: #94BFF3; } |
259 | .literal { color: #BFEBBF; } | 259 | .literal { color: #BFEBBF; } |
260 | .macro { color: #94BFF3; } | 260 | .macro { color: #94BFF3; } |
@@ -303,6 +303,14 @@ fn main() { | |||
303 | 303 | ||
304 | y; | 304 | y; |
305 | } | 305 | } |
306 | |||
307 | enum E<X> { | ||
308 | V(X) | ||
309 | } | ||
310 | |||
311 | impl<X> E<X> { | ||
312 | fn new<T>() -> E<T> {} | ||
313 | } | ||
306 | "# | 314 | "# |
307 | .trim(), | 315 | .trim(), |
308 | ); | 316 | ); |