Skip to content

Commit 802facd

Browse files
committed
[Interactive] Include scope completions for synthic select tree
Previously, in case if query matches on existing class member the returned completions were not returning symbols from scope. Fixes the following case: ```scala class Y { def bar: Unit = val argument: Int = 42 arg@@ // should return both `local.argument` and `this.arg` // but tree looks like select - `Select(This(Ident(Y)), Ident("arg"))` def arg: String = ??? } ``
1 parent 82677da commit 802facd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ object Completion {
112112
val completer = new Completer(mode, prefix, pos)
113113

114114
val completions = path match {
115-
case Select(qual, _) :: _ => completer.selectionCompletions(qual)
115+
case Select(qual, _) :: _ =>
116+
val scope = if (qual.span.isSynthetic) completer.scopeCompletions else Map.empty
117+
scope ++ completer.selectionCompletions(qual)
116118
case Import(expr, _) :: _ => completer.directMemberCompletions(expr)
117119
case (_: untpd.ImportSelector) :: Import(expr, _) :: _ => completer.directMemberCompletions(expr)
118120
case _ => completer.scopeCompletions

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,4 +857,17 @@ class CompletionTest {
857857
|}""".withSource
858858
.completion(m1, Set(("show",Method, "(using x$2: x$1.reflect.Printer[x$1.reflect.Tree]): String")))
859859
}
860+
861+
@Test def includeScopeForSyntheticThis: Unit = {
862+
code"""|class Y() {
863+
| def bar: Unit =
864+
| val argument: Int = ???
865+
| arg${m1}
866+
|
867+
| def arg: String = ???
868+
|}
869+
|""".withSource
870+
.completion(m1, Set(("arg", Method, "=> String"),
871+
("argument", Field, "Int")))
872+
}
860873
}

0 commit comments

Comments
 (0)