Skip to content

Commit b89874b

Browse files
committed
Fix REPL completion of symbolic identifiers
Recover part of the identifier that preceded the cursor from the source, rather than from the name in the `Select` node, which might contains an encoded name that differs in length from the one in source.
1 parent 46211dd commit b89874b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/interactive/scala/tools/nsc/interactive/Global.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,8 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
12231223
def typeCompletions(tree: Tree, qual: Tree, nameStart: Int, name: Name): CompletionResult = {
12241224
val qualPos = qual.pos
12251225
val allTypeMembers = typeMembers(qualPos).toList.flatten
1226-
12271226
val positionDelta: Int = nameStart - pos.start
1228-
val subName = name.subName(0, -positionDelta)
1227+
val subName: Name = name.newName(new String(pos.source.content, nameStart, pos.start - nameStart)).encodedName
12291228
CompletionResult.TypeMembers(positionDelta, qual, tree, allTypeMembers, subName)
12301229
}
12311230
focus1 match {

test/junit/scala/tools/nsc/interpreter/CompletionTest.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ class CompletionTest {
4848
checkExact(completer, """class C { asInstanceO""")("asInstanceOf")
4949

5050
// Output is sorted
51-
assertEquals(List("prefix_aaa", "prefix_nnn", "prefix_zzz"), completer.complete("""class C { def prefix_nnn = 0; def prefix_zzz = 0; def prefix_aaa = 0; prefix_""").candidates)
51+
assertEquals(List("prefix_aaa", "prefix_nnn", "prefix_zzz"), completer.complete( """class C { def prefix_nnn = 0; def prefix_zzz = 0; def prefix_aaa = 0; prefix_""").candidates)
52+
}
53+
54+
@Test
55+
def symbolically(): Unit = {
56+
val intp = newIMain()
57+
val completer = new PresentationCompilerCompleter(intp)
58+
checkExact(completer, """class C { def +++(a: Any) = 0; def ---(a: Any) = 0; this.++""")("+++")
5259
}
5360

5461
@Test

0 commit comments

Comments
 (0)