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 13a6e7cdb7cb..0bc558aaa3cf 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 557d1762720b..6c53488e076e 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala @@ -121,7 +121,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.tpe.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 9f1a5a0e9bff..0dbd9a8e4ee2 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/KeywordsCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/KeywordsCompletions.scala @@ -26,7 +26,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 => @@ -78,7 +78,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("/*