Skip to content
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

syncToText: Support reviving lost nodes #11866

Open
kazcw opened this issue Dec 13, 2024 · 0 comments
Open

syncToText: Support reviving lost nodes #11866

kazcw opened this issue Dec 13, 2024 · 0 comments

Comments

@kazcw
Copy link
Contributor

kazcw commented Dec 13, 2024

syncToText applies a text edit to an AST. Currently, it uses a heuristic that tries to maintain identities of nodes from the state before the edit in the state after the edit. There are some cases that occur in practice that it is impossible for such a heuristic to address, especially occurring when using the code editor (which commits changes frequently).

When typing in the code editor it is common for a series of character edits that, as a whole, result in a state that is syntactically similar to the original state, to pass through a state which is syntactically very different from the original state, and from the final state. Because of this, a syncToCode that tries to preserve identity during each incremental step can lose identities (node positions, etc) that would have been preserved by a syncToCode from the initial state directly to the final state. However, incremental commit is usually desirable (outside of some exceptional cases; see #11865).

We can reconcile incremental commit with this "big picture" view of identity preservation by broadening the inputs to the syncToCode heuristic: When seeking identities to preserve in the output, the algorithm should look not only at the current state, but at a pool of recent states--then it would be able to see past transient structural changes to maintain node identities (and metadata).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

2 participants