scalameta / metals

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

Can't import Tapir into metals #6780

Closed adamw closed 1 month ago

adamw commented 1 month ago

Describe the bug

When opening Tapir using VSCode + Metals, I get an "empty build targets" warning. Doctor says the following:

Metals Java: 21.0.2 from Oracle Corporation located at /Users/adamw/.sdkman/candidates/java/21.0.2-open

Metals Server version: 1.3.5

Below are listed the build targets for this workspace. One build target corresponds to one classpath. For example, normally one sbt project maps to two build targets: main and test.

Project's Java: 21.0.2 located at /Users/adamw/.sdkman/candidates/java/current

Build server currently being used is Bloop v1.6.0.

⚠️ No build targets were detected in this workspace so most functionality won't work.

Make sure the workspace directory '/Users/adamw/projects/tapir' matches the root of your build.
Try removing the directories .metals/ and .bloop/, then restart metals And import the build again.

Indeed. most functionality doesn't work.

Logs:

2024.09.17 09:40:29 INFO  Started: Metals version 1.3.5 in folders '/Users/adamw/projects/tapir' for client Visual Studio Code 1.93.1.
SLF4J(W): Class path contains multiple SLF4J providers.
SLF4J(W): Found provider [scribe.slf4j.ScribeServiceProvider@9f9977]
SLF4J(W): Found provider [ch.qos.logback.classic.spi.LogbackServiceProvider@d9405af]
SLF4J(W): See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J(I): Actual provider is of type [scribe.slf4j.ScribeServiceProvider@9f9977]
2024.09.17 09:40:29 WARN  Flyway upgrade recommended: H2 2.3.230 is newer than this version of Flyway and support has not been tested. The latest supported version of H2 is 2.2.220.
2024.09.17 09:40:29 INFO  Attempting to connect to the build server...
2024.09.17 09:40:30 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /Users/adamw/projects/tapir/.metals/bsp.trace.json or /Users/adamw/Library/Caches/org.scalameta.metals/bsp.trace.json
2024.09.17 09:40:30 INFO  time: Connected to build server in 0.4s
2024.09.17 09:40:30 INFO  Connected to Build server: Bloop v1.6.0
2024.09.17 09:40:30 INFO  time: Imported build in 0.12s
2024.09.17 09:40:30 INFO  running doctor check
2024.09.17 09:40:30 INFO  java targets: 
2024.09.17 09:40:30 INFO  no build target found for /Users/adamw/projects/tapir/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala. Using presentation compiler with project's scala-library version: 3.3.3
Sep 17, 2024 9:40:31 AM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 9
Sep 17, 2024 9:40:31 AM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 10
2024.09.17 09:40:31 INFO  no build target found for /Users/adamw/projects/tapir/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala. Using presentation compiler with project's scala-library version: 3.3.3
2024.09.17 09:40:35 INFO  no build target found for /Users/adamw/projects/tapir/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala. Using presentation compiler with project's scala-library version: 3.3.3
2024.09.17 09:40:39 WARN  Flyway upgrade recommended: H2 2.3.230 is newer than this version of Flyway and support has not been tested. The latest supported version of H2 is 2.2.220.
2024.09.17 09:40:39 INFO  time: indexed workspace in 9.54s
2024.09.17 09:40:39 WARN  no build target for: /Users/adamw/projects/tapir/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala
2024.09.17 09:40:57 INFO  no build target found for /Users/adamw/projects/tapir/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala. Using presentation compiler with project's scala-library version: 3.3.3

The `SchemaMacroTest.scala bit looks suspicious. Other projects work fine. As in other projects, I have sbt settings which aims to import the projects only for one specific Scala version:

val scala3 = "3.3.3"
val ideScalaVersion = scala3

  ideSkipProject := (scalaVersion.value != ideScalaVersion) ||
    thisProjectRef.value.project.contains("Native") ||
    thisProjectRef.value.project.contains("JS"),
  bspEnabled := !ideSkipProject.value,

Expected behavior

Working project ;)

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

1.3.5

Extra context or search terms

No response

tgodzik commented 1 month ago

Thanks for reporting! Does your .bloop directory contain any json files? Did it fail to import maybe? I will double check on my end

adamw commented 1 month ago

Ah yes, I removed .vscode, .metals, .bloop and .bsp before trying again. I did have to run sbt before opening metals, though, as otherwise bloop reported some other errors. Running sbt seems to initialise bloop

tgodzik commented 1 month ago

Best to use the reset command, which will leave json files around. It looks like the initial issues caused you to remove .bloop, which then caused the new errors. Why did you remove them in the first place? This is probably what we should concentrate on.

adamw commented 1 month ago

I removed them to try a "clean import" as the project didn't import - not sure what where the exact errors, maybe the same

tgodzik commented 1 month ago

the project didn't import <- would be great to see the error from that if possible. It should actually be in .metals,though you unfortunately removed it, which is why I recommend doing a reset workspace, which only removes the files that could get corrupted.

Clean import of tapir seems to work otherwise.

adamw commented 1 month ago

Hm well I'm not sure what you'd like me to do :) I still get the same error, and the logs have

2024.09.17 14:58:27 INFO  no build target found for /Users/adamw/projects/tapir/build.sbt. Using presentation compiler with project's scala-library version: 3.3.3
tgodzik commented 1 month ago

Did you run metals.build-import after deleting? This should regenerate all the .bloop files. Otherwise it will not load any build targets.

adamw commented 1 month ago

Ah ... clicking "import build" seems to have fixed the issue, after removing everything one more time (this time alse project/.bloop). But maybe this would have helped from the beginning ...

Anyway, thanks! :)