lsp

2025-09-29T20:34:21.904629Z

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.

borkdude 2025-09-29T20:41:03.378819Z

Does zed support opening the project in server (like vscode for example, you can type $project/server code . and a window opens in server

borkdude 2025-09-29T20:44:06.520559Z

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

ericdallo 2025-09-29T20:44:12.934079Z

@stopachka I'll give a suggestion that will be the best IMO:

ericdallo 2025-09-29T20:46:09.192229Z

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

ericdallo 2025-09-29T20:46:34.312549Z

this way clojure-lsp will start at root but recognize the repos you want, all in a single process

borkdude 2025-09-29T20:47:38.926929Z

@ericdallo should users also specify which aliases clojure-lsp uses to calculate the classpath, like :dev?

ericdallo 2025-09-29T20:47:53.308549Z

otherwise you can configure project-specs clojure-lsp setting to customize that

ericdallo 2025-09-29T20:48:15.779879Z

clojure-lsp uses dev and test aliases by default, user can define that via source-aliases if wanted

2025-09-29T20:48:51.305449Z

Oo this is really interesting!

borkdude 2025-09-29T20:50:19.153749Z

@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?

ericdallo 2025-09-29T20:55:06.310819Z

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

borkdude 2025-09-29T20:57:52.324699Z

I still don't understand 2. Usually aliases are a combination of paths and deps right? Not just project sources

borkdude 2025-09-29T20:58:20.270369Z

or does it only look at :paths and :extra-paths from those aliases for project sources

borkdude 2025-09-29T21:00:29.294939Z

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

Drew Harris 2025-09-29T21:08:36.701009Z

@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

Drew Harris 2025-09-29T21:10:14.766169Z

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

borkdude 2025-09-29T21:10:49.939799Z

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"}}}}}

Drew Harris 2025-09-29T21:12:42.951319Z

I get this error when using that:

borkdude 2025-09-29T21:13:20.257929Z

I fixed it after a couple of iterations, hopefully.

borkdude 2025-09-29T21:14:35.695489Z

(typing code in slack is harder than in an editor)

Drew Harris 2025-09-29T21:14:36.493059Z

added the extra squiggle bracket, now I have 100s of errors and warning for undefined variables and imports

borkdude 2025-09-29T21:15:45.415299Z

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

Drew Harris 2025-09-29T21:20:05.884779Z

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:

borkdude 2025-09-29T21:22:59.399389Z

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

Drew Harris 2025-09-29T21:23:19.815859Z

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

Drew Harris 2025-09-29T21:24:24.386849Z

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

borkdude 2025-09-29T21:25:46.324309Z

Ah look what I found:

:kondo-config-dir nil ; defaults to <project-root-uri>/.clj-kondo

borkdude 2025-09-29T21:26:01.114189Z

you can set this in .lsp/config.edn in your project root apparently

borkdude 2025-09-29T21:26:39.130689Z

(set it to "server" obviously)

borkdude 2025-09-29T21:27:01.024299Z

or move everything to the root .clj-kondo directory. one of both

Drew Harris 2025-09-29T21:28:56.617489Z

That fixes 14 random errors that I had but go to definition are still broken

borkdude 2025-09-29T21:31:53.445469Z

which option did you go with?

Drew Harris 2025-09-29T21:48:51.851759Z

thank you for your help! everything is working now we ended up doing the deps.edn with the clj-kondo directory

borkdude 2025-09-29T21:49:17.820919Z

👍

❤️ 2