neovim
neovim copied to clipboard
Structural Editing : Tracking Issue
Structural editing
Currently, we use treesitter as an overlay over buffer contents. While this is already really cool, what would be better is being able to edit the tree itself and change the content of the buffer, keeping it in a valid state syntactically speaking : this is Structural Editing.
We can think of two way of using it :arrow_double_down:
- Inserting things in the buffer, and keeping it in a valid state, think of it as some kind of snippet
- Changing multiple parts of the tree at the same time, by moving nodes around, like some really powerful search and replace
Blockers
We need the insights of @maxbrunsfeld here, because the relation between text and tree is only one way as of today (and from what we know), but we don't have a way to edit the tree itself, and dump the new text generated from there.
Furthermore, we would need to insert partially complete nodes, like a binary_expression
node looking like
binary_expression
left: MISSING
right: MISSING
So that one can go down in this tree by adding the nodes one by one.
what we would need is some textual representation that directly maps to any missing element of the tree-sitter grammar. So we can have a buffer with somehing like x = funccal(a, b + {expr-hole}, c);
where {expr-hole}
is an unambiguous representation of a missing expression node.
see https://github.com/vigoux/architext.nvim for some exciting in progress work
Tentatively pushing this ahead to 0.5. 0.5 should contain all the core code needed to make architext.nvim the best possible experience it could be.
Related https://github.com/neovim/neovim/issues/1767