Skip to content

Commit

Permalink
Use only path computed from ctx.compilationUnit.tpdTree
Browse files Browse the repository at this point in the history
  • Loading branch information
rochala committed Nov 9, 2023
1 parent c7b3d7b commit 9286291
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -82,7 +78,7 @@ class CompletionProvider(
buildTargetIdentifier,
completionPos,
indexedCtx,
path,
tpdPath,
config,
folderPath,
autoImportsGen,
Expand All @@ -96,7 +92,7 @@ class CompletionProvider(
idx,
autoImportsGen,
completionPos,
path,
tpdPath,
indexedCtx
)(using newctx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ class ScalaCliCompletions(
pos.lineContent.take(pos.column).stripPrefix("/*<script>*/")
)
path match
case Nil => scalaCliDep
case Nil | (_: PackageDef) :: _ => scalaCliDep
// generated script file will end with .sc.scala
case (_: TypeDef) :: Nil if pos.source.file.path.endsWith(".sc.scala") =>
case (_: TypeDef) :: (_: PackageDef) :: Nil if pos.source.file.path.endsWith(".sc.scala") =>
scalaCliDep
case (_: Template) :: (_: TypeDef) :: Nil
if pos.source.file.path.endsWith(".sc.scala") =>
case (_: Template) :: (_: TypeDef) :: Nil if pos.source.file.path.endsWith(".sc.scala") =>
scalaCliDep
case head :: next => None

Expand Down

0 comments on commit 9286291

Please sign in to comment.