LSP
LSP copied to clipboard
Support URI navigation
Is your feature request related to a problem? Please describe. I would like to be able to click a file URI in hovers and be taken to the correct file and range. This works in vscode, but not in Sublime LSP.
Describe the solution you'd like I would like Sublime to parse URI links in the format and on click navigates to the correct place. The Line, Char definition in the fragment is 1-based.
file://path/to/file#L34,1-L35,3
file://path/to/file#34,1-35,3
file://path/to/file#L34,1-35,3
file://path/to/file#L34
file://path/to/file#L34,1
Describe alternatives you've considered none
Additional context
An example hover:
How vscode navigates and select on click on URI in hover:

Interesting, which server is it that uses such links?
There is already some simple logic implemented to parse and open URIs in the form file://path/to/file#34 on the respective line:
https://github.com/sublimelsp/LSP/blob/2ac87a73b3a4d95c74d10c39caca4d5820d31e0c/plugin/hover.py#L304-L313
It could probably extended in a way to open the file with a particular selection already applied, if given in the link fragment.
But the problem is rather that there is no convention in the LSP specs on how file URIs from Markdown content should look. The only thing specified is that
If the format is markdown the content should follow the GitHub Flavored Markdown Specification.
But the format of file URIs with line numbers is of course not specified in the GFM docs. Right now I fear that different language servers might use different formats, and as long as it is not specified and kept as a secret VSCode behavior instead, I expect that such implementations would only work for particular servers. Some servers might even decide the link format for the Markdown hover dependent on which client is currently in use; for example the Julia server uses file://path/to/file#34 for VSCode and Sublime Text, and file://path/to/file:34 for other clients - https://github.com/julia-vscode/LanguageServer.jl/blob/146ad42b9e3a53af475cffef5a6dd36a573c9143/src/requests/hover.jl#L168-L174
It's the (new) Snyk Language Server backing our Eclipse plugin :).
There is no convention in the LSP spec, but Microsoft as inventor uses it extensively in vscode, and there it seems to be implemented like described. When it comes to LSP, I'd support the way vscode does, as they are the drivers and inventors of the whole LSP spec. I just searched for their implementation, and it looks like this: https://github.com/microsoft/vscode/blob/b51955e4c878c8facdd775709740c8aa5d1192d6/src/vs/platform/opener/common/opener.ts#L162.
As for our server, we would try not to cater to clients, as this is not maintainable in the long run.
In our server, we use this regexp for matching and extracting the URI fragment parts to a range:
^(.+)://((.*)@)?(.+?)(:(\d*))?/?((.*)\?)?((.*)#)L?(\d+)(?:,(\d+))?(-L?(\d+)(?:,(\d+))?)?
The match groups would be 1,2,4,5 for startLine, startChar, endLine, endChar (see https://github.com/eclipse/lsp4e/pull/196/files).