Skip to content

[Interactive] Include scope completions for synthic select tree #13515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 select from `This` because in code it was `Ident`
// See example in dotty.tools.languageserver.CompletionTest.syntheticThis
case Select(qual @ This(_), _) :: _ if qual.span.isSynthetic => completer.scopeCompletions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's non-obvious why this would be needed, I suggest adding a comment with an example here (or a reference to the added test case).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

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")))
}
}