Fork me on GitHub
#lsp
<
2021-07-10
>
valtteri12:07:52

I’ve recently started using clojure-lsp with CIDER and emacs. With CLJS “jump to definition” jumps to files in my /out folder where figwheel outputs. I should probably tell lsp to not look into this directory…?

ericdallo12:07:45

Try using the setting :ignore-classpath-folders true

ericdallo12:07:23

I meant ignore-classpath-directories

valtteri12:07:56

Thanks for a very quick response! If I set this, can I still jump into dependencies sources? :thinking_face:

valtteri12:07:35

I added a .lsp/config.edn file into my project with this content {:ignore-classpath-directories true} and restarted emacs but it still jumps to out/...

ericdallo12:07:36

Could you share you project.clj or deps.edn?

ericdallo12:07:55

You can suppress dependencies if you want

valtteri12:07:45

If it helps, my emacs config is stolen from Borkdude and jump to definition is defined like this

(defun find-definition ()
  "Try to find definition of cursor via LSP otherwise fallback to cider."
  (interactive)
  (let ((cursor (point))
        (buffer (current-buffer)))
    (lsp-find-definition)
    (when (and (eq buffer (current-buffer))
               (eq cursor (point)))
      (cider-find-var))))
But I think it’s using the lsp functionality in this case

valtteri12:07:41

Haven’t yet pushed .lsp files to the repo

valtteri12:07:55

But I haven’t made modifications to project.clj

valtteri12:07:10

Sorry I’ll have to jump away for a couple of hours but after that I’ll look into this again!

valtteri12:07:22

And thanks for the help already

ericdallo12:07:37

Np, I'll try repro local with that repo

ericdallo12:07:49

What symbol are estou try to go to definition?

ericdallo13:07:26

I can't make the project generate the out folder, I'm getting:

java.io.FileNotFoundException: /home/greg/dev/lipas/webapp/dist/index.bundle.js (No such file or directory) 
during lein figwheel

ericdallo13:07:03

Also, probably not related with your issue, but I maybe found another one, clojure-lsp is resolving this source-paths as Automatically resolved source-paths from project.clj: #{"test/clj" "src/cljc" "src/clj"} , are you sure is not missing src/cljs in your project.clj :source-paths? if this is intended, you can still tell to clojure-lsp use specific :source-paths in your .lsp/config.edn

ericdallo13:07:30

Otherwise, some features may not work for your cljs files, like find-references or find-definition of a re-frame sub/event

ericdallo13:07:05

anyway, I still can't generate the out folder, LMK when you back what I'm missing

valtteri15:07:37

Under :cljsbuild I have :source-paths ["src/cljs" "src/cljc"]

valtteri15:07:54

I don’t know if I should have :cljs on top-level as well :thinking_face:

valtteri15:07:17

Locally you need to install and bundle npm dependencies. npm install npx webpack Then leing figwheel should probably work

ericdallo15:07:31

Alright, so you can fix it with :source-aliases clojure-lsp config, specifying the cljsbuild alias

valtteri15:07:39

Ok, cool. Now I’m using cider-jack-in-clj&cljs so I get both repls. Should I have separate configs for backend / frontend from lsp point of view?

valtteri15:07:30

Ach.. Reading the docs and it looks like source-aliases should just do the trick. I’ll give it a spin

ericdallo15:07:49

Your project is only webapp, right? Or is there any other project/folder ?

valtteri15:07:12

Just the webapp

valtteri15:07:23

Hmmm tried :source-aliases but no cigar

ericdallo15:07:28

I suggest you use LSP on that webapp project root so

ericdallo15:07:54

Could you check clojure-lsp logs?

valtteri15:07:17

How? 😛 N00b with lsp

ericdallo15:07:41

Also, make sure you imported the project-root with lsp-mode on the webapp folder, not the root of the repo

ericdallo15:07:25

You can confirm that with lsp-workspace-folders-remove and then lsp and I to import it manually

valtteri15:07:54

Hmmm I had both the project root and /webapp in workspace folders. That could’ve messed it up

ericdallo15:07:23

Usually the repo root is the project root, so most users don't have that issue

valtteri15:07:07

Do I btw need to restart something after config changes or workspace changes or should it just be effective immediately?

ericdallo15:07:57

ATM you need to restart

ericdallo15:07:15

There are plans to improve that in the future

👌 3
valtteri15:07:47

Now I have only /webapp in workspace folders but still it jumps to /out. Looking at the logs now. Is there something particular you’re looking for or would you like me to dump the whole file here?

ericdallo15:07:05

Hum, about the out issue not sure we will find anything useful on logs, it'd be better if I could repro here

ericdallo15:07:34

How can I generate the out folder? I was getting a File not found exception

valtteri15:07:19

> 2021-07-10T15:51:46.297Z Tipo INFO [clojure-lsp.crawler:244] - Using default source-paths: #{“src” “test”}

valtteri15:07:36

This is probably OK

ericdallo15:07:55

Oh missed that msg, I'm not near the note right now, but I'll try to repro following those steps

ericdallo15:07:19

Meanwhile, you may need to configure correctly the source-paths

ericdallo15:07:50

The src and test default seems not a good default for your project

ericdallo16:07:22

Clojure-lsp should check the project.clj source-paths and resolve automatically, following the source-aliases setting

ericdallo16:07:48

In last case, you can configure manually the source-paths as well

valtteri16:07:50

Hmm all my sources are under src/ and test/. out/ is under resources/something/something

ericdallo16:07:25

Hum, but from your project.clj the source-paths are others, you can check if the namespaces of your code match the source-paths

ericdallo16:07:41

src is not the same of src/cljc for example, it may behave wrong as your namespace name would be my-project.foo and not cljc.my-project.foo

ericdallo16:07:32

Tldr, check the docs and try to use source-aliases and on last case if that doesn't work, source-paths settings on config.edn

valtteri16:07:43

I have this in my .lsp/config.edn :source-aliases #{:dev :test :cljsbuild} Should I see some mention about :cljsbuild in logs?

ericdallo16:07:57

the source-aliases should point to a alias that has a source-paths keyword in your project.clj

valtteri16:07:29

Yeah cljsbuild is probably the only alias that has source-paths

ericdallo16:07:58

Yeah, your source-aliases config seems correct

ericdallo16:07:07

Yes, you should see a mention of it

ericdallo16:07:28

Otherwise, it may be a clojure-lsp issue :p

valtteri16:07:03

No mention of it there

ericdallo16:07:17

What the auto resolve log says?

valtteri16:07:48

I just tried grepping all the clojure-lsp.xxxxxx.out files with cljsbuild and no hits

valtteri16:07:01

What is auto resolve log? Is it in these logs or something else?

ericdallo16:07:47

Yes, it's a line in the log file

ericdallo16:07:54

I recommend you use a log-path setting

ericdallo16:07:03

To log to the same file every time you restart server

valtteri16:07:17

Can’t find anything with autoresolve or resolve in the logs :thinking_face:

ericdallo16:07:52

It's one of the first logs when server starts

ericdallo16:07:07

Search for source-paths instead

valtteri16:07:27

Found this in one of the logs > [37mcom.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine[m [32m PosixJavaThreads.java: 192[m > [37mcom.oracle.svm.core.thread.JavaThreads.threadStartRoutine[m [32m JavaThreads.java: 553[m > [37mjava.util.concurrent.ForkJoinWorkerThread.run[m [32mForkJoinWorkerThread.java: 183[m > [37mjava.util.concurrent.ForkJoinPool.runWorker[m [32m ForkJoinPool.java: 1594[m > [37mjava.util.concurrent.ForkJoinPool.scan[m [32m ForkJoinPool.java: 1656[m > [37mjava.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec[m [32m ForkJoinPool.java: 1020[m > [37mjava.util.concurrent.ForkJoinTask.doExec[m [32m ForkJoinTask.java: 290[m > [37mjava.util.concurrent.CompletableFuture$AsyncSupply.exec[m [32m CompletableFuture.java: 1692[m > [37mjava.util.concurrent.CompletableFuture$AsyncSupply.run[m [32m CompletableFuture.java: 1700[m > [33mclojure-lsp.main.LSPTextDocumentService/reify/[1;33mget[m [32m main.clj: 187[m > [33mclojure-lsp.handlers/[1;33mcode-actions[m [32m handlers.clj: 248[m > [33mclojure-lsp.feature.code-actions/[1;33mall[m [32m code_actions.clj: 281[m > [33mclojure-lsp.refactor.transform/[1;33mfind-other-colls[m [32m transform.clj: 26[m > [33mrewrite-clj.zip/[1;33msexpr[m [32m zip.cljc: 237[m > [33mrewrite-clj.zip.base/[1;33msexpr[m [32m base.cljc: 72[m > [33mrewrite-clj.node.protocols/[1;33msexpr[m [32m protocols.cljc: 49[m > [33mrewrite-clj.node.seq.SeqNode/[1;33msexpr*[m [32m seq.cljc: 19[m > [33mrewrite-clj.node.seq/map-node/[1;33mfn[m [32m seq.cljc: 142[m > [33mclojure.core/[1;33mapply[m [32m core.clj: 667[m > [37m...[m [32m [m > [33mclojure.core/[1;33mhash-map[m [32m core.clj: 381[m > [33mclojure.core/[1;33mhash-map[m [32m core.clj: 389[m > [37m...[m [32m [m > [1;31mjava.lang.IllegalArgumentException[m: [3mNo value supplied for key: source-aliases[m

valtteri16:07:11

This is my config.edn

{:ignore-classpath-directories true
 :source-aliases               #{:dev :test :cljsbuild}} 

ericdallo16:07:08

Oh thats a bug

🐛 3
ericdallo16:07:20

Would you mind open an issue with that info and how to repro?

valtteri16:07:46

I can try to make even a minimal repro a bit later today. 🙂

valtteri16:07:51

And will open the issue then

ericdallo16:07:05

I can try to fix it soon, meanwhile you can use the source-paths LSP config manually

👌 3
ericdallo16:07:13

That would be perfect

valtteri16:07:46

Yep, this is not a showstopper for me now. 🙂 But thanks a ton for looking into this!

👍 3
valtteri18:07:12

Started creating minimal repro but now I can’t repro it even with the original repo. 😄 Jump to definition works like a charm. Tried even removing :ignore-classpath-directories but it still works as it should after emacs restart. I’m a bit confused but happy. I’ll be working tomorrow with the large project and I’ll investigate more if/when the problem manifests again. Also if I have time I’ll still try backtrack all the things we tried earlier today and see if there was something that actually made it work.

ericdallo18:07:34

Haha, alright, lmk if need any help

ericdallo18:07:51

Oh, that exception was not a bug actually, it's not important :)

👌 3