Slightly off-topic as this isn't a polylith issue per se, but an issue with neovim and the lsp client and using the right root directory (ie top-level, not a component deps.edn) Hi all. I'm using neovim. While this isn't a polylith issue, it looks as if clojure-lsp is being started at the root of a component (ie a project nested within a top-level directory), and not at the top-level root. I think this is because there is some logic that starts at the file opened and works up the filetree looking for a deps.edn file, and so this logic is wrong for a polylith structured project. Is there any easy way of configuring clojure-lsp to use the right root directory?
i am not sure on that I tend to open project then select a file inside the project that I wish to edit from there I do the jack in I imagine the workflow is similar in vim
Hmm thanks all. I’ll do an experiment and check whether which file I open first changes the lsp attached to any given subsequently opened buffer. Thank you.
When I started using polylith this caused me much confusion because dependencies I knew I added at the root where not available eventually it twigged why, and now I just start in the development folder when jacking in.
This works for me:
clojure_lsp = {
autostart = true,
root_dir = util.find_git_ancestor or util.root_pattern('workspace.edn', 'deps.edn', 'project.clj', 'bb.edn'),
},
EDIT:
where util is:
local util = require 'lspconfig.util'Thanks all. I can confirm that if one opens a file in the root directory, any subprojects that are subsequently opened will use an LSP configured at the root. @timok - thanks for that - I will also try that and that will save a step.
FYI, in Calva (VS Code), it has settings to prefer starting LSP in the root of the project. Maybe this is a question for #neovim -- but I suspect it has no concept of "project", only "files", and so it has to look up the tree for deps.edn to attempt to determine the project root?
Yes I think you are right. Just after posting the question I found the option in the lsp config :project-specs which if I give it a classpath - which I can get at the root level using clojure -A:dev -Spath - then I might override the default root.
Ah, per-project LSP configuration to tell it where the root is? Could be problematic if you share the project with others that have their filesystem organized differently?
Yes and it didn't work either.... Perhaps I will instead ask on #neovim as perhaps there's a way of tweaking the way it starts up the lsp server. Thanks for your pointer - it probably is better as a function of an editor rather than the filesystem.
Emacs has the same behaviour, you just have to remember to jack into the project from a file inside the development folder, which is normally what you want as you get access to all your components and projects this way, but this often catches me out as I usually open the file i want to edit and jack in
Can you open the directory instead of a file? That's typically what I do with VS Code: code . in Linux and it opens the whole project as a "workspace" and starts LSP from there.