diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/handlers/add_missing_impl_members.rs | 3 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/generate_new.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/move_bounds.rs | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/utils.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 19 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_fn_param.rs | 38 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_keyword.rs | 36 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/patterns.rs | 6 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items/traits.rs | 4 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 9 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated/nodes.rs | 71 |
12 files changed, 118 insertions, 78 deletions
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index f185e61e5..a2d9006e4 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -112,7 +112,7 @@ fn add_missing_impl_members_inner( | |||
112 | ) -> Option<()> { | 112 | ) -> Option<()> { |
113 | let _p = ra_prof::profile("add_missing_impl_members_inner"); | 113 | let _p = ra_prof::profile("add_missing_impl_members_inner"); |
114 | let impl_def = ctx.find_node_at_offset::<ast::ImplDef>()?; | 114 | let impl_def = ctx.find_node_at_offset::<ast::ImplDef>()?; |
115 | let impl_item_list = impl_def.item_list()?; | 115 | let impl_item_list = impl_def.assoc_item_list()?; |
116 | 116 | ||
117 | let trait_ = resolve_target_trait(&ctx.sema, &impl_def)?; | 117 | let trait_ = resolve_target_trait(&ctx.sema, &impl_def)?; |
118 | 118 | ||
@@ -121,6 +121,7 @@ fn add_missing_impl_members_inner( | |||
121 | ast::AssocItem::FnDef(def) => def.name(), | 121 | ast::AssocItem::FnDef(def) => def.name(), |
122 | ast::AssocItem::TypeAliasDef(def) => def.name(), | 122 | ast::AssocItem::TypeAliasDef(def) => def.name(), |
123 | ast::AssocItem::ConstDef(def) => def.name(), | 123 | ast::AssocItem::ConstDef(def) => def.name(), |
124 | ast::AssocItem::MacroCall(_) => None, | ||
124 | } | 125 | } |
125 | .map(|it| it.text().clone()) | 126 | .map(|it| it.text().clone()) |
126 | }; | 127 | }; |
diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index e27def1d8..25bc171bf 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs | |||
@@ -158,7 +158,7 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option<Opti | |||
158 | } | 158 | } |
159 | 159 | ||
160 | fn has_new_fn(imp: &ast::ImplDef) -> bool { | 160 | fn has_new_fn(imp: &ast::ImplDef) -> bool { |
161 | if let Some(il) = imp.item_list() { | 161 | if let Some(il) = imp.assoc_item_list() { |
162 | for item in il.assoc_items() { | 162 | for item in il.assoc_items() { |
163 | if let ast::AssocItem::FnDef(f) = item { | 163 | if let ast::AssocItem::FnDef(f) = item { |
164 | if let Some(name) = f.name() { | 164 | if let Some(name) = f.name() { |
diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs index ba3dafb99..6b73fff44 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs | |||
@@ -38,8 +38,8 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext | |||
38 | let anchor = match_ast! { | 38 | let anchor = match_ast! { |
39 | match parent { | 39 | match parent { |
40 | ast::FnDef(it) => it.body()?.syntax().clone().into(), | 40 | ast::FnDef(it) => it.body()?.syntax().clone().into(), |
41 | ast::TraitDef(it) => it.item_list()?.syntax().clone().into(), | 41 | ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(), |
42 | ast::ImplDef(it) => it.item_list()?.syntax().clone().into(), | 42 | ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(), |
43 | ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), | 43 | ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), |
44 | ast::StructDef(it) => { | 44 | ast::StructDef(it) => { |
45 | it.syntax().children_with_tokens() | 45 | it.syntax().children_with_tokens() |
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 02de902d6..27c33df23 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -63,7 +63,7 @@ pub fn get_missing_assoc_items( | |||
63 | let mut impl_fns_consts = FxHashSet::default(); | 63 | let mut impl_fns_consts = FxHashSet::default(); |
64 | let mut impl_type = FxHashSet::default(); | 64 | let mut impl_type = FxHashSet::default(); |
65 | 65 | ||
66 | if let Some(item_list) = impl_def.item_list() { | 66 | if let Some(item_list) = impl_def.assoc_item_list() { |
67 | for item in item_list.assoc_items() { | 67 | for item in item_list.assoc_items() { |
68 | match item { | 68 | match item { |
69 | ast::AssocItem::FnDef(f) => { | 69 | ast::AssocItem::FnDef(f) => { |
@@ -83,6 +83,7 @@ pub fn get_missing_assoc_items( | |||
83 | impl_fns_consts.insert(n.syntax().to_string()); | 83 | impl_fns_consts.insert(n.syntax().to_string()); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | ast::AssocItem::MacroCall(_) => (), | ||
86 | } | 87 | } |
87 | } | 88 | } |
88 | } | 89 | } |
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index eb1da4632..4fc21a642 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs | |||
@@ -153,13 +153,12 @@ impl Ctx { | |||
153 | self.forced_visibility = forced_vis; | 153 | self.forced_visibility = forced_vis; |
154 | } | 154 | } |
155 | 155 | ||
156 | fn lower_assoc_item(&mut self, item: &ast::Item) -> Option<AssocItem> { | 156 | fn lower_assoc_item(&mut self, item: &ast::AssocItem) -> Option<AssocItem> { |
157 | match item { | 157 | match item { |
158 | ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into), | 158 | ast::AssocItem::FnDef(ast) => self.lower_function(ast).map(Into::into), |
159 | ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), | 159 | ast::AssocItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), |
160 | ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()), | 160 | ast::AssocItem::ConstDef(ast) => Some(self.lower_const(ast).into()), |
161 | ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), | 161 | ast::AssocItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), |
162 | _ => None, | ||
163 | } | 162 | } |
164 | } | 163 | } |
165 | 164 | ||
@@ -419,9 +418,9 @@ impl Ctx { | |||
419 | let generic_params = | 418 | let generic_params = |
420 | self.lower_generic_params_and_inner_items(GenericsOwner::Trait(trait_def), trait_def); | 419 | self.lower_generic_params_and_inner_items(GenericsOwner::Trait(trait_def), trait_def); |
421 | let auto = trait_def.auto_token().is_some(); | 420 | let auto = trait_def.auto_token().is_some(); |
422 | let items = trait_def.item_list().map(|list| { | 421 | let items = trait_def.assoc_item_list().map(|list| { |
423 | self.with_inherited_visibility(visibility, |this| { | 422 | self.with_inherited_visibility(visibility, |this| { |
424 | list.items() | 423 | list.assoc_items() |
425 | .filter_map(|item| { | 424 | .filter_map(|item| { |
426 | let attrs = Attrs::new(&item, &this.hygiene); | 425 | let attrs = Attrs::new(&item, &this.hygiene); |
427 | this.collect_inner_items(item.syntax()); | 426 | this.collect_inner_items(item.syntax()); |
@@ -454,9 +453,9 @@ impl Ctx { | |||
454 | 453 | ||
455 | // We cannot use `assoc_items()` here as that does not include macro calls. | 454 | // We cannot use `assoc_items()` here as that does not include macro calls. |
456 | let items = impl_def | 455 | let items = impl_def |
457 | .item_list() | 456 | .assoc_item_list() |
458 | .into_iter() | 457 | .into_iter() |
459 | .flat_map(|it| it.items()) | 458 | .flat_map(|it| it.assoc_items()) |
460 | .filter_map(|item| { | 459 | .filter_map(|item| { |
461 | self.collect_inner_items(item.syntax()); | 460 | self.collect_inner_items(item.syntax()); |
462 | let assoc = self.lower_assoc_item(&item)?; | 461 | let assoc = self.lower_assoc_item(&item)?; |
diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 7a53083f5..d4b6112a5 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs | |||
@@ -18,26 +18,36 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
18 | } | 18 | } |
19 | 19 | ||
20 | let mut params = FxHashMap::default(); | 20 | let mut params = FxHashMap::default(); |
21 | |||
21 | let me = ctx.token.ancestors().find_map(ast::FnDef::cast); | 22 | let me = ctx.token.ancestors().find_map(ast::FnDef::cast); |
23 | let mut process_fn = |func: ast::FnDef| { | ||
24 | if Some(&func) == me.as_ref() { | ||
25 | return; | ||
26 | } | ||
27 | func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { | ||
28 | let text = param.syntax().text().to_string(); | ||
29 | params.entry(text).or_insert(param); | ||
30 | }) | ||
31 | }; | ||
32 | |||
22 | for node in ctx.token.parent().ancestors() { | 33 | for node in ctx.token.parent().ancestors() { |
23 | let items = match_ast! { | 34 | match_ast! { |
24 | match node { | 35 | match node { |
25 | ast::SourceFile(it) => it.items(), | 36 | ast::SourceFile(it) => it.items().filter_map(|item| match item { |
26 | ast::ItemList(it) => it.items(), | 37 | ast::Item::FnDef(it) => Some(it), |
38 | _ => None, | ||
39 | }).for_each(&mut process_fn), | ||
40 | ast::ItemList(it) => it.items().filter_map(|item| match item { | ||
41 | ast::Item::FnDef(it) => Some(it), | ||
42 | _ => None, | ||
43 | }).for_each(&mut process_fn), | ||
44 | ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item { | ||
45 | ast::AssocItem::FnDef(it) => Some(it), | ||
46 | _ => None, | ||
47 | }).for_each(&mut process_fn), | ||
27 | _ => continue, | 48 | _ => continue, |
28 | } | 49 | } |
29 | }; | 50 | }; |
30 | for item in items { | ||
31 | if let ast::Item::FnDef(func) = item { | ||
32 | if Some(&func) == me.as_ref() { | ||
33 | continue; | ||
34 | } | ||
35 | func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { | ||
36 | let text = param.syntax().text().to_string(); | ||
37 | params.entry(text).or_insert(param); | ||
38 | }) | ||
39 | } | ||
40 | } | ||
41 | } | 51 | } |
42 | 52 | ||
43 | params | 53 | params |
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index fcdaeef49..1581b2d5d 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs | |||
@@ -66,27 +66,24 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
66 | add_keyword(ctx, acc, "fn", "fn $0() {}") | 66 | add_keyword(ctx, acc, "fn", "fn $0() {}") |
67 | } | 67 | } |
68 | 68 | ||
69 | if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) | 69 | if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { |
70 | || ctx.block_expr_parent | ||
71 | { | ||
72 | add_keyword(ctx, acc, "trait", "trait $0 {}"); | 70 | add_keyword(ctx, acc, "trait", "trait $0 {}"); |
73 | add_keyword(ctx, acc, "impl", "impl $0 {}"); | 71 | add_keyword(ctx, acc, "impl", "impl $0 {}"); |
74 | } | 72 | } |
75 | 73 | ||
76 | return; | 74 | return; |
77 | } | 75 | } |
78 | if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { | 76 | if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent |
77 | { | ||
79 | add_keyword(ctx, acc, "fn", "fn $0() {}"); | 78 | add_keyword(ctx, acc, "fn", "fn $0() {}"); |
80 | } | 79 | } |
81 | if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) | 80 | if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { |
82 | || ctx.block_expr_parent | ||
83 | { | ||
84 | add_keyword(ctx, acc, "use", "use "); | 81 | add_keyword(ctx, acc, "use", "use "); |
85 | add_keyword(ctx, acc, "impl", "impl $0 {}"); | 82 | add_keyword(ctx, acc, "impl", "impl $0 {}"); |
86 | add_keyword(ctx, acc, "trait", "trait $0 {}"); | 83 | add_keyword(ctx, acc, "trait", "trait $0 {}"); |
87 | } | 84 | } |
88 | 85 | ||
89 | if ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent { | 86 | if ctx.has_item_list_or_source_file_parent { |
90 | add_keyword(ctx, acc, "enum", "enum $0 {}"); | 87 | add_keyword(ctx, acc, "enum", "enum $0 {}"); |
91 | add_keyword(ctx, acc, "struct", "struct $0"); | 88 | add_keyword(ctx, acc, "struct", "struct $0"); |
92 | add_keyword(ctx, acc, "union", "union $0 {}"); | 89 | add_keyword(ctx, acc, "union", "union $0 {}"); |
@@ -108,29 +105,28 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
108 | add_keyword(ctx, acc, "else", "else {$0}"); | 105 | add_keyword(ctx, acc, "else", "else {$0}"); |
109 | add_keyword(ctx, acc, "else if", "else if $0 {}"); | 106 | add_keyword(ctx, acc, "else if", "else if $0 {}"); |
110 | } | 107 | } |
111 | if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) | 108 | if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { |
112 | || ctx.block_expr_parent | ||
113 | { | ||
114 | add_keyword(ctx, acc, "mod", "mod $0 {}"); | 109 | add_keyword(ctx, acc, "mod", "mod $0 {}"); |
115 | } | 110 | } |
116 | if ctx.bind_pat_parent || ctx.ref_pat_parent { | 111 | if ctx.bind_pat_parent || ctx.ref_pat_parent { |
117 | add_keyword(ctx, acc, "mut", "mut "); | 112 | add_keyword(ctx, acc, "mut", "mut "); |
118 | } | 113 | } |
119 | if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { | 114 | if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent |
115 | { | ||
120 | add_keyword(ctx, acc, "const", "const "); | 116 | add_keyword(ctx, acc, "const", "const "); |
121 | add_keyword(ctx, acc, "type", "type "); | 117 | add_keyword(ctx, acc, "type", "type "); |
122 | } | 118 | } |
123 | if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) | 119 | if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { |
124 | || ctx.block_expr_parent | ||
125 | { | ||
126 | add_keyword(ctx, acc, "static", "static "); | 120 | add_keyword(ctx, acc, "static", "static "); |
127 | }; | 121 | }; |
128 | if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) | 122 | if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { |
129 | || ctx.block_expr_parent | ||
130 | { | ||
131 | add_keyword(ctx, acc, "extern", "extern "); | 123 | add_keyword(ctx, acc, "extern", "extern "); |
132 | } | 124 | } |
133 | if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent || ctx.is_match_arm { | 125 | if ctx.has_item_list_or_source_file_parent |
126 | || has_trait_or_impl_parent | ||
127 | || ctx.block_expr_parent | ||
128 | || ctx.is_match_arm | ||
129 | { | ||
134 | add_keyword(ctx, acc, "unsafe", "unsafe "); | 130 | add_keyword(ctx, acc, "unsafe", "unsafe "); |
135 | } | 131 | } |
136 | if ctx.in_loop_body { | 132 | if ctx.in_loop_body { |
@@ -142,7 +138,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
142 | add_keyword(ctx, acc, "break", "break"); | 138 | add_keyword(ctx, acc, "break", "break"); |
143 | } | 139 | } |
144 | } | 140 | } |
145 | if ctx.has_item_list_or_source_file_parent && !ctx.has_trait_parent { | 141 | if ctx.has_item_list_or_source_file_parent || ctx.has_impl_parent { |
146 | add_keyword(ctx, acc, "pub", "pub ") | 142 | add_keyword(ctx, acc, "pub", "pub ") |
147 | } | 143 | } |
148 | 144 | ||
diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index b2fe13280..175209d8a 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs | |||
@@ -13,7 +13,7 @@ use crate::completion::test_utils::check_pattern_is_applicable; | |||
13 | 13 | ||
14 | pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { | 14 | pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { |
15 | not_same_range_ancestor(element) | 15 | not_same_range_ancestor(element) |
16 | .filter(|it| it.kind() == ITEM_LIST) | 16 | .filter(|it| it.kind() == ASSOC_ITEM_LIST) |
17 | .and_then(|it| it.parent()) | 17 | .and_then(|it| it.parent()) |
18 | .filter(|it| it.kind() == TRAIT_DEF) | 18 | .filter(|it| it.kind() == TRAIT_DEF) |
19 | .is_some() | 19 | .is_some() |
@@ -25,7 +25,7 @@ fn test_has_trait_parent() { | |||
25 | 25 | ||
26 | pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool { | 26 | pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool { |
27 | not_same_range_ancestor(element) | 27 | not_same_range_ancestor(element) |
28 | .filter(|it| it.kind() == ITEM_LIST) | 28 | .filter(|it| it.kind() == ASSOC_ITEM_LIST) |
29 | .and_then(|it| it.parent()) | 29 | .and_then(|it| it.parent()) |
30 | .filter(|it| it.kind() == IMPL_DEF) | 30 | .filter(|it| it.kind() == IMPL_DEF) |
31 | .is_some() | 31 | .is_some() |
@@ -73,7 +73,7 @@ pub(crate) fn has_item_list_or_source_file_parent(element: SyntaxElement) -> boo | |||
73 | #[test] | 73 | #[test] |
74 | fn test_has_item_list_or_source_file_parent() { | 74 | fn test_has_item_list_or_source_file_parent() { |
75 | check_pattern_is_applicable(r"i<|>", has_item_list_or_source_file_parent); | 75 | check_pattern_is_applicable(r"i<|>", has_item_list_or_source_file_parent); |
76 | check_pattern_is_applicable(r"impl { f<|> }", has_item_list_or_source_file_parent); | 76 | check_pattern_is_applicable(r"mod foo { f<|> }", has_item_list_or_source_file_parent); |
77 | } | 77 | } |
78 | 78 | ||
79 | pub(crate) fn is_match_arm(element: SyntaxElement) -> bool { | 79 | pub(crate) fn is_match_arm(element: SyntaxElement) -> bool { |
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs index c819e33be..ef9c8ff5b 100644 --- a/crates/ra_parser/src/grammar/items/traits.rs +++ b/crates/ra_parser/src/grammar/items/traits.rs | |||
@@ -50,7 +50,7 @@ pub(crate) fn trait_item_list(p: &mut Parser) { | |||
50 | item_or_macro(p, true, ItemFlavor::Trait); | 50 | item_or_macro(p, true, ItemFlavor::Trait); |
51 | } | 51 | } |
52 | p.expect(T!['}']); | 52 | p.expect(T!['}']); |
53 | m.complete(p, ITEM_LIST); | 53 | m.complete(p, ASSOC_ITEM_LIST); |
54 | } | 54 | } |
55 | 55 | ||
56 | // test impl_def | 56 | // test impl_def |
@@ -107,7 +107,7 @@ pub(crate) fn impl_item_list(p: &mut Parser) { | |||
107 | item_or_macro(p, true, ItemFlavor::Mod); | 107 | item_or_macro(p, true, ItemFlavor::Mod); |
108 | } | 108 | } |
109 | p.expect(T!['}']); | 109 | p.expect(T!['}']); |
110 | m.complete(p, ITEM_LIST); | 110 | m.complete(p, ASSOC_ITEM_LIST); |
111 | } | 111 | } |
112 | 112 | ||
113 | // test impl_type_params | 113 | // test impl_type_params |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 625f0c822..56dadc6af 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -213,6 +213,7 @@ pub enum SyntaxKind { | |||
213 | TUPLE_FIELD_DEF, | 213 | TUPLE_FIELD_DEF, |
214 | ENUM_VARIANT_LIST, | 214 | ENUM_VARIANT_LIST, |
215 | ITEM_LIST, | 215 | ITEM_LIST, |
216 | ASSOC_ITEM_LIST, | ||
216 | ATTR, | 217 | ATTR, |
217 | META_ITEM, | 218 | META_ITEM, |
218 | USE_TREE, | 219 | USE_TREE, |
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index abc7a646c..01a310f66 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -80,9 +80,12 @@ where | |||
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | impl ast::ItemList { | 83 | impl ast::AssocItemList { |
84 | #[must_use] | 84 | #[must_use] |
85 | pub fn append_items(&self, items: impl IntoIterator<Item = ast::AssocItem>) -> ast::ItemList { | 85 | pub fn append_items( |
86 | &self, | ||
87 | items: impl IntoIterator<Item = ast::AssocItem>, | ||
88 | ) -> ast::AssocItemList { | ||
86 | let mut res = self.clone(); | 89 | let mut res = self.clone(); |
87 | if !self.syntax().text().contains_char('\n') { | 90 | if !self.syntax().text().contains_char('\n') { |
88 | res = make_multiline(res); | 91 | res = make_multiline(res); |
@@ -92,7 +95,7 @@ impl ast::ItemList { | |||
92 | } | 95 | } |
93 | 96 | ||
94 | #[must_use] | 97 | #[must_use] |
95 | pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { | 98 | pub fn append_item(&self, item: ast::AssocItem) -> ast::AssocItemList { |
96 | let (indent, position) = match self.assoc_items().last() { | 99 | let (indent, position) = match self.assoc_items().last() { |
97 | Some(it) => ( | 100 | Some(it) => ( |
98 | leading_indent(it.syntax()).unwrap_or_default().to_string(), | 101 | leading_indent(it.syntax()).unwrap_or_default().to_string(), |
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index dfda79550..7ccb7ea7f 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -112,7 +112,7 @@ impl ImplDef { | |||
112 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | 112 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } |
113 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | 113 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
114 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | 114 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } |
115 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 115 | pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) } |
116 | } | 116 | } |
117 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 117 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
118 | pub struct MacroCall { | 118 | pub struct MacroCall { |
@@ -180,7 +180,7 @@ impl TraitDef { | |||
180 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | 180 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } |
181 | pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) } | 181 | pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) } |
182 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } | 182 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } |
183 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 183 | pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) } |
184 | } | 184 | } |
185 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 185 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
186 | pub struct TypeAliasDef { | 186 | pub struct TypeAliasDef { |
@@ -238,11 +238,6 @@ impl Visibility { | |||
238 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 238 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
239 | } | 239 | } |
240 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 240 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
241 | pub struct Abi { | ||
242 | pub(crate) syntax: SyntaxNode, | ||
243 | } | ||
244 | impl Abi {} | ||
245 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
246 | pub struct Name { | 241 | pub struct Name { |
247 | pub(crate) syntax: SyntaxNode, | 242 | pub(crate) syntax: SyntaxNode, |
248 | } | 243 | } |
@@ -250,6 +245,20 @@ impl Name { | |||
250 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | 245 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } |
251 | } | 246 | } |
252 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 247 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
248 | pub struct ItemList { | ||
249 | pub(crate) syntax: SyntaxNode, | ||
250 | } | ||
251 | impl ast::ModuleItemOwner for ItemList {} | ||
252 | impl ItemList { | ||
253 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
254 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
255 | } | ||
256 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
257 | pub struct Abi { | ||
258 | pub(crate) syntax: SyntaxNode, | ||
259 | } | ||
260 | impl Abi {} | ||
261 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
253 | pub struct TypeParamList { | 262 | pub struct TypeParamList { |
254 | pub(crate) syntax: SyntaxNode, | 263 | pub(crate) syntax: SyntaxNode, |
255 | } | 264 | } |
@@ -367,11 +376,10 @@ impl TypeBoundList { | |||
367 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } | 376 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } |
368 | } | 377 | } |
369 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 378 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
370 | pub struct ItemList { | 379 | pub struct AssocItemList { |
371 | pub(crate) syntax: SyntaxNode, | 380 | pub(crate) syntax: SyntaxNode, |
372 | } | 381 | } |
373 | impl ast::ModuleItemOwner for ItemList {} | 382 | impl AssocItemList { |
374 | impl ItemList { | ||
375 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 383 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
376 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } | 384 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } |
377 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 385 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
@@ -1336,10 +1344,10 @@ pub enum AssocItem { | |||
1336 | FnDef(FnDef), | 1344 | FnDef(FnDef), |
1337 | TypeAliasDef(TypeAliasDef), | 1345 | TypeAliasDef(TypeAliasDef), |
1338 | ConstDef(ConstDef), | 1346 | ConstDef(ConstDef), |
1347 | MacroCall(MacroCall), | ||
1339 | } | 1348 | } |
1340 | impl ast::AttrsOwner for AssocItem {} | 1349 | impl ast::AttrsOwner for AssocItem {} |
1341 | impl ast::NameOwner for AssocItem {} | 1350 | impl ast::NameOwner for AssocItem {} |
1342 | impl ast::VisibilityOwner for AssocItem {} | ||
1343 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1351 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1344 | pub enum Pat { | 1352 | pub enum Pat { |
1345 | OrPat(OrPat), | 1353 | OrPat(OrPat), |
@@ -1574,8 +1582,8 @@ impl AstNode for Visibility { | |||
1574 | } | 1582 | } |
1575 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1583 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1576 | } | 1584 | } |
1577 | impl AstNode for Abi { | 1585 | impl AstNode for Name { |
1578 | fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } | 1586 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } |
1579 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1587 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1580 | if Self::can_cast(syntax.kind()) { | 1588 | if Self::can_cast(syntax.kind()) { |
1581 | Some(Self { syntax }) | 1589 | Some(Self { syntax }) |
@@ -1585,8 +1593,19 @@ impl AstNode for Abi { | |||
1585 | } | 1593 | } |
1586 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1594 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1587 | } | 1595 | } |
1588 | impl AstNode for Name { | 1596 | impl AstNode for ItemList { |
1589 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } | 1597 | fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } |
1598 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1599 | if Self::can_cast(syntax.kind()) { | ||
1600 | Some(Self { syntax }) | ||
1601 | } else { | ||
1602 | None | ||
1603 | } | ||
1604 | } | ||
1605 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1606 | } | ||
1607 | impl AstNode for Abi { | ||
1608 | fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } | ||
1590 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1609 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1591 | if Self::can_cast(syntax.kind()) { | 1610 | if Self::can_cast(syntax.kind()) { |
1592 | Some(Self { syntax }) | 1611 | Some(Self { syntax }) |
@@ -1728,8 +1747,8 @@ impl AstNode for TypeBoundList { | |||
1728 | } | 1747 | } |
1729 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1748 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1730 | } | 1749 | } |
1731 | impl AstNode for ItemList { | 1750 | impl AstNode for AssocItemList { |
1732 | fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } | 1751 | fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_ITEM_LIST } |
1733 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1752 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1734 | if Self::can_cast(syntax.kind()) { | 1753 | if Self::can_cast(syntax.kind()) { |
1735 | Some(Self { syntax }) | 1754 | Some(Self { syntax }) |
@@ -3144,10 +3163,13 @@ impl From<TypeAliasDef> for AssocItem { | |||
3144 | impl From<ConstDef> for AssocItem { | 3163 | impl From<ConstDef> for AssocItem { |
3145 | fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } | 3164 | fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } |
3146 | } | 3165 | } |
3166 | impl From<MacroCall> for AssocItem { | ||
3167 | fn from(node: MacroCall) -> AssocItem { AssocItem::MacroCall(node) } | ||
3168 | } | ||
3147 | impl AstNode for AssocItem { | 3169 | impl AstNode for AssocItem { |
3148 | fn can_cast(kind: SyntaxKind) -> bool { | 3170 | fn can_cast(kind: SyntaxKind) -> bool { |
3149 | match kind { | 3171 | match kind { |
3150 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, | 3172 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF | MACRO_CALL => true, |
3151 | _ => false, | 3173 | _ => false, |
3152 | } | 3174 | } |
3153 | } | 3175 | } |
@@ -3156,6 +3178,7 @@ impl AstNode for AssocItem { | |||
3156 | FN_DEF => AssocItem::FnDef(FnDef { syntax }), | 3178 | FN_DEF => AssocItem::FnDef(FnDef { syntax }), |
3157 | TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), | 3179 | TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), |
3158 | CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), | 3180 | CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), |
3181 | MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }), | ||
3159 | _ => return None, | 3182 | _ => return None, |
3160 | }; | 3183 | }; |
3161 | Some(res) | 3184 | Some(res) |
@@ -3165,6 +3188,7 @@ impl AstNode for AssocItem { | |||
3165 | AssocItem::FnDef(it) => &it.syntax, | 3188 | AssocItem::FnDef(it) => &it.syntax, |
3166 | AssocItem::TypeAliasDef(it) => &it.syntax, | 3189 | AssocItem::TypeAliasDef(it) => &it.syntax, |
3167 | AssocItem::ConstDef(it) => &it.syntax, | 3190 | AssocItem::ConstDef(it) => &it.syntax, |
3191 | AssocItem::MacroCall(it) => &it.syntax, | ||
3168 | } | 3192 | } |
3169 | } | 3193 | } |
3170 | } | 3194 | } |
@@ -3515,12 +3539,17 @@ impl std::fmt::Display for Visibility { | |||
3515 | std::fmt::Display::fmt(self.syntax(), f) | 3539 | std::fmt::Display::fmt(self.syntax(), f) |
3516 | } | 3540 | } |
3517 | } | 3541 | } |
3518 | impl std::fmt::Display for Abi { | 3542 | impl std::fmt::Display for Name { |
3519 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3543 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3520 | std::fmt::Display::fmt(self.syntax(), f) | 3544 | std::fmt::Display::fmt(self.syntax(), f) |
3521 | } | 3545 | } |
3522 | } | 3546 | } |
3523 | impl std::fmt::Display for Name { | 3547 | impl std::fmt::Display for ItemList { |
3548 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3549 | std::fmt::Display::fmt(self.syntax(), f) | ||
3550 | } | ||
3551 | } | ||
3552 | impl std::fmt::Display for Abi { | ||
3524 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3553 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3525 | std::fmt::Display::fmt(self.syntax(), f) | 3554 | std::fmt::Display::fmt(self.syntax(), f) |
3526 | } | 3555 | } |
@@ -3585,7 +3614,7 @@ impl std::fmt::Display for TypeBoundList { | |||
3585 | std::fmt::Display::fmt(self.syntax(), f) | 3614 | std::fmt::Display::fmt(self.syntax(), f) |
3586 | } | 3615 | } |
3587 | } | 3616 | } |
3588 | impl std::fmt::Display for ItemList { | 3617 | impl std::fmt::Display for AssocItemList { |
3589 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3618 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3590 | std::fmt::Display::fmt(self.syntax(), f) | 3619 | std::fmt::Display::fmt(self.syntax(), f) |
3591 | } | 3620 | } |