Skip to content

Commit 9321210

Browse files
committed
Extract name kind from ERROR
The parser tells us whether the error happened in term or type position, so we can use this to provide better completion.
1 parent ace5092 commit 9321210

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dotty.tools.dotc.core.NameKinds.SimpleNameKind
1111
import dotty.tools.dotc.core.NameOps.NameDecorator
1212
import dotty.tools.dotc.core.Symbols.{defn, NoSymbol, Symbol}
1313
import dotty.tools.dotc.core.Scopes
14-
import dotty.tools.dotc.core.StdNames.nme
14+
import dotty.tools.dotc.core.StdNames.{nme, tpnme}
1515
import dotty.tools.dotc.core.TypeError
1616
import dotty.tools.dotc.core.Types.{NamedType, NameFilter, Type, takeAllFilter}
1717
import dotty.tools.dotc.printing.Texts._
@@ -45,7 +45,8 @@ object Completion {
4545
private def completionMode(path: List[Tree], pos: SourcePosition): Mode = {
4646
path match {
4747
case (ref: RefTree) :: _ =>
48-
if (ref.name == nme.ERROR) Mode.Term | Mode.Type
48+
if (ref.name == tpnme.ERROR) Mode.Type
49+
else if (ref.name == nme.ERROR) Mode.Term
4950
else if (ref.name.isTermName) Mode.Term
5051
else if (ref.name.isTypeName) Mode.Type
5152
else Mode.None

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,17 @@ class CompletionTest {
175175
|}""".withSource
176176
.completion(m1, results => assertTrue(results.nonEmpty))
177177
}
178+
179+
@Test def completeErrorKnowsKind: Unit = {
180+
code"""object Bar {
181+
| class Zig
182+
| val Zag: Int = 0
183+
| val b = 3 + Bar.${m1}
184+
|}""".withSource
185+
.completion(m1, completionItems => {
186+
val results = CodeCompletion.simplifyResults(completionItems)
187+
assertTrue(results.contains(("Zag", Field, "Int")))
188+
assertFalse(results.exists((label, _, _) => label == "Zig"))
189+
})
190+
}
178191
}

0 commit comments

Comments
 (0)