lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
borkdude 2021-02-27T10:31:42.270400Z

@ericdallo Not sure if this is a good idea, but would it be possible to activate showing the docstring / arg position when pressing TAB when writing a function call like (foo [TAB])

ericdallo 2021-02-27T12:47:36.270500Z

Hum, if lsp supports the tab char, I think so

borkdude 2021-02-27T12:48:35.270700Z

isn't this the same key that activates completions?

ericdallo 2021-02-27T12:50:37.271Z

Yes, for vanilla Emacs yes, so not sure that could has some conflict

2021-02-27T16:27:12.272100Z

clojure-lsp seems to be having a problem with code like this:

(def foo
  {:foo :bar
   #?@(:clj
        [:baz :quux])})

2021-03-02T00:19:34.340400Z

@ericdallo 2021.03.01-19.18.54 no longer shows the exception in the log but auto-completion still does not work when there’s a splicing reader conditional in the file

2021-03-02T00:21:20.340900Z

Not a big deal for me, just an FYI 🙂

ericdallo 2021-03-02T00:22:16.341100Z

I see, yeah, that probably would only be possible to fix with rewrite-cljc, we will need to wait for the v1 branch

2021-02-27T16:28:19.272800Z

The log shows an exception: java.lang.IllegalArgumentException: No value supplied for key: (read-string "#?@(:clj\n [:baz :quux])")

ericdallo 2021-02-27T16:30:20.273Z

Hum, yes, it'd failing to return the code actions

ericdallo 2021-02-27T16:30:57.273200Z

BTW, is this form correct? I get a missing-map-value clj-kondo error

2021-02-27T16:31:47.273400Z

It works fine in .cljc files. Maybe it’s a clj-kondo issue?

2021-02-27T16:32:12.273600Z

The result should be {:foo :bar, :baz :quux}

2021-02-27T16:32:33.273800Z

…for Clojure of course, just {:foo :bar} for CLJS

ericdallo 2021-02-27T16:33:10.274Z

oh I was not in cljc file, my bad 😅

ericdallo 2021-02-27T16:33:32.274200Z

yes, so it's a clojure-lsp issue indeed to get the code actions for that piece of code

ericdallo 2021-02-27T16:34:19.274400Z

Actually it could be a rewrite-clj issue on parding that code

2021-02-27T16:34:31.274600Z

Yeah, rewrite-clj is in the stack trace

ericdallo 2021-02-27T16:35:20.274800Z

this doesn't work for me:

(z/of-string "{:foo :bar
              #?@(:clj
                  [:baz :quux])}")

ericdallo 2021-02-27T16:35:30.275Z

@lee Am I missing anything? 😅

ericdallo 2021-02-27T16:38:30.275200Z

Hum, probably related with the fact that clojure-lsp use clj-commons/rewrite-clj and not https://github.com/lread/rewrite-cljc-playground

ericdallo 2021-02-27T16:38:50.275500Z

probably we may need to wait @lee work on merging rewrite-cljc with rewrite-clj?

lread 2021-02-27T16:39:15.275700Z

Maybe… I just tried your sample above in rewrite-clj v1 branch and got not exceptions.

ericdallo 2021-02-27T16:39:49.275900Z

nice, exited to see that v1 get merged 🙂

lread 2021-02-27T16:40:03.276100Z

I toil daily :simple_smile:

❤️ 1
lread 2021-02-27T16:40:35.276400Z

Just to make sure I understand, you were just expecting that the above be parseable, right?

ericdallo 2021-02-27T16:40:43.276600Z

yes

lread 2021-02-27T16:41:03.276800Z

And it throws for you on rewrite-clj v0?

ericdallo 2021-02-27T16:41:22.277Z

yep

ericdallo 2021-02-27T16:41:38.277200Z

@jkrasnay feel free to open a clojure-lsp issue so we can close it after using rewrite-clj v1

2021-02-27T16:42:40.278100Z

Will do. Thanks, you guys rock!

1
lread 2021-02-27T16:42:44.278400Z

coolio!

2021-02-27T16:42:47.278600Z

My clojure lsp server is not starting.. This is the message I get

Server clojure-lsp:5242 status:starting exited with status exit. Do you want to restart it? (y or n) y

2021-02-27T16:43:09.279200Z

It was working a couple days agao

ericdallo 2021-02-27T16:43:41.279600Z

download latest version from Github releases

ericdallo 2021-02-27T16:43:54.279800Z

how did you installed it? what is the clojure-lsp --version

2021-02-27T16:44:14.280Z

./clojure-lsp --help
clojure-lsp 2021.02.26-13.58.48
clj-kondo 2021.02.14-SNAPSHOT

2021-02-27T16:44:20.280200Z

Downloaded the latest this morning

2021-02-27T16:44:30.280400Z

using the install-script from github

2021-02-27T16:44:38.280600Z

running on macos

ericdallo 2021-02-27T16:44:47.280800Z

hum, we need to check why it's crashing, anything from the log file?

2021-02-27T16:44:55.281Z

thankyou will checkout the troubleshooting guide…

2021-02-27T16:45:01.281200Z

oh.. where is the log file?

ericdallo 2021-02-27T16:46:00.281400Z

for most system is on /tmp/clojure-lsp.*.out

2021-02-27T16:47:07.281600Z

hmm.. no log file there…

ericdallo 2021-02-27T16:47:31.281800Z

probably it's in another path so, you can specify the log path in clojure-lsp settings

2021-02-27T16:47:50.282Z

ohk.. I’ll try that

ericdallo 2021-02-27T16:47:57.282200Z

with log-file setting

ericdallo 2021-02-27T16:49:18.282400Z

Do you recall what was the version before the issue?

ericdallo 2021-02-27T16:49:39.282600Z

if you used the script, probably there is a backup version on ~/bin

2021-02-27T16:49:41.282800Z

I missed. that

2021-02-27T16:49:53.283Z

previously I installed manually

ericdallo 2021-02-27T16:50:04.283200Z

ok

ericdallo 2021-02-27T16:50:14.283400Z

so we need to check the log to find the exception

1
2021-02-27T16:53:52.283800Z

Interesting, on reading through the troubleshooting page. It says runing clojure-lsp executable should print the following

{}

Apr 12, 2019 7:07:02 AM org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer fireError
SEVERE: Missing header Content-Length in input "{}

"
java.lang.IllegalStateException: Missing header Content-Length in input "{}""""
Mine prints nothing, just hangs

ericdallo 2021-02-27T16:54:39.284Z

test it with your editor

ericdallo 2021-02-27T16:54:48.284200Z

when it crash, check the logs again

2021-02-27T16:55:21.284400Z

sorry, my bad.. read the doc wrong… my executable seems to work

./clojure-lsp
{}

Feb 27, 2021 8:54:36 AM org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer fireError
SEVERE: Missing header Content-Length in input "{}

"
java.lang.IllegalStateException: Missing header Content-Length in input "{}

"

ericdallo 2021-02-27T16:56:00.284600Z

oh, probably lsp-mode is not finding clojure-lsp

ericdallo 2021-02-27T16:56:07.284800Z

are you using Emacs?

2021-02-27T16:56:12.285Z

yes

ericdallo 2021-02-27T16:56:40.285200Z

alright

ericdallo 2021-02-27T16:57:00.285400Z

check here: https://emacs-lsp.github.io/lsp-mode/tutorials/clojure-guide/ you need to configure lsp-clojure-custom-server-command

ericdallo 2021-02-27T16:57:15.285700Z

to point to the ~/bin/clojure-lsp executable

2021-02-27T16:57:44.285900Z

that’s there.. I have configured it

2021-02-27T16:58:03.286100Z

do I have to specify log-file in config.edn ?

ericdallo 2021-02-27T16:58:21.286600Z

yes

2021-02-27T16:58:39.286800Z

ohk thnku

ericdallo 2021-02-27T17:12:17.287Z

oh sorry, there is no log-file setting 😅 That's something that I want to add

ericdallo 2021-02-27T17:12:35.287200Z

you can get the log-file but only after server initialized 😕

ericdallo 2021-02-27T17:13:22.287400Z

I think for some macos the log file is persisted in some weird folder /var/... https://clojurians.slack.com/archives/CPABC1H61/p1613922700052500?thread_ts=1613921955.048800&cid=CPABC1H61

2021-02-27T17:22:45.287700Z

hmm that might be the http://java.io.tmpdir ? which is usually some random path under /var …

ericdallo 2021-02-27T17:23:11.287900Z

Exactly

ericdallo 2021-02-27T17:23:36.288100Z

I will add today a flag to pass the log file to help debug those cases

ericdallo 2021-02-27T17:23:47.288300Z

But only available on next release, probably tomorrow

2021-02-27T17:45:06.288500Z

thku

2021-02-27T17:52:59.288700Z

this is the log

Starting server...
DEBUG [clojure-lsp.nrepl:24] - nrepl not found, skipping nrepl server start...

2021-02-27T17:53:14.288900Z

found TMPDIR from env vars and then greped for lsp

ericdallo 2021-02-27T18:04:58.289200Z

Nice, any exceptions on it?

2021-02-27T18:14:08.289400Z

Found the problem. I had to set lsp-clojure-server-command ‘(“bash” “-c” “/Users/rratti/bin/clojure-lsp”) instead of lsp-clojure-custom-server-command '("bash" "-c" "/Users/rratti/bin/clojure-lsp")

2021-02-27T18:15:18.289600Z

the manual mentions

(setq lsp-clojure-custom-server-command '("bash" "-c" "/path/to/clojure-lsp"))

ericdallo 2021-02-27T18:21:54.290200Z

Oh, it's wrong indeed

ericdallo 2021-02-27T18:22:02.290400Z

Sorry for that, will fix it, thank you!

2021-02-27T18:40:21.290600Z

thks, It works great now!

ericdallo 2021-02-27T18:45:40.290800Z

@rdsr both variable should work, lsp-clojure-server-command is deprecated in favor of lsp-clojure-custom-server-command

ericdallo 2021-02-27T18:50:07.291300Z

You probably have a lsp-mode outdated?

borkdude 2021-02-27T19:48:45.292800Z

Wanted: Some elisp or emacs config which allows me to bind a function to M-. which uses cider (without prompting for a symbol) and when it doesn't find the var, falls back to lsp-find-definition (or vice versa, whatever gets me to the function)

Eamonn Sullivan 2021-03-01T16:35:33.326600Z

This is great -- I needed this too, but I had to add

(define-key cider-mode-map (kbd "M-.") #'find-definition)
Possibly because I had set up
(clojure-mode . cider-mode)
in cider?

ericdallo 2021-02-27T19:52:47.292900Z

Maybe something like this:

(defun find-definition ()
  "Try to find definition of cursor via LSP otherwise fallback to cider."
  (interactive)
  (let ((cursor (point)))
    (lsp-find-definition)
    (when (eq cursor (point))
      (cider-find-var))))

borkdude 2021-02-27T19:54:35.293200Z

Almost, I think. It redirects me to the right definition, but is still going to invoke the cider one too

ericdallo 2021-02-27T19:55:08.293400Z

I updated the code

ericdallo 2021-02-27T19:55:14.293600Z

it seems to work for me

borkdude 2021-02-27T19:55:20.293800Z

oh you updated ok

borkdude 2021-02-27T19:55:44.294Z

yep, works!

borkdude 2021-02-27T19:55:49.294200Z

Now I must override the key binding

ericdallo 2021-02-27T19:55:55.294400Z

nice 🙂

borkdude 2021-02-27T19:56:56.294600Z

How do I do this for clojure-mode?

ericdallo 2021-02-27T19:58:11.294800Z

I think:

(define-key clojure-mode-map (kbd "M-.") #'find-definition)

borkdude 2021-02-27T19:58:30.295Z

aaaaah....

2021-02-27T20:04:21.295600Z

I’ll check

ericdallo 2021-02-27T22:26:03.296300Z

This will not work if the definition is in another buffer. Updated:

(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))))

borkdude 2021-02-27T22:26:51.296500Z

ok, updating