Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant path calculation from Completions in PC #18889

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading