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 08aae18
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ object Completion {
val completer = new Completer(mode, prefix, pos)

val completions = path match {
case Select(qual, _) :: _ => completer.selectionCompletions(qual)
case Import(expr, _) :: _ => completer.directMemberCompletions(expr)
case (_: untpd.ImportSelector) :: Import(expr, _) :: _ => completer.directMemberCompletions(expr)
case _ => completer.scopeCompletions
// Ignore synthetic `This` because in code it was `Ident`
// See exmaple in dotty.tools.languageserver.CompletionTest.syntheticThis
case Select(qual @ This(_), _) :: _ if qual.span.isSynthetic => completer.scopeCompletions
case Select(qual, _) :: _ => completer.selectionCompletions(qual)
case Import(expr, _) :: _ => completer.directMemberCompletions(expr)
case (_: untpd.ImportSelector) :: Import(expr, _) :: _ => completer.directMemberCompletions(expr)
case _ => completer.scopeCompletions
}

val describedCompletions = describeCompletions(completions)
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 syntheticThis: 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 08aae18

Please sign in to comment.