Fork me on GitHub
#calva
<
2022-09-17
>
Mario Trost11:09:23

I work in a project where the repo root is not the lein project root, like so:

- reporoot
  - src (I don't know yet, why this exists)
  - code (project is started inside here with lein dev)
    - project.clj
When I open the folder reporoot I don't get any IDE goodies like code navigation from Calva/Clojure-LSP, but it works fine when I open the folder code. As expected, Clojure-lsp Server Info command shows an empty classpath vector when opening reporoot but a correctly populated one when opening code folder. What I tried: 1. Setting reporoot/.lsp/config.edn :project-path to code/project.clj results in warning that project.clj could not be located 2. Setting :project-path to code results in errors (as expected from reading Clojure-lsp Docs) 3. Trying to cd into code before lein classpath is called by changing :classpath-cmd to [ "cd" "code" "&&" "lein" "classpath" ] , because the warning from try number 1. suggests to me that Clojure-lsp calls lein classpath from reporoot instead of code 4. Also some tries changing :source-paths in config.end to include code/src and also some changes to :source-paths in code/project.clj that didn't work out. Is there some way to call lein classpath from inside a subfolder of reporoot (if indeed that is the problem)?

Mario Trost11:09:23

Addendum: This is not urgent so enjoy your weekends if you can 🙂

skylize13:09:53

:thinking_face: I don't use Lein. But for a tools.deps project: If I make an empty folder folder (optionally adding an empty deps.edn in folder), copy some existing project project into folder, and then open folder in Code: 1. I get all the expected behavior from Calva in files inside project. 2. If I run Jack-In, I am presented with a menu to choose to run Jack-In on either /path/to/folder or path/to/folder/project.

pez13:09:22

Hmmm. I don't get any clojure-lsp help regardless if I have a tools.deps or Leiningen project in a sub folder of the opened root.

skylize13:09:26

I guess I'm just lucky? ☺️

pez13:09:15

It could also be that we differ on ”all the expected behavior” 😃 Can you navigate to any clojure core stuff?

pez14:09:52

I can make tools.deps work for me if I put a this deps.edn in reporoot:

{:deps {sub-proj/sub-proj {:local/root "sub-tools-deps-project"}}}

pez14:09:18

Hmmm, now it works without a deps.edn file. And I get navigation in a Leiningen sub-project as well...

pez14:09:09

Very strange. Especially this with that at first it didn't work, then it ”works”. Putting that into quotes, because clojure-lsp server-info reports a classpath of [] if I don't have a deps.edn file. And will only get the correct classpath for the tools.deps project if I specifiy the local/root of the sub project. For the Leiningen sub project I have no clue how to make it work. Probably we need help with getting the clojure-lsp settings right. Ping @UKFSJSM38

ericdallo14:09:46

clojure-lsp project itself is a example of a mono-repo deps project which works great, but deps allow that and make it easy with local/root, lein makes that harder. I don't know what setting is project-path you mentioned @ULA8H51LP, maybe you could provide a sample repro that doesn't work for you so we can try it as well?

skylize14:09:10

Not sure what you mean by "navigate to" clojure core stuff. Must be a feature I don't know about? I do get a popup of the docs when I hover over a core function symbol.

pez14:09:24

Popup is fine too. 😃 Navigate to some definition by cmd-clicking it. Or hit F12.

☝️ 1
skylize14:09:21

Ooh. Nice. 🍦

skylize14:09:49

But yeah. That works just fine in my attempt at a repro.

Mario Trost14:09:21

> If I run Jack-In, I am presented with a menu to choose to run Jack-In on either /path/to/folder or path/to/folder/project. That behavior is identical to with what I get, thanks for trying it out!

Mario Trost14:09:10

> Hmmm, now it works without a deps.edn file. And I get navigation in a Leiningen sub-project as well... Strange: It worked once for me but then I tried it again and it didn't.

Mario Trost15:09:48

> I don't know what setting is project-path you mentioned @ULA8H51LP, maybe you could provide a sample repro that doesn't work for you so we can try it as well? With project-path I meant the project-specs setting that can be configured with a .lsp/config.edn file (https://clojure-lsp.io/settings/#classpath-scan)

👍 1
Mario Trost15:09:19

The project public on Github but I just started working there 2 days ago and check with them if I can share it. If they rather I don't I try to create a repro. Thanks for all your help!

skylize15:09:39

From your link: > Note that clojure-lsp will make this scan to save the cache when: > • The project has no cache (`.lsp/.cache`) > • The project deps file (`project.clj` for example) changed. > • The clj-kondo config has changed. Perhaps LSP is not scanning for classpath because no trigger to indicate cache is out of date? What if you just delete reporoot/.lsp/cache and try again?

ericdallo15:09:43

@U90R0EPHA you thought makes sense, but we search for specific data in the cache here: https://github.com/clojure-lsp/clojure-lsp/blob/master/lib/src/clojure_lsp/crawler.clj#L198, so it's hard to be a corrupted cache, even so, worth the try

Mario Trost17:09:49

That didn't work either, here is a small repro: https://github.com/MTrost/reporoot I can share the bigger project too but the repro worked so made more sense to share that. But don't feel any urgency to fix this, I can work with just opening the code folder for. Thanks again for all the help!

ericdallo18:09:23

Thanks, I will try it myself soon

ericdallo21:09:44

@ULA8H51LP answering your question, lein does not support running from a different dir which is bad, but you can https://stackoverflow.com/questions/34078811/how-to-run-lein-from-another-directory-without-cd-to-project-dir, even so, there are other clojure-lsp features that rely on :project-root-uri to work properly, which is something client(Calva) sends, using the current opened dir IIRC. Fixing the classpath command would help but would be a workaround, the best would be if Calva allows users to send a different project-root-uri during LSP initialize request, lsp-mode (Emacs), for example allows that.

🙏 1
pez07:09:42

Issue please. 😃

🙌 1
pez09:09:40

I just tried it. (And got reminded that we've been trying it before.) VS Code won't allow it, whatever I send, VS Code will use the workspace root. I think our options here are: 1. Send the project-root-uri in some non-standard way 2. Not support this use case

👍 1
Mario Trost09:09:04

That's a bumber 😄 Issue is here, feel free to close again: https://github.com/BetterThanTomorrow/calva/issues/1866

🙏 1
pez10:09:30

I found a workaround, using VS Code Workspaces. I updated the issue with it. Please see if it works for you, @ULA8H51LP.

Mario Trost10:09:43

🎉🎉🎉 Works like a charm, thank you so much!

pez10:09:30

Awesome! Would you like to provide a PR adding that workaround to http://calva.io? I think it could go onto the general clojure-lsp page as well as get cross referenced from the page about workspace layouts.

pez10:09:19

I can of course do this myself, since I have things set up. But it is more fun with a contribution. 😃

Mario Trost10:09:12

yeah sure I give it a try!

pez10:09:36

Great! Please direct this one to dev (we usually direct doc changes to published) because it would be good with a changelog entry going with it that points to the issue you created.

Mario Trost10:09:07

:thumbsup: Should get to it later in the day

Mario Trost14:09:10

Here you go! Thanks again for the support to all of you! And for Calva, and for Clojure-LSP!

gratitude 2
phill21:09:45

Calva's command "Toggle the REPL connection" doesn't complain, but the prompt still says clj:user. I had started the Clojure process with Calva's jack-in -> Leiningen+Shadow. For the most part, everything went fine, but there was a remark "Failed starting cljs repl for build: :app. Is the build running and connected?". (That's the right build keyword.) By "connected" is it referring to the browser? At that exact moment, the browser was not open. I subsequently opened the browser to the page served by Shadow's dev http. Shadow's "npx shadow-cljs cljs-repl :app" REPL works. Can Calva also connect? The symptom looks similar to https://github.com/BetterThanTomorrow/calva/issues/1285 but I am trying with Leiningen+Shadow, not deps.edn.

bringe18:09:07

@U0ETXRFEW Any ideas here? You’re more familiar with this area of Calva.

pez19:09:55

Oh, thanks for the heads-up, @U9A1RLFNV. I had missed this one.

pez19:09:56

That's a confusing error message: ”Is the build running and connected?” because it doesn't need to be running or connected for the cljs REPL to start. I should reword that.

pez19:09:23

@U0HG4EHMH I think you might run into a Leiningen issue there, where it doesn't pick up the nrepl middleware configuration from the command line. You'll need to configure that in project.clj. See https://calva.io/connect/#leiningen-shadow-cljs-middleware-issue

fabrao23:09:08

Hello all, After start with VSCODE in Clojure project, I'm getting this: [Error - 20:45:32] Server initialization failed. Message: Internal error Code: -32603 [object Object] [Error - 20:45:32] Clojure Language Client client: couldn't create connection to server. Message: Internal error Code: -32603 In WSL is ok, only problem with Windows 11

ericdallo00:09:08

it seems calva is not finding clojure-lsp :thinking_face:

fabrao00:09:53

it says downloading ... but stop after

ericdallo00:09:51

so it's not being able to download clojure-lsp for some reason, as a workaround while Calva maintainers don't take a look, you could point to a clojure-lsp manually downloaded

ericdallo00:09:32

and there is a calva config to point the clojure-lsp path

fabrao01:09:43

only point to .exe like?

pez07:09:22

Yes, use the full path of the exe.

bringe18:09:32

Also, please create an issue for your problem.

fabrao23:09:32

Windows 11 Pro

🧵 1
fabrao23:09:32

Calva is utilizing cider-nrepl and clojure-lsp to create this VS Code experience.
  nREPL dependencies configured:
    nrepl: 1.0.0
    cider-nrepl: 0.28.5
    cider/piggieback: 0.5.3
  clojure-lsp version configured: latest

🧵 1