Skip to content

Do not perform completion on higher kinded trees #13700

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 3 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ object Completion {
val completions = path match {
// 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
case Select(qual, _) :: _ => completer.selectionCompletions(qual)
case Import(expr, _) :: _ => completer.directMemberCompletions(expr)
case (_: untpd.ImportSelector) :: Import(expr, _) :: _ => completer.directMemberCompletions(expr)
case _ => completer.scopeCompletions
case Select(qual @ This(_), _) :: _ if qual.span.isSynthetic => completer.scopeCompletions
case Select(qual, _) :: _ if !qual.tpe.hasSimpleKind => Map.empty
case Select(qual, _) :: _ => completer.selectionCompletions(qual)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend swapping these 2 cases to avoid the unnecessary negation:

Suggested change
case Select(qual, _) :: _ if !qual.tpe.hasSimpleKind => Map.empty
case Select(qual, _) :: _ => completer.selectionCompletions(qual)
case Select(qual, _) :: _ if qual.tpe.hasSimpleKind => completer.selectionCompletions(qual)
case Select(qual, _) :: _ => Map.empty

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 @@ -169,3 +169,21 @@ class CustomCompletionTests extends DottyTest:

assert(offset == prefix.length)
assert(labels.contains("scala.Function2"))

@Test def i12465_hkt(): Unit =
Copy link
Contributor

Choose a reason for hiding this comment

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

Move these tests to CompletionTest.scala where they can be written in a much more concise way:

  @Test def i12465_hkt: Unit =
    code"""???.asInstanceOf[scala.collection.Seq].${m1}""".withSource
      .completion(m1, Set())

  @Test def i12465_hkt_alias: Unit =
    code"""???.asInstanceOf[Seq].${m1}""".withSource
      .completion(m1, Set())

val prefix = "???.asInstanceOf[scala.collection.Seq]"
val input = prefix + "."

val (offset, completions0) = completions(input)
val labels = completions0.map(_.label)

assert(labels.isEmpty)

@Test def i12465_hkt_alias(): Unit =
val prefix = "???.asInstanceOf[Seq]"
val input = prefix + "."

val (offset, completions0) = completions(input)
val labels = completions0.map(_.label)

assert(labels.isEmpty)