diff --git a/metals/src/main/scala/scala/meta/internal/metals/scalacli/ScalaCli.scala b/metals/src/main/scala/scala/meta/internal/metals/scalacli/ScalaCli.scala index 121f4af7729..23b763af946 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/scalacli/ScalaCli.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/scalacli/ScalaCli.scala @@ -7,7 +7,6 @@ import java.net.URI import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths -import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicBoolean @@ -22,7 +21,6 @@ import scala.util.Properties import scala.util.Success import scala.util.control.NonFatal -import scala.meta.internal.async.ConcurrentQueue import scala.meta.internal.bsp.BuildChange import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.BuildInfo @@ -65,31 +63,16 @@ class ScalaCli( )(implicit ec: ExecutionContextExecutorService) extends Cancelable { - private val createdFiles = new ConcurrentLinkedQueue[AbsolutePath]() - private def registerFile(path: AbsolutePath) = { - createdFiles.add(path) - path - } - private def localTmpWorkspace(path: AbsolutePath) = { - val root = if (path.isDirectory) path else path.parent - root.resolve(s".metals-scala-cli/") - } - private val scalaCliBuildDirectory = - new AtomicReference[Option[AbsolutePath]](None) - import ScalaCli.ConnectionState private val isCancelled = new AtomicBoolean(false) def cancel(): Unit = if (isCancelled.compareAndSet(false, true)) try { - scalaCliBuildDirectory.set(None) disconnectOldBuildServer().asJava.get(100, TimeUnit.MILLISECONDS) } catch { case NonFatal(_) => case _: TimeoutException => - } finally { - ConcurrentQueue.pollAll(createdFiles).foreach(_.deleteRecursively()) } private val state = @@ -226,44 +209,13 @@ class ScalaCli( ifConnectedOrElse(st => Option(st.path))(None) def start(path: AbsolutePath): Future[Unit] = { - val workspace = { - val globalTmpDir = - scalaCliBuildDirectory.get() match { - case Some(workspace) => workspace - case None => - val tmpFile = registerFile { - AbsolutePath( - Files.createTempDirectory(s"metals-scala-cli") - ) - } - val Some(workspace) = - scalaCliBuildDirectory.updateAndGet { - case None => Some(tmpFile) - case some => some - } - workspace - } - - // When path and workspace have different roots on Windows `scala-cli` throws an error, - // so we fallback to creating a tmp dir relative to `path`. - if (globalTmpDir.toNIO.getRoot() == path.toNIO.getRoot()) globalTmpDir - else - registerFile { - val workspace = localTmpWorkspace(path) - if (!workspace.exists) Files.createDirectory(workspace.toNIO) - workspace - } - } - disconnectOldBuildServer().onComplete { case Failure(e) => scribe.warn("Error disconnecting old Scala CLI server", e) case Success(()) => } - val command = - cliCommand :+ "bsp" :+ "--workspace" :+ workspace.toString :+ path - .toString() + val command = cliCommand :+ "bsp" :+ path.toString() val connDir = if (path.isDirectory) path else path.parent