lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
bringe 2021-01-02T00:25:29.108400Z

I was thinking this as well ^. Some dev/contrib/how-to-hack guide.

ericdallo 2021-01-02T00:26:28.108600Z

Good tip, I can help with that docs

bringe 2021-01-02T00:32:58.108800Z

@pez To send from Calva's code, I think you can do something like

const serverInfo = client.sendRequest('workspace/executeCommand', {
                    'command': 'server-info'
                   });
But if you want to connect Calva to the clojure-lsp's nrepl server, connect to the port in clojure-lsp.out, where you'll find something like:
INFO  clojure-lsp.main: Starting server...
INFO  clojure-lsp.main: ====== LSP nrepl server started on port 35353
Then I think you're directly in the running clojure-lsp code. Maybe I misunderstand what you want to do though.

โ˜๏ธ 1
pez 2021-01-02T00:54:49.116300Z

Calva implements server-info already. That is not the issue here. What I was doing was to extend server-info and I wanted to test that from Calva. The only way I could figure out to do it was to build a new jar, install that in Calva and restart the extension host. A roundtrip of several minutes. I want to keep Calvaโ€™s extension host running, connected to the lsp server while I am modifying the lsp server.

ericdallo 2021-01-02T01:04:09.116600Z

Yeah, a docs describing a basic dev flow and how to get the nrepl port would help with that indeed

bringe 2021-01-02T01:05:54.116800Z

Didn't realize Calva implements it now, lol. I see what you mean though, it would be ideal to be able to modify the lsp code that Calva is talking to, from a repl.

bringe 2021-01-02T01:07:42.117Z

I have been reluctantly doing that roundtrip for some time to test certain changes

ericdallo 2021-01-02T01:09:42.117200Z

yeah, I almost don't use that, since in general a test cover what I'm working for, but for calva test I agree this is a good aproach

bringe 2021-01-02T01:21:39.117400Z

@pez I just did it ๐ŸŽ‰

bringe 2021-01-02T01:26:56.117600Z

1. Open clojure-lsp in vs code (you want to have this open first so it's clear that the last nrepl port you see in the logs later is the one for your extension host client) 2. Start the extension development host for Calva in another vs code instance and open a project, then wait for clojure-lsp to start 3. Look at /tmp/clojure-lsp.out for the last place it said the server was starting, and note the nrepl port. e.g. ====== LSP nrepl server started on port 36387 4. Go back to the clojure-lsp project, and run the Calva connect command, using the port from the logs 5. Open clojure-lsp.handlers ns, change something in the server-info function (add a map entry), then in your extension host run the server-info Calva command and you should see the new data you added to server-info

bringe 2021-01-02T01:27:41.117800Z

I was able to see the changes I made in the repl, without restarting my extension host (ran the command, then made the change, ran it again, saw the change)

bringe 2021-01-02T01:28:11.118Z

I guess this info should be in the dev guide

snoe 2021-01-02T03:03:36.118200Z

Ah, see nvim starts up clojure-lsp for the clojure-lsp project, so I can call server-info and then connect to that port and start evaling

snoe 2021-01-02T03:05:34.118400Z

I guess the trick is for dev to have your client launch lein run instead of a binary.

borkdude 2021-01-02T10:38:43.119200Z

First review for 1108: https://github.com/borkdude/clj-kondo/pull/1108. @snoe

borkdude 2021-01-02T10:55:00.120200Z

for 1109 (https://github.com/borkdude/clj-kondo/issues/1109) I have trouble understanding why exactly you need the location of the var name symbol. Does this have to do with 1108 / local analysis?

borkdude 2021-01-02T10:55:28.121Z

I have read all the linked comments, but I still don't entirely grasp it, so some elaboration would be welcome

snoe 2021-01-02T22:53:22.121400Z

@borkdude hrm ok I'll give it a shot, if not maybe we can hop on a voice chat. It's not related to locals but locals might also need this info, right now I think we don't but vars are less consistent about pointing at the name. So the main API for LSP clients generally send a filename and a position to the server (clojure-lsp). So for example (simplified) we see (rename file.clj 10 1 foo). Then our job is to find the thing under position 10,1 so we know what we're renaming. I can't see how to find what's at that position from kondo's analysis as is (ignoring locals). So I imagine our code would look through var-definitions and var-usages for the file, and find the thing that encompasses the 10,1 position in that file. From there we find the definition and other usages and perform the rename. What I saw when I tried that earlier is: (defn b|ar []) would come up blank, because the bar definition is at col 0 and defn usage is at col 1, and I can't find what's up fee the cursor. I'm happy to figure out what's under my cursor some other way if I'm missing something.

borkdude 2021-01-02T22:59:09.121600Z

Ah I see. So, from the clojure-lsp lib, how easy / difficult is it to look one token to the left and infer that the name is a var name, hence you should look it up by the location of the form wrapping it?

snoe 2021-01-02T23:22:12.122300Z

so like tokenize the file, and jump left to see defn then assume I was on the name? that gets nasty with metadata and stuff and defn-like macros.

borkdude 2021-01-02T23:23:52.122500Z

yeah ok. I was thinking the analysis data can get crowded with info that not everyone might need, so maybe hiding this behind an option (like suggested in the other issue) might be nice

snoe 2021-01-02T23:24:02.122700Z

knowing where the form is also a parsing task I think.

snoe 2021-01-02T23:25:03.122900Z

Yeah, I when I was doing the locals flag, it felt maybe too specific, maybe there's simple and full analysis, but lots of different options as you described in the other issue makes sense too.

borkdude 2021-01-02T23:25:20.123100Z

{:output {:analysis {:var-definitions {:name-locations true}}}}
something like this?

snoe 2021-01-02T23:27:42.123400Z

maybe, I guess whatever feels most idiomatic to kondo

borkdude 2021-01-02T23:29:05.123600Z

I think that will work, reflecting the structure of what is returned, a bit

borkdude 2021-01-02T23:29:28.123800Z

so every sub thing can have new options for additional info

borkdude 2021-01-02T23:30:37.124Z

and this can be documented here: https://github.com/borkdude/clj-kondo/blob/master/analysis/README.md

๐Ÿ‘ 1