Fork me on GitHub
#lsp
<
2021-08-26
>
Jakub Holý (HolyJak)09:08:52

Hello! I see in the logs > ERROR Could not load project cache from '/path/2/fulcro-rad-demo/.lsp/sqlite.db But this is a new project and I have not used LSP there before. So perhaps it should be just info/warning, not error?

ericdallo12:08:57

yeah, probably a warn for this would be better

Jakub Holý (HolyJak)09:08:26

I also get > INFO [clojure-lsp.crawler:21] - Finding classpath via clojure -Spath > ERROR [clojure-lsp.crawler:40] - Error while looking up classpath info in .../fulcro-rad-demo Cannot run program "clojure" (in directory ".../fulcro-rad-demo"): error=2, No such file or directory Yet, in the shell, it is just fine:

❯ which clojure
/usr/local/bin/clojure
Does LSP have a different path? How to verify/fix that?

ericdallo12:08:56

it seems related with your project root :thinking_face:

ericdallo12:08:30

it didn't find the path ../fulcro-rad-demo

ericdallo12:08:24

is your project a lein one? a shadow-cljs one? both?

Jakub Holý (HolyJak)13:08:35

(I run LSP via Cursive and its LSP Support plugin)

ericdallo13:08:23

let me test it

❤️ 3
ericdallo13:08:35

Everything worked as expected with emacs, I suspect you LSP plugin sent a wrong project root ../fulcro-rad-demo instead of /absolute/path/to/fulcro-rad-demo

ericdallo13:08:45

(I added a log on clojure-lsp server to log the project-root to easily find issues like that)

❤️ 3
Jakub Holý (HolyJak)13:08:11

cool, thanks! how can I get the version with the log added?

ericdallo13:08:40

only on next release or building manually on master, but there are other ways to get that

ericdallo13:08:07

As mentioned https://clojure-lsp.github.io/clojure-lsp/troubleshooting/#client-server-log, every client should provide the client<->server log

ericdallo13:08:19

check the LSP intellij plugin on how to get that

ericdallo13:08:35

on that log, it should mention the initialized request with the project-root-uri

Jakub Holý (HolyJak)13:08:39

I have clojure-lsp log file, if that is what you mean

Jakub Holý (HolyJak)13:08:40

I just tried again after restarting LSP and get the same error, this time with abs. paths > Error while looking up classpath info in /Users/me/Projects/external/fulcro-all/fulcro-rad-demo Cannot run program "clojure" (in directory "/Users/me/Projects/external/fulcro-all/fulcro-rad-demo"): error=2, No such file or directory (+ the same error for npx )

ericdallo14:08:27

on, I think somewhere else using LSP plugin reported the same issue

ericdallo14:08:42

it was related with Intellij/LSP plugin not finding clojure/npx on your PATH

Jakub Holý (HolyJak)14:08:29

quite possible, since clojure is under /usr/local/... and npx is in /Users/me/.nvm/versions/node/v10.24.1/bin/npx

ericdallo14:08:01

yeah, probably the shell that LSP plugin is using to launch clojure-lsp doesn't have there commands on PATH

💯 3
Jakub Holý (HolyJak)14:08:10

Perhaps print $PATH when you cannot find the executable?

ericdallo14:08:16

oh, good finding

ericdallo14:08:33

it's not easy to know if the executable is not in the PATH

ericdallo14:08:35

I think we already log this to both clojure-lsp server log and client so checking the exception seems good enough, is just that the java exception is not clear enough for shell commands

Proctor13:08:06

Does LSP handle ClojureScript’s “Clojure Namespace Aliasing” for things like Goto Definition and Show Doc String? https://clojurescript.org/guides/ns-forms#_clojure_namespace_aliasing

Proctor13:08:01

Not sure if it is directly that, or related to the reader macro for language conditionals, as macros in a .cljc file guarded with a #?(:clj also don’t show anything when trying to Goto Definition or Show Doc String

ericdallo13:08:41

If I understood correctly, you are asking if clojure-lsp will go to cljs.test even if you required clojure.test in a cljs project?

Proctor13:08:03

Trying to understand which things I can expect to lookup vs not, and I think that is what I am seeing at least

Proctor13:08:13

wasn’t sure if that was a known thing, or if something possibly related to setup

Proctor13:08:45

other CLJ based macros in ClojureScript also seem to behave similar, but not sure if that is related or not

ericdallo13:08:38

This definitely doesn't works with clojure-lsp, unless clj-kondo return the cljs.test analysis in the place of clojure.test

ericdallo13:08:56

feel free to open an issue for that, but I think we would need to do some improvements on clj-kondo as well, right @U04V15CAJ?

borkdude13:08:23

yeah, repro would be nice

ericdallo13:08:15

As far as I can understand, reading that docs is that doesn't need to be a cljc file

Proctor13:08:01

:thumbsup: Will see about getting something together for a baseline to reproduce, just wanted to make sure I was on the right track and understanding what I am thinking is happening. 😉

👍 6
Proctor15:08:11

Not sure if you want a full basic project setup, or just the file, but if the file, I pasted it above

Proctor15:08:41

the async go and <! references don’t show up with the help, regardless of which reference is used…

Proctor15:08:00

I can add a basic skeleton project out on github if that helps

borkdude15:08:06

yeah, that would help :)

Proctor15:08:48

just pushed some screenshots up as well

Proctor15:08:15

if there are any logs or any other things that might be helpful, I can push them up there too

Proctor15:08:21

thank you!

borkdude16:08:16

nice! I'll have a look

Jakub Holý (HolyJak)16:08:48

How does clojure-lsp communicate with an editor? Do they use stdin+stdout, or...?

ericdallo16:08:32

the LSP client (editor) is responsible for spawning the LSP server process, not as a daemon, but as a process, and they communicate via stdin/out

ericdallo16:08:47

sending and receiving LSP JSON

Jakub Holý (HolyJak)16:08:40

ok, thx! Now I understand I must not mess with the stdin/out 🙂

ericdallo16:08:56

haha yes, you can easily try clojure-lsp from your terminal to understand that if you want

ericdallo16:08:00

./clojure-lsp

👍 3
ericdallo16:08:15

and then it'll start to listen for json + content-length

Jakub Holý (HolyJak)16:08:59

My log file contains only

[clojure-lsp.server:419] - Starting server...
[clojure-lsp.nrepl:20] - ====== LSP nrepl server started on port 65034
[clojure-lsp.server:304] - Initializing...
It has run for 4 minutes now. Is it possible it got stuck somehow? I execute it from an editor via this script
#!/bin/bash -l
eval "$(direnv hook bash)" > /dev/null
exec /usr/local/bin/clojure-lsp #--verbose

ericdallo16:08:34

no, what happens is:

ericdallo16:08:54

after that Initializing.. log, clojure-lsp checks for the :log-path config and change log to log to that path

ericdallo16:08:13

you probably have something setted for :log-path right?

Jakub Holý (HolyJak)16:08:56

OMG, you are right, and I completely forgot

ericdallo16:08:14

yeah, maybe we can fix that somehow in the future, is not that easy though

Jakub Holý (HolyJak)16:08:32

Ok, I removed the setting and now the log file also has

[clojure-lsp.source-paths:135] - Automatically resolved source-paths from project.clj: #{"src" "src/main/clojure" "dev" "test" "src/test/clojure"}
but according to ps , lsp is not running anymore

ericdallo17:08:05

:thinking_face: odd, it should not stop/finish unless a huge exception

Jakub Holý (HolyJak)17:08:20

I tried again and I see a number of clojure-lsp runs, one by one. From the log:

T17:01:15.970Z [clojure-lsp.server:419] - Starting server...
T17:01:15.990Z [clojure-lsp.nrepl:20] - ====== LSP nrepl server started on port 65034
T17:01:15.997Z [clojure-lsp.server:304] - Initializing...
T17:01:16.021Z [clojure-lsp.source-paths:135] - Automatically resolved source-paths from project.clj: #{"src" "src/main/clojure" "dev" "test" "src/test/clojure"}
T17:01:10.953Z [clojure-lsp.server:419] - Starting server...
T17:01:10.975Z [clojure-lsp.nrepl:20] - ====== LSP nrepl server started on port 65034
T17:01:10.983Z [clojure-lsp.server:304] - Initializing...
T17:01:11.009Z [clojure-lsp.source-paths:135] - Automatically resolved source-paths from project.clj: #{"src" "src/main/clojure" "dev" "test" "src/test/clojure"}
T17:01:05.938Z [clojure-lsp.server:419] - Starting server...
T17:01:05.961Z [clojure-lsp.nrepl:20] - ====== LSP nrepl server started on port 65034
T17:01:05.968Z [clojure-lsp.server:304] - Initializing...
T17:01:05.997Z [clojure-lsp.source-paths:135] - Automatically resolved source-paths from project.clj: #{"src" "src/main/clojure" "dev" "test" "src/test/clojure"}
T17:00:55.896Z [clojure-lsp.server:419] - Starting server...
T17:00:55.924Z [clojure-lsp.nrepl:20] - ====== LSP nrepl server started on port 65034
T17:00:55.936Z [clojure-lsp.server:304] - Initializing...

Jakub Holý (HolyJak)17:08:16

it seems the IntelliJ LSP plugin is simply cursed 😿

ericdallo17:08:47

I already saw people setupping and running correctly, probably is not well documented what it's needed to do

ericdallo17:08:54

I can try to setup that on the weekend

ericdallo17:08:11

meanwhile, there are somethings you may debug:

ericdallo17:08:50

• any bad exceptions goes to the stderr, but depending on the exception, if not critical, goes to server log

Jakub Holý (HolyJak)17:08:20

the server log has nothing and lsp/log/clojure_err_20210826.log as well as _out_ are empty

ericdallo17:08:44

what is your clojure-lsp --version

Jakub Holý (HolyJak)17:08:55

clojure-lsp 2021.08.24-14.41.56 clj-kondo 2021.08.07-SNAPSHOT

ericdallo17:08:20

alright, let's step back and check if clojure-lsp is ok

ericdallo17:08:43

we will try to send the initialize request via CLI

ericdallo17:08:58

so you will need to do something like we do for clojure-lsp integration-tests

Jakub Holý (HolyJak)17:08:22

Hm, it works on another project. In failing one I see a WARN log from the intellij LSP plugin about invalid url for a maven dependency I have, it is possible despite being just warning that the plugin rashes

ericdallo17:08:28

first, what's your project absolute path?

ericdallo17:08:35

yes, probably

ericdallo17:08:55

You can try on your terminal:

echo "Content-Length: 168

{"jsonrpc":"2.0","method":"initialize","params":{"rootUri":"file:///path/to/your/project/","initializationOptions":{"lint-project-files-after-startup?":false}},"id":1}
" | ./clojure-lsp
remeber to update both project root and Content Lenght of the json

Jakub Holý (HolyJak)17:08:20

Ok! I have made some progress. I have got my wrapper script to work and use it to set PATH so that lsp finds both clojure and npx. Thus it stopped popping errors in intellij but still IntelliJ times out, perhaps because the analysis takes too long. Last log is > Analyzing 1/4 batch paths with clj-kondo... from 2 minutes ago. Perhaps it just takes a while the first time?

ericdallo17:08:06

Oh, some user said that he needed to increase the timeout for the LSP plugin

ericdallo17:08:32

but yeah, the very first time takes longer because it scans whole classpath, next startups should be few seconds

ericdallo17:08:51

I think there is a option to increase the timeout via the plugin

Jakub Holý (HolyJak)17:08:57

Ok, will try that. The "Analyzing 1/4 batch paths with clj-kondo" flog is the last one and there is no clojure-lsp process running, don't know whether it died itself or the intellij plugin killed it upon timeout

Jakub Holý (HolyJak)17:08:16

Yep , it seems indeed the plugin kills clojure-lsp if it takes over its timeout

Jakub Holý (HolyJak)17:08:09

Ok, now it works, after I increased the timeout and restarted intellij (it took about 1min for clojure-lsp to do its job)

Jakub Holý (HolyJak)17:08:36

Awesome, now it works on the other prj as well. So the key was to increase the timeout sufficiently

Jakub Holý (HolyJak)17:08:48

thx a lot for your invaluable help!!!

ericdallo17:08:21

Nice! I really don't know why this plugin has a timeout like that, but we should surely add that to the clojure-lsp client intellij section docs, willing to open a PR later ?

3
Jakub Holý (HolyJak)19:08:48

Perhaps LSP Support has such a short timeout for Init because it expects it to be short, not to do the whole analysis thing. Perhaps it thinks the analysis is just started and runs async, in the background?

ericdallo19:08:05

yeah, but a lot of features may not work if the analysis scan didn't finish yet, that's why we wait

👍 3
ericdallo19:08:20

even kondo diagnostics depend on that scan