lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
devn 2021-03-02T00:24:12.342700Z

I am I think having a similar issue maybe? In the same file, I see two function bodies. One follows the other:

(defn foo []
  (log/error ...))

(defn bar []
  (log/error ...))
For the first instance, I get unresolved var. For the second, no highlight. It shouldn’t be unresolved. The same thing for an @(http/post …) in a function body. I upgraded clj-kondo from brew, and have latest clojure-lsp installed via hombrew.

ericdallo 2021-03-02T12:21:22.356Z

So, it's a clj-kondo issue, I'll add the details to the issue

devn 2021-03-02T00:27:05.343100Z

I blew away .lsp/sqlite* and .clj-kondo/.cache.

devn 2021-03-02T00:27:09.343300Z

no change

ericdallo 2021-03-02T00:27:25.343500Z

What's your clojure-lsp --version?

devn 2021-03-02T00:27:38.343700Z

clojure-lsp 2021.02.24-14.23.08

ericdallo 2021-03-02T00:27:52.343900Z

BTW clj-kondo only warn the first unresolved symbol

ericdallo 2021-03-02T00:27:59.344100Z

Hum, odd, the same issue indeed

ericdallo 2021-03-02T00:29:12.344300Z

We didn't change that code recently(latest releases), Could you open a issue with a reprod of clj-kondo on command line working where clojure-lsp doesn't?

devn 2021-03-02T00:29:33.344500Z

I mean, on the upside, it’s kind of a repro? I don’t have the smallest reproducible case, but I assume it won’t be too difficult.

devn 2021-03-02T00:29:51.344700Z

sure

devn 2021-03-02T00:36:44.344900Z

@ericdallo will include this in the report, but just FWIW: I did not update clj-kondo until after I saw this issue.

ericdallo 2021-03-02T00:42:03.345100Z

Clojure-lsp use a specific clj-kondo version(also show on clojure-lsp --version), not your clj-kondo installed

ericdallo 2021-03-02T00:42:43.345300Z

A minimal repro in a issue is a good start to start debugging the problem

devn 2021-03-02T00:46:36.345500Z

of course I can’t get the minimal repro case to work in a fresh repo 🤦

devn 2021-03-02T00:55:41.345700Z

ah, there it goes

ericdallo 2021-03-02T00:59:04.345900Z

That why I suggested removing the cache files, check if you have anything on your deps.edn that may cause that

ericdallo 2021-03-02T00:59:22.346100Z

A different alias for classpath or something

devn 2021-03-02T01:00:36.346300Z

so, i am not sure if I am able to reliably reproduce

devn 2021-03-02T01:01:14.346500Z

and it’s possible it has something to do with clj-kondo/config.edn’s existence? but it seems to come and go across restarts + clearing of the cache and sqlite db

devn 2021-03-02T01:11:16.347Z

updated with a repo where I can reliably reproduce

devn 2021-03-02T01:11:23.347200Z

@ericdallo ^

devn 2021-03-02T01:12:54.347400Z

@kommen If you happen to have a minute, https://github.com/clojure-lsp/clojure-lsp/issues/352 — can you reproduce by follow the repro steps in this issue?

devn 2021-03-02T01:16:12.347600Z

It looks like if I remove my .clj-kondo directory (and by extension its config.edn), that fixes it.

devn 2021-03-02T01:19:48.347800Z

anyway, updated the repro steps. please let me know if I can be of any help in testing. (DM generally works better)

ericdallo 2021-03-02T01:25:53.348Z

Thank you! Too late here, but I'll look tomorrow morning

anonimitoraf 2021-03-02T03:24:26.348200Z

What is *clj for? (I found that filtering without this doesn't filter at all)

ericdallo 2021-03-02T16:58:04.382Z

Update your clojure-lsp version, it should fix that filter

orestis 2021-03-02T08:02:52.349400Z

If I’ve integrated lsp in my editor, does kondo provide anything on top?

borkdude 2021-03-02T08:04:37.351300Z

Clojure-LSP uses clj-kondo so you will get the same diagnostics (provided LSP calls clj-kondo correctly, there have been some problems)

orestis 2021-03-02T08:16:45.351600Z

That was my impression, thanks for confirming

orestis 2021-03-02T08:22:28.352Z

Hm, homebrew reports that the latest version of clojure-lsp is still 2021.02.24-14.23.08

borkdude 2021-03-02T08:43:51.352800Z

Eric Dallo told me yesterday that automagically updating the homebrew package failed. FWIW, I always do this manually for my packages.

borkdude 2021-03-02T08:44:03.353100Z

You can download the binary manually from Github releases for now

orestis 2021-03-02T09:09:53.353700Z

Sounds like a pain to update homebrew manually, I feel for you...

orestis 2021-03-02T09:10:24.354500Z

Yeah I'm going to download the binary from Github, just wanted to let someone know. How amazing is that we have binaries for this, BTW...

borkdude 2021-03-02T09:53:43.355100Z

@orestis Of course I have scripts for this, but it's a manual action which takes me about 10 seconds

borkdude 2021-03-02T09:54:26.355900Z

This is relatively nothing compared to the time that goes into a developing the release

ericdallo 2021-03-02T12:33:46.356800Z

@orestis I bumped clojure-lsp tap, you can now install latest via homebrew, I'll work on the auto bump soon

❤️ 1
orestis 2021-03-02T16:30:14.359600Z

An obvious thing I’m seeing using lsp for diagnostics is that it frequently gets out of sync or stops producing diagnostics. Of course the neovim client is alpha so perhaps there’s more work to be done there...

borkdude 2021-03-02T16:30:48.360700Z

This can be a "too many open files" problem, I'm also seeing this sometimes in emacs

orestis 2021-03-02T16:30:51.360900Z

Also I’m not sure how well Clojure-lsp handles multiple clients at the same time on the same project?

orestis 2021-03-02T16:31:37.361800Z

It’s super common to have multiple vim processes running

borkdude 2021-03-02T16:31:44.362Z

killall clojure-lsp I did this today ;)

borkdude 2021-03-02T16:32:02.362400Z

wasn't clojure-lsp killing itself after some time of inactivity @ericdallo?

borkdude 2021-03-02T16:32:10.362600Z

would make sense maybe

borkdude 2021-03-02T16:32:20.362900Z

or are these watchers created client side... yeah of course

orestis 2021-03-02T16:32:51.363700Z

I would much prefer for now to launch the lsp server manually and see the diagnostics in my console.

orestis 2021-03-02T16:33:00.364Z

But I’m not sure if this is a possibility

borkdude 2021-03-02T16:33:20.364200Z

you can just use clj-kondo from the console

borkdude 2021-03-02T16:33:48.364600Z

or disable diagnostics in lsp-mode and use clj-kondo proper (this is what I'm doing)

ericdallo 2021-03-02T16:40:23.365400Z

Not sure, never had a problem like that, but I know Calva already had the same issue

ericdallo 2021-03-02T16:40:47.366100Z

And I already had 4-5 clojure-lsp running for different projects at same time

ericdallo 2021-03-02T16:41:24.367100Z

Also the gets of sync looks a odd issue, we really would need some kind of repro I think

borkdude 2021-03-02T16:41:30.367300Z

I often get "too many open files"

borkdude 2021-03-02T16:41:44.367700Z

but I also usually have several projects open at once

ericdallo 2021-03-02T16:42:05.368200Z

What is "too many open files" an lsp-mode error or something?

borkdude 2021-03-02T16:43:19.368600Z

next time I have it, I'll make a screenshot

👍 1
borkdude 2021-03-02T16:43:33.368900Z

but basically all of LSP stops working

ericdallo 2021-03-02T16:43:54.369400Z

Really odd, never saw a error like that

borkdude 2021-03-02T16:45:04.369600Z

what is your lsp-file-watch-threshold ?

borkdude 2021-03-02T16:45:19.370Z

I set it to 10k since else a lot of projects just don't work

borkdude 2021-03-02T16:45:28.370300Z

this was adviced by the guy on discord

borkdude 2021-03-02T16:45:57.371400Z

this has to do with lsp-mode not respecting .gitignore

ericdallo 2021-03-02T16:45:59.371600Z

The file watch is just for lsp-mode watch changes on all those files, should not kill anything

borkdude 2021-03-02T16:46:13.372Z

I know, but if it doesn't watch any file, you don't get lsp

borkdude 2021-03-02T16:46:22.372400Z

right?

borkdude 2021-03-02T16:46:50.373700Z

in any way, I think this is causing the error I'm seeing, because when I killall clojure-lsp it works again

ericdallo 2021-03-02T16:47:38.375100Z

No, imagine something else change a file that is not open on Emacs, with file watch, lsp-mod e will know that and warn lap server. But when you open a file in Emacs, lsp-mod e will manage it anyway

ericdallo 2021-03-02T16:48:02.375900Z

So the file watch is just something more, but not related with lsp in a single file

ericdallo 2021-03-02T16:48:22.376500Z

You can even disable the file watch

borkdude 2021-03-02T16:48:33.377100Z

I know, but when I get the message, it's blocking something else that should work

ericdallo 2021-03-02T16:48:34.377200Z

And most things should keep working

borkdude 2021-03-02T16:48:44.377500Z

ok, let me disable it then

borkdude 2021-03-02T16:48:51.377900Z

how?

ericdallo 2021-03-02T16:49:05.378400Z

Oh, yeah because it's spawning the watches for every files

ericdallo 2021-03-02T16:49:36.379400Z

I think you can just set to nil lsp-file-watch-ignored or something, let me confirm

ericdallo 2021-03-02T16:50:05.379800Z

lsp-enable-file-watchers

borkdude 2021-03-02T16:50:58.380100Z

ok, I will try this

borkdude 2021-03-02T16:51:40.380600Z

Not sure what I will be missing, but also not sure why it needs a watcher at all

ericdallo 2021-03-02T16:52:48.381700Z

Git file changes I think it's a example, but I think restarting lsp should fix it though

borkdude 2021-03-02T16:53:02.381900Z

yeah, I'll rather just do that

orestis 2021-03-02T17:25:48.383100Z

So just to get it clear, it’s the editor that notifies the LSP server about file changes?

orestis 2021-03-02T17:26:14.383700Z

In other words, could the LSP server just watch the files itself

ericdallo 2021-03-02T17:27:55.384100Z

Yes, it's client responsibility to tell server which files to watch

orestis 2021-03-02T17:56:32.385100Z

So the server is the one with access to the filesystem? Or does the client sends chunks of text that have changed to the server?

borkdude 2021-03-02T18:22:26.385500Z

both

ericdallo 2021-03-02T19:05:52.386700Z

Yes, both, but for changes like that, the responsibility is from the client to watch for the file changes

orestis 2021-03-02T19:06:24.387100Z

So currently I have a "stuck" lsp server. How can I best debug to see what might be up? /tmp/clojure-lsp... isn't showing up.

orestis 2021-03-02T19:07:23.387400Z

Oh wait it's $TMPDIR/clojure-lsp... in macOS

ericdallo 2021-03-02T19:07:25.387500Z

Check for the log file with lsp-clojure-server-info

ericdallo 2021-03-02T19:07:43.387700Z

it should has a key log-file

orestis 2021-03-02T19:10:57.388100Z

clojure-lsp.main.LSPTextDocumentService/didChange                         main.clj:  117
                                      clojure-lsp.handlers/did-change                     handlers.clj:   58
                       clojure-lsp.feature.file-management/did-change              file_management.clj:  119
                                                  clojure.core/reduce                         core.clj: 6833
                                          clojure.core.protocols/fn/G                    protocols.clj:   13
                                            clojure.core.protocols/fn                    protocols.clj:   75
                                    clojure.core.protocols/seq-reduce                    protocols.clj:   31
                                          clojure.core.protocols/fn/G                    protocols.clj:   19
                                            clojure.core.protocols/fn                    protocols.clj:  136
                                                                  ...
                    clojure-lsp.feature.file-management/did-change/fn              file_management.clj:  122
                     clojure-lsp.feature.file-management/replace-text              file_management.clj:   96
                          clojure-lsp.feature.file-management/offsets              file_management.clj:   82
                                                                  ...
java.lang.NullPointerException:

orestis 2021-03-02T19:11:10.388400Z

(TIL about less -R to handle the ansi escape sequences)

ericdallo 2021-03-02T19:11:40.389300Z

Yeah, it seems a issue on the replace text logic, please open a issue with a minimal repro

orestis 2021-03-02T19:12:11.389900Z

So it seems like what's happened is because the didChange handler isn't working, the file gets out of sync, then everything else seems to be working but on the wrong text 😄

orestis 2021-03-02T19:12:27.390200Z

Getting a minimal repro might be hard to do but I will give it a try.

ericdallo 2021-03-02T19:13:28.390900Z

The file gets out of sync indeed, but nothing related with file watches, but related with a recent change where we introduced incremental text changes

orestis 2021-03-02T19:25:49.391300Z

I can reproduce this consistently with a specific file. I see a lot of debug messages like so:

2021-03-02T19:24:23.733Z frosty.local DEBUG [clojure-lsp.crawler:142] - Cannot find position data when analysing fn* {:name fn*, :filename "/Users/orestis/dev/nosco/nosco-gamma/cljs/nosco/views/idea_single.cljs", :from nosco.views.idea-single, :col nil, :from-var IdeaNavigation, :arity 2, :bucket :var-usages, :row nil, :to cljs.core} nil

ericdallo 2021-03-02T19:26:16.392Z

that message is not related with the issue, is just a log that I need to avoid logging unecessary

orestis 2021-03-02T19:26:43.392500Z

I restart the server, attach a new client, add a new empty line to the file, hit save... boom.

ericdallo 2021-03-02T19:27:49.392900Z

Could you open an issue with the minimal repro please?

orestis 2021-03-02T19:29:37.393300Z

It's not exactly minimal, it's a big file I have here. I can probably attach it though?

orestis 2021-03-02T19:30:11.393900Z

I will clear the nvim lsp log to get you a clean slate of that too

ericdallo 2021-03-02T19:30:40.394300Z

in a small file/repro the issue doesn't happen?

orestis 2021-03-02T19:33:36.394800Z

It does happen on a 50 line file so it's probably not that.

orestis 2021-03-02T19:33:54.395200Z

I'm kinda out of it now, I will resume tomorrow morning with a fresh slate.

👍 1
orestis 2021-03-02T19:35:22.395900Z

All I can offer is that it's the didChange handler, and AFAICT from neovim, it's sending always the entire file down the pipes...

ericdallo 2021-03-02T19:36:22.396300Z

hum, it could be a issue with neovim if does not support the incremental text changes

orestis 2021-03-02T19:40:19.396700Z

[ DEBUG ] 2021-03-02T20:38:52+0100 ] ...im/HEAD-dc3ca16_1/share/nvim/runtime/lua/vim/lsp/rpc.lua:388 ]	"rpc.send.payload"	{  jsonrpc = "2.0",  method = "textDocument/didChange",  params = {    contentChanges = { {        text = '(ns nosco.react)\n\n\n(defmacro forward-ref!\n  "Takes a component symbol and updates the definition with React.forwardRef,\n  preserving metadata on the component var."\n  [component]\n  `(set! ~component (.forwardRef nosco.react/React ~component)))\n\n\n'      } },    textDocument = {      uri = "file:///Users/orestis/dev/nosco/nosco-gamma/cljs/nosco/react.clj",      version = 3    }  }}

orestis 2021-03-02T19:40:34.397100Z

Here's the command that neovim sends on the change. It's the entire text of the buffer.

orestis 2021-03-02T19:42:02.397800Z

Hope it gives some light. I'll be off to bed now.. thanks for your time on this project! Please apply for clj-together funding 🙂

☝️ 2
ericdallo 2021-03-02T19:45:14.398700Z

I already applied 🤞 😄 It helps, I think clojure-lsp is not considering the full text, I'll take a look on this later today, thanks 👋!

orestis 2021-03-04T12:14:50.426900Z

Hi, I think https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/feature/file_management.clj#L119 might be the piece of code in charge, it expects a range of changed characters. I will see if I can get LSP running locally so that I can confirm and submit a PR, it might be tomorrow though.

ericdallo 2021-03-04T12:16:08.427200Z

Yes, it is, that was changed recently, probably we are having some race condition on there, we need to check how vim is sending the didChange texts

orestis 2021-03-04T14:32:48.427400Z

I think the issue might be simpler: NeoVim doesn't send a start/range at all because it's sending the entire text. So replace-text is getting nil values in line, col, end-line, end-coland throws the NPE

ericdallo 2021-03-04T14:33:48.427600Z

It could be indeed, but even so I think it should send the position according to the LSP spec

orestis 2021-03-04T14:34:16.427800Z

I did a small POC locally and indeed it throws an NPE, and of course the fix is trivial -- I will try tomorrow to run LSP locally so I can verify that this is indeed happening and add a test.

orestis 2021-03-04T14:35:24.428Z

/**
 * An event describing a change to a text document. If range and rangeLength are
 * omitted the new text is considered to be the full content of the document.
 */

orestis 2021-03-04T14:35:26.428200Z

from the spec

orestis 2021-03-04T14:38:03.428400Z

Seems like a NeoVim bug though.

ericdallo 2021-03-04T14:38:57.428600Z

Oh, missed that, cool 🙂

orestis 2021-03-04T14:40:00.428800Z

The client should respect the incremental sync but it seems like it doesn't... but I guess that yeah supporting that on the server is easy enough...

orestis 2021-03-04T14:40:02.429Z

Thanks!

ericdallo 2021-03-04T14:41:21.429200Z

yes, probably handling the didChange as full text when the range is not present seems a valid approach

orestis 2021-03-04T19:14:34.434400Z

https://github.com/clojure-lsp/clojure-lsp/pull/357

ericdallo 2021-03-04T19:20:49.434700Z

Thanks! I added some suggestions, looks good though

orestis 2021-03-04T19:27:17.434900Z

Thanks for the suggestions, they look obvious in retrospect 🙂

😅 1
orestis 2021-03-04T19:28:07.435200Z

If you could capture somewhere the format that the emacs lsp client sends the changes I might be able to provide a test that covers both cases... But not tonight.

orestis 2021-03-04T19:29:17.435400Z

Any more action needed on my part? I think testing on Emacs is the blocker here. I've setup NeoVim to run my local fork of clojure-lsp so if something like this comes up again it'll be easy to validate.

ericdallo 2021-03-04T19:31:14.435600Z

Sure, for a range this is a sample:

(ns foo)

(let [a 1
      b 2]
  (+ a b))
[Trace - 04:30:39 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///home/greg/dev/nu/zakarum/postman/integration/aux/init.clj",
    "version": 55
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 4,
          "character": 7
        },
        "end": {
          "line": 4,
          "character": 8
        }
      },
      "rangeLength": 1,
      "text": "c"
    }
  ]
}
changing it to
(ns foo)

(let [a 1
      b 2]
  (+ a c))

ericdallo 2021-03-04T19:32:03.435900Z

I can test manually the PR tonight (couple of hours), if everything ok, I can merge it

👍 1
devn 2021-03-02T21:59:50.400500Z

@ericdallo @borkdude thanks to both of you for looking into that issue I created. My bad on the unresolved vars linting! Probably a silly question, but is there any way to like… help automate the creation of :lint-as entries? (Perhaps this is a question better asked in #clj-kondo but)

ericdallo 2021-03-02T22:01:27.402Z

Np! Yeah, that's something I'd like too

ericdallo 2021-03-02T22:01:59.402200Z

it's a feature I already thought about it, it'd be a clojure-lsp responsibility I think

devn 2021-03-02T22:02:05.402400Z

like, if I see a situation where I need to add a :lint-as, having an easier way to stub it in my clj-kondo/config.edn would be nice. in addition, it would be sweet to be able to select from already understood options

ericdallo 2021-03-02T22:02:14.402600Z

Cursive has that feature indeed

devn 2021-03-02T22:02:25.402800Z

i knew i had seen it somewhere 🙂

ericdallo 2021-03-02T22:03:12.403Z

Yeah, I think if we could know what is the clj-kondo file used, we could have some kind of code action: Lint as def or Lint as defn

ericdallo 2021-03-02T22:03:15.403200Z

something like that

devn 2021-03-02T22:03:28.403400Z

additionally, some shared repository of common lint-as entries would be nice. i guess it’s kind of like externs or something at that point?

devn 2021-03-02T22:03:38.403600Z

“give me the lint-as stuff for httpkit” for instance

ericdallo 2021-03-02T22:04:08.403800Z

yes, maybe @borkdude already have a repo with some examples?

borkdude 2021-03-02T22:04:34.404200Z

https://github.com/clj-kondo/config

devn 2021-03-02T22:04:48.404600Z

🎉

ericdallo 2021-03-02T22:05:29.404800Z

one more improvement, clj-kondo could report the finding with some metadata, like suggested lint-as

ericdallo 2021-03-02T22:05:54.405Z

then clojure-lsp could use that for the code action: Lint as blabla

ericdallo 2021-03-02T22:06:45.405400Z

That's one of the coolest features from Cursive IMO, it'd be really cool to have something like that

devn 2021-03-02T22:06:50.405600Z

one last pie in the sky scenario that would be rad: i often kind of stumble around a project, finding them one at a time. that’s kind of why i mentioned some kind of “stub them all” command.

devn 2021-03-02T22:07:21.405800Z

then i can just focus on filling in the correct lint-as info in the file

devn 2021-03-02T22:07:48.406Z

or leave them stubbed, but at least there’s a map of what i have provided lint info for vs what i haven’t

devn 2021-03-02T22:08:09.406200Z

does that make sense?

borkdude 2021-03-02T22:10:13.406400Z

As for: > suggested lint-as You guess is as good as mine. If clj-kondo could make this suggestion it might just already lint it like that.

borkdude 2021-03-02T22:10:29.406600Z

Which it won't, because it can never guess this right

devn 2021-03-02T22:10:44.406800Z

eh, i suppose that’s harder than it looks… for instance, you wouldn’t want to create lint-as entries for http/get, http/post, etc. since the lint-as {org.httpkit.client/defreq clojure.core/def} is the actual solution

devn 2021-03-02T22:10:55.407Z

yeah

borkdude 2021-03-02T22:11:55.407200Z

exactly. people should just PR their configs to the clj-kondo/config project

ericdallo 2021-03-02T22:12:01.407400Z

yes, but that's how cursive suggests I think, it suggests to lint as def or defn or a custom one(?)

borkdude 2021-03-02T22:12:06.407600Z

or to the corresponding libs and then you will get a message when you lint the deps

borkdude 2021-03-02T22:12:24.407800Z

that's nice but what if it's the wrong suggestion?

devn 2021-03-02T22:12:47.408Z

then it’s basically “ignore this” right?

devn 2021-03-02T22:13:04.408200Z

or it has no effect?

ericdallo 2021-03-02T22:13:14.408400Z

yes, I think it's good to have a repo for that, but it's better to make the IDE fix for you. Not sure, only saw folks from work using it

borkdude 2021-03-02T22:14:16.408700Z

I think clj-kondo.lint-as/def-catch-all might be the best default

borkdude 2021-03-02T22:14:27.408900Z

since that will try to account for most weird deflike macros

devn 2021-03-02T22:14:34.409100Z

do i understand correctly that maintainers of libs /could/ provide linting definitions as part of their artifacts?

devn 2021-03-02T22:14:43.409300Z

and we could then pick those up?

borkdude 2021-03-02T22:14:48.409500Z

yes, that's correct

ericdallo 2021-03-02T22:14:53.409700Z

Found it! https://cursive-ide.com/userguide/macros.html

ericdallo 2021-03-02T22:15:25.410Z

Looks really cool indeed

ericdallo 2021-03-02T22:15:42.410200Z

it seems you can specify a already know var

devn 2021-03-02T22:16:16.410400Z

> Currently this is only supported for a hard-coded list of namespaces for projects which are known to be problematic. If your project uses one of these namespaces, Cursive will prompt you with a notification:

ericdallo 2021-03-02T22:16:17.410600Z

this probably is another future step, I think just suggesting the basic lint as could be really cool/helpful

devn 2021-03-02T22:16:31.410800Z

back to borkdude’s point about just submitting the lint-as defs to maintainers or to the central repo