scalameta / metals-sublime

Sublime Text package for Metals, a language server for Scala
https://packagecontrol.io/packages/LSP-metals
Apache License 2.0
16 stars 10 forks source link

Goto Implementation - Unable to open URI #118

Closed ninth-dev closed 1 month ago

ninth-dev commented 2 months ago

When using Goto Implementation on a dependency, we will get a Unable to Open URI error.

  1. Current viewing the source of "Monad.scala" from the cats package.
Step 1 - Goto Implementation
  1. Using LSP: Goto Implementation
    • Here we can see a list of implementation. However the URI is "jar:file:///....."
Step 2 - List of implementations
  1. Selecting any results in an error with "Unable to open URI"
Error

Trying the same thing in with vscode works as intended.

Some notes on how it works in vscode.


Possible solution

  1. in metals.py override on_open_uri_async.

Called when a language server reports to open an URI. If you know how to handle this URI, then return True and invoke the passed-in callback some time.

  1. Here we can check if the URI starts with "jar:"

  2. invoke the LspMetalsFileDecoderCommand instead of the callback.

    • we will need to make some changes here to allow "jar"

The above would work. However when viewing the opened file - LSP will no longer be enabled. ( maybe because the file is open as a scratch file? )

To ensure LSP is still enabled when viewing these files, we can simulate what Goto Defintion does.

I've got a rough implementation working. See PR #119

rchl commented 2 months ago

The above would work. However when viewing the opened file - LSP will no longer be enabled. ( maybe because the file is open as a scratch file? )

To ensure LSP is still enabled when viewing these files, we can simulate what Goto Defintion does.

This is how you enable LSP for your custom URI: https://github.com/sublimelsp/LSP-jdtls/blob/e723885514c765cf67d94fff21eba269f782977b/LSP-jdtls.sublime-settings#L5-L10

ayoub-benali commented 1 month ago

Fixed by https://github.com/scalameta/metals-sublime/pull/120