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

Path remapping for LSP #5204

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

UseAfterFreee
Copy link

Path remapping for LSP

(See issue #3002 for more context)

Sometimes it is useful to have the language server running in a docker container with all the required dependencies for the project, whereas the editor is running on the developers local machine. In this case helix can use the docker executable to open a tty with the language server running in the container. However since the volume mapping of the container likely causes path mismatches the communication between the editor and the language server is not done correctly.

A simple approach to fix this would be to scan the strings going over the transport layers and map the paths accordingly, however this might mistakenly modify certain pieces of the communication that are not specifying paths to be used by the editor or the language server. One example could be a string literal in the source code containing one of the path prefixes.

Solution implemented in this PR

In this PR an alternative approach is implemented where a remap method is added to the lsp::Url struct. Then everywhere where the editor sends something to the language server a mapping is performed to adjust the paths. Similarly whenever the editor uses a path it obtained from the LSP (for example in the diagnostics and the code actions) it maps it back to the correct paths.

The mapping is made configurable in the languages.toml file (and thus can be done on a project by project basis with different path mappings for each project in the $PROJECT_DIR/.helix/languages.toml file)

an example configuration could be as follows:

[[language]]
name="rust"
language-server = { command = "docker", args = ["start", "-i", "rust-analyzer"], path-mapping = { from = "/home/user/dev/some-project", to = "/app" } }

This allows the language server and the editor to run in two different filesystems with potentially different root_uri's.
Fixes helix-editor#3002.
@pascalkuthe pascalkuthe added C-enhancement Category: Improvements A-language-server Area: Language server client S-waiting-on-review Status: Awaiting review from a maintainer. labels Dec 18, 2022
@thomasaarholt
Copy link
Contributor

Is there something blocking this PR? I think this would be a great feature, perhaps particularly if it could be combined with a way to connect to running containers dynamically (see my feature request in #7472).

@roqvist
Copy link

roqvist commented Nov 23, 2023

Anyway to help this forward?

@natearn
Copy link

natearn commented Jan 2, 2024

This would be a great help. I use this workflow often, and getting LSP features working with it has been a persistent challenge.

@rsmirnov90
Copy link

Indeed... this would be a gamechanger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-enhancement Category: Improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants