diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-22 11:08:18 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-22 11:08:18 +0100 |
commit | 38c0a1e3331f4b2b9efc7caa20b5927874024686 (patch) | |
tree | 321dd22a931c2ca11d2e207d734f283844af656d /crates/ra_syntax/src/ptr.rs | |
parent | 76e0129a21661029dc6cdbea2412ab53efe33aa1 (diff) | |
parent | b73a978b95810b188090a37e002a22403a9067bd (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_syntax/src/ptr.rs')
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index 15a8b94cd..b0816b135 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs | |||
@@ -10,7 +10,7 @@ use crate::{ | |||
10 | /// specific node across reparses of the same file. | 10 | /// specific node across reparses of the same file. |
11 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 11 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
12 | pub struct SyntaxNodePtr { | 12 | pub struct SyntaxNodePtr { |
13 | range: TextRange, | 13 | pub(crate) range: TextRange, |
14 | kind: SyntaxKind, | 14 | kind: SyntaxKind, |
15 | } | 15 | } |
16 | 16 | ||