Hey team, has any zed user here had luck "changing the project root" with clojure lsp? Context We have a repo like this:
instant
server
// our clojure project
client
Goal
We want to open the main repo, and have clojure-lsp know that the project root should be server/
Problem
Even when we tell Zed to pass in the -p command, the lsp seems to still get the project root as instant, rather than instant/server
Here's the config:
{
"lsp": {
"clojure-lsp": {
"binary": {
"arguments": ["-p", "server"]
},
"initialization_options": {
"log-path": "/tmp/clojure-lsp.out",
"cache-path": "/dev/null"
}
}
}
}
And here is what clojure-lsp.out says:
2025-09-29T20:31:41.273Z INFO [clojure-lsp.handlers:219] - :lsp/shutdown 0ms
2025-09-29T20:31:41.433Z INFO [clojure-lsp.db:83] - :db/read-cache 0ms
2025-09-29T20:31:41.433Z INFO [clojure-lsp.dep-graph:280] - :internal/maintain-dep-graph 0ms
2025-09-29T20:31:41.437Z DEBUG [clojure-lsp.startup:273] - [startup] Using cached classpath #{}
2025-09-29T20:31:41.438Z INFO [clojure-lsp.source-paths:86] - [startup] Using default source-paths: ["/Users/drew/programs/instant/src" "/Users/drew/programs/instant/test"]
2025-09-29T20:31:41.438Z WARN [clojure-lsp.kondo:372] - [clj-kondo] No configs copied.
2025-09-29T20:31:41.438Z INFO [clojure-lsp.startup:151] - :internal/copy-kondo-configs 0ms
2025-09-29T20:31:41.438Z INFO [clojure-lsp.startup:314] - [startup] Analyzing source paths for project root /Users/drew/programs/instant
We tried creating a wrapper script, which does cd server && clojure-lsp but that unfortunately didn't do the trick either.Does zed support opening the project in server (like vscode for example, you can type $project/server code . and a window opens in server
This might also help:
{:project-specs [{:project-path "deps.edn"
:env {"PATH" "/some/custom/path"} ;; optional if you want to override the PATH used in the classpath-cmd
:classpath-cmd ["clojure" "-A:my-custom-alias" "-Spath"]}]}
in .clojure-lsp/config.edn@stopachka I'll give a suggestion that will be the best IMO:
clojure-lsp is a mono-repo itself like your case, it has cli and lib deps submodules.
The way I recommend is to start at the mono-repo indeed and tell clojure-lsp what are the source-paths to look, the way we do it is have a top-level https://github.com/clojure-lsp/clojure-lsp/blob/master/deps.edn#L2-L3
this way clojure-lsp will start at root but recognize the repos you want, all in a single process
@ericdallo should users also specify which aliases clojure-lsp uses to calculate the classpath, like :dev?
otherwise you can configure project-specs clojure-lsp setting to customize that
clojure-lsp uses dev and test aliases by default, user can define that via source-aliases if wanted
Oo this is really interesting!
@ericdallo A couple more questions. 1. Does clojure-lsp combine all project specs into one classpath to analyze deps? 2. What source "source-" mean in source-aliases? Does it treat those as project sources? What if you also specify dependencies in those "source" aliases?
1. yes, it runs all project-specs cmds and if returns anything, it just merges 2. in the end clojure-lsp will need a classpath string, and consider that as the things to analyze, being local code or local deps
I still don't understand 2. Usually aliases are a combination of paths and deps right? Not just project sources
or does it only look at :paths and :extra-paths from those aliases for project sources
you probably defined the extra-paths here just for lsp since when depending on lib and cli via local/root you'd also get those path directories on your classpath? https://github.com/clojure-lsp/clojure-lsp/blob/e8d078f7bafda75a6bf2f09722ea79fee3b6ecc3/deps.edn#L2-L5
@ericdallo is there a reason why --project-path “server” wouldn’t be the option I am looking for?
Here is the layout of our repo (img):
Everything works perfectly when i run zed server and use the clojure lsp from that server.
But running zed . with the -p server cli argument doesn’t behave the same way
I am running the lsp with these settings in zed “clojure-lsp”: { “binary”: { “path”: “/opt/homebrew/bin/clojure-lsp”, “arguments”: [“-p”, “server”, “--log-path”, “/tmp/lsaidjf”], “ignore_system_version”: true } } It is sending the logs to /tmp/lsaidjs so I know that the args are being put though, but from what I can tell, the -p server has no effect on anything
Don't know why -p isn't working, but if I understand Eric correctly, adding a deps.edn with this at your project root should solve your issue.
{:aliases {:dev {:extra-deps {instant/instant {:local/root "server"}}}}}I get this error when using that:
I fixed it after a couple of iterations, hopefully.
(typing code in slack is harder than in an editor)
added the extra squiggle bracket, now I have 100s of errors and warning for undefined variables and imports
what if you also add :extra-paths ["server/src" "server/test"] to the alias? I'm not sure how it works, I was asking Eric about this
Go to definition works now, but i have more errors. Most of them are related to sql which we have stuff for in this folder. and here are some example errors:
it seems clj-kondo isn't correctly called with the right config dir by clojure-lsp. it probably expects you to move all of that stuff into a $project-root/clj-kondo directory
Is there an environment variable I can set that changes the root folder that everything gets run from?
Since if i open my editor in server/ everything works perfectly, we have spent a lot of time trying to “trick” the lsp into thinking that it is running in that folder, to no avail
Does “--project-root” do something other than running the whole server from a different folder? I’m new to Clojure so not sure if the terminology is leading me down the wrong path
Ah look what I found:
:kondo-config-dir nil ; defaults to <project-root-uri>/.clj-kondoyou can set this in .lsp/config.edn in your project root apparently
(set it to "server" obviously)
or move everything to the root .clj-kondo directory. one of both
That fixes 14 random errors that I had but go to definition are still broken
which option did you go with?
thank you for your help! everything is working now we ended up doing the deps.edn with the clj-kondo directory
👍