10

I just switched to using lsp for my C++ and Python IDE needs. However, I am running into a constant issue where Python and C++ files have the wrong root, as reported by (lsp-workspace-root).

The root is considered to be the git root (I assume from projectile) which is not the case in my project. When I first opened the file I did not get a prompt asking me for the project root and I made sure to delete the lsp session file (as set in lsp-session-file).

Any help is much appreciated.

1 Answer 1

10

You probably want (lsp-workspace-folders-add) to add sub-root directories. For example, if your Python files are located in the tests/ subdirectory, you add it as such with the command. Then, upon starting an LSP server in any of tests or tests/foo or tests/bar, the current working directory will be set to tests.

There's also more information at this reddit post, quoting:

lsp rely on projectile or project.el now only for suggesting project root. Once you open new file in a project and start lsp it will provide several options(import project, blacklist project, select other directory root). Once you select a root it will be persisted and used for the next sessions.

Then there is a command:

lsp-workspace-folders-add - Add workspace folder

Finally under configuration:

lsp-session-file - Automatically guess the project root using projectile/project.

4
  • 6
    Good enough. The command lsp-workspace-folders-add is what I was looking for. Thanks!
    – Tohiko
    Commented Aug 10, 2020 at 20:29
  • revisiting, it should recognise emacs project root configured by project-find-functions but doesnt.
    – RichieHH
    Commented Jun 11, 2021 at 8:35
  • Would it be possible to list added folders into lsp-workspace?
    – alper
    Commented Mar 21, 2022 at 17:50
  • @alper you can see the global list of all folders with (lsp-session-folders (lsp-session)). There is also a function (lsp-workspace-folders) that supposed to do the same per workspace, however it accepts a parameter which I haven't figured out where to get from.
    – Hi-Angel
    Commented Mar 7, 2023 at 6:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.