Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala metals lsp not loading in Helix #10783

Closed
xpetitt123 opened this issue May 17, 2024 · 2 comments
Closed

Scala metals lsp not loading in Helix #10783

xpetitt123 opened this issue May 17, 2024 · 2 comments

Comments

@xpetitt123
Copy link

xpetitt123 commented May 17, 2024

Summary

After installing Metals via coursier, Helix doesn't load or detect the lsp server inside a .scala file.

Logs

[tomasp@tomasp ~]$ hx --health scala
Configured language servers:
  ✓ metals: /home/tomasp/.local/share/coursier/bin/metals
Configured debug adapter: None
Configured formatter: None
Highlight queries: ✓
Textobject queries: ✓
Indent queries: ✓

~/.cache/helix/helix.log

2024-05-17T14:51:23.202 helix_lsp::transport [ERROR] metals <- InternalError: Internal error.
2024-05-17T14:51:23.202 helix_lsp [ERROR] failed to initialize language server: protocol error: InternalError: Internal error.
2024-05-17T14:51:45.172 helix_lsp::transport [ERROR] metals <- InternalError: Internal error.
2024-05-17T14:51:45.172 helix_lsp [ERROR] failed to initialize language server: protocol error: InternalError: Internal error.
2024-05-17T14:56:20.311 helix_lsp::client [WARN] language server failed to terminate gracefully - server closed the stream
2024-05-17T14:58:26.000 helix_lsp::transport [ERROR] metals <- InternalError: Internal error.
2024-05-17T14:58:26.000 helix_lsp [ERROR] failed to initialize language server: protocol error: InternalError: Internal error.
2024-05-17T14:58:52.623 helix_lsp::client [WARN] language server failed to terminate gracefully - server closed the stream
2024-05-17T15:00:15.794 helix_lsp::transport [ERROR] metals <- InternalError: Internal error.
2024-05-17T15:00:15.794 helix_lsp [ERROR] failed to initialize language server: protocol error: InternalError: Internal error.
2024-05-17T15:00:23.526 helix_lsp::client [WARN] language server failed to terminate gracefully - server closed the stream

languages.toml

[[language]]
name = "scala"
scope = "source.scala"
roots = ["build.sbt", "build.sc", "build.gradle", "build.gradle.kts", "pom.xml", ".scala-build"]
file-types = ["scala", "sbt", "sc"]
comment-token = "//"
block-comment-tokens = { start = "/*", end = "*/" }
indent = { tab-width = 2, unit = "  " }
language-servers = [ "metals" ]

[[grammar]]
name = "scala"
source = { git = "https://github.com/tree-sitter/tree-sitter-scala", rev = "7891815f42dca9ed6aeb464c2edc39d479ab965c" }

hx -v

2024-05-17T15:41:49.391 helix_vcs [INFO] Error {
    context: "failed to open git repo",
    source: Discover(
        NoGitRepository {
            path: "/home/tomasp/Documents/Programs/Scala",
        },
    ),
}
2024-05-17T15:41:49.391 helix_vcs [INFO] failed to open diff base for /home/tomasp/Documents/Programs/Scala/class.scala
2024-05-17T15:41:49.391 helix_vcs [INFO] Error {
    context: "failed to open git repo",
    source: Discover(
        NoGitRepository {
            path: "/home/tomasp/Documents/Programs/Scala",
        },
    ),
}
2024-05-17T15:41:49.391 helix_vcs [INFO] failed to obtain current head name for /home/tomasp/Documents/Programs/Scala/class.scala
2024-05-17T15:41:49.392 helix_lsp::client [INFO] Using custom LSP config: {"isHttpEnabled":true}
2024-05-17T15:41:49.392 helix_lsp::transport [INFO] metals -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"fileOperations":{"didRename":true,"willRename":true},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"24.3 (2cadec0b)"},"initializationOptions":{"isHttpEnabled":true},"processId":18986,"rootPath":"/home/tomasp","rootUri":null,"workspaceFolders":[]},"id":0}
2024-05-17T15:41:50.108 helix_lsp::transport [INFO] metals <- {"jsonrpc":"2.0","id":0,"error":{"code":-32603,"message":"Internal error.","data":"java.lang.RuntimeException: java.lang.reflect.InvocationTargetException\n\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)\n\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)\n\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)\n\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)\n\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)\n\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)\n\tat org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)\n\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:829)\nCaused by: java.lang.reflect.InvocationTargetException\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\n\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)\n\t... 11 more\nCaused by: java.lang.IllegalArgumentException: Missing scheme\n\tat java.base/java.nio.file.Path.of(Path.java:199)\n\tat java.base/java.nio.file.Paths.get(Paths.java:97)\n\tat scala.meta.internal.mtags.MtagsEnrichments$XtensionURIMtags.toAbsolutePath(MtagsEnrichments.scala:131)\n\tat scala.meta.internal.mtags.MtagsEnrichments$XtensionStringMtags.toAbsolutePath(MtagsEnrichments.scala:187)\n\tat scala.meta.internal.metals.MetalsEnrichments$XtensionString.toAbsolutePath(MetalsEnrichments.scala:741)\n\tat scala.meta.internal.metals.MetalsEnrichments$XtensionString.toAbsolutePath(MetalsEnrichments.scala:738)\n\tat scala.meta.metals.MetalsLanguageServer.$anonfun$initialize$3(MetalsLanguageServer.scala:142)\n\tat scala.Option.map(Option.scala:242)\n\tat scala.meta.metals.MetalsLanguageServer.initialize(MetalsLanguageServer.scala:140)\n\t... 16 more\n"}}
2024-05-17T15:41:50.108 helix_lsp::transport [ERROR] metals <- InternalError: Internal error.
2024-05-17T15:41:50.108 helix_lsp [ERROR] failed to initialize language server: protocol error: InternalError: Internal error.
2024-05-17T15:42:02.201 helix_lsp::transport [INFO] Language server not initialized, shutting down
2024-05-17T15:42:02.201 helix_lsp::client [WARN] language server failed to terminate gracefully - server closed the stream

Versions

  • helix 24.3 (2cadec0)
  • metals 1.3.1
  • Scala code runner version 3.4.2
  • coursier version 2.1.10

Terminal emulator

  • alacritty 0.13.2

OS

  • Void Linux

Did I miss a step in setting the language server up?

@zetashift
Copy link
Contributor

Did you import the build?
There is a workspace command :lsp-workspace-command called import build that sets things up https://scalameta.org/metals/docs/editors/helix#importing-builds

You can also configure metals to do this automatically, by adding this to your languages.toml:

[language-server.metals.config.metals]
autoImportBuild = "all"

@xpetitt123
Copy link
Author

Thank you for that. I initially added the line to the languages.toml file and nothing happened - I kept receiving a "no language servers" message after using :lsp-workplace-command. Going through the log file of hx -v I failed to notice that metals apparently requires the directory to be a git directory. After a git init, :lsp-workplace-command did offer me the option to import the build and everything works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants