This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-25
Channels
- # announcements (10)
- # babashka (21)
- # calva (8)
- # cider (6)
- # clj-commons (5)
- # clj-kondo (37)
- # cljfx (16)
- # clojure (31)
- # clojure-australia (1)
- # clojure-europe (7)
- # conjure (8)
- # cursive (3)
- # data-science (4)
- # datalevin (6)
- # datomic (18)
- # emacs (10)
- # holy-lambda (3)
- # honeysql (4)
- # humbleui (1)
- # introduce-yourself (1)
- # lsp (13)
- # malli (6)
- # portal (8)
- # scittle (5)
- # specter (1)
- # vscode (9)
- # xtdb (5)
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)
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.
So with this in your config, all you need to do is to touch .project.el
in the /projects/foo
and /projects/bar
Of course you could also choose to look for deps.edn
TBH it's a little strange that eglot doesn't support this not uncommon setup out of the box
I'm no eglot user, lsp-mode, but I know eglot has some limitations with clojure-lsp, like going to java source not working 😔
Didn't run into those problems yet - so far eglot has been a much smoother experience than lsp-mode, except for the monorepo issue
Wrote it up as a gist, who knows who will need it https://gist.github.com/pesterhazy/e8e445e6715f5d8bae3c62bc9db32469