Skip to content

Commit

Permalink
[Interactive] Include scope completions for synthic select tree
Browse files Browse the repository at this point in the history
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 = ???
}
```
  • Loading branch information
dos65 committed Sep 13, 2021
1 parent 82677da commit 8a560b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ object Completion {
val completer = new Completer(mode, prefix, pos)

val completions = path match {
case Select(qual @ This(_), _) :: _ =>
val scope = if (qual.span.isSynthetic) completer.scopeCompletions else Map.empty
scope ++ completer.selectionCompletions(qual)
case Select(qual, _) :: _ => completer.selectionCompletions(qual)
case Import(expr, _) :: _ => completer.directMemberCompletions(expr)
case (_: untpd.ImportSelector) :: Import(expr, _) :: _ => completer.directMemberCompletions(expr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,17 @@ class CompletionTest {
|}""".withSource
.completion(m1, Set(("show",Method, "(using x$2: x$1.reflect.Printer[x$1.reflect.Tree]): String")))
}

@Test def includeScopeForSyntheticThis: Unit = {
code"""|class Y() {
| def bar: Unit =
| val argument: Int = ???
| arg${m1}
|
| def arg: String = ???
|}
|""".withSource
.completion(m1, Set(("arg", Method, "=> String"),
("argument", Field, "Int")))
}
}

0 comments on commit 8a560b9

Please sign in to comment.