Fork me on GitHub
#lsp
<
2022-09-25
>
pesterhazy20:09:36

For anyone who's trying to use emacs + eglot + monorepo: By default eglot picks the repo root as its scope. But in a monorepo, that's often not what you want. In a large repo, analyzing all the *.clj file could take 30s or longer. So I wanted to scope eglot to a subfolder of the monorepo. Eglot is built on top of project.el and uses its (project-current) function to determine the root. Sadly project.el doesn't have a built-in way to say what your repo root is (a strange omission for a project management tool.) However, you can customize the behavior with some elisp

(defun zkj-project-override (dir)
  (let ((override (locate-dominating-file dir ".project.el")))
    (if override
      (cons 'vc override)
      nil)))

(add-hook 'project-find-functions #'zkj-project-override)

pesterhazy20:09:52

What this does is to set up an alternative root-finding mechanism. It looks for a "dominating file", i.e. a file called ".project.el", in the parent folder and its parent folder and so on. If it finds one, it picks that as the root.

pesterhazy20:09:23

So with this in your config, all you need to do is to touch .project.el in the /projects/foo and /projects/bar

pesterhazy20:09:42

Of course you could also choose to look for deps.edn

pesterhazy20:09:14

TBH it's a little strange that eglot doesn't support this not uncommon setup out of the box

👍 1
ericdallo20:09:15

I'm no eglot user, lsp-mode, but I know eglot has some limitations with clojure-lsp, like going to java source not working 😔

pesterhazy20:09:16

Didn't run into those problems yet - so far eglot has been a much smoother experience than lsp-mode, except for the monorepo issue

👍 1
🚀 1
borkdude20:10:12

Perhaps this snippet could live in a wiki on the clojure-lsp repo or so

borkdude20:10:19

or even in the official docs