diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/complete_trait_impl.rs | 50 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/display/navigation_target.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/display/structure.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/expand_macro.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/impls.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 127 | ||||
-rw-r--r-- | crates/ra_ide/src/references/classify.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 1 |
10 files changed, 111 insertions, 129 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 9a27c164b..18a1d2995 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | //! This module adds the completion items related to implementing associated | 3 | //! This module adds the completion items related to implementing associated |
4 | //! items within a `impl Trait for Struct` block. The current context node | 4 | //! items within a `impl Trait for Struct` block. The current context node |
5 | //! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node | 5 | //! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node |
6 | //! and an direct child of an `IMPL_BLOCK`. | 6 | //! and an direct child of an `IMPL_DEF`. |
7 | //! | 7 | //! |
8 | //! # Examples | 8 | //! # Examples |
9 | //! | 9 | //! |
@@ -55,49 +55,43 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext | |||
55 | _ => false, | 55 | _ => false, |
56 | }); | 56 | }); |
57 | 57 | ||
58 | let impl_block = trigger | 58 | let impl_def = trigger |
59 | .as_ref() | 59 | .as_ref() |
60 | .and_then(|node| node.parent()) | 60 | .and_then(|node| node.parent()) |
61 | .and_then(|node| node.parent()) | 61 | .and_then(|node| node.parent()) |
62 | .and_then(ast::ImplBlock::cast); | 62 | .and_then(ast::ImplDef::cast); |
63 | 63 | ||
64 | if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) { | 64 | if let (Some(trigger), Some(impl_def)) = (trigger, impl_def) { |
65 | match trigger.kind() { | 65 | match trigger.kind() { |
66 | SyntaxKind::FN_DEF => { | 66 | SyntaxKind::FN_DEF => { |
67 | for missing_fn in | 67 | for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map( |
68 | get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| { | 68 | |item| match item { |
69 | match item { | 69 | hir::AssocItem::Function(fn_item) => Some(fn_item), |
70 | hir::AssocItem::Function(fn_item) => Some(fn_item), | 70 | _ => None, |
71 | _ => None, | 71 | }, |
72 | } | 72 | ) { |
73 | }) | ||
74 | { | ||
75 | add_function_impl(&trigger, acc, ctx, &missing_fn); | 73 | add_function_impl(&trigger, acc, ctx, &missing_fn); |
76 | } | 74 | } |
77 | } | 75 | } |
78 | 76 | ||
79 | SyntaxKind::TYPE_ALIAS_DEF => { | 77 | SyntaxKind::TYPE_ALIAS_DEF => { |
80 | for missing_fn in | 78 | for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map( |
81 | get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| { | 79 | |item| match item { |
82 | match item { | 80 | hir::AssocItem::TypeAlias(type_item) => Some(type_item), |
83 | hir::AssocItem::TypeAlias(type_item) => Some(type_item), | 81 | _ => None, |
84 | _ => None, | 82 | }, |
85 | } | 83 | ) { |
86 | }) | ||
87 | { | ||
88 | add_type_alias_impl(&trigger, acc, ctx, &missing_fn); | 84 | add_type_alias_impl(&trigger, acc, ctx, &missing_fn); |
89 | } | 85 | } |
90 | } | 86 | } |
91 | 87 | ||
92 | SyntaxKind::CONST_DEF => { | 88 | SyntaxKind::CONST_DEF => { |
93 | for missing_fn in | 89 | for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map( |
94 | get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| { | 90 | |item| match item { |
95 | match item { | 91 | hir::AssocItem::Const(const_item) => Some(const_item), |
96 | hir::AssocItem::Const(const_item) => Some(const_item), | 92 | _ => None, |
97 | _ => None, | 93 | }, |
98 | } | 94 | ) { |
99 | }) | ||
100 | { | ||
101 | add_const_impl(&trigger, acc, ctx, &missing_fn); | 95 | add_const_impl(&trigger, acc, ctx, &missing_fn); |
102 | } | 96 | } |
103 | } | 97 | } |
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 81321a897..9aa5a705d 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -27,7 +27,7 @@ pub(crate) struct CompletionContext<'a> { | |||
27 | pub(super) use_item_syntax: Option<ast::UseItem>, | 27 | pub(super) use_item_syntax: Option<ast::UseItem>, |
28 | pub(super) record_lit_syntax: Option<ast::RecordLit>, | 28 | pub(super) record_lit_syntax: Option<ast::RecordLit>, |
29 | pub(super) record_lit_pat: Option<ast::RecordPat>, | 29 | pub(super) record_lit_pat: Option<ast::RecordPat>, |
30 | pub(super) impl_block: Option<ast::ImplBlock>, | 30 | pub(super) impl_def: Option<ast::ImplDef>, |
31 | pub(super) is_param: bool, | 31 | pub(super) is_param: bool, |
32 | /// If a name-binding or reference to a const in a pattern. | 32 | /// If a name-binding or reference to a const in a pattern. |
33 | /// Irrefutable patterns (like let) are excluded. | 33 | /// Irrefutable patterns (like let) are excluded. |
@@ -81,7 +81,7 @@ impl<'a> CompletionContext<'a> { | |||
81 | use_item_syntax: None, | 81 | use_item_syntax: None, |
82 | record_lit_syntax: None, | 82 | record_lit_syntax: None, |
83 | record_lit_pat: None, | 83 | record_lit_pat: None, |
84 | impl_block: None, | 84 | impl_def: None, |
85 | is_param: false, | 85 | is_param: false, |
86 | is_pat_binding: false, | 86 | is_pat_binding: false, |
87 | is_trivial_path: false, | 87 | is_trivial_path: false, |
@@ -161,12 +161,12 @@ impl<'a> CompletionContext<'a> { | |||
161 | self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); | 161 | self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); |
162 | } | 162 | } |
163 | 163 | ||
164 | self.impl_block = self | 164 | self.impl_def = self |
165 | .token | 165 | .token |
166 | .parent() | 166 | .parent() |
167 | .ancestors() | 167 | .ancestors() |
168 | .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) | 168 | .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) |
169 | .find_map(ast::ImplBlock::cast); | 169 | .find_map(ast::ImplDef::cast); |
170 | 170 | ||
171 | let top_node = name_ref | 171 | let top_node = name_ref |
172 | .syntax() | 172 | .syntax() |
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 5afb23764..4d3dd477e 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs | |||
@@ -269,7 +269,7 @@ impl ToNav for hir::Module { | |||
269 | } | 269 | } |
270 | } | 270 | } |
271 | 271 | ||
272 | impl ToNav for hir::ImplBlock { | 272 | impl ToNav for hir::ImplDef { |
273 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 273 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
274 | let src = self.source(db); | 274 | let src = self.source(db); |
275 | let frange = if let Some(item) = self.is_builtin_derive(db) { | 275 | let frange = if let Some(item) = self.is_builtin_derive(db) { |
diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs index 944cc79df..5774e9a8b 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs | |||
@@ -129,7 +129,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
129 | ast::RecordFieldDef(it) => { decl_with_ascription(it) }, | 129 | ast::RecordFieldDef(it) => { decl_with_ascription(it) }, |
130 | ast::ConstDef(it) => { decl_with_ascription(it) }, | 130 | ast::ConstDef(it) => { decl_with_ascription(it) }, |
131 | ast::StaticDef(it) => { decl_with_ascription(it) }, | 131 | ast::StaticDef(it) => { decl_with_ascription(it) }, |
132 | ast::ImplBlock(it) => { | 132 | ast::ImplDef(it) => { |
133 | let target_type = it.target_type()?; | 133 | let target_type = it.target_type()?; |
134 | let target_trait = it.target_trait(); | 134 | let target_trait = it.target_trait(); |
135 | let label = match target_trait { | 135 | let label = match target_trait { |
@@ -360,7 +360,7 @@ fn very_obsolete() {} | |||
360 | label: "impl E", | 360 | label: "impl E", |
361 | navigation_range: [239; 240), | 361 | navigation_range: [239; 240), |
362 | node_range: [234; 243), | 362 | node_range: [234; 243), |
363 | kind: IMPL_BLOCK, | 363 | kind: IMPL_DEF, |
364 | detail: None, | 364 | detail: None, |
365 | deprecated: false, | 365 | deprecated: false, |
366 | }, | 366 | }, |
@@ -369,7 +369,7 @@ fn very_obsolete() {} | |||
369 | label: "impl fmt::Debug for E", | 369 | label: "impl fmt::Debug for E", |
370 | navigation_range: [265; 266), | 370 | navigation_range: [265; 266), |
371 | node_range: [245; 269), | 371 | node_range: [245; 269), |
372 | kind: IMPL_BLOCK, | 372 | kind: IMPL_DEF, |
373 | detail: None, | 373 | detail: None, |
374 | deprecated: false, | 374 | deprecated: false, |
375 | }, | 375 | }, |
diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs index 5a079de27..f6667cb33 100644 --- a/crates/ra_ide/src/expand_macro.rs +++ b/crates/ra_ide/src/expand_macro.rs | |||
@@ -195,7 +195,7 @@ fn some_thing() -> u32 { | |||
195 | mat<|>ch_ast! { | 195 | mat<|>ch_ast! { |
196 | match container { | 196 | match container { |
197 | ast::TraitDef(it) => {}, | 197 | ast::TraitDef(it) => {}, |
198 | ast::ImplBlock(it) => {}, | 198 | ast::ImplDef(it) => {}, |
199 | _ => { continue }, | 199 | _ => { continue }, |
200 | } | 200 | } |
201 | } | 201 | } |
@@ -207,7 +207,7 @@ fn some_thing() -> u32 { | |||
207 | assert_snapshot!(res.expansion, @r###" | 207 | assert_snapshot!(res.expansion, @r###" |
208 | { | 208 | { |
209 | if let Some(it) = ast::TraitDef::cast(container.clone()){} | 209 | if let Some(it) = ast::TraitDef::cast(container.clone()){} |
210 | else if let Some(it) = ast::ImplBlock::cast(container.clone()){} | 210 | else if let Some(it) = ast::ImplDef::cast(container.clone()){} |
211 | else { | 211 | else { |
212 | { | 212 | { |
213 | continue | 213 | continue |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 621ab982c..e67585203 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -477,7 +477,7 @@ mod tests { | |||
477 | } | 477 | } |
478 | } | 478 | } |
479 | ", | 479 | ", |
480 | "impl IMPL_BLOCK FileId(1) [12; 73)", | 480 | "impl IMPL_DEF FileId(1) [12; 73)", |
481 | "impl Foo {...}", | 481 | "impl Foo {...}", |
482 | ); | 482 | ); |
483 | 483 | ||
@@ -491,7 +491,7 @@ mod tests { | |||
491 | } | 491 | } |
492 | } | 492 | } |
493 | ", | 493 | ", |
494 | "impl IMPL_BLOCK FileId(1) [12; 73)", | 494 | "impl IMPL_DEF FileId(1) [12; 73)", |
495 | "impl Foo {...}", | 495 | "impl Foo {...}", |
496 | ); | 496 | ); |
497 | 497 | ||
@@ -505,7 +505,7 @@ mod tests { | |||
505 | } | 505 | } |
506 | } | 506 | } |
507 | ", | 507 | ", |
508 | "impl IMPL_BLOCK FileId(1) [15; 75)", | 508 | "impl IMPL_DEF FileId(1) [15; 75)", |
509 | "impl Foo {...}", | 509 | "impl Foo {...}", |
510 | ); | 510 | ); |
511 | 511 | ||
@@ -518,7 +518,7 @@ mod tests { | |||
518 | } | 518 | } |
519 | } | 519 | } |
520 | ", | 520 | ", |
521 | "impl IMPL_BLOCK FileId(1) [15; 62)", | 521 | "impl IMPL_DEF FileId(1) [15; 62)", |
522 | "impl Foo {...}", | 522 | "impl Foo {...}", |
523 | ); | 523 | ); |
524 | } | 524 | } |
@@ -538,7 +538,7 @@ mod tests { | |||
538 | } | 538 | } |
539 | } | 539 | } |
540 | ", | 540 | ", |
541 | "impl IMPL_BLOCK FileId(1) [49; 115)", | 541 | "impl IMPL_DEF FileId(1) [49; 115)", |
542 | "impl Make for Foo {...}", | 542 | "impl Make for Foo {...}", |
543 | ); | 543 | ); |
544 | 544 | ||
@@ -555,7 +555,7 @@ mod tests { | |||
555 | } | 555 | } |
556 | } | 556 | } |
557 | ", | 557 | ", |
558 | "impl IMPL_BLOCK FileId(1) [49; 115)", | 558 | "impl IMPL_DEF FileId(1) [49; 115)", |
559 | "impl Make for Foo {...}", | 559 | "impl Make for Foo {...}", |
560 | ); | 560 | ); |
561 | } | 561 | } |
diff --git a/crates/ra_ide/src/impls.rs b/crates/ra_ide/src/impls.rs index bf82b2a16..68529c8a5 100644 --- a/crates/ra_ide/src/impls.rs +++ b/crates/ra_ide/src/impls.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{Crate, ImplBlock, Semantics}; | 3 | use hir::{Crate, ImplDef, Semantics}; |
4 | use ra_ide_db::RootDatabase; | 4 | use ra_ide_db::RootDatabase; |
5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; | 5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; |
6 | 6 | ||
@@ -42,12 +42,12 @@ fn impls_for_def( | |||
42 | ast::NominalDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), | 42 | ast::NominalDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), |
43 | }; | 43 | }; |
44 | 44 | ||
45 | let impls = ImplBlock::all_in_crate(sema.db, krate); | 45 | let impls = ImplDef::all_in_crate(sema.db, krate); |
46 | 46 | ||
47 | Some( | 47 | Some( |
48 | impls | 48 | impls |
49 | .into_iter() | 49 | .into_iter() |
50 | .filter(|impl_block| ty.is_equal_for_find_impls(&impl_block.target_ty(sema.db))) | 50 | .filter(|impl_def| ty.is_equal_for_find_impls(&impl_def.target_ty(sema.db))) |
51 | .map(|imp| imp.to_nav(sema.db)) | 51 | .map(|imp| imp.to_nav(sema.db)) |
52 | .collect(), | 52 | .collect(), |
53 | ) | 53 | ) |
@@ -60,7 +60,7 @@ fn impls_for_trait( | |||
60 | ) -> Option<Vec<NavigationTarget>> { | 60 | ) -> Option<Vec<NavigationTarget>> { |
61 | let tr = sema.to_def(node)?; | 61 | let tr = sema.to_def(node)?; |
62 | 62 | ||
63 | let impls = ImplBlock::for_trait(sema.db, krate, tr); | 63 | let impls = ImplDef::for_trait(sema.db, krate, tr); |
64 | 64 | ||
65 | Some(impls.into_iter().map(|imp| imp.to_nav(sema.db)).collect()) | 65 | Some(impls.into_iter().map(|imp| imp.to_nav(sema.db)).collect()) |
66 | } | 66 | } |
@@ -86,7 +86,7 @@ mod tests { | |||
86 | struct Foo<|>; | 86 | struct Foo<|>; |
87 | impl Foo {} | 87 | impl Foo {} |
88 | ", | 88 | ", |
89 | &["impl IMPL_BLOCK FileId(1) [12; 23)"], | 89 | &["impl IMPL_DEF FileId(1) [12; 23)"], |
90 | ); | 90 | ); |
91 | } | 91 | } |
92 | 92 | ||
@@ -99,7 +99,7 @@ mod tests { | |||
99 | impl Foo {} | 99 | impl Foo {} |
100 | impl Foo {} | 100 | impl Foo {} |
101 | ", | 101 | ", |
102 | &["impl IMPL_BLOCK FileId(1) [12; 23)", "impl IMPL_BLOCK FileId(1) [24; 35)"], | 102 | &["impl IMPL_DEF FileId(1) [12; 23)", "impl IMPL_DEF FileId(1) [24; 35)"], |
103 | ); | 103 | ); |
104 | } | 104 | } |
105 | 105 | ||
@@ -116,7 +116,7 @@ mod tests { | |||
116 | impl super::Foo {} | 116 | impl super::Foo {} |
117 | } | 117 | } |
118 | ", | 118 | ", |
119 | &["impl IMPL_BLOCK FileId(1) [24; 42)", "impl IMPL_BLOCK FileId(1) [57; 75)"], | 119 | &["impl IMPL_DEF FileId(1) [24; 42)", "impl IMPL_DEF FileId(1) [57; 75)"], |
120 | ); | 120 | ); |
121 | } | 121 | } |
122 | 122 | ||
@@ -133,7 +133,7 @@ mod tests { | |||
133 | //- /b.rs | 133 | //- /b.rs |
134 | impl crate::Foo {} | 134 | impl crate::Foo {} |
135 | ", | 135 | ", |
136 | &["impl IMPL_BLOCK FileId(2) [0; 18)", "impl IMPL_BLOCK FileId(3) [0; 18)"], | 136 | &["impl IMPL_DEF FileId(2) [0; 18)", "impl IMPL_DEF FileId(3) [0; 18)"], |
137 | ); | 137 | ); |
138 | } | 138 | } |
139 | 139 | ||
@@ -146,7 +146,7 @@ mod tests { | |||
146 | struct Foo; | 146 | struct Foo; |
147 | impl T for Foo {} | 147 | impl T for Foo {} |
148 | ", | 148 | ", |
149 | &["impl IMPL_BLOCK FileId(1) [23; 40)"], | 149 | &["impl IMPL_DEF FileId(1) [23; 40)"], |
150 | ); | 150 | ); |
151 | } | 151 | } |
152 | 152 | ||
@@ -164,7 +164,7 @@ mod tests { | |||
164 | //- /b.rs | 164 | //- /b.rs |
165 | impl crate::T for crate::Foo {} | 165 | impl crate::T for crate::Foo {} |
166 | ", | 166 | ", |
167 | &["impl IMPL_BLOCK FileId(2) [0; 31)", "impl IMPL_BLOCK FileId(3) [0; 31)"], | 167 | &["impl IMPL_DEF FileId(2) [0; 31)", "impl IMPL_DEF FileId(3) [0; 31)"], |
168 | ); | 168 | ); |
169 | } | 169 | } |
170 | 170 | ||
@@ -180,9 +180,9 @@ mod tests { | |||
180 | impl T for &Foo {} | 180 | impl T for &Foo {} |
181 | ", | 181 | ", |
182 | &[ | 182 | &[ |
183 | "impl IMPL_BLOCK FileId(1) [23; 34)", | 183 | "impl IMPL_DEF FileId(1) [23; 34)", |
184 | "impl IMPL_BLOCK FileId(1) [35; 52)", | 184 | "impl IMPL_DEF FileId(1) [35; 52)", |
185 | "impl IMPL_BLOCK FileId(1) [53; 71)", | 185 | "impl IMPL_DEF FileId(1) [53; 71)", |
186 | ], | 186 | ], |
187 | ); | 187 | ); |
188 | } | 188 | } |
@@ -195,7 +195,7 @@ mod tests { | |||
195 | #[derive(Copy)] | 195 | #[derive(Copy)] |
196 | struct Foo<|>; | 196 | struct Foo<|>; |
197 | ", | 197 | ", |
198 | &["impl IMPL_BLOCK FileId(1) [0; 15)"], | 198 | &["impl IMPL_DEF FileId(1) [0; 15)"], |
199 | ); | 199 | ); |
200 | } | 200 | } |
201 | } | 201 | } |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 35e3f782d..69098a630 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -5,7 +5,7 @@ use ra_ide_db::RootDatabase; | |||
5 | use ra_prof::profile; | 5 | use ra_prof::profile; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, | 7 | ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, |
8 | match_ast, SmolStr, SyntaxNode, TextRange, | 8 | match_ast, SmolStr, TextRange, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{FileId, FunctionSignature}; | 11 | use crate::{FileId, FunctionSignature}; |
@@ -28,50 +28,76 @@ pub(crate) fn inlay_hints( | |||
28 | file_id: FileId, | 28 | file_id: FileId, |
29 | max_inlay_hint_length: Option<usize>, | 29 | max_inlay_hint_length: Option<usize>, |
30 | ) -> Vec<InlayHint> { | 30 | ) -> Vec<InlayHint> { |
31 | let _p = profile("inlay_hints"); | ||
31 | let sema = Semantics::new(db); | 32 | let sema = Semantics::new(db); |
32 | let file = sema.parse(file_id); | 33 | let file = sema.parse(file_id); |
34 | |||
33 | let mut res = Vec::new(); | 35 | let mut res = Vec::new(); |
34 | for node in file.syntax().descendants() { | 36 | for node in file.syntax().descendants() { |
35 | get_inlay_hints(&mut res, &sema, &node, max_inlay_hint_length); | 37 | match_ast! { |
38 | match node { | ||
39 | ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, ast::Expr::from(it)); }, | ||
40 | ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, ast::Expr::from(it)); }, | ||
41 | ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, max_inlay_hint_length, it); }, | ||
42 | _ => (), | ||
43 | } | ||
44 | } | ||
36 | } | 45 | } |
37 | res | 46 | res |
38 | } | 47 | } |
39 | 48 | ||
40 | fn get_inlay_hints( | 49 | fn get_param_name_hints( |
50 | acc: &mut Vec<InlayHint>, | ||
51 | sema: &Semantics<RootDatabase>, | ||
52 | expr: ast::Expr, | ||
53 | ) -> Option<()> { | ||
54 | let args = match &expr { | ||
55 | ast::Expr::CallExpr(expr) => expr.arg_list()?.args(), | ||
56 | ast::Expr::MethodCallExpr(expr) => expr.arg_list()?.args(), | ||
57 | _ => return None, | ||
58 | }; | ||
59 | let args_count = args.clone().count(); | ||
60 | |||
61 | let fn_signature = get_fn_signature(sema, &expr)?; | ||
62 | let n_params_to_skip = | ||
63 | if fn_signature.has_self_param && fn_signature.parameter_names.len() > args_count { | ||
64 | 1 | ||
65 | } else { | ||
66 | 0 | ||
67 | }; | ||
68 | let hints = fn_signature | ||
69 | .parameter_names | ||
70 | .iter() | ||
71 | .skip(n_params_to_skip) | ||
72 | .zip(args) | ||
73 | .filter(|(param, arg)| should_show_param_hint(&fn_signature, param, &arg)) | ||
74 | .map(|(param_name, arg)| InlayHint { | ||
75 | range: arg.syntax().text_range(), | ||
76 | kind: InlayKind::ParameterHint, | ||
77 | label: param_name.into(), | ||
78 | }); | ||
79 | |||
80 | acc.extend(hints); | ||
81 | Some(()) | ||
82 | } | ||
83 | |||
84 | fn get_bind_pat_hints( | ||
41 | acc: &mut Vec<InlayHint>, | 85 | acc: &mut Vec<InlayHint>, |
42 | sema: &Semantics<RootDatabase>, | 86 | sema: &Semantics<RootDatabase>, |
43 | node: &SyntaxNode, | ||
44 | max_inlay_hint_length: Option<usize>, | 87 | max_inlay_hint_length: Option<usize>, |
88 | pat: ast::BindPat, | ||
45 | ) -> Option<()> { | 89 | ) -> Option<()> { |
46 | let _p = profile("get_inlay_hints"); | 90 | let ty = sema.type_of_pat(&pat.clone().into())?; |
47 | let db = sema.db; | ||
48 | match_ast! { | ||
49 | match node { | ||
50 | ast::CallExpr(it) => { | ||
51 | get_param_name_hints(acc, sema, ast::Expr::from(it)); | ||
52 | }, | ||
53 | ast::MethodCallExpr(it) => { | ||
54 | get_param_name_hints(acc, sema, ast::Expr::from(it)); | ||
55 | }, | ||
56 | ast::BindPat(it) => { | ||
57 | let pat = ast::Pat::from(it.clone()); | ||
58 | let ty = sema.type_of_pat(&pat)?; | ||
59 | |||
60 | if should_not_display_type_hint(db, &it, &ty) { | ||
61 | return None; | ||
62 | } | ||
63 | 91 | ||
64 | acc.push( | 92 | if should_not_display_type_hint(sema.db, &pat, &ty) { |
65 | InlayHint { | 93 | return None; |
66 | range: pat.syntax().text_range(), | 94 | } |
67 | kind: InlayKind::TypeHint, | 95 | |
68 | label: ty.display_truncated(db, max_inlay_hint_length).to_string().into(), | 96 | acc.push(InlayHint { |
69 | } | 97 | range: pat.syntax().text_range(), |
70 | ); | 98 | kind: InlayKind::TypeHint, |
71 | }, | 99 | label: ty.display_truncated(sema.db, max_inlay_hint_length).to_string().into(), |
72 | _ => (), | 100 | }); |
73 | } | ||
74 | }; | ||
75 | Some(()) | 101 | Some(()) |
76 | } | 102 | } |
77 | 103 | ||
@@ -120,43 +146,6 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ | |||
120 | false | 146 | false |
121 | } | 147 | } |
122 | 148 | ||
123 | fn get_param_name_hints( | ||
124 | acc: &mut Vec<InlayHint>, | ||
125 | sema: &Semantics<RootDatabase>, | ||
126 | expr: ast::Expr, | ||
127 | ) -> Option<()> { | ||
128 | let args = match &expr { | ||
129 | ast::Expr::CallExpr(expr) => expr.arg_list()?.args(), | ||
130 | ast::Expr::MethodCallExpr(expr) => expr.arg_list()?.args(), | ||
131 | _ => return None, | ||
132 | } | ||
133 | .into_iter() | ||
134 | // we need args len to determine whether to skip or not the &self parameter | ||
135 | .collect::<Vec<_>>(); | ||
136 | |||
137 | let fn_signature = get_fn_signature(sema, &expr)?; | ||
138 | let n_params_to_skip = | ||
139 | if fn_signature.has_self_param && fn_signature.parameter_names.len() > args.len() { | ||
140 | 1 | ||
141 | } else { | ||
142 | 0 | ||
143 | }; | ||
144 | let hints = fn_signature | ||
145 | .parameter_names | ||
146 | .iter() | ||
147 | .skip(n_params_to_skip) | ||
148 | .zip(args) | ||
149 | .filter(|(param, arg)| should_show_param_hint(&fn_signature, param, &arg)) | ||
150 | .map(|(param_name, arg)| InlayHint { | ||
151 | range: arg.syntax().text_range(), | ||
152 | kind: InlayKind::ParameterHint, | ||
153 | label: param_name.into(), | ||
154 | }); | ||
155 | |||
156 | acc.extend(hints); | ||
157 | Some(()) | ||
158 | } | ||
159 | |||
160 | fn should_show_param_hint( | 149 | fn should_show_param_hint( |
161 | fn_signature: &FunctionSignature, | 150 | fn_signature: &FunctionSignature, |
162 | param_name: &str, | 151 | param_name: &str, |
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 91b21429a..fdd07d8d1 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs | |||
@@ -61,7 +61,7 @@ pub(crate) fn classify_name_ref( | |||
61 | PathResolution::Local(local) => NameDefinition::Local(local), | 61 | PathResolution::Local(local) => NameDefinition::Local(local), |
62 | PathResolution::TypeParam(par) => NameDefinition::TypeParam(par), | 62 | PathResolution::TypeParam(par) => NameDefinition::TypeParam(par), |
63 | PathResolution::Macro(def) => NameDefinition::Macro(def), | 63 | PathResolution::Macro(def) => NameDefinition::Macro(def), |
64 | PathResolution::SelfType(impl_block) => NameDefinition::SelfType(impl_block), | 64 | PathResolution::SelfType(impl_def) => NameDefinition::SelfType(impl_def), |
65 | }; | 65 | }; |
66 | Some(res) | 66 | Some(res) |
67 | } | 67 | } |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index b94b6a022..28117b4d8 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -120,7 +120,6 @@ pub(crate) fn highlight( | |||
120 | if let Some(token) = element.as_token().cloned().and_then(ast::RawString::cast) { | 120 | if let Some(token) = element.as_token().cloned().and_then(ast::RawString::cast) { |
121 | let expanded = element_to_highlight.as_token().unwrap().clone(); | 121 | let expanded = element_to_highlight.as_token().unwrap().clone(); |
122 | if highlight_injection(&mut res, &sema, token, expanded).is_some() { | 122 | if highlight_injection(&mut res, &sema, token, expanded).is_some() { |
123 | eprintln!("res = {:?}", res); | ||
124 | continue; | 123 | continue; |
125 | } | 124 | } |
126 | } | 125 | } |