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

improvement: Check if compiled unit is available before using #6216

Merged
merged 1 commit into from Mar 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -53,12 +53,15 @@ object MtagsEnrichments extends ScalametaCommonEnrichments:
new SourcePosition(source, span)
end sourcePosition

def localContext(params: OffsetParams): Context =
if driver.currentCtx.run.units.isEmpty then
def latestRun =
if driver.currentCtx.run.units.nonEmpty then
driver.currentCtx.run.units.head
else
throw new RuntimeException(
"No source files were passed to the Scala 3 presentation compiler"
"No source files were compiled. Might be an error in the compiler itself."
)
val unit = driver.currentCtx.run.units.head
def localContext(params: OffsetParams): Context =
val unit = driver.latestRun
val pos = driver.sourcePosition(params)
val newctx = driver.currentCtx.fresh.setCompilationUnit(unit)
val tpdPath =
Expand Down
Expand Up @@ -34,7 +34,7 @@ final class AutoImportsProvider(
uri,
SourceFile.virtual(filePath.toString, params.text),
)
val unit = driver.currentCtx.run.units.head
val unit = driver.latestRun
val tree = unit.tpdTree

val pos = driver.sourcePosition(params)
Expand Down
Expand Up @@ -27,7 +27,7 @@ final class ConvertToNamedArgumentsProvider(
uri,
SourceFile.virtual(filePath.toString, params.text),
)
val unit = driver.currentCtx.run.units.head
val unit = driver.latestRun
val newctx = driver.currentCtx.fresh.setCompilationUnit(unit)
val pos = driver.sourcePosition(params)
val trees = driver.openedTrees(uri)
Expand Down
Expand Up @@ -42,7 +42,7 @@ final class ExtractMethodProvider(
val filePath = Paths.get(uri)
val source = SourceFile.virtual(filePath.toString, text)
driver.run(uri, source)
val unit = driver.currentCtx.run.units.head
val unit = driver.latestRun
val pos = driver.sourcePosition(range).startPos
val path =
Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx)
Expand Down
Expand Up @@ -69,7 +69,7 @@ final class InferredTypeProvider(
val source =
SourceFile.virtual(filePath.toString, sourceText)
driver.run(uri, source)
val unit = driver.currentCtx.run.units.head
val unit = driver.latestRun
val pos = driver.sourcePosition(params)
val path =
Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx)
Expand Down
Expand Up @@ -44,7 +44,7 @@ abstract class PcCollector[T](
driver.run(uri, source)
given ctx: Context = driver.currentCtx

val unit = driver.currentCtx.run.units.head
val unit = driver.latestRun
val compilatonUnitContext = ctx.fresh.setCompilationUnit(unit)
val offset = params match
case op: OffsetParams => op.offset()
Expand Down
Expand Up @@ -39,7 +39,7 @@ class PcInlayHintsProvider(
SourceFile.virtual(filePath.toString, sourceText)
driver.run(uri, source)
given ctx: Context = driver.currentCtx
val unit = driver.currentCtx.run.units.head
val unit = driver.latestRun
given InferredType.Text = InferredType.Text(text)
val pos = driver.sourcePosition(params)

Expand Down
Expand Up @@ -8,6 +8,7 @@ import java.nio.file.Paths
import scala.util.Properties

import scala.meta.internal.mtags.MD5
import scala.meta.internal.mtags.MtagsEnrichments.*

import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.semanticdb.ExtractSemanticDB
Expand All @@ -32,7 +33,7 @@ class SemanticdbTextDocumentProvider(
uri,
SourceFile.virtual(filePath.toString, validCode),
)
val tree = driver.currentCtx.run.units.head.tpdTree
val tree = driver.latestRun.tpdTree
val extract = ExtractSemanticDB()
val extractor = extract.Extractor()
extractor.traverse(tree)(using driver.currentCtx)
Expand Down
Expand Up @@ -177,7 +177,7 @@ object OverrideCompletions:
uri,
SourceFile.virtual(uri.toASCIIString, params.text),
)
val unit = driver.currentCtx.run.units.head
val unit = driver.latestRun
val pos = driver.sourcePosition(params)

val newctx = driver.currentCtx.fresh.setCompilationUnit(unit)
Expand Down