scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.08k stars 326 forks source link

Remote Containers (I cannot run any hello-world application that is generated by Metals in a Spark Image) #4571

Closed razilevin closed 1 year ago

razilevin commented 1 year ago

Describe the bug

FYI works with remote container of type

ARG VARIANT="jammy" FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}

and installing the extension.

{ "name": "Ubuntu", "build": { "dockerfile": "Dockerfile", // Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04 // Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon. "args": { "VARIANT": "ubuntu-22.04" } }, "remoteUser": "vscode" }

Using the following

Dockerfile

FROM apache/spark USER root

devcontainer.json

{ "name": "Spark", "build": { "dockerfile": "Dockerfile" }, "forwardPorts": [ 4040 ], "customizations": { "vscode": { "extensions": [] } } }

Java home: /usr/local/openjdk-11 Metals version: 0.11.9 2022.10.25 16:47:25 INFO logging to file /workspaces/hello-world/.metals/metals.log 2022.10.25 16:47:25 INFO Started: Metals version 0.11.9 in workspace '/workspaces/hello-world' for client Visual Studio Code 1.72.2. 2022.10.25 16:47:25 WARN Can't instantiate JavaInteractiveSemanticdb (version: JdkVersion(11), jdkHome: /usr/local/openjdk-11, javac exists: false) 2022.10.25 16:47:25 INFO Flyway Community Edition 9.4.0 by Redgate 2022.10.25 16:47:25 INFO See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.4.0 2022.10.25 16:47:25 INFO 2022.10.25 16:47:25 INFO Database: jdbc:h2:file:/workspaces/hello-world/.metals/metals (H2 2.1) 2022.10.25 16:47:25 INFO Successfully validated 4 migrations (execution time 00:00.023s) 2022.10.25 16:47:25 INFO Current version of schema "PUBLIC": 4 2022.10.25 16:47:25 INFO Schema "PUBLIC" is up to date. No migration necessary. 2022.10.25 16:47:26 INFO time: initialize in 0.86s Initializing Scala Debugger Release notes was not shown: is a remote environment dev-container 2022.10.25 16:47:27 INFO Attempting to connect to the build server... 2022.10.25 16:47:27 INFO Bloop uses /usr/local/openjdk-11 defined at /root/.bloop/bloop.json 2022.10.25 16:47:27 INFO skipping build import with status 'Installed' 2022.10.25 16:47:31 INFO tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /workspaces/hello-world/.metals/bsp.trace.json or /root/.cache/metals/bsp.trace.json 2022.10.25 16:47:31 INFO Attempting to connect to the build server... 2022.10.25 16:47:31 INFO Bloop uses /usr/local/openjdk-11 defined at /root/.bloop/bloop.json 2022.10.25 16:47:31 INFO tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /workspaces/hello-world/project/.metals/bsp.trace.json or /root/.cache/metals/bsp.trace.json 2022.10.25 16:47:31 INFO time: Connected to build server in 3.64s 2022.10.25 16:47:31 INFO Connected to Build server: Bloop v1.5.4 2022.10.25 16:47:31 INFO time: Imported build in 0.17s 2022.10.25 16:47:34 WARN Could not find java sources in /usr/local/src.zip, /usr/local/lib/src.zip, /usr/local/openjdk-11/src.zip, /usr/local/openjdk-11/lib/src.zip. Java symbols will not be available. 2022.10.25 16:47:34 WARN Could not find java sources in /usr/local/src.zip, /usr/local/lib/src.zip, /usr/local/openjdk-11/src.zip, /usr/local/openjdk-11/lib/src.zip. Java symbols will not be available. 2022.10.25 16:47:34 WARN Could not find java sources in /usr/local/src.zip, /usr/local/lib/src.zip, /usr/local/openjdk-11/src.zip, /usr/local/openjdk-11/lib/src.zip. Java symbols will not be available. 2022.10.25 16:47:34 INFO time: indexed workspace in 3.43s 2022.10.25 16:48:07 INFO compiling hello-world (1 scala source) 2022.10.25 16:48:10 INFO time: compiled hello-world in 3.12s 2022.10.25 16:48:37 INFO Deduplicating compilation of hello-world from bsp client 'Metals 0.11.9' (since 1m 6.121s) [Error - 4:48:37 PM] Request workspace/executeCommand failed. Message: Internal error. Code: -32603 java.util.concurrent.CompletionException: scala.meta.internal.metals.MetalsBspException: BSP connection failed in the attempt to get: DebugSessionAddress at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source) at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:29) at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:26) at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:484) at scala.concurrent.ExecutionContext$parasitic$.execute(ExecutionContext.scala:222) at scala.concurrent.impl.Promise$Transformation.submitWithValue(Promise.scala:429) at scala.concurrent.impl.Promise$DefaultPromise.submitWithValue(Promise.scala:338) at scala.concurrent.impl.Promise$DefaultPromise.tryComplete0(Promise.scala:285) at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:504) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused by: scala.meta.internal.metals.MetalsBspException: BSP connection failed in the attempt to get: DebugSessionAddress at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.$anonfun$applyOrElse$6(BuildServerConnection.scala:358) at scala.Option.getOrElse(Option.scala:201) at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.applyOrElse(BuildServerConnection.scala:356) at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.applyOrElse(BuildServerConnection.scala:339) at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:490) ... 3 more Caused by: org.eclipse.lsp4j.jsonrpc.MessageIssueException: Message could not be parsed. at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleResponseIssues(RemoteEndpoint.java:358) at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handle(RemoteEndpoint.java:317) at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:198) at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94) at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.base/java.util.concurrent.FutureTask.run(Unknown Source) ... 3 more

Expected behavior

I would expect to be able to run and debug the scala code.

Operating system

Linux

Editor/Extension

VS Code

Version of Metals

v0.11.9

Extra context or search terms

No response

razilevin commented 1 year ago

Is this a JDK issue since the bloops server uses JDK 17 when using its default JDK. I wonder if I can point Metals to use the JDK it comes bundled with like in the ubuntu image.

FYI JAVA_HOME and JAVA_VERSION declare -x JAVA_HOME="/usr/local/openjdk-11" declare -x JAVA_VERSION="11.0.15"

razilevin commented 1 year ago

Hmm I had to start the Scala CLI BSP Server now I can run and debug...

tanishiking commented 1 year ago

I'm not sure that Dockerfile has install everything needed for development, maybe you wanna build a docker file based on https://github.com/scalameta/metals/discussions/4466#discussioncomment-3833181

tanishiking commented 1 year ago

I guess it's caused by lack of sbt (and openjdk-src)

tgodzik commented 1 year ago

@razilevin Looks Bloop was started and it's using JDK11: INFO Bloop uses /usr/local/openjdk-11 defined at /root/.bloop/bloop.json There is something weird about that JDK though: WARN Can't instantiate JavaInteractiveSemanticdb (version: JdkVersion(11), jdkHome: /usr/local/openjdk-11, javac exists: false)

I think you might use the dockerfile suggested by Rikito. Closing for now since I don't think it's something we can fix on our side.