-
Notifications
You must be signed in to change notification settings - Fork 196
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
DustinCampbell
approved these changes
Sep 9, 2024
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionSpanExtensions.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionSpanExtensions.cs
Outdated
Show resolved
Hide resolved
This was referenced Sep 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 likeSourceText
a lot, which uses theTextChange
struct instead. This meant lots of code to convert to and from the two types. Changing the whole formatting engine over toTextChange
, and using moreTextSpan
,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[]
toImmutableArray<TextChange>
, and this let me to places where pooled array builders could be used, and places whereRange
andPosition
were used which didn't make much sense, and then the constructor forLinePosition
threw at one point because it turns out we were only using theLine
property from thePosition
that used to be used, and so never validated the characters, so that API moved toint
, 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.