I am well aware that this question has been asked a million times. At least I feel like I’ve read one million descriptions of this (and just fewer than that in purported solutions). Nothing has worked so far and I’m losing my mind.
I frequently work in a giant monorepo. Historically, this was mostly a Golang codebase, so the repo itself has many Go packages under one top-level go.mod
and the whole repo lives under $GOPATH. But by now it additionally has dozens of Rust, TS, Python, whatever projects. I still have to contribute to many Go projects, so I want to configure lsp-go
with gopls to use the whole repo as its workspace (since we don’t use Go submodules). I also work in many Rust projects that are subdirectories of the repo. So I want to configure many subdirectories of the git repo to be themselves project workspaces for rustic
and rust-analyzer.
Here is the start of the section of my emacs configuration that concerns lsp-* things. In lsp-mode
I do have (setq lsp-auto-guess-root nil)
, which seems to be the most commonly mentioned important setting. I have also deleted everything that existed with lsp-workspace-folders-remove
, and I’m trying to add back (very tediously, I should say) every project I think I’ll work with using lsp-workspace-folders-add
.
The problem is that if at any time I add the Go workspace that subsumes everything else before I try another project, I get no interactive prompt to set a root for the project in a subdirectory, and it just chooses the git root automatically.
Notably, I use projectile
and I understand, but not well enough I guess, that this package plays a large part in this calculation. This is the configuration at the time of this post, but I’ve played around with more detailed configuration involving projectile-project-root-functions
. I’ve tried adding a .projectile
in the non-Go projects. I’ve tried approaches with a .dir-locals.el
file. All of my efforts have failed.
This can’t be that hard, right? I have really tried to fix this on my own before coming here. Can someone please point out where I’ve gone wrong? Or point me to some material that isn’t old enough to mention functions that don’t exist any longer, in case I haven’t seen that yet? If projectile
is the real problem, I would be so happy to not use it anymore, so that’s a possible answer too.