You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working on formatting for .razor files, I noticed something odd. Under certain conditions, GetTextChanges would return invalid edits. I'm not sure exactly under what conditions. I was able to come up with a (somewhat) minimal repro.
Version Used:
Microsoft.CodeAnalysis 3.4.0
dotnet 3.1.101
Steps to Reproduce:
dotnet new console -o SourceTextBug
cd SourceTextBug
Replace Program.cs content with the following,
Program.cs
usingSystem;usingMicrosoft.CodeAnalysis.Text;namespaceSourceTextBug{classProgram{staticvoidMain(string[]args){varcontent=@"@functions{ public class Foo {void Method(){} }}";Console.WriteLine("Initial:");Console.WriteLine(content);Console.WriteLine();vartext=SourceText.From(content);varedits1=newTextChange[]{newTextChange(newTextSpan(39,0)," "),newTextChange(newTextSpan(42,0)," "),newTextChange(newTextSpan(57,0)," "),newTextChange(newTextSpan(58,0),"\r\n"),newTextChange(newTextSpan(64,2)," "),newTextChange(newTextSpan(69,0)," "),};varchangedText=text.WithChanges(edits1);Console.WriteLine("After first set of edits:");Console.WriteLine(changedText.ToString());Console.WriteLine();varedits2=newTextChange[]{newTextChange(newTextSpan(35,4),string.Empty),newTextChange(newTextSpan(46,4),string.Empty),newTextChange(newTextSpan(73,4),string.Empty),newTextChange(newTextSpan(88,0)," "),newTextChange(newTextSpan(90,4),string.Empty),newTextChange(newTextSpan(105,4),string.Empty),};varchangedText2=changedText.WithChanges(edits2);Console.WriteLine("After second set of edits:");Console.WriteLine(changedText2.ToString());Console.WriteLine();Console.WriteLine("Diff of final text vs original:");varchanges=changedText2.GetTextChanges(text);foreach(varchangeinchanges){Console.WriteLine(change);}}}}
FYI to @jinujoseph and @vatsalyaagrawal that this is potentially impacting ASP.NET's team to take on some ownership of the ASP.NET formatting code paths. I'm not sure if we really have an owner of this code or not. It was most recently touched in #39258 but it seems there's still some issues in it.
When working on formatting for .razor files, I noticed something odd. Under certain conditions,
GetTextChanges
would return invalid edits. I'm not sure exactly under what conditions. I was able to come up with a (somewhat) minimal repro.Version Used:
Microsoft.CodeAnalysis 3.4.0
dotnet 3.1.101
Steps to Reproduce:
dotnet new console -o SourceTextBug
cd SourceTextBug
Program.cs
content with the following,Program.cs
dotnet run
Expected Behavior:
The set of
TextChange
s produced should be valid and not overlap.Actual Behavior:
Overlapping changes are produced.
Output
Notice the two overlapping edits,
[64..66) and [62..66)
The text was updated successfully, but these errors were encountered: