LSP icon indicating copy to clipboard operation
LSP copied to clipboard

add path-mapping function

Open 95833 opened this issue 11 months ago • 9 comments

95833 avatar Dec 12 '24 13:12 95833

Why did you close this? It seems useful. Note that it can be hard for maintainers to make time to review every pull request. I will re-open this just in case.

rwols avatar Dec 22 '24 09:12 rwols

I am fixing some bugs, so I have temporarily closed it.

95833 avatar Dec 22 '24 10:12 95833

I have converted the PR status to "draft" then. You can remove the "draft" status when you think it's ready.

rwols avatar Dec 22 '24 10:12 rwols

Alright, it should now be usable to some extent. At least on the surface, it seems that no new trouble have been introduced.

95833 avatar Dec 22 '24 11:12 95833

There are still some bugs, but I am unable to fix them. for example: 1 When I click on it, it opens a path that is not the displayed one, but rather a path that has not been mapped. After I tracked down the _diagnostics_async function in the documents.py file and added a print(sb.diagnostics) statement as shown in the image below, 3 The following content was printed out. 2 It can be seen that the initial diagnostic path has been successfully mapped, but then it prints out paths that have not been mapped. I don't know how to fix it.

95833 avatar Dec 22 '24 15:12 95833

Could you describe the use case for this; there isn't any linked issue or explanation in the opening comment, and I don't have any intuition just from the config description

Map the paths of URIs in the data exchanged between the server and the client.

why I would want to map paths like that. Apparently it has something to do with WSL. I think from the regular contributors I'm the only Windows user, but I've never really used WSL, so if this requires a certain setup then a step by step description would be useful if we want to test this PR.

Ideally this PR would have a test with something that currently doesn't work, but will be fixed by this PR (if this is applicable here).

jwortmann avatar Dec 23 '24 10:12 jwortmann

I use it in the WSL environment, but it is a general feature. clangd also has a path mapping option, and their functions should be consistent. However, clangd also has bugs and cannot meet my needs. @rwols Should be able to provide more explanation about this feature.

In my use case, I code using an editor on Windows and compile it with the toolchain and libraries in WSL. Since the project is compiled on Linux, the paths in the compile_commands used by clangd are all Linux paths. To correctly navigate to files, the LSP needs to map the Linux paths provided by clangd to Windows paths.

It's not the most natural way to implement it, but for someone like me who is not familiar with the LSP source code, it's the simplest way to do it. Even so, a strange bug still occurred.

95833 avatar Dec 23 '24 11:12 95833

Thanks for the explanation.

I see now that the "path_maps" config already existed in the code, it was just not documented (unfinished implementation?). Then it should also be added into the JSON schema under https://github.com/sublimelsp/LSP/blob/fb0fc753ed9b918d1903d8efa9ea084866ef4281/sublime-package.json#L323-L327

I wonder why path_maps is a list of dicts, and not just simply a single dict. But I'm also not very familiar with that part of the code, and it might not be a good idea to change it now if that would be breaking.

jwortmann avatar Dec 25 '24 11:12 jwortmann

Most of the code should be provided by @rwols , I am just using his code to meet some of my needs. He is more familiar with this part of the code than we are, so he should decide how to handle this PR.

95833 avatar Dec 25 '24 12:12 95833