Fork me on GitHub
#lsp
<
2022-02-08
>
fuad15:02:59

Is there a way to know which config files have been loaded for a clojure-lsp process? I’m trying to determine whether the proper config files have been loaded (in the context of a monorepo with configs at multiple levels).

👀 1
fuad15:02:17

I checked the logs but I don’t see an explicit log entry for config files

ericdallo15:02:30

Yes, if using emacs try lsp-clojure-server-info check final settings

ericdallo15:02:45

I think calva has the same command if using it

ericdallo15:02:36

But, eve if in a mono-repo, clojure-lsp will only consider project-root config

fuad15:02:55

I’m on neovim with the built-in client:sob:

fuad15:02:06

My scenario seems to be similar to the one described https://clojurians.slack.com/archives/CPABC1H61/p1643018024170800

ericdallo15:02:23

That command is available for all clients, you just need to know how to call it from your client

👀 1
ericdallo15:02:11

My suggestion for your case is:

fuad15:02:27

My current solution to the problem is what borkdude described https://clojurians.slack.com/archives/CPABC1H61/p1643018141171800, but I was trying to figure out if I could have something smarter.

ericdallo15:02:38

Have a clj-kondo config at project root with :config-paths, pointing to the submodules configs

ericdallo15:02:44

It should work

fuad15:02:47

I’m not exactly unsatisfied with that solution, just curious

ericdallo15:02:34

Yeah, for lein mono-repo projects, this is the recommended for now: https://clojurians.slack.com/archives/CPABC1H61/p1643018184172800

fuad15:02:45

> Have a clj-kondo config at project root with :config-paths, pointing to the submodules configs If I understand correctly, what I have now is the opposite. One shared config at the monorepo root and one config per-project pointing to the monorepo root via config-paths. Are you suggesting the opposite?

ericdallo15:02:56

Both works, but I prefer to have specific on each submodule and just link from the project root as I mentioned

fuad15:02:06

> specific on each submodule and just link from the project root as I mentioned So, in a scenario with root config , module a and module b, you have: • module a-specific config • module b -specific config • root config with config-paths pointing to module a and module b • lsp root is set to the dir containing the root config Is that right?

fuad17:02:44

and that’s for lsp or for clj-kondo? or for both?

fuad17:02:08

I do have .lsp/config.edn at the monorepo root adding source-paths to sub-projects along with sub-project/.lsp/config.edn files

fuad17:02:36

I guess I’m confused by the interaction between lsp and clj-kondo and how each one defines the configs. I have to look that up first

ericdallo17:02:00

yeah, my suggestion was to clj-kondo config

ericdallo17:02:08

about lsp, we only support a root one

ericdallo17:02:43

Why you need to specify source-paths manually? clojure-lsp has a logic to find it automatically, isn't that working for your project?

fuad18:02:32

I’m actually trying to figure that out right now (that’s why I asked about inspecting which config files were loaded). I figured I can use :LspInfo from nvim-lsp to get the project root. If I open a subproject file, I get the following:

Language client log: /Users/fuad/.cache/nvim/lsp.log
 Detected filetype:   clojure
 
 1 client(s) attached to this buffer: 
 
 Client: clojure_lsp (id: 1, pid: 20845, bufnr: [1])
 	filetypes:       clojure, edn
 	autostart:       true
 	root directory:  <path-to-sub-project-root>
 	cmd:             clojure-lsp
 
 Configured servers list: html, jsonls, cssls, tsserver, eslint, clojure_lsp

fuad18:02:50

This is true for all sub-projects that contain a <sub-project>/.lsp/config file.

ericdallo18:02:59

yeah, that sounds wrong, you need to configure vim to open the subproject with the root as the project mono-repo root

👀 1
ericdallo18:02:12

it's not related with having a .lsp/config.edn though

👀 1
ericdallo18:02:31

it's a LSP client thing, there should be a way to configure this on coc-vim/neovim

ericdallo18:02:40

maybe @UMMMKKADU knows

👀 1
fuad18:02:03

right, so I know I can do the following:

(defn opts [default-server-opts]
  (a.merge default-server-opts {:on_attach on-attach
                                :root_dir (util.root_pattern ".git")}))
this would tell it to use .git to detect the root

ericdallo18:02:34

I don't know about vim, but sounds right

rafaeldelboni18:02:51

Woah such nice thread between two great devs haha!

2
rafaeldelboni18:02:20

Hey weah I would consider playing with root_pattern

fuad18:02:23

cool. so, is it right to say that, in the context of a monorepo, it doesn’t make sense to have lsp configs at multiple levels?

fuad18:02:54

I did read this in the docs > clojure-lsp will look for project specific settings in a file called `.lsp/config.edn`. It will search from your project root folder up the directory structure so you can have multiple projects share the same settings.

ericdallo18:02:57

yes, it probably makes sense for some cases but we don't have support for that yet 😅

rafaeldelboni18:02:10

what we do here is something like this, with symbolic links (not the best tho)

👀 1
rafaeldelboni18:02:48

and I always start vim from backoffice folder

rafaeldelboni18:02:59

since it has it's own deps.edn

rafaeldelboni18:02:02

it works fine

1
ericdallo18:02:37

@U3RBA0P4L check it out the config search logic https://github.com/clojure-lsp/clojure-lsp/blob/master/lib/src/clojure_lsp/config.clj#L58, we actually check for project-root and parents, I forgot about that 😅

👀 1
ericdallo18:02:18

so having multiple configs on sub-a and mono-repo, should work, but I don't remember the last time I tested or saw that work 😂

fuad18:02:32

Right! So if I set the lsp root to the monorepo root, it does give me a different result when running :LspInfo . The root config adds "source-paths" for the sub-projects, but then I don’t know if it’s picking up the sub-projects’s lsp configs. My guess is no but I’ll try to confirm that.

ericdallo18:02:03

it's probably not picking up the sub ones

ericdallo18:02:12

we only check for parent folders not child ones

ericdallo18:02:40

so opening project mono/sub would search for sub and mono configs

1
ericdallo18:02:11

but opeining as mono would search only on mono (and parents until /)

1
fuad18:02:49

cool! so our understanding is the same. I’m not even sure we need configs at multiple levels, so • if we need different configs at multiple levels ◦ we should prefer to pick up mono/sub/.lsp/config and let clojure-lsp recurse up to get the parent one • if we don’t need different configs at multiple levels ◦ we should prefer to pick up mono/.lsp/config

ericdallo18:02:04

yeah, as my experience you may face other issues opening sub projects instead of the mono one, so I'd suggest using always the mono-repo one with one single config to avoid confusion

fuad18:02:34

ok ok that makes sense to me thanks2

👍 1
fuad18:02:48

now, just for the sake of completeness, going back to the initial clj-kondo considerations: different clj-kondo configs per-project might be needed. if I have a single clj-kondo config at the root with :config-paths pointing to sub-projects, does that mean I can have different linting rules per project?

fuad18:02:24

or does that mean I would have to go with the 1-config-per-project-each-one-pointing-to-the-root approach?

ericdallo18:02:00

yes, the former should work, a config on mono-repo pointing to the subprojects ones

fuad19:02:44

ok, so the bottom-up approach (which @UMMMKKADU also mentioned) works fine for me. however, I can’t get my setup to work with just one monorepo top-level clj-kondo config. lsp simply doesn’t pick it up. looking at this https://github.com/clojure-lsp/clojure-lsp/blob/fe232a719707258ee53d72bf44166d5149e6ee0b/lib/src/clojure_lsp/kondo.clj#L27-L30 I think it should just work since my lsp project root is the monorepo root

ericdallo19:02:12

yeah, looks correct to me

pez08:02:28

👋 > you need to configure vim to open the subproject with the root as the project mono-repo root I'd like to share that, afaik, VS Code can't be configured to open a subproject like this. You need to open the project root. And to be able to open the same project root in separate VS Code windows, you need to create separate workspaces and at the same project root folder to them.

👍 1
pez08:02:22

I'm working in the same monorepo as @U3RBA0P4L, btw. 😃