Skip to content
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

Merged
merged 9 commits into from
Apr 3, 2017

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Apr 1, 2017

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.

@CyrusNajmabadi
Copy link
Member Author

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)
Copy link
Member

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));
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#fixed.

@CyrusNajmabadi
Copy link
Member Author

@Pilchie Ready for another review.

@CyrusNajmabadi CyrusNajmabadi merged commit 6dd6dda into dotnet:master Apr 3, 2017
@CyrusNajmabadi CyrusNajmabadi deleted the codeCleanupErrors2 branch April 3, 2017 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants