Skip to content

Conversation

@nicolasstucki
Copy link
Contributor

No description provided.

hb.toString
case str: String if ctx.settings.color.value != "never" =>
new String(SyntaxHighlighting(str).toArray)
if (str.matches(".*\u001b\\[.*?m.*")) str // was already colored by some other printer
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems very expensive. Error messages are colored because of the hl string interpolator. The interpolator call show on its arguments. Can we instead disable syntax highlighting when calling show for the argument of the interpolator?

Copy link
Contributor

Choose a reason for hiding this comment

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

Redefining hl as:

def hl(args: Any*)(implicit ctx: Context): String = {
  val nestedCtx = ctx.fresh.setSetting(ctx.settings. color, true)
  new SyntaxFormatter(sc).assemble(args)(nestedCtx).stripMargin
)

should work. I am wondering how expensive is ctx.fresh though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might work if the argument in args is still of type Text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point it is too late. I created instead an AlreadyColored that fixes the issue for each specific case. It should be added to any printed tree that is already colored.

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

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

Otherwise, LGTM

new String(SyntaxHighlighting(str).toArray)
case _ => super.showArg(arg)
case x :: xs =>
showArg(x) + (if (xs.isEmpty) "" else ", " + showArg(xs))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove this special case. This seems completely arbitrary to special case List.
If a user want to pretty print a List like this, then he should do it himself.

@nicolasstucki nicolasstucki merged commit 6de4253 into scala:master Dec 12, 2017
@allanrenucci allanrenucci deleted the fix-#3614 branch December 12, 2017 10:33
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