Switch formatting engine over to using TextChange instead of TextEdit#10855
Merged
davidwengier merged 16 commits intodotnet:mainfrom Sep 10, 2024
Merged
Switch formatting engine over to using TextChange instead of TextEdit#10855davidwengier merged 16 commits intodotnet:mainfrom
TextChange instead of TextEdit#10855davidwengier merged 16 commits intodotnet:mainfrom
Conversation
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
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionSpanExtensions.cs
Show resolved
Hide resolved
This was referenced Sep 12, 2024
davidwengier
added a commit
that referenced
this pull request
Feb 3, 2025
This file contains hidden or 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
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
TextEditclass, which makes some sense, but also uses Roslyn APIs likeSourceTexta lot, which uses theTextChangestruct instead. This meant lots of code to convert to and from the two types. Changing the whole formatting engine over toTextChange, and using moreTextSpan,LinePositionSpanetc. 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 whereRangeandPositionwere used which didn't make much sense, and then the constructor forLinePositionthrew at one point because it turns out we were only using theLineproperty from thePositionthat 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.