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 @@ -117,7 +117,7 @@ class Completions(
117
117
val allAdvanced = advanced ++ keywords
118
118
path match
119
119
// should not show completions for toplevel
120
- case Nil if pos.source.file.extension != " sc" =>
120
+ case Nil | ( _ : PackageDef ) :: _ if pos.source.file.extension != " sc" =>
121
121
(allAdvanced, SymbolSearch .Result .COMPLETE )
122
122
case Select (qual, _) :: _ if qual.typeOpt.isErroneous =>
123
123
(allAdvanced, SymbolSearch .Result .COMPLETE )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ object KeywordsCompletions:
24
24
checkIfNotInComment(completionPos.cursorPos, comments)
25
25
26
26
path match
27
- case Nil if completionPos.query.isEmpty() =>
27
+ case Nil | ( _ : PackageDef ) :: _ if completionPos.query.isEmpty() =>
28
28
Keyword .all.collect {
29
29
// topelevel definitions are allowed in Scala 3
30
30
case kw if (kw.isPackage || kw.isTemplate) && notInComment =>
@@ -76,7 +76,7 @@ object KeywordsCompletions:
76
76
77
77
private def isPackage (enclosing : List [Tree ]): Boolean =
78
78
enclosing match
79
- case Nil => true
79
+ case Nil | ( _ : PackageDef ) :: _ => true
80
80
case _ => false
81
81
82
82
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