Skip to content

Fix #5460: Improve completion of import nodes #5476

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 14 commits into from
Nov 23, 2018
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dotty.tools.dotc.core.NameKinds.SimpleNameKind
import dotty.tools.dotc.core.NameOps.NameDecorator
import dotty.tools.dotc.core.Symbols.{defn, NoSymbol, Symbol}
import dotty.tools.dotc.core.Scopes
import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core.StdNames.{nme, tpnme}
import dotty.tools.dotc.core.TypeError
import dotty.tools.dotc.core.Types.{NamedType, NameFilter, Type, takeAllFilter}
import dotty.tools.dotc.printing.Texts._
Expand Down Expand Up @@ -45,7 +45,8 @@ object Completion {
private def completionMode(path: List[Tree], pos: SourcePosition): Mode = {
path match {
case (ref: RefTree) :: _ =>
if (ref.name == nme.ERROR) Mode.Term | Mode.Type
if (ref.name == tpnme.ERROR) Mode.Type
else if (ref.name == nme.ERROR) Mode.Term
else if (ref.name.isTermName) Mode.Term
else if (ref.name.isTypeName) Mode.Type
else Mode.None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,17 @@ class CompletionTest {
|}""".withSource
.completion(m1, results => assertTrue(results.nonEmpty))
}

@Test def completeErrorKnowsKind: Unit = {
code"""object Bar {
| class Zig
| val Zag: Int = 0
| val b = 3 + Bar.${m1}
|}""".withSource
.completion(m1, completionItems => {
val results = CodeCompletion.simplifyResults(completionItems)
assertTrue(results.contains(("Zag", Field, "Int")))
assertFalse(results.exists((label, _, _) => label == "Zig"))
})
}
}