Skip to content

Improve printing of encoded unicode chars #5764

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
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ object Completion {
nameToSymbols.map { case (name, symbols) =>
val typesFirst = symbols.sortWith((s1, s2) => s1.isType && !s2.isType)
val desc = description(typesFirst)
val label = NameTransformer.decodeIllegalChars(name.toString)
Completion(label, desc, typesFirst)
Completion(name.show, desc, typesFirst)
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import scala.tasty.util.Chars.isOperatorPart
import transform.TypeUtils._

import language.implicitConversions
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.util.{NameTransformer, SourcePosition}
import dotty.tools.dotc.ast.untpd.{MemberDef, Modifiers, PackageDef, RefTree, Template, TypeDef, ValOrDefDef}

class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
Expand Down Expand Up @@ -75,7 +75,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
}.toCommonFlags

override def nameString(name: Name): String =
if (ctx.settings.YdebugNames.value) name.debugString else name.toString
if (ctx.settings.YdebugNames.value) name.debugString else NameTransformer.decodeIllegalChars(name.toString)

override protected def simpleNameString(sym: Symbol): String =
nameString(if (ctx.property(XprintMode).isEmpty) sym.originalName else sym.name)
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/util/NameTransformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ object NameTransformer {
var i = 0
while (i < name.length) {
if (i < name.length - 5 && name(i) == '$' && name(i + 1) == 'u') {
sb.append(Integer.valueOf(name.substring(i + 2, i + 6), 16).toChar)
val numbers = name.substring(i + 2, i + 6)
try sb.append(Integer.valueOf(name.substring(i + 2, i + 6), 16).toChar)
catch {
case _: java.lang.NumberFormatException =>
sb.append("$u").append(numbers)
}
i += 6
} else {
sb.append(name(i))
Expand Down
9 changes: 9 additions & 0 deletions compiler/test-resources/repl/unicodeChars
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
scala> type →

scala> def bar: → = ???
def bar: →

scala> type `🤪`

scala> def baz: `🤪` = ???
def baz: 🤪
12 changes: 12 additions & 0 deletions language-server/test/dotty/tools/languageserver/HoverTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,16 @@ class HoverTest {
.hover(m1 to m2, hoverContent("Int(1)"))
.hover(m3 to m4, hoverContent("Int(1) @annot1 @annot2 @annot3 @annot4 @annot5"))
}

@Test def unicodeChar: Unit = {
code"""object Test {
| type →
| type `🤪`
| def ${m1}bar${m2}: → = ???
| def ${m3}baz${m4}: `🤪` = ???
|}""".withSource
.hover(m1 to m2, hoverContent("Test.→"))
.hover(m3 to m4, hoverContent("Test.🤪"))

}
}