lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
anonimitoraf 2021-04-06T13:03:12.221700Z

@ericdallo I've raised: https://github.com/clojure-lsp/clojure-lsp/issues/396 Weird if I'm the only one experiencing this lol Thanks

1👍1
snoe 2021-04-06T17:56:37.227700Z

so I think there's a pretty big issue with caching we need to solve - imo an important constraint to uphold is that when the server starts, its state should reflect the state of the filesytem. pre-kondo we used checksums to see if dependencies changed and only cached those; project sources were never cached. With kondo we are now also caching project sources. The problem is most prevalent when I git pull in the morning and start up vim. New functions and namespaces are reported as unresolved and the analysis is missing. So I think we either have to rm files from the kondo cache on startup, or ideally if kondo can be given a flag to ignore the cache for any files being analyzed.

snoe 2021-04-06T17:56:51.228Z

thoughts @ericdallo @borkdude?

ericdallo 2021-04-06T18:00:01.228100Z

Hum, I understand the issue but I don't recall having this issue, did you mean new functions and namespaces are reported as unused or unresolved? I'm not sure I have this issue

snoe 2021-04-06T19:23:49.228300Z

here's an example

$ cat src/a.clj src/b.clj
(ns a (:require b)) (b/foo) (b/bar)
(ns b) (defn foo [] 1)
open up a.clj - clojure-lsp should say b/bar is unresolved shut it down
echo " (defn bar [] 2)" >> src/b.clj
start it back up, opening only a.clj and b/bar will still be unresolved.

ericdallo 2021-04-06T19:26:18.228500Z

I see now, it makes sense indeed

ericdallo 2021-04-06T19:27:28.228700Z

but wait, https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/crawler.clj#L218 will always be called and should lint project everytime, right?

snoe 2021-04-06T19:27:40.229Z

I think in kondo caching always wins but I think it would be nice to say if i lint a.clj and b.clj - that the cache will not be used by the files

snoe 2021-04-06T19:28:24.229200Z

right but the kondo cache, afaict won't pick up that b.clj changed as it lints a.clj

ericdallo 2021-04-06T19:28:26.229400Z

so what we need is on that analyze-paths accept a use-cache? that will not use the :cache flag on clj-kondo

snoe 2021-04-06T19:28:44.229600Z

no, cause the cache for deps still needs to be used

ericdallo 2021-04-06T19:29:36.230100Z

yes, I meant, only on that line call, because we call the analyze-paths on both classpath analysis and project source-paths analysis

ericdallo 2021-04-06T19:30:06.230300Z

this way we could use the cache for deps/classpath analysis and don't use the cache on the next call, the source-paths analysis

borkdude 2021-04-06T19:30:17.230500Z

You can say :cache false but I don't understand why you would not use the cache, as clj-kondo won't learn about new arities etc for the linted functions?

ericdallo 2021-04-06T19:31:19.230700Z

Oh, I thought the :cache false would just don't use some cached previous analysis, I didn't know would affect the analysis features

snoe 2021-04-06T19:31:20.230900Z

right, we want definitely want it to learn.

borkdude 2021-04-06T19:31:58.231100Z

I see, so whenever some sources have changed outside of clj-kondo's visibility, you effectively want to re-lint the entire project

1
borkdude 2021-04-06T19:32:16.231400Z

or at least all of your own sources probably

1👍
borkdude 2021-04-06T19:32:26.231700Z

as libraries don't tend to change

ericdallo 2021-04-06T19:32:45.231900Z

yes, unless a change on deps.edn/project.clj deps

snoe 2021-04-06T19:32:46.232100Z

right, and we can checksum and reset if those do

borkdude 2021-04-06T19:33:07.232300Z

ok, I think clj-kondo supports all you need right now, but if not, feel free to post an issue

snoe 2021-04-06T19:35:34.232900Z

on the a/b example above, what args would you pass kondo if you relint the two files?

borkdude 2021-04-06T19:36:35.233100Z

if you re-lint both files, no special args are needed - why do you think this is the case?

ericdallo 2021-04-06T19:38:25.233300Z

So we are already linting project source-paths on every startup, but still this is not working, is that right @snoe?

snoe 2021-04-06T19:44:08.233500Z

yeah, I'm not sure if it's on the kondo side or ours tho - having trouble taking the time to figure it out

borkdude 2021-04-06T19:44:59.233700Z

if you re-lint sources, clj-kondo should have a consistent view of interactions between those files. no special options needed

borkdude 2021-04-06T19:45:34.233900Z

you could maybe log which files are linted or something, to find out what happens

1☝️
2021-04-06T19:50:34.235500Z

Hey team, does someone have a config a nvim or some such config I could look at, for commands like “add missing require/import”? (I know https://github.com/snoe/dotfiles/blob/master/home/.vimrc, but I don’t think the “add-missing-require” call is there) Will play with it soon, but if there are more files I could look at for inspiration would appreciate it!

dharrigan 2021-04-08T08:26:37.257400Z

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

1❤️
ericdallo 2021-04-06T19:51:10.235700Z

c/c @dharrigan @rafaeldelboni

dharrigan 2021-04-06T19:52:15.236Z

<https://github.com/dharrigan/vimconfig>

1
ericdallo 2021-04-06T19:55:28.236200Z

Maybe we should link your config https://clojure-lsp.github.io/clojure-lsp/clients/#vim @dharrigan if you agree 🙂

1👍
dharrigan 2021-04-06T19:56:18.236500Z

Sure, as an example of course 😉

2021-04-06T19:57:53.236700Z

ah! looks like add-missing-libspec is what I wanted. Thanks team

ericdallo 2021-04-06T19:58:53.238Z

@stopachka I suggest you always use the code actions as if there is a available way to import the ns, it will be there

ericdallo 2021-04-06T19:59:27.238300Z

Check add-missing-require https://clojure-lsp.github.io/clojure-lsp/features/#code-actions

2021-04-06T20:00:36.238700Z

Thanks Eric. Apologies for the noobie question here, but am not quite sure I understand the codeaction bit. Would you mind expanding a bit deeper?

2021-04-06T20:01:22.239100Z

(in dharrigan’s vimrc, I see:

call CocRequest('clojure-lsp', 'workspace/executeCommand', {'command': 'add-missing-libspec', 'arguments': [Expand('%:p'), line('.') - 1, col('.') - 1]})
is add-missing-libspec here a codeaction, or something else?)

2021-04-06T20:01:51.239600Z

Okay, one more noob question. Looks like add-missing-libspec command can auto-import namespaces. It seems to fail with java classes though. (i.e if I hover over FlexmarkHtmlConverter, and run add-missing-libspec, would love it do: (:import (com.vladsch.flexmark.html2md.converter FlexmarkHtmlConverter)) ) Is something like this supported with clojure-lsp yet? If yes, what’s the way to trigger it?

2021-04-06T20:04:00.239700Z

Ah, I think I understand. code-actions are the commands listed here (https://clojure-lsp.github.io/clojure-lsp/features/#code-actions) — and I guess coc may already have mappings to them. Will check coc to see how to invoke the correct code action to add missing require.

ericdallo 2021-04-06T20:04:49.240100Z

yes, the server return the available code actions, and you, user, select what you want to execute

ericdallo 2021-04-06T20:05:16.240300Z

if that function could be required/imported, then the server will return a code action for that on that line 🙂

rafaeldelboni 2021-04-06T20:05:56.240500Z

I have some keymaps for code-actions if you need a second source for your vim config https://github.com/rafaeldelboni/dotfiles/blob/master/config/nvim/init.vim#L206

2
ericdallo 2021-04-06T20:06:44.240900Z

ATM clojure-lsp don't know too much about java, it doesn't know about the available java on classpath, but you can manually import it with add-import-to-namespace

1👍
2021-04-06T20:08:15.241400Z

oo I see!

2
2021-04-06T20:15:38.242100Z

Okay, one more noob question: Say I have

nnoremap &lt;silent&gt; crml :call CocRequest('clojure-lsp', 'workspace/executeCommand', {'command': 'move-to-let', 'arguments': [Expand('%:p'), line('.') - 1, col('.') - 1, input('Binding name: ')]})&lt;CR&gt;
Could I do above with a codeAction? If I do @rafaeldelboni ac , I don’t see move-to-let as an option. If I try
:call CocActionAsync('codeAction',          'move-to-let')
It says it is unsupported That keyboard shortcut does seem to work though

ericdallo 2021-04-06T20:17:43.242300Z

if the move to let action show on code actions, it should work for the current buffer cursor

ericdallo 2021-04-06T20:18:21.242500Z

oh, not sure clojure-lsp suggest the move to let as a code action

1👍
ericdallo 2021-04-06T20:18:33.242800Z

if not, only calling manually indeed

2021-04-06T20:18:45.243Z

(indeed, it does not seem to show) Okay, I think I understand this much better. Thanks team!

ericdallo 2021-04-06T20:20:06.243200Z

I think that's the only one missing on code actions :thinking_face: we could add that

2021-04-06T20:31:07.243400Z

Cool! May have mistunderstood a bit more. What about something like “extract-function”? If I hover over a form, and run coc-codeaction, I still only see these suggestions:

ericdallo 2021-04-06T20:32:18.243800Z

yeah, that one too 😂

1❤️
2021-04-06T20:35:40.244100Z

xD — indeed could be nice add! if you like can make an issue on GH. I don’t know when I’ll have time, but could add to my someday to write a pr. Great work on lsp team — my vim setup has become object of envy from friends — it’s so darn cool now.

ericdallo 2021-04-06T20:36:27.244300Z

glad to hear 😄 Yeah, feel free to open an issue or PR 🙂

1❤️
2021-04-06T20:50:20.244600Z

done!

2021-04-06T20:50:26.244800Z

Okay, one final noob q for the day:

2021-04-06T20:51:05.245Z

whenever I run code-action, it seems like I only get these 4 results. For example, in this one I expected to find thread-first or something like this

ericdallo 2021-04-06T20:53:18.245400Z

are you with the cursor inside the ( ?

2021-04-06T20:55:42.245600Z

was outside. Interestingly, inside ( does not show any codeactions.

2021-04-06T20:56:12.245800Z

howeever, if I visually select the form, it shows up!

ericdallo 2021-04-06T20:59:36.246200Z

yeah, that depends on how vim sens that buffer position, on emacs it works on both

1👍
walterl 2021-04-06T21:35:41.246500Z

@stopachka visual select is also where the "move to let" is hiding. You just need to select something inside of a let-block

2❤️
2021-04-06T21:36:08.246800Z

ah, awesome @clojurians-slack100! Thanks

1👍
anonimitoraf 2021-04-06T22:59:24.247200Z

@ericdallo I opened https://github.com/Yomguithereal/clj-fuzzy/issues/49for clj-fuzzy. It doesn't feel appropriate to put this algorithm into clj-fuzzy. So, I'm thinking I just publish a separate lib (like https://github.com/lewang/flx, so maybe call it clj-flx or something). Then I'll make a PR to clojure-lsp so that {:workspace-symbol-filter :flx} uses the lib?

ericdallo 2021-04-06T23:01:10.247600Z

Oh, seems good 🙂

1👍
ericdallo 2021-04-06T23:01:56.248100Z

If the algo is better than the current one, I think we could just replace the clj-fuzzy with that new one

anonimitoraf 2021-04-06T23:02:35.248300Z

Right, ok. I'll write extensive unit tests to show how intuitive (or otherwise) it is

1🤘