File tree 4 files changed +11
-16
lines changed
presentation-compiler/src/main/dotty/tools/pc/completions
4 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -52,19 +52,15 @@ class CompletionProvider(
52
52
val pos = driver.sourcePosition(params)
53
53
val (items, isIncomplete) = driver.compilationUnits.get(uri) match
54
54
case Some (unit) =>
55
- val path =
56
- Interactive .pathTo(driver.openedTrees(uri), pos)(using ctx)
57
55
58
56
val newctx = ctx.fresh.setCompilationUnit(unit)
59
- val tpdPath =
60
- Interactive .pathTo(newctx.compilationUnit.tpdTree, pos.span)(
61
- using newctx
62
- )
57
+ val tpdPath = Interactive .pathTo(newctx.compilationUnit.tpdTree, pos.span)(using newctx)
58
+
63
59
val locatedCtx =
64
60
Interactive .contextOfPath(tpdPath)(using newctx)
65
61
val indexedCtx = IndexedContext (locatedCtx)
66
62
val completionPos =
67
- CompletionPos .infer(pos, params, path )(using newctx)
63
+ CompletionPos .infer(pos, params, tpdPath )(using newctx)
68
64
val autoImportsGen = AutoImports .generator(
69
65
completionPos.sourcePos,
70
66
text,
@@ -82,7 +78,7 @@ class CompletionProvider(
82
78
buildTargetIdentifier,
83
79
completionPos,
84
80
indexedCtx,
85
- path ,
81
+ tpdPath ,
86
82
config,
87
83
folderPath,
88
84
autoImportsGen,
@@ -96,7 +92,7 @@ class CompletionProvider(
96
92
idx,
97
93
autoImportsGen,
98
94
completionPos,
99
- path ,
95
+ tpdPath ,
100
96
indexedCtx
101
97
)(using newctx)
102
98
}
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ class Completions(
121
121
val allAdvanced = advanced ++ keywords
122
122
path match
123
123
// should not show completions for toplevel
124
- case Nil if pos.source.file.extension != " sc" =>
124
+ case Nil | ( _ : PackageDef ) :: _ if pos.source.file.extension != " sc" =>
125
125
(allAdvanced, SymbolSearch .Result .COMPLETE )
126
126
case Select (qual, _) :: _ if qual.tpe.isErroneous =>
127
127
(allAdvanced, SymbolSearch .Result .COMPLETE )
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ object KeywordsCompletions:
26
26
checkIfNotInComment(completionPos.cursorPos, comments)
27
27
28
28
path match
29
- case Nil if completionPos.query.isEmpty() =>
29
+ case Nil | ( _ : PackageDef ) :: _ if completionPos.query.isEmpty() =>
30
30
Keyword .all.collect {
31
31
// topelevel definitions are allowed in Scala 3
32
32
case kw if (kw.isPackage || kw.isTemplate) && notInComment =>
@@ -78,7 +78,7 @@ object KeywordsCompletions:
78
78
79
79
private def isPackage (enclosing : List [Tree ]): Boolean =
80
80
enclosing match
81
- case Nil => true
81
+ case Nil | ( _ : PackageDef ) :: _ => true
82
82
case _ => false
83
83
84
84
private def isParam (enclosing : List [Tree ]): Boolean =
Original file line number Diff line number Diff line change @@ -16,12 +16,11 @@ class ScalaCliCompletions(
16
16
pos.lineContent.take(pos.column).stripPrefix(" /*<script>*/" )
17
17
)
18
18
path match
19
- case Nil => scalaCliDep
19
+ case Nil | ( _ : PackageDef ) :: _ => scalaCliDep
20
20
// generated script file will end with .sc.scala
21
- case (_ : TypeDef ) :: Nil if pos.source.file.path.endsWith(" .sc.scala" ) =>
21
+ case (_ : TypeDef ) :: ( _ : PackageDef ) :: Nil if pos.source.file.path.endsWith(" .sc.scala" ) =>
22
22
scalaCliDep
23
- case (_ : Template ) :: (_ : TypeDef ) :: Nil
24
- if pos.source.file.path.endsWith(" .sc.scala" ) =>
23
+ case (_ : Template ) :: (_ : TypeDef ) :: Nil if pos.source.file.path.endsWith(" .sc.scala" ) =>
25
24
scalaCliDep
26
25
case head :: next => None
27
26
You can’t perform that action at this time.
0 commit comments