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

Custom project root for all files in a project #3518

Open
witek opened this issue May 11, 2022 · 7 comments
Open

Custom project root for all files in a project #3518

witek opened this issue May 11, 2022 · 7 comments

Comments

@witek
Copy link

witek commented May 11, 2022

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 in lsp--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.
@yyoncho
Copy link
Member

yyoncho commented May 12, 2022

I discovered that I can get this behavior by providing always the same value /p/dummy-workspace 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.

lsp-mode persists the roots in lsp-session-file and you should not be asked again.

@witek
Copy link
Author

witek commented May 12, 2022

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.

@yyoncho
Copy link
Member

yyoncho commented May 12, 2022

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.

@witek
Copy link
Author

witek commented May 12, 2022

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?

@yyoncho
Copy link
Member

yyoncho commented May 12, 2022

@witek we should add setting like we do here: https://github.com/yyoncho/lsp-mode/blob/master/clients/lsp-pylsp.el#L426

@witek
Copy link
Author

witek commented May 12, 2022

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.

@yyoncho
Copy link
Member

yyoncho commented May 12, 2022

the setting can be exposed for all servers. The different servers might have different logic regarding the outside of root files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants