Skip to content

implement structured editing API #779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matklad opened this issue Feb 10, 2019 · 3 comments
Closed

implement structured editing API #779

matklad opened this issue Feb 10, 2019 · 3 comments
Labels
E-hard fun A technically challenging issue with high impact

Comments

@matklad
Copy link
Member

matklad commented Feb 10, 2019

Currently, the API to modify source file is based on text edits: the user of the API should specify which text ranges should be replaced with which text.

We are primarily dealing with syntax trees, so having APIs which work directly on syntax trees should be useful. Specifically, we need three kinds of "well-typed" API for every ast node:

  • a factory/builder API to create node from components
  • a "setter" API which allows to change an existing node in arbitrary ways
  • a high-level DWIM API for semantic modification (ie, add a new field to a struct, and figure out appropriate placing and spacing automatically)

A good inspiration is, as usual, Swift.

Note that the precise shape of the API is not trivial: because tree contains parent pointers, just mutating node in place probably will not work. I think we should have a functional-style with_* APIs which return a copy of the node with None parent.

A possibly interesting first target for the API would be "merge import" action, which replaces use foo::bar; use foo::baz; with use foo::{bar, baz};. I imagine a nice structural editing API should allow to write this in "merge two imports, repeat" style, without computing a single global edit.

@matklad matklad added E-hard fun A technically challenging issue with high impact labels Feb 10, 2019
@eulerdisk
Copy link
Contributor

As I said in #762, can all the builders/setters be autogenerated from the grammar ?
@matklad Is there something that prevents it?

@matklad
Copy link
Member Author

matklad commented Feb 11, 2019

Yep, level 1 and 2 API can and should be generated from the grammar.ron

@matklad
Copy link
Member Author

matklad commented Jul 15, 2020

We have something like this in edit.rs and make.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-hard fun A technically challenging issue with high impact
Projects
None yet
Development

No branches or pull requests

2 participants