From fb4b25157b6619e64d153e15a9a06560ac54738b Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Thu, 19 Oct 2023 14:17:01 +0200 Subject: [PATCH] bugfix: move bsp config for detected project root --- .../internal/bsp/BspConfigGenerator.scala | 13 ++++++----- .../scala/tests/scalacli/ScalaCliSuite.scala | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala b/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala index 4abae2d2cdc..dc85352442d 100644 --- a/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala +++ b/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala @@ -47,21 +47,22 @@ final class BspConfigGenerator( try { val bsp = ".bsp" workspace.resolve(bsp).createDirectories() - val buildToolBspDir = buildTool.projectRoot.resolve(bsp).toNIO + val buildToolBspDir = buildTool.projectRoot.resolve(bsp) val workspaceBspDir = workspace.resolve(bsp).toNIO buildToolBspDir.toFile.listFiles().foreach { file => val path = file.toPath() if (!file.isDirectory() && path.filename.endsWith(".json")) { - val to = - workspaceBspDir.resolve(path.relativize(buildToolBspDir)) + val to = workspaceBspDir.resolve(path.filename) Files.move(path, to, StandardCopyOption.REPLACE_EXISTING) } } - Files.delete(buildToolBspDir) + buildToolBspDir.deleteRecursively() Generated } catch { - case NonFatal(_) => - Failed(Right("Could not move bsp config from project root")) + case NonFatal(e) => + val message = s"Could not move bsp config from project root: $e" + scribe.error(message) + Failed(Right(message)) } case status => status } diff --git a/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala b/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala index 93e7f645873..ccc3f76cd69 100644 --- a/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala +++ b/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala @@ -249,6 +249,29 @@ class ScalaCliSuite extends BaseScalaCliSuite(V.scala3) { } yield () } + test("inner") { + for { + _ <- scalaCliInitialize(useBsp = false)( + s"""|/inner/project.scala + |//> using scala "$scalaVersion" + |//> using lib "com.lihaoyi::utest::0.8.1" + |/inner/MyTests.scala + |import utest._ + | + |object MyTests extends TestSuite { + | val tests = Tests { + | test("foo") { + | assert(2 + 2 == 4) + | } + | } + |} + |""".stripMargin + ) + _ <- server.didOpen("inner/MyTests.scala") + _ = assert(!client.workspaceDiagnostics.contains("Not found: utest")) + } yield () + } + test("relative-semanticdb-root") { for { _ <- scalaCliInitialize(useBsp = false)(