scalameta / metals

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

References to another project causing issues in current project (stale Bloop stuff?) #5279

Open ckipp01 opened 1 year ago

ckipp01 commented 1 year ago

Describe the bug

So I originally hit on a very similiar issue to this with scala-cli and created an issue for it here, although I'm starting to think the issue actually lays deeper in Bloop. I'll create here to try and diagnose whether it's an issue with Bloop or maybe with Metals somehow, but my gut tells me Bloop.

The issue I linked about hints at Bloop holding onto some stale state and this seems to be the same case again. It's hard to reproduce, but let me outline how this happened for me. I was working on the coursier codebase and triggered a full clean compile. When looking at the logs I saw:

2023.05.27 12:19:45 INFO  time: compiled interop.cats.js[2.13.6] in 2.01s
May 27, 2023 12:19:56 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleNotification
WARNING: Notification threw an exception: {
  "jsonrpc": "2.0",
  "method": "build/publishDiagnostics",
  "params": {
    "textDocument": {
      "uri": "file:///Users/ckipp/Documents/scala-workspace/dotty/warning:%5Boptions%5D%20bootstrap%20class%20path%20not%20set%20in%20conjunction%20with%20-source%208%0A/Users/ckipp/Documents/scala-workspace/coursier/modules/cache/jvm/src/main/java/coursier/cache/internal/SigWinch.java"
    },
    "buildTarget": {
      "uri": "file:/Users/ckipp/Documents/scala-workspace/coursier/modules/cache/jvm/?id\u003dcache.jvm[2.13.6]"
    },
    "diagnostics": [
      {
        "range": {
          "start": {
            "line": 2,
            "character": 0
          },
          "end": {
            "line": 2,
            "character": 0
          }
        },
        "severity": 2,
        "source": "bloop",
        "message": " Signal is internal proprietary API and may be removed in a future release"
      }
    ],
    "reset": true
  }
}
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)
        at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:152)
        at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:220)
        at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:187)
        at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
        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(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.reflect.InvocationTargetException
        at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
        ... 11 more
Caused by: java.nio.file.NoSuchFileException: /Users/ckipp/Documents/scala-workspace/dotty/warning:[options] bootstrap class path not set in conjunction with -source 8
/Users/ckipp/Documents/scala-workspace/coursier/modules/cache/jvm/src/main/java/coursier/cache/internal/SigWinch.java
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
        at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
        at java.base/java.nio.file.Files.newByteChannel(Files.java:380)
        at java.base/java.nio.file.Files.newByteChannel(Files.java:432)
        at java.base/java.nio.file.Files.readAllBytes(Files.java:3288)
        at scala.meta.internal.io.PlatformFileIO$.slurp(PlatformFileIO.scala:45)
        at scala.meta.internal.io.FileIO$.slurp(FileIO.scala:24)
        at scala.meta.internal.mtags.ScalametaCommonEnrichments$XtensionAbsolutePath.toInput(ScalametaCommonEnrichments.scala:378)
        at scala.meta.internal.metals.Diagnostics.onPublishDiagnostics(Diagnostics.scala:166)
        at scala.meta.internal.metals.Diagnostics.onBuildPublishDiagnostics(Diagnostics.scala:146)
        at scala.meta.internal.metals.clients.language.ForwardingMetalsBuildClient.onBuildPublishDiagnostics(ForwardingMetalsBuildClient.scala:110)
        ... 15 more

2023.05.27 12:19:59 INFO  compiling interop.cats.jvm[2.13.6] (2 scala sources)
2023.05.27 12:19:59 INFO  compiling interop.scalaz.jvm[2.13.6] (2 scala sources)

Notice that right between the logs about certain modules being compiled I get an error thrown by the build server about a URI found in my local dotty codebase. That project isn't open, and shouldn't be appearing in the workspace logs of another project.

Expected behavior

I would never expect any reference to another project to appear and be causing issue in another project.

Operating system

macOS

Editor/Extension

Nvim (nvim-metals)

Version of Metals

0.11.12+77-cce28f19-SNAPSHOT

Extra context or search terms

No response

ghostbuster91 commented 7 months ago

I think I've just hit the same issue after trying to run metals in coursier codebase (fresh clone).

Editor/Extension

Nvim (nvim-metals)

Version of Metals

### Workspace: /home/kghost/workspace/coursier
 - Build definition is coming from mill.
 - Build server currently being used is Bloop v1.5.15.
2024.02.13 14:48:15 INFO  Attempting to connect to the build server...
2024.02.13 14:48:15 INFO  Bloop uses /nix/store/cjmqi7kaibr1ss560ybfmygyrxd22fnr-openjdk-17.0.7+7 defined at /home/kghost/.bloop/bloop.json
2024.02.13 14:48:15 INFO  Bloop currently uses settings: -Xmx8G,-Xss10m,-XX:+CrashOnOutOfMemoryError
2024.02.13 14:48:18 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/kghost/workspace/coursier/.metals/bsp.trace.json or /home/kghost/.cache/metals/bsp.trace.json
2024.02.13 14:48:18 INFO  time: Connected to build server in 2.4s
2024.02.13 14:48:18 INFO  Connected to Build server: Bloop v1.5.15
2024.02.13 14:48:18 INFO  time: Imported build in 0.22s
2024.02.13 14:48:21 INFO  time: indexed workspace in 3.04s
2024.02.13 14:48:21 WARN  no build target for: /home/kghost/workspace/coursier/build.sc
Feb 13, 2024 2:48:23 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 4
2024.02.13 14:48:26 INFO  time: code lens generation in 4.19s
2024.02.13 14:48:30 INFO  compiling cache.jvm[2.13.12] (39 scala sources and 7 java sources)
2024.02.13 14:48:42 WARN  Invalid text document uri received from build server: file:///home/kghost/workspace/coursier/warning:%5Boptions%5D%20bootstrap%20class%20path%20not%20set%20in%20conjunction%20with%20-source%208%0A/home/kghost/workspace/coursier/modules/cache/jvm/src/main/java/coursier/cache/internal/SigWinch.java
2024.02.13 14:48:42 INFO  BSP server:  Signal is internal proprietary API and may be removed in a future release
2024.02.13 14:48:42 WARN  javac exited with exit code 1
2024.02.13 14:48:42 INFO  time: compiled cache.jvm[2.13.12] in 11s