aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs50
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs8
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs2
-rw-r--r--crates/ra_ide/src/display/structure.rs6
-rw-r--r--crates/ra_ide/src/expand_macro.rs4
-rw-r--r--crates/ra_ide/src/goto_definition.rs12
-rw-r--r--crates/ra_ide/src/impls.rs28
-rw-r--r--crates/ra_ide/src/references/classify.rs2
8 files changed, 53 insertions, 59 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
272impl ToNav for hir::ImplBlock { 272impl 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
3use hir::{Crate, ImplBlock, Semantics}; 3use hir::{Crate, ImplDef, Semantics};
4use ra_ide_db::RootDatabase; 4use ra_ide_db::RootDatabase;
5use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; 5use 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/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}