Fork me on GitHub
#lsp
<
2021-09-15
>
bruno.bonacci09:09:14

Hi all, here is the recording of last night's event in case you missed it: Turning your editor into a Clojure IDE with clojure-lsp (by Eric Dallo) https://www.youtube.com/watch?v=grL3DQyvneI Many thanks to @ericdallo for the great presentation and for clojure-lsp

thanks 4
jumar11:09:40

Disclaimer: I know almost nothing about LSP and haven't used clojure-lsp yet. What I'd like to try is to write very minimal language server and integrate it with emacs - like a "hello world" example. The broader idea is that for any file I open in my project I can fetch some interesting data from a 3rd party server and present it to the user. But initially I just want to understand how all the pieces fit together and show a simple "Hello" message in the client/emacs UI. What is a best example online that could get me started? Any good documentation?

borkdude11:09:49

@jumar I wrote a hello world LSP server recently here: https://github.com/zen-lang/zen-lsp It supports linting a custom language defined in EDN.

borkdude12:09:08

It's based on the clj-kondo lsp server which only provides diagnostics, no other lsp features

borkdude12:09:54

The easiest way to test this is really VSCode I think. I'm writing the server in emacs, but testing it in VSCode

borkdude12:09:23

including cider-nrepl during development so you see live updates made while developing in vscode

jumar12:09:30

Fair enough šŸ™‚ Thanks a lot for the pointers - I'll look at those

dharrigan15:09:13

You know what might be nice, that when a missing require (or import) is added by LSP, to add it and then sort the require/imports (for at the moment, it adds missing items to the end each time). Do you think that might be a nice addition?

ericdallo16:09:24

yes, I already noticed that, it would be a good feature indeed

dpsutton16:09:59

90% of the time clojure-lsp sorts according to how we like it, but not all of the time. Especially relating to long lists of imported classes or long lists of refers. If this is enabled, please have a way to disable it

dharrigan16:09:23

yes, have it opt-in perhaps, rather than opt-out šŸ˜‰

ericdallo16:09:47

@U11BV7MTK Can you elaborate an example on how the sort doesn't makes sense?

dharrigan16:09:50

Shall I raise an issue on the venerable github?

dpsutton16:09:57

yeah. i don't care which way the default is. as long as it is configurable

dpsutton16:09:26

yeah the easiest way for me to check this would be to run the command line option to sort the ns's. do you know that offhand?

dpsutton16:09:29

i'll look at the diff

dpsutton16:09:23

oh nice. there's a --dry option. Although it seems that the command line doesn't use the existing cache? i'm at 54,000 ms analyzing the project

dpsutton16:09:47

final runtime to analyze: Analyzing project... 144150ms

ericdallo16:09:58

it should use the cache @U11BV7MTK

dpsutton16:09:46

dan@dan-mbp metabase % clojure-lsp --dry clean-ns
Analyzing project... 144150ms
Checking namespaces...
dan@dan-mbp metabase % clojure-lsp clean-ns --dry
Analyzing project... 151930ms
Checking namespaces...
the --dry clean-ns did not report a diff, now trying clean-ns --dry to see if that makes it report a diff. But it again seems to not have used the cache

dpsutton16:09:35

but no diff came from it, nor any files changed. now just running without --dry and i'll just discard any diffs it changes

ericdallo16:09:27

seems it's happening an error, could you try with --verbose?

dpsutton16:09:10

as soon as this run ends i'll do that

dpsutton16:09:33

ok it ran fine without --dry

dpsutton16:09:37

-            [metabase.models :refer [Card Collection Dashboard DashboardCard Database Field Metric NativeQuerySnippet
-                                     Pulse Segment Table User]]
+            [metabase.models :refer [Card Collection Dashboard DashboardCard Database Field Metric NativeQuerySnippet Pulse Segment Table User]]

dpsutton16:09:47

here it removed newlines in long lists of refers

ericdallo16:09:16

I see, so would be ideal to clojure-lsp keep the newlines on refers, right?

ericdallo16:09:28

probably a opt-in flag to keep new-lines makes sense I think

ericdallo16:09:35

or just always keep :thinking_face:

dpsutton16:09:08

yeah. also removed a comment

-            [metabase.query-processor-test.order-by-test :as qp-test.order-by-test] ; used for one SSL connectivity test
+            [metabase.query-processor-test.order-by-test :as qp-test.order-by-test]

ericdallo16:09:23

yeah, we can probably improve that logic

dpsutton16:09:34

java.util.concurrent.TimeUnit
+           org.apache.sshd.client.SshClient
            org.apache.sshd.client.future.ConnectFuture
            org.apache.sshd.client.session.ClientSession
            org.apache.sshd.client.session.forward.PortForwardingTracker
-           org.apache.sshd.client.SshClient
here it sorted the capital S before lowercase f

dpsutton16:09:13

here it sorted refers capital S before lowercase d

[medley.core :as m]
-            [metabase.models.setting :as setting :refer [defsetting Setting]]
+            [metabase.models.setting :as setting :refer [Setting defsetting]]

dharrigan16:09:39

(as an addition, I noticed too, that if I have something like #_{:clj-kondo/ignore.....} against a require/import and I sort it, that gets removed too)

ericdallo16:09:25

It seems valid, Please open an issue with those details @U11BV7MTK so I can investigate later

dpsutton16:09:42

will do. do you want a single issue with these or each one as a separate issue?

ericdallo16:09:06

I think one for the comments and another for the sorting

šŸ‘ 2
ericdallo17:09:59

Thank you for the detailed issues @U11BV7MTK I'll try to take a look soon!

dpsutton17:09:16

thank you for this amazing work

seancorfield17:09:01

I've noticed .lsp/.cache/sqlite.db rather than .lsp/sqlite.db in a couple of projects -- is that a recent change in LSP?

ericdallo17:09:14

this was something bad for gitignores but the ideia is to move the db impl to a .cache folder

ericdallo17:09:29

and when we change the db impl in the future, this will cause no more issues for users

seancorfield17:09:50

OK, I'll update the various gitignore templates in clj-new and deps-new then.

ericdallo17:09:52

clojure-lsp has already a logic to auto move the .lsp/sqlite.db to .lsp/.cache/sqlite.db

borkdude18:09:01

@U04V70XH6 if you update those templates, do you also include .clj-kondo/.cache ?

JonR20:09:06

Hey @ericdallo thanks again for pointing me towards getting start with lsp-clojure. It's amazing! I don't know everything I can with it though and can't find a list of commands and docs on the docs site. Could your, or anyone, share where I could find this info? FYI I'm also new to lsp in general in emacs so I might be missing something obvious.

ericdallo20:09:14

Thank you :) What editor are you using?

JonR20:09:28

doom emacs

ericdallo20:09:38

but since you use doom you can find probably most of commands with SPC c witch will prompt all the commands for the code section

JonR20:09:40

Perfect! I thought I had seen this but couldn't find it again

JonR20:09:51

Ah, I'm not in evil

ericdallo20:09:58

for example, for find references/usages of a function you can use SPC c D

JonR20:09:35

Do you by chance know the non evil mode hot keys?

ericdallo20:09:19

AFAIK the evil keybindings are g D for example, the one I told was the doom-emacs one that is available for both users :thinking_face:

ericdallo20:09:02

anyway, you can probably check that with: M-x and then type lsp- , this will show all available commands and the keybindings if any for those commands :)

ericdallo20:09:21

also, make sure you enabled +lsp module in your init.el

JonR20:09:40

Ok, didn't connect a couple dots. Now I see them

JonR20:09:00

Their are just a ton of commands so I didn't see key bindings next to them. Now when I scroll down I do

JonR20:09:06

sweet, just what I needed! Thanks again

ericdallo20:09:45

cool :) Good coding!

JonR21:09:44

Ok, I'm rolling now and my mind is blown. Execute code action was what I was really missing.

JonR21:09:46

I start with clj-kondo and had to specify a couple of my helix helpers should be used like defn, do I move that to .lsp?

ericdallo21:09:02

yeah, usually is SPC c a on doom-emacs

JonR21:09:16

I have a defcompoent macro that I would love to see the usages next to the symbol

ericdallo21:09:23

nope, clojure-lsp use clj-kondo under the hood

ericdallo21:09:34

so your clj-kondo config should work with clojure-lsp as well

ericdallo21:09:54

you just need to have properly configured on .clj-kondo/config.edn

JonR21:09:52

With clj-kondo I have

:lint-as {mxv.client.react/defrc   clojure.core/defn
           helix.hooks/use-callback clj-kondo.lint-as/def-catch-all
           helix.hooks/use-memo     clj-kondo.lint-as/def-catch-all}

JonR21:09:08

And that lints as expected. Do I need something different for the usages to work?

JonR21:09:17

ah, checking your link above now

ericdallo21:09:52

that code action will just add the configuration to the lint-as as you pasted above

ericdallo21:09:58

that should work

ericdallo21:09:54

some things to confirm: ā€¢ make sure you have latest clojure-lsp ā€¢ remove .lsp/.cache and restart the server with lsp-workspace-restart if you changed the clj-kondo config after started

JonR21:09:46

k, checking on those

JonR21:09:49

Is there a way (or discussion about) for libs to share their kondo settings? A lot of the new and active repos/libs I see have their own but it would be so nice to be able to auto import or merge into a project using them

ericdallo21:09:30

it's possible to configure the clj-kondo config on the lib itself, making it easy for users of that lib

ericdallo21:09:43

so users just need to add to their clj-kondo config something like :

{:config-paths ["nubank/state-flow"]}

JonR21:09:33

Amazing, just what I was hoping for. Thanks again

šŸ‘ 2
borkdude21:09:20

Perhaps we can collect libraries with such config in the clj-kondo readme

borkdude21:09:23

so we have lot of examples

ericdallo21:09:47

that would be really nice!

JonR21:09:50

Yeah that would be great

JonR21:09:31

OR a badge/link or something even on readme signifying it's clj-kondo compliant and available to import the config

JonR21:09:35

Maybe overkill

JonR21:09:26

I added helix to that, I'm gonna try and remove my custom config for that and import to make sure I'm getting the setup

borkdude21:09:45

I just noticed that lsp automatically dumped the rewrite-clj config in my .clj-kondo dir :) Since I'm not using that in nbb, I simply added it to the .gitignore

borkdude21:09:15

Added a bunch more

ericdallo21:09:26

awesome! I have on my backlog, down there, to open an PR on https://github.com/plumatic/plumbing šŸ˜… for fnk macro and probably others

JonR21:09:52

@ericdallo last ? of the day and then I'll stop spaming the chanel šŸ™‚ I was seeing usages next to defn symbol names but now I don't... Is that something I need to activate somehow?

JonR21:09:10

Yes exactly

JonR21:09:20

Do I call that manually when I want to see the results then?

ericdallo21:09:27

for emacs, you need to (setq lsp-lens-enable t)

JonR21:09:39

ah, ok. THanks

ericdallo21:09:41

and lsp-mode will always activate them when kicks in