9

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.

Tohiko
  • 1,589
  • 1
  • 10
  • 22

1 Answers1

9

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.

Hi-Angel
  • 525
  • 6
  • 18
RichieHH
  • 848
  • 4
  • 9
  • 6
    Good enough. The command `lsp-workspace-folders-add` is what I was looking for. Thanks! – Tohiko Aug 10 '20 at 20:29
  • revisiting, it should recognise emacs project root configured by project-find-functions but doesnt. – RichieHH Jun 11 '21 at 08:35
  • Would it be possible to list added folders into `lsp-workspace`? – alper Mar 21 '22 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 Mar 07 '23 at 06:18