Skip to content

Commit 86bf70d

Browse files
committed
Remove cases which are impossible to match
1 parent 26d3808 commit 86bf70d

File tree

6 files changed

+51
-66
lines changed

6 files changed

+51
-66
lines changed

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

+9-27
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,20 @@ object Completion:
9090

9191
val completionSymbolKind: Mode =
9292
path match
93-
case untpd.Ident(_) :: untpd.Import(_, _) :: _ => Mode.ImportOrExport
94-
case untpd.Ident(_) :: (_: untpd.ImportSelector) :: _ => Mode.ImportOrExport
95-
case untpd.Literal(Constants.Constant(_: String)) :: _ => Mode.Term // literal completions
93+
case untpd.Ident(_) :: (_: untpd.ImportSelector) :: _ => Mode.ImportOrExport // import scala.@@
94+
case untpd.Ident(_) :: (_: untpd.ImportOrExport) :: _ => Mode.ImportOrExport | Mode.Scope // import TrieMa@@
95+
96+
case untpd.Literal(Constants.Constant(_: String)) :: _ => Mode.Term | Mode.Scope // literal completions
9697
case (ref: untpd.RefTree) :: _ =>
97-
if (ref.name.isTermName) Mode.Term
98-
else if (ref.name.isTypeName) Mode.Type
99-
else Mode.None
98+
val maybeSelectMembers = if ref.isInstanceOf[untpd.Select] then Mode.Member else Mode.Scope
10099

101-
case (sel: untpd.ImportSelector) :: _ =>
102-
if sel.imported.span.contains(pos.span) then Mode.ImportOrExport
103-
else Mode.None // Can't help completing the renaming
100+
if (ref.name.isTermName) Mode.Term | maybeSelectMembers
101+
else if (ref.name.isTypeName) Mode.Type | maybeSelectMembers
102+
else Mode.None
104103

105-
case (_: untpd.ImportOrExport) :: _ => Mode.ImportOrExport
106104
case _ => Mode.None
107105

108-
val completionKind: Mode =
109-
path match
110-
case Nil | (_: untpd.PackageDef) :: _ => Mode.None
111-
case untpd.Ident(_) :: (_: untpd.ImportSelector) :: _ => Mode.Member
112-
case (_: untpd.Select) :: _ => Mode.Member
113-
case _ => Mode.Scope
114-
115-
completionSymbolKind | completionKind
106+
completionSymbolKind
116107

117108
/** When dealing with <errors> in varios palces we check to see if they are
118109
* due to incomplete backticks. If so, we ensure we get the full prefix
@@ -141,18 +132,10 @@ object Completion:
141132
i + 1
142133

143134
path match
144-
case (sel: untpd.ImportSelector) :: _ =>
145-
completionPrefix(sel.imported :: Nil, pos)
146-
147135
case untpd.Ident(_) :: (sel: untpd.ImportSelector) :: _ if !sel.isGiven =>
148136
if sel.isWildcard then pos.source.content()(pos.point - 1).toString
149137
else completionPrefix(sel.imported :: Nil, pos)
150138

151-
case (tree: untpd.ImportOrExport) :: _ =>
152-
tree.selectors.find(_.span.contains(pos.span)).map: selector =>
153-
completionPrefix(selector :: Nil, pos)
154-
.getOrElse("")
155-
156139
// Foo.`se<TAB> will result in Select(Ident(Foo), <error>)
157140
case (select: untpd.Select) :: _ if select.name == nme.ERROR =>
158141
checkBacktickPrefix(select.source.content(), select.nameSpan.start, select.span.end)
@@ -211,7 +194,6 @@ object Completion:
211194
case tpd.Select(qual, _) :: _ if qual.typeOpt.hasSimpleKind => completer.selectionCompletions(qual)
212195
case tpd.Select(qual, _) :: _ => Map.empty
213196
case (tree: tpd.ImportOrExport) :: _ => completer.directMemberCompletions(tree.expr)
214-
case (_: untpd.ImportSelector) :: tpd.Import(expr, _) :: _ => completer.directMemberCompletions(expr)
215197
case _ => completer.scopeCompletions
216198

217199
interactiv.println(i"""completion info with pos = $pos,

presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala

+1-8
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,7 @@ class Completions(
542542
else false,
543543
)
544544
Some(search.searchMethods(query, buildTargetIdentifier, visitor).nn)
545-
else
546-
val filtered = indexedContext.scopeSymbols
547-
.filter(sym => !sym.isConstructor && (!sym.is(Synthetic) || sym.is(Module)))
548-
549-
filtered.map { sym =>
550-
visit(CompletionValue.Scope(sym.decodedName, sym, findSuffix(sym)))
551-
}
552-
Some(SymbolSearch.Result.INCOMPLETE)
545+
else Some(SymbolSearch.Result.INCOMPLETE)
553546

554547
end enrichWithSymbolSearch
555548

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionInterpolatorSuite.scala

-12
Original file line numberDiff line numberDiff line change
@@ -558,18 +558,6 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite:
558558
filter = _.contains("hello")
559559
)
560560

561-
@Test def `brace-token-error-pos` =
562-
checkEditLine(
563-
"""|object Main {
564-
| val hello = ""
565-
| ___
566-
|}
567-
|""".stripMargin,
568-
"""s"Hello ${@@"""".stripMargin,
569-
"""s"Hello ${hello"""".stripMargin,
570-
filter = _.contains("hello")
571-
)
572-
573561
@Test def `brace-token-error` =
574562
checkEditLine(
575563
"""|object Main {

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionKeywordSuite.scala

+3-16
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
3838
| // tr@@
3939
|}
4040
|""".stripMargin,
41-
"transparentTrait - scala.annotation (commit: '')",
41+
"",
4242
includeCommitCharacter = true
4343
)
4444

@@ -57,7 +57,7 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
5757
| **/
5858
|}
5959
|""".stripMargin,
60-
"transparentTrait - scala.annotation (commit: '')",
60+
"",
6161
includeCommitCharacter = true
6262
)
6363

@@ -412,8 +412,6 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
412412
|}
413413
""".stripMargin,
414414
"""|def
415-
|derived - scala.CanEqual
416-
|deprecated - scala.runtime.stdLibPatches.language
417415
|""".stripMargin,
418416
)
419417

@@ -428,7 +426,6 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
428426
""".stripMargin,
429427
"""|val
430428
|var
431-
|varargs - scala.annotation
432429
|""".stripMargin
433430
)
434431

@@ -467,26 +464,16 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
467464
| def hello(u@@)
468465
|}""".stripMargin,
469466
"""|using (commit: '')
470-
|unsafe - scala.caps (commit: '')
471-
|unsafeNulls - scala.runtime.stdLibPatches.language (commit: '')
472-
|unused - scala.annotation (commit: '')
473-
|unshared - scala.annotation.internal (commit: '')
474467
|""".stripMargin,
475468
includeCommitCharacter = true,
476-
topLines = Some(5)
477469
)
478470

479471
@Test def `not-using` =
480472
check(
481473
"""|object A{
482474
| def hello(a: String, u@@)
483475
|}""".stripMargin,
484-
"""|unsafe - scala.caps
485-
|unsafeNulls - scala.runtime.stdLibPatches.language
486-
|unused - scala.annotation
487-
|unshared - scala.annotation.internal
488-
|unspecialized - scala.annotation""".stripMargin,
489-
topLines = Some(5)
476+
"",
490477
)
491478

492479
@Test def `extends-class` =

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionPatternSuite.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ class CompletionPatternSuite extends BaseCompletionSuite:
5454
| case ma@@
5555
| }
5656
|}""".stripMargin,
57-
"""|macros - scala.languageFeature.experimental
58-
|macroImpl - scala.reflect.macros.internal
59-
|""".stripMargin
57+
""
6058
)
6159

6260
@Test def `bind2` =

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

+37
Original file line numberDiff line numberDiff line change
@@ -1734,3 +1734,40 @@ class CompletionSuite extends BaseCompletionSuite:
17341734
filter = _.contains("[")
17351735
)
17361736

1737+
@Test def `empty-import` =
1738+
check(
1739+
"""|import @@
1740+
|""".stripMargin,
1741+
"""|java <root>
1742+
|javax <root>
1743+
|""".stripMargin,
1744+
filter = _.startsWith("java")
1745+
)
1746+
1747+
@Test def `empty-import-selector` =
1748+
check(
1749+
"""|import java.@@
1750+
|""".stripMargin,
1751+
"""|util java
1752+
|""".stripMargin,
1753+
filter = _.startsWith("util")
1754+
)
1755+
1756+
@Test def `empty-export` =
1757+
check(
1758+
"""|export @@
1759+
|""".stripMargin,
1760+
"""|java <root>
1761+
|javax <root>
1762+
|""".stripMargin,
1763+
filter = _.startsWith("java")
1764+
)
1765+
1766+
@Test def `empty-export-selector` =
1767+
check(
1768+
"""|export java.@@
1769+
|""".stripMargin,
1770+
"""|util java
1771+
|""".stripMargin,
1772+
filter = _.startsWith("util")
1773+
)

0 commit comments

Comments
 (0)