polylith

Mark Wardle 2024-07-31T20:17:58.030799Z

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?

Oliver Marks 2024-08-01T07:31:50.982609Z

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

Mark Wardle 2024-08-01T07:49:29.348199Z

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.

Oliver Marks 2024-08-01T07:55:17.437689Z

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.

👍 1
timo 2024-08-01T08:56:42.793449Z

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'

👍 2
Mark Wardle 2024-08-01T09:02:12.520899Z

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.

seancorfield 2024-07-31T20:22:39.906239Z

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?

Mark Wardle 2024-07-31T20:25:06.226419Z

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.

seancorfield 2024-07-31T20:29:49.074309Z

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?

Mark Wardle 2024-07-31T20:32:28.676939Z

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.

Oliver Marks 2024-08-01T05:45:29.025379Z

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

seancorfield 2024-08-01T05:55:21.624949Z

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.