File tree Expand file tree Collapse file tree 4 files changed +11
-16
lines changed
presentation-compiler/src/main/dotty/tools/pc/completions Expand file tree Collapse file tree 4 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -52,19 +52,15 @@ class CompletionProvider(
5252 val pos = driver.sourcePosition(params)
5353 val (items, isIncomplete) = driver.compilationUnits.get(uri) match
5454 case Some (unit) =>
55- val path =
56- Interactive .pathTo(driver.openedTrees(uri), pos)(using ctx)
5755
5856 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+
6359 val locatedCtx =
6460 Interactive .contextOfPath(tpdPath)(using newctx)
6561 val indexedCtx = IndexedContext (locatedCtx)
6662 val completionPos =
67- CompletionPos .infer(pos, params, path )(using newctx)
63+ CompletionPos .infer(pos, params, tpdPath )(using newctx)
6864 val autoImportsGen = AutoImports .generator(
6965 completionPos.sourcePos,
7066 text,
@@ -82,7 +78,7 @@ class CompletionProvider(
8278 buildTargetIdentifier,
8379 completionPos,
8480 indexedCtx,
85- path ,
81+ tpdPath ,
8682 config,
8783 folderPath,
8884 autoImportsGen,
@@ -96,7 +92,7 @@ class CompletionProvider(
9692 idx,
9793 autoImportsGen,
9894 completionPos,
99- path ,
95+ tpdPath ,
10096 indexedCtx
10197 )(using newctx)
10298 }
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ class Completions(
121121 val allAdvanced = advanced ++ keywords
122122 path match
123123 // 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" =>
125125 (allAdvanced, SymbolSearch .Result .COMPLETE )
126126 case Select (qual, _) :: _ if qual.tpe.isErroneous =>
127127 (allAdvanced, SymbolSearch .Result .COMPLETE )
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ object KeywordsCompletions:
2626 checkIfNotInComment(completionPos.cursorPos, comments)
2727
2828 path match
29- case Nil if completionPos.query.isEmpty() =>
29+ case Nil | ( _ : PackageDef ) :: _ if completionPos.query.isEmpty() =>
3030 Keyword .all.collect {
3131 // topelevel definitions are allowed in Scala 3
3232 case kw if (kw.isPackage || kw.isTemplate) && notInComment =>
@@ -78,7 +78,7 @@ object KeywordsCompletions:
7878
7979 private def isPackage (enclosing : List [Tree ]): Boolean =
8080 enclosing match
81- case Nil => true
81+ case Nil | ( _ : PackageDef ) :: _ => true
8282 case _ => false
8383
8484 private def isParam (enclosing : List [Tree ]): Boolean =
Original file line number Diff line number Diff line change @@ -16,12 +16,11 @@ class ScalaCliCompletions(
1616 pos.lineContent.take(pos.column).stripPrefix(" /*<script>*/" )
1717 )
1818 path match
19- case Nil => scalaCliDep
19+ case Nil | ( _ : PackageDef ) :: _ => scalaCliDep
2020 // 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" ) =>
2222 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" ) =>
2524 scalaCliDep
2625 case head :: next => None
2726
You can’t perform that action at this time.
0 commit comments