diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-09-21 10:06:24 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-21 10:06:24 +0100 |
commit | 3b52d3181a44a0ccedd30c52e70ce84231918e72 (patch) | |
tree | 0cf70a2a1d5db2b7afa39dafcb0fcd72ba05dc4d /crates/syntax/src | |
parent | e70cf706bb7c6c07e8c33b537ad24e5333aa5e75 (diff) | |
parent | 7d90bb1f47e1ab6f0ac1d7a042d7161295cf9320 (diff) |
Merge #6043
6043: Allow missing trait members assist without needing braces r=matklad a=M-J-Hooper
Assist to complete missing items when implementing a trait does not appear without impl def braces (see #5144 ).
The reason behind this was that this assist is based on `ast::AssocItemList` which only appears in the AST after the braces are added to the impl def.
Instead of relying on and replacing the item list, we now instead replace the entire `ast::Impl` and add the item list if its missing.
Co-authored-by: Matt Hooper <[email protected]>
Diffstat (limited to 'crates/syntax/src')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 16 | ||||
-rw-r--r-- | crates/syntax/src/ast/make.rs | 4 |
2 files changed, 20 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 45cf31f13..dda0a0319 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs | |||
@@ -93,6 +93,22 @@ where | |||
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | impl ast::Impl { | ||
97 | #[must_use] | ||
98 | pub fn with_assoc_item_list(&self, items: ast::AssocItemList) -> ast::Impl { | ||
99 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); | ||
100 | if let Some(old_items) = self.assoc_item_list() { | ||
101 | let to_replace: SyntaxElement = old_items.syntax().clone().into(); | ||
102 | to_insert.push(items.syntax().clone().into()); | ||
103 | self.replace_children(single_node(to_replace), to_insert) | ||
104 | } else { | ||
105 | to_insert.push(make::tokens::single_space().into()); | ||
106 | to_insert.push(items.syntax().clone().into()); | ||
107 | self.insert_children(InsertPosition::Last, to_insert) | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
96 | impl ast::AssocItemList { | 112 | impl ast::AssocItemList { |
97 | #[must_use] | 113 | #[must_use] |
98 | pub fn append_items( | 114 | pub fn append_items( |
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 6868feed9..4a0ffcbb0 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -21,6 +21,10 @@ pub fn ty(text: &str) -> ast::Type { | |||
21 | ast_from_text(&format!("impl {} for D {{}};", text)) | 21 | ast_from_text(&format!("impl {} for D {{}};", text)) |
22 | } | 22 | } |
23 | 23 | ||
24 | pub fn assoc_item_list() -> ast::AssocItemList { | ||
25 | ast_from_text("impl C for D {};") | ||
26 | } | ||
27 | |||
24 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { | 28 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { |
25 | ast_from_text(&format!("use {};", name_ref)) | 29 | ast_from_text(&format!("use {};", name_ref)) |
26 | } | 30 | } |