Skip to content

Fix #4405 REPL highlight for StringLiteral #4531

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

Merged
merged 2 commits into from
May 28, 2018

Conversation

fabianpage
Copy link
Contributor

@fabianpage fabianpage commented May 15, 2018

Fix #4405.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@fabianpage
Copy link
Contributor Author

I sign the CLA

@Blaisorblade Blaisorblade changed the title fix-#4405 REPL highlight for StringLiteral Fix #4405 REPL highlight for StringLiteral May 15, 2018
@Blaisorblade
Copy link
Contributor

Thanks @fabianpage, CLA signed. I'll leave the actual review to somebody else.

@allanrenucci
Copy link
Contributor

@fabianpage Can you please add test cases to SyntaxHighlightingTests. Some suggestions:

s"Hello"
s"Hello $name!"
raw"Hello"

@fabianpage
Copy link
Contributor Author

@allanrenucci I think these 3 tests are enough or do you think it need's some more?

@@ -50,6 +50,9 @@ class SyntaxHighlightingTests {
def strings = {
// For some reason we currently use literal color for string
test("\"Hello\"", "<L|\"Hello\">")
test("s\"Hello\"", "s<L|\"Hello\">")
test("s\"Hello $name\"", "s<L|\"Hello <V|$name<L|\">")
test("raw\"Hello\"", "raw<L|\"Hello\">")
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add one more with triple quotes: s"""Hello"""

case _ => false
}

def tryInterpolatorPrefix(n: Char, remaining: Stream[Char]): Option[String] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't fully understand what you are doing below. Could you explain in detail?

The previous solution didn't work because it assumed that the interpolator prefix was on length 1. So we just need to consume characters as long as they are valid prefixes. Something like:

val (prefix, after) = remaining.span(interpolationPrefixes.contains)
if (after.startsWith("\"")) {
   ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem was that it also didn't supported string literals with symbols in it. something like a_+""

@fabianpage
Copy link
Contributor Author

@allanrenucci back from Berlin. Should i continue working on this PR or will #4537 be merged soon and my change is not needed any more?

@allanrenucci
Copy link
Contributor

Not sure when #4537 will be merged. But yes, the fix in it is more generic and it will replace all the actual code that does syntax highlighting.

@fabianpage
Copy link
Contributor Author

@allanrenucci Then i will try to finish this PR. Should i try to change the existing code to only support longer interpreter suffix?

@allanrenucci
Copy link
Contributor

Should i try to change the existing code to only support longer interpreter suffix?

Sounds good! Then we can get this PR merged before #4537

@fabianpage
Copy link
Contributor Author

@allanrenucci What do you think? I think this way there are only minimal changes.

appendString('"', next == "\"\"\"")
val (prefix, after) = remaining.span(interpolationPrefixes.contains)
if (after.startsWith("\"")) {
newBuf ++= (n +: prefix)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will create an intermediate collection, prefer:

newBuf += n ++= prefix

@allanrenucci allanrenucci merged commit c44c9bb into scala:master May 28, 2018
@allanrenucci
Copy link
Contributor

Thanks @fabianpage! 🎉

@fabianpage fabianpage deleted the fix-#4405 branch August 16, 2018 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants