diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala index 5cac776279b1..b3b7d1fde07d 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala @@ -52,19 +52,15 @@ class CompletionProvider( val pos = driver.sourcePosition(params) val (items, isIncomplete) = driver.compilationUnits.get(uri) match case Some(unit) => - val path = - Interactive.pathTo(driver.openedTrees(uri), pos)(using ctx) val newctx = ctx.fresh.setCompilationUnit(unit) - val tpdPath = - Interactive.pathTo(newctx.compilationUnit.tpdTree, pos.span)( - using newctx - ) + val tpdPath = Interactive.pathTo(newctx.compilationUnit.tpdTree, pos.span)(using newctx) + val locatedCtx = Interactive.contextOfPath(tpdPath)(using newctx) val indexedCtx = IndexedContext(locatedCtx) val completionPos = - CompletionPos.infer(pos, params, path)(using newctx) + CompletionPos.infer(pos, params, tpdPath)(using newctx) val autoImportsGen = AutoImports.generator( completionPos.sourcePos, text, @@ -82,7 +78,7 @@ class CompletionProvider( buildTargetIdentifier, completionPos, indexedCtx, - path, + tpdPath, config, folderPath, autoImportsGen, @@ -96,7 +92,7 @@ class CompletionProvider( idx, autoImportsGen, completionPos, - path, + tpdPath, indexedCtx )(using newctx) } diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala index 41db3a7f055e..aead7b754fa6 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala @@ -117,7 +117,7 @@ class Completions( val allAdvanced = advanced ++ keywords path match // should not show completions for toplevel - case Nil if pos.source.file.extension != "sc" => + case Nil | (_: PackageDef) :: _ if pos.source.file.extension != "sc" => (allAdvanced, SymbolSearch.Result.COMPLETE) case Select(qual, _) :: _ if qual.typeOpt.isErroneous => (allAdvanced, SymbolSearch.Result.COMPLETE) diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/KeywordsCompletions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/KeywordsCompletions.scala index 2e3007b8e586..e912bc49032f 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/KeywordsCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/KeywordsCompletions.scala @@ -24,7 +24,7 @@ object KeywordsCompletions: checkIfNotInComment(completionPos.cursorPos, comments) path match - case Nil if completionPos.query.isEmpty() => + case Nil | (_: PackageDef) :: _ if completionPos.query.isEmpty() => Keyword.all.collect { // topelevel definitions are allowed in Scala 3 case kw if (kw.isPackage || kw.isTemplate) && notInComment => @@ -76,7 +76,7 @@ object KeywordsCompletions: private def isPackage(enclosing: List[Tree]): Boolean = enclosing match - case Nil => true + case Nil | (_: PackageDef) :: _ => true case _ => false private def isParam(enclosing: List[Tree]): Boolean = diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala index 551322c8ac43..fce35ab69ce3 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala @@ -16,12 +16,11 @@ class ScalaCliCompletions( pos.lineContent.take(pos.column).stripPrefix("/*