lsp-mode
lsp-mode copied to clipboard
Custom project root for all files in a project
lsp--calculate-root
calculates the project root by asking the user via lsp--find-root-interactively
. Here I am missing an option to provide a custom project root for all files in the current project.
My simplified problem / use case:
- First Clojure git project
/p/mylib
- Second Clojure git project
/p/myapp
By default, Emacs starts a lsp-server / lsp session for each of these projects. This causes that lsp-find-references
in /p/mylib
does not find the references in /p/myapp
. I would prefer the default behavior from VSCode. When adding two "folders" to a VSCode-workspace, there is a single lsp-server which serves both. And all lsp commands work across both folders.
Since Emacs has projects instead of VSCode-workspaces and folders, this is tricky. I still want commands like projectile-find-file
or magit-status
to work on the individual projects. But I want lsp commands like lsp-find-references
to work accross multiple projects.
I discovered that I can get this behavior by providing always the same value /p/all-clj
as project root to the interactive question from lsp--find-root-interactively
. But this question pops up on every file I open. There is no option to persist my custom root directory.
Proposals:
- Provide a new option in
lsp--find-root-interactively
so that the user can provide a custom project root which is saved as the value for all files in the current project. - Extend the
(or ...)
form inlsp--calculate-root
so that a variable is used as the return value. So that the user can set this variable in his configuration or in his.dir-locals.el
.
I discovered that I can get this behavior by providing always the same value
/p/dummy-workspace
as project root to the interactive question fromlsp--find-root-interactively
. But this question pops up on every file I open. There is no option to persist my custom root directory.
lsp-mode persists the roots in lsp-session-file and you should not be asked again.
This is the content of my lsp-session-file
:
#s(lsp-session ("/p/all-clj") nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ()) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ()) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ()))
I am very new to Emacs / elisp and I do not understend what this content means. But it seams impossible that this saves the association of all files I have associated to a given lsp-session. It seams it saved the lsp-session /p/all-clj
. But it did not save that I have connected /p/mylib/src/mylib/core.clj
and /p/myapp/src/myapp/main.clj
with this session. And I would like lsp-mode to auto-connect all files from /p/mylib
and /p/myapp
with this lsp-session.
We use the nearest project root if it is already added. If you want to associate files outside of project root with a particular workspace, then there is :library-folders-fn
when registering the client which typically is used for /usr/lib
like stuff.
This is exactly the case. My projects /p/mylib
and /p/myapp
do not have a common project directory, but I want them to have the same lsp-session /p/all-clj
.
How can I leverage :library-folders-fn
to customize the lsp-session for my projects?
@witek we should add setting like we do here: https://github.com/yyoncho/lsp-mode/blob/master/clients/lsp-pylsp.el#L426
we should add setting like we do here: https://github.com/yyoncho/lsp-mode/blob/master/clients/lsp-pylsp.el#L426
But is this really specific to the language specific code? I can imagine having the same issue regardless of the language.
the setting can be exposed for all servers. The different servers might have different logic regarding the outside of root files.