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

bugfix: Don't start mtags with full classpath #6439

Merged
merged 1 commit into from
May 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metals-bench/src/main/scala/bench/PcBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class PcBenchmark {
val pc = MtagsResolver.default().resolve(version) match {
case Some(MtagsBinaries.BuildIn) => new ScalaPresentationCompiler()
case Some(artifacts: MtagsBinaries.Artifacts) =>
embedded.presentationCompiler(artifacts, classpath)
embedded.presentationCompiler(artifacts)
case _ =>
throw new RuntimeException(
s"Forgot to release scala version: $version ?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ class CompilerConfiguration(
protected def newCompiler(classpath: Seq[Path]): PresentationCompiler = {
val name = scalaTarget.scalac.getTarget().getUri
val options = enrichWithReleaseOption(scalaTarget)
fromMtags(mtags, options, classpath ++ additionalClasspath, name, search)
fromMtags(
mtags,
options,
classpath ++ additionalClasspath,
name,
search,
)
.withBuildTargetName(scalaTarget.displayName)
}

Expand Down Expand Up @@ -253,7 +259,7 @@ class CompilerConfiguration(
val pc = mtags match {
case MtagsBinaries.BuildIn => new ScalaPresentationCompiler()
case artifacts: MtagsBinaries.Artifacts =>
embedded.presentationCompiler(artifacts, classpathSeq)
embedded.presentationCompiler(artifacts)
}

val filteredOptions = plugins.filterSupportedOptions(options)
Expand Down
19 changes: 9 additions & 10 deletions metals/src/main/scala/scala/meta/internal/metals/Embedded.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ final class Embedded(
}

def presentationCompiler(
mtags: MtagsBinaries.Artifacts,
classpath: Seq[Path],
mtags: MtagsBinaries.Artifacts
): PresentationCompiler = {
val classloader = presentationCompilers.getOrElseUpdate(
ScalaVersions.dropVendorSuffix(mtags.scalaVersion),
newPresentationCompilerClassLoader(mtags, classpath),
newPresentationCompilerClassLoader(mtags),
)

val presentationCompilerClassname =
Expand Down Expand Up @@ -158,10 +157,9 @@ final class Embedded(
}

private def newPresentationCompilerClassLoader(
mtags: MtagsBinaries.Artifacts,
classpath: Seq[Path],
mtags: MtagsBinaries.Artifacts
): URLClassLoader = {
val allJars = Iterator(mtags.jars, classpath).flatten
val allJars = mtags.jars.iterator
val allURLs = allJars.map(_.toUri.toURL).toArray
// Share classloader for a subset of types.
val parent =
Expand Down Expand Up @@ -205,7 +203,7 @@ object Embedded {
if (!ScalaVersions.isScala3Version(scalaVersion))
resolutionParams.forceVersions(
List(
Dependency.of("org.scala-lang", "scala-library", scalaVersion),
scalaLibraryDependency(scalaVersion),
Dependency.of("org.scala-lang", "scala-compiler", scalaVersion),
Dependency.of("org.scala-lang", "scala-reflect", scalaVersion),
).map(d => (d.getModule, d.getVersion)).toMap.asJava
Expand All @@ -223,7 +221,8 @@ object Embedded {
.withResolutionParams(resolutionParams)
.withMainArtifacts()
}
private def scalaDependency(scalaVersion: String): Dependency =

private def scalaLibraryDependency(scalaVersion: String): Dependency =
Dependency.of("org.scala-lang", "scala-library", scalaVersion)

private def scala3Dependency(scalaVersion: String): Dependency = {
Expand Down Expand Up @@ -308,7 +307,7 @@ object Embedded {

def downloadScalaSources(scalaVersion: String): List[Path] =
downloadDependency(
scalaDependency(scalaVersion),
scalaLibraryDependency(scalaVersion),
Some(scalaVersion),
classfiers = Seq("sources"),
)
Expand Down Expand Up @@ -383,7 +382,7 @@ object Embedded {
if (ScalaVersions.isScala3Version(scalaVersion))
scala3Dependency(scalaVersion)
else
scalaDependency(scalaVersion)
scalaLibraryDependency(scalaVersion)
downloadDependency(dependency, Some(scalaVersion))
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/main/scala/tests/TestScala3Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object TestScala3Compiler {
val status = new WorkDoneProgress(client, time)(ec)
val embedded = new Embedded(status)
val pc = embedded
.presentationCompiler(mtags, mtags.jars)
.presentationCompiler(mtags)
.newInstance(
name,
input.classpath.entries.map(_.toNIO).asJava,
Expand Down
Loading