aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/complete_postfix.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-22 11:08:18 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-22 11:08:18 +0100
commit38c0a1e3331f4b2b9efc7caa20b5927874024686 (patch)
tree321dd22a931c2ca11d2e207d734f283844af656d /crates/ra_ide_api/src/completion/complete_postfix.rs
parent76e0129a21661029dc6cdbea2412ab53efe33aa1 (diff)
parentb73a978b95810b188090a37e002a22403a9067bd (diff)
Merge #1184
1184: Start structured editing API r=matklad a=matklad I think I finally understand how to provide nice, mutable structured editing API on top of red-green trees. The problem I am trying to solve is that any modification to a particular `SyntaxNode` returns an independent new file. So, if you are editing a struct literal, and add a field, you get back a SourceFile, and you have to find the struct literal inside it yourself! This happens because our trees are immutable, but have parent pointers. The main idea here is to introduce `AstEditor<T>` type, which abstracts away that API. So, you create an `AstEditor` for node you want to edit and call various `&mut` taking methods on it. Internally, `AstEditor` stores both the original node and the current node. All edits are applied to the current node, which is replaced by the corresponding node in the new file. In the end, `AstEditor` computes a text edit between old and new nodes. Note that this also should sole a problem when you create an anchor pointing to a subnode and mutate the parent node, invalidating anchor. Because mutation needs `&mut`, all anchors must be killed before modification. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_postfix.rs')
-rw-r--r--crates/ra_ide_api/src/completion/complete_postfix.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs
index 4dfa5f176..278b1b797 100644
--- a/crates/ra_ide_api/src/completion/complete_postfix.rs
+++ b/crates/ra_ide_api/src/completion/complete_postfix.rs
@@ -40,7 +40,7 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
40 ctx, 40 ctx,
41 "match", 41 "match",
42 "match expr {}", 42 "match expr {}",
43 &format!("match {} {{\n${{1:_}} => {{$0\\}},\n}}", receiver_text), 43 &format!("match {} {{\n ${{1:_}} => {{$0\\}},\n}}", receiver_text),
44 ) 44 )
45 .add_to(acc); 45 .add_to(acc);
46 postfix_snippet( 46 postfix_snippet(