-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Don't perform 'commit cleanup' on regions of code with syntax errors *and* multi-line strings. #18372
Don't perform 'commit cleanup' on regions of code with syntax errors *and* multi-line strings. #18372
Conversation
Tagging @dotnet/roslyn-ide @Pilchie |
@@ -12,10 +15,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CaseCorrecting | |||
Private Async Function TestAsync(input As XElement, expected As XElement, Optional interProject As Boolean = False) As Tasks.Task | |||
If (interProject) Then | |||
Await TestAsync(input, expected.NormalizedValue) | |||
Await TestAsync(input, expected.NormalizedValue) |
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.
We just did this twice for fun? @heejaechang do you know why this was here?
@@ -25,13 +25,13 @@ internal interface ICodeCleanerService : ILanguageService | |||
/// <summary> | |||
/// This will run all provided code cleaners in an order that is given to the method. | |||
/// </summary> | |||
Task<Document> CleanupAsync(Document document, ImmutableArray<TextSpan> spans, ImmutableArray<ICodeCleanupProvider> providers, CancellationToken cancellationToken); | |||
Task<Document> CleanupAsync(Document document, ImmutableArray<TextSpan> spans, ImmutableArray<ICodeCleanupProvider> providers, CancellationToken cancellationToken = default(CancellationToken)); |
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.
This shouldn't be optional on an internal interface.
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.
sure.
|
||
Private Sub ProcessToken(token As SyntaxToken, result As ArrayBuilder(Of TextSpan)) | ||
If token.ContainsDiagnostics Then | ||
Dim parentMultiLineNode = GetMultiLineContainer(token.Parent) |
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.
For each token, we walk up and then back down to all the Descendant tokens? Is there something better we can do here?
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.
For each token that contains a syntax diagnostic, yes.
One thing we could potentially do is just skip tokens that intersect the last reported bad span. That seems like an easy check to add.
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.
#fixed.
@Pilchie Ready for another review. |
c0e04c5
to
97a35ca
Compare
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems?id=397014&triage=true&_a=edit
Because VB automatically makes an unterminated string into a multi-line string it's easily possible for someone to not terminate a string, and cause that to wildly change how code is parsed. Specifically, the unterminated string will eventually terminate at the start of the next string in the file. And the contents of that next string will then be parsed as code.
If we then cleanup this code, we end up really screwing with text that user intends to be the contents of a string literal (i.e. text like "as" gets corrected to "As" and so on).
To avoid this, we determine spans of code that we consider off-limits while cleaning things up. Right now that includes regions of code that have syntax errors and which contain multiline strings. This is a general heuristic that works well, but which can be tweaked/augmented in the future if we run into more cases where we do not want to cleanup.