-
Notifications
You must be signed in to change notification settings - Fork 78
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
experimental HiFi tree diff algorithm for use with quick-fixes and refactoring commands in the IDE #2031
base: main
Are you sure you want to change the base?
Conversation
…factoring commands in the IDE
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2031 +/- ##
=======================================
- Coverage 49% 49% -1%
+ Complexity 6311 6299 -12
=======================================
Files 664 664
Lines 59636 59637 +1
Branches 8648 8648
=======================================
- Hits 29480 29468 -12
- Misses 27936 27955 +19
+ Partials 2220 2214 -6 ☔ View full report in Codecov by Sentry. |
@tvdstorm @DavyLandman I don't have the energy to finish this now, so I'm parking it here until I do. I wanted you to know it exists, because low-fidelity rewrites are a common issue we have to solve and because refactoring and quick-fixes in VScode are now under our fingertips. |
Cool stuff 👍 |
…se indentation in O(1)
This transforms a pair of parse Trees <original, rewritten> to a list[TextEdit]s. The resulting
TextEdits are ready for use in VScode extensions via LSP features in util::LanguageServer and
util::IDEServices.
The single pass parse tree recursion maps sub-tree and sub-list differences to textual differences in a special way.
It lifts on the semantics of special parse tree non-terminals (literals, lexicals, separators) to ignore certain
superfluous changes made in the rewritten tree. As a result the edited source text retains more of
its original layout, including indentation and comments, as compared to yielding the
rewritten parse tree to a string and replacing the entire file.
Especially with separated lists this algorithm does amazing work. Suppose you have a target pattern:
<Element e>, <{Element ","}* newElems, <Element f>
andnewElems
happens to be empty, then:e
and before thef
eventhough these have been replaced by the concrete target pattern.
original list where possible.
The smaller diffs are not only good for high-fidelity in general, but also in particular smaller diffs are essential for providing interactive preview and undo features in the IDE. This PR enables language engineers to use parse tree rewriting rather than collecting the text edits themselves.
TODO's: