neovim icon indicating copy to clipboard operation
neovim copied to clipboard

Structural Editing : Tracking Issue

Open vigoux opened this issue 4 years ago • 4 comments

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.

vigoux avatar Sep 03 '20 13:09 vigoux

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.

bfredl avatar Sep 03 '20 15:09 bfredl

see https://github.com/vigoux/architext.nvim for some exciting in progress work

bfredl avatar Sep 04 '20 08:09 bfredl

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.

bfredl avatar Sep 04 '20 11:09 bfredl

Related https://github.com/neovim/neovim/issues/1767

janlazo avatar Dec 26 '20 16:12 janlazo