-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Relax the requirement in WithChanges that changes be ordered #26798
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -633,7 +633,19 @@ public virtual SourceText WithChanges(IEnumerable<TextChange> changes) | |
| // there can be no overlapping changes | ||
| if (change.Span.Start < position) | ||
| { | ||
| throw new ArgumentException(CodeAnalysisResources.ChangesMustBeOrderedAndNotOverlapping, nameof(changes)); | ||
| // Handle the case of unordered changes by sorting the input and retrying. This is inefficient, but | ||
| // downstream consumers have been known to hit this case in the past and we want to avoid crashes. | ||
| // https://github.com/dotnet/roslyn/pull/26339 | ||
| if (change.Span.End <= changeRanges.Last().Span.Start) | ||
|
||
| { | ||
| changes = from c in changes | ||
| where !c.Span.IsEmpty || c.NewText?.Length > 0 | ||
| orderby c.Span | ||
| select c; | ||
|
||
| return WithChanges(changes); | ||
|
||
| } | ||
|
|
||
| throw new ArgumentException(CodeAnalysisResources.ChangesMustNotOverlap, nameof(changes)); | ||
| } | ||
|
|
||
| var newTextLength = change.NewText?.Length ?? 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there no tests for the exceptional behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
➡️ Tests are included for both normal and exceptional behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please point me to tests for the exceptional behavior? Are those existing tests?
In reply to: 187682548 [](ancestors = 187682548)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only test I could find is one existing test
TestChangedTextWithMultipleOverlappingChangesIn reply to: 188384892 [](ancestors = 188384892,187682548)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gafter Yes, that is the test for the condition which is still a failure