Code Monkey home page Code Monkey logo

Comments (4)

izeigerman avatar izeigerman commented on June 12, 2024 1

I've run into the same issue with SBT and investigated it.
Unfortunately the message in the emacs log is quite confusing. What in fact happens is that the call to Metals fails. In .metals/metals.log I found the following:

2021.09.08 17:13:20 ERROR No project associated with Uri(file:///<path-to-my-project-root>?id=root)
Sep 08, 2021 5:13:20 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SEVERE: Internal error: scala.meta.internal.metals.MetalsBspException: BSP connection failed in the attempt to get: DebugSessionAddress.  No project associated with Uri(file:///<path-to-my-project-root>?id=root)
java.util.concurrent.CompletionException: scala.meta.internal.metals.MetalsBspException: BSP connection failed in the attempt to get: DebugSessionAddress.  No project associated with Uri(file:///<path-to-my-project-root>?id=root)
	at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
	at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
	at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:647)
	at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:632)
	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
	at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
	at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:29)
	at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:26)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
	at scala.concurrent.BatchingExecutor$Batch.processBatch$1(BatchingExecutor.scala:67)
	at scala.concurrent.BatchingExecutor$Batch.$anonfun$run$1(BatchingExecutor.scala:82)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:85)
	at scala.concurrent.BatchingExecutor$Batch.run(BatchingExecutor.scala:59)
	at scala.concurrent.Future$InternalCallbackExecutor$.unbatchedExecute(Future.scala:875)
	at scala.concurrent.BatchingExecutor.execute(BatchingExecutor.scala:110)
	at scala.concurrent.BatchingExecutor.execute$(BatchingExecutor.scala:107)
	at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:873)
	at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:72)
	at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1(Promise.scala:288)
	at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1$adapted(Promise.scala:288)
	at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:288)
	at scala.concurrent.Promise.complete(Promise.scala:53)
	at scala.concurrent.Promise.complete$(Promise.scala:52)
	at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:187)
	at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: scala.meta.internal.metals.MetalsBspException: BSP connection failed in the attempt to get: DebugSessionAddress.  No project associated with Uri(file:///<path-to-my-project-root>?id=root)
	at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.applyOrElse(BuildServerConnection.scala:237)
	at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.applyOrElse(BuildServerConnection.scala:229)
	at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:417)
	at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:41)
	... 4 more

After additional digging I realized that the failure occurs in Bloop and not Metals (relevant code line)

What Bloop is trying to do there is to extract a project name with the given ID (here).
From Metals' logs we can see that the passed ID is root, so it's trying to fetch a module with this ID and fails.

Long story short lsp-metals has the root ID hardcoded (here) which means that each project is expected to have a root module and not just submodules.

In my build.sbt I was missing the following:

lazy val root = (project in file("."))
  .aggregate(<the_list_of_my_submodules>)

After introducing above lines to my build.sbt the dap-debug with the Scala Attach template worked as expected.

Unfortunately I don't know how to work this around in Gradle.

I wish this behavior was at least documented somewhere. Ideally this should be fixed.

from lsp-metals.

izeigerman avatar izeigerman commented on June 12, 2024

@huangbohong I tried your example and noticed that if I rename the core module to root, the Scala Attach template works as expected. Perhaps you can find a way to create an umbrella root project in Gradle similarly to how I did this in SBT (see my previous comment).

from lsp-metals.

izeigerman avatar izeigerman commented on June 12, 2024

I've created a PR (#59) which makes the project ID configurable. If it gets merged then the original Gradle issue can be addressed using the following config:

(dap-register-debug-template
  "Scala Attach Core"
  (list :type "scala"
        :request "attach"
        :name "Scala Attach Core"
        :buildTarget "core"
        :hostName "localhost"
        :port 5005))

Note that the buildTarget is set to the module name from attached sources.

UPD: updated the above snippet based on changes in the PR.

from lsp-metals.

bohonghuang avatar bohonghuang commented on June 12, 2024

@huangbohong I tried your example and noticed that if I rename the core module to root, the Scala Attach template works as expected. Perhaps you can find a way to create an umbrella root project in Gradle similarly to how I did this in SBT (see my previous comment).

I did as you instructed and it works as expected. Thanks!

from lsp-metals.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.