Skip to content

[5.0][IDE][syntax-coloring] Treat unterminated raw strings as strings for syntax coloring purposes #22925

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

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Feb 26, 2019

Cherry-pick of #22845

  • Explanation: Unterminated string literals get lexed as unknown tokens. For syntax highlighting we check if an unknown token starts with a " and highlight it as a string in order to provide feedback to the user as soon as they start writing a string. This check doesn't work for raw string literals, though (e.g. #"I am "raw" "# or ##" I am #"raw"# "##) that were introduced in this release. This patch adjusts the check to trim off any leading # characters before checking for an opening quote when determining if an unknown token should be highlighted as a string.
  • Scope: Affects syntax highlighting of raw strings the user has not yet terminated correctly
  • Issue: rdar://problem/48269826
  • Risk: Very low. This only affects the syntax highlighting of unknown tokens and the entire code change is modifying the existing check from Tok.getRawText().startswith("\"") to Tok.getRawText().ltrim('#').startswith("\"")
  • Testing: Extended the syntax highlighting regression tests with unterminated raw strings, and valid raw strings with a varied number of leading/trailing # characters and interpolations, and all existing tests pass. Also manually verified raw string highlighting works as expected with these changes in Xcode.
  • Reviewer: Xi Ge (in the master PR)

Resolves rdar://problem/48269826

…syntax coloring purposes

The existing check assumed unterminated strings started with " which is no
longer true now we have raw strings.

Resolves rdar://problem/48269826
@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes marked this pull request as ready for review February 26, 2019 23:21
@nathawes nathawes requested a review from a team as a code owner February 26, 2019 23:21
@nathawes
Copy link
Contributor Author

@swift-ci please nominate

@akyrtzi akyrtzi merged commit fb9f864 into swiftlang:swift-5.0-branch Feb 27, 2019
@nathawes nathawes deleted the unterminated-raw-string-syntax-highlighting-5.0 branch July 9, 2019 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants