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

Switch formatting engine over to using TextChange instead of TextEdit #10855

Merged
merged 16 commits into from
Sep 10, 2024

Conversation

davidwengier
Copy link
Contributor

@davidwengier davidwengier commented Sep 9, 2024

Fixes #10842

The formatting self-nerd-sniping continues.

The formatting engine was written to use the LSP TextEdit class, which makes some sense, but also uses Roslyn APIs like SourceText a lot, which uses the TextChange struct instead. This meant lots of code to convert to and from the two types. Changing the whole formatting engine over to TextChange, and using more TextSpan, LinePositionSpan etc. removes a lot of this code. It also makes a lot more sense in cohosting, to boot.

I wouldn't claim that I've gone through and improved the perf of the formatting engine, but rather I've use the changes to lead me to things that need fixing. ie, I started out moving from TextEdit[] to ImmutableArray<TextChange>, and this let me to places where pooled array builders could be used, and places where Range and Position were used which didn't make much sense, and then the constructor for LinePosition threw at one point because it turns out we were only using the Line property from the Position that used to be used, and so never validated the characters, so that API moved to int, etc.

TL;DR the commits tell the story, and there could well be something I missed, if it never came across my plate for another reason.

This commit wasn't purely mechanical, but it was close. Just making things mostly compile, no optimizations or anything yet, and probably still a bunch more renames to come.
Haven't run the tests yet :)
All tests pass!
Most places already passed an ImmutableArray here. I left the method itself being an iterator, as 50% of callers need an ImmutableArray result, but the other 50% need an array, so no clear winner.
All callers did the conversion anyway
@davidwengier davidwengier requested a review from a team as a code owner September 9, 2024 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert formatting engine to TextChange and ImmutableArray
3 participants