Skip to content

Fix #3932: ANSI color leak in repl #4462

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 12, 2018

Conversation

OlivierBlanvillain
Copy link
Contributor

No description provided.

@allanrenucci
Copy link
Contributor

I believe the REPL had its syntax highlighting mechanism before we introduced colors in Printer.

I think a better fix is to make the REPL only relies on the mechanism from the Printers (i.e. replace call to SyntaxHighlighting in ReplDriver by call to show).

@OlivierBlanvillain
Copy link
Contributor Author

OlivierBlanvillain commented May 4, 2018

Unless we want to stop highlighting code "as it's been written", we won't be able to get ride of the REPL syntax highlighting.

Given thaz we have two syntax highlighters, it's not clear to me what we would gain by using the one from RefinedPrinter over the REPL one.

@allanrenucci
Copy link
Contributor

The syntax highlighter from the printers is supposed to be more fined grained (it knows the semantic of what it is printing) and is also configurable (using the compiler options).

The issue in #3932 is because we are currently calling SyntaxHighlighting.apply on the result of a show and it is coloring twice. We call show anyway, so why not let it do syntax highlighting.

You are right for code "as it's been written", we have to keep using SyntaxHighlighting.apply because in this case we consume a String and not a Tree or a Symbol. However this is not done in the ReplDriver but in the AmonniteReader. I didn't mean to change that

@smarter
Copy link
Member

smarter commented May 4, 2018

You are right for code "as it's been written", we have to keep using SyntaxHighlighting.apply because in this case we consume a String and not a Tree or a Symbol.

Side-note: we could use the regular Parser to handle this String. Our parser is supposed to recover from errors (needed for the IDE to work well), so it could also work for syntax highlighting as you type in the REPL.

@@ -0,0 +1,2 @@
scala> def f(erased a: Int): Int = ???
def f(erased a: Int): Int
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test case for erased implicit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -169,7 +169,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
"<noprefix>"
case tp: MethodType =>
changePrec(GlobalPrec) {
(if (tp.isImplicitMethod) "(implicit " else "(") ~ paramsText(tp) ~
("(" + (if (tp.isImplicitMethod) "implicit " else "")
+ (if (tp.isErasedMethod) "erased " else "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Print erased first. erased implicit seems to be better than implicit erased based on the feedback I have received in the past.

@nicolasstucki
Copy link
Contributor

@OlivierBlanvillain is this still a WIP?

@OlivierBlanvillain
Copy link
Contributor Author

It's good to go!

@OlivierBlanvillain OlivierBlanvillain merged commit c38a6b7 into scala:master May 12, 2018
@allanrenucci allanrenucci deleted the fix-3932 branch May 12, 2018 10:09
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