Skip to content

Commit c85bc8e

Browse files
committed
Implement decodeIllegalChars
1 parent 1f6aadc commit c85bc8e

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dotty.tools.dotc.interactive
22

3+
import java.nio.charset.Charset
4+
35
import dotty.tools.dotc.ast.Trees._
46
import dotty.tools.dotc.config.Printers.interactiv
57
import dotty.tools.dotc.core.Contexts.{Context, NoContext}
@@ -10,13 +12,13 @@ import dotty.tools.dotc.core.Flags._
1012
import dotty.tools.dotc.core.Names.{Name, TermName}
1113
import dotty.tools.dotc.core.NameKinds.SimpleNameKind
1214
import dotty.tools.dotc.core.NameOps.NameDecorator
13-
import dotty.tools.dotc.core.Symbols.{defn, NoSymbol, Symbol}
15+
import dotty.tools.dotc.core.Symbols.{NoSymbol, Symbol, defn}
1416
import dotty.tools.dotc.core.Scopes
1517
import dotty.tools.dotc.core.StdNames.{nme, tpnme}
1618
import dotty.tools.dotc.core.TypeError
17-
import dotty.tools.dotc.core.Types.{NameFilter, NamedType, Type, NoType}
19+
import dotty.tools.dotc.core.Types.{NameFilter, NamedType, NoType, Type}
1820
import dotty.tools.dotc.printing.Texts._
19-
import dotty.tools.dotc.util.{NoSourcePosition, SourcePosition}
21+
import dotty.tools.dotc.util.{NameTransformer, NoSourcePosition, SourcePosition}
2022

2123
import scala.collection.mutable
2224

@@ -150,8 +152,7 @@ object Completion {
150152
nameToSymbols.map { case (name, symbols) =>
151153
val typesFirst = symbols.sortWith((s1, s2) => s1.isType && !s2.isType)
152154
val desc = description(typesFirst)
153-
val strName = name.toString
154-
val label = if (strName == "$u2192") "" else strName // TODO fix name.decode and use it
155+
val label = NameTransformer.decodeIllegalChars(name.toString)
155156
Completion(label, desc, typesFirst)
156157
}
157158
}

compiler/src/dotty/tools/dotc/util/NameTransformer.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ object NameTransformer {
5555
else name
5656
}
5757

58+
/** Decode expanded characters starting with `$u`, followed by the character's unicode expansion. */
59+
def decodeIllegalChars(name: String): String = {
60+
if (name.contains("$u")) {
61+
val sb = new mutable.StringBuilder()
62+
var i = 0
63+
while (i < name.length - 5) {
64+
if (name(i) == '$' && name(i + 1) == 'u') {
65+
sb.append(Integer.valueOf(name.substring(i + 2, i + 6), 16).toChar)
66+
i += 6
67+
} else {
68+
sb.append(name(i))
69+
i += 1
70+
}
71+
}
72+
while (i < name.length) {
73+
sb.append(name(i))
74+
i += 1
75+
}
76+
sb.result()
77+
}
78+
else name
79+
}
80+
5881
/** Replace operator symbols by corresponding expansion strings.
5982
*
6083
* @param name the string to encode

0 commit comments

Comments
 (0)