Skip to content

Commit 586458b

Browse files
committed
Fix completion
1 parent a010017 commit 586458b

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,20 +1574,15 @@ object Parsers {
15741574

15751575
/** SimpleType ::= SimpleType TypeArgs
15761576
* | SimpleType `#' id
1577-
* | Singleton `.' id
1577+
* | SimpleClassType
15781578
* | Singleton `.' type
1579-
* | `(' ArgTypes `)'
15801579
* | `_' TypeBounds
15811580
* | Refinement
15821581
* | Literal
15831582
* | ‘$’ ‘{’ Block ‘}’
15841583
*/
15851584
def simpleType(): Tree = simpleTypeRest {
1586-
if (in.token == LPAREN)
1587-
atSpan(in.offset) {
1588-
makeTupleOrParens(inParens(argTypes(namedOK = false, wildOK = true)))
1589-
}
1590-
else if (in.token == LBRACE)
1585+
if in.token == LBRACE then
15911586
atSpan(in.offset) { RefinedTypeTree(EmptyTree, refinement()) }
15921587
else if (isSimpleLiteral) { SingletonTypeTree(literal(inType = true)) }
15931588
else if isIdent(nme.raw.MINUS) && numericLitTokens.contains(in.lookahead.token) then
@@ -1611,21 +1606,30 @@ object Parsers {
16111606
else if (isSplice)
16121607
splice(isType = true)
16131608
else
1614-
singletonCompletion(simpleRef())
1609+
simpleClassType()
16151610
}
16161611

1617-
/** Singleton ::= SimpleRef
1618-
* | Singleton ‘.’ id
1612+
/** SimpleClassType ::= [Singleton ‘.’] id
1613+
* | ‘(’ ArgTypes ‘)’
1614+
* Singleton ::= SimpleRef
1615+
* | Singleton ‘.’ id
16191616
*/
1620-
def singletonCompletion(t: Tree): Tree =
1621-
if in.token == DOT then
1622-
in.nextToken()
1623-
if in.token == TYPE then
1624-
in.nextToken()
1625-
atSpan(startOffset(t)) { SingletonTypeTree(t) }
1626-
else
1627-
singletonCompletion(idSelector(t))
1628-
else convertToTypeId(t)
1617+
def simpleClassType(): Tree =
1618+
if in.token == LPAREN then
1619+
atSpan(in.offset) {
1620+
makeTupleOrParens(inParens(argTypes(namedOK = false, wildOK = true)))
1621+
}
1622+
else
1623+
def singletonCompletion(t: Tree): Tree =
1624+
if in.token == DOT then
1625+
in.nextToken()
1626+
if in.token == TYPE then
1627+
in.nextToken()
1628+
atSpan(startOffset(t)) { SingletonTypeTree(t) }
1629+
else
1630+
singletonCompletion(idSelector(t))
1631+
else convertToTypeId(t)
1632+
singletonCompletion(simpleRef())
16291633

16301634
private def simpleTypeRest(t: Tree): Tree = in.token match {
16311635
case HASH => simpleTypeRest(typeProjection(t))
@@ -3145,13 +3149,15 @@ object Parsers {
31453149
mkTree(qual, ImportSelector(wildcardSelectorId()) :: Nil)
31463150
case LBRACE =>
31473151
mkTree(qual, inBraces(importSelectors(idOK = true)))
3148-
case _ =>
3152+
case IDENTIFIER | BACKQUOTED_IDENT =>
31493153
val start = in.offset
31503154
val name = ident()
31513155
if in.token == DOT then
31523156
importSelection(atSpan(startOffset(qual), start) { Select(qual, name) })
31533157
else
31543158
mkTree(qual, ImportSelector(atSpan(start) { Ident(name) }) :: Nil)
3159+
case _ =>
3160+
idSelector(qual) // this will produce an error, which can lead to a completion in the repl
31553161

31563162
() => importSelection(simpleRef())
31573163
}

compiler/test/dotty/tools/repl/TabcompleteTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class TabcompleteTests extends ReplTest {
100100
@Test def importScala = fromInitialState { implicit s =>
101101
val comp = tabComplete("import scala.")
102102
// check that there are no special symbols leaked: <byname>, <special-ops>, ...
103-
assertEquals(comp.find(_.startsWith("<")), Some("<:<"))
103+
assertEquals(Some("<:<"), comp.find(_.startsWith("<")))
104104
assert(!comp.contains("package"))
105105
}
106106

0 commit comments

Comments
 (0)