Fork me on GitHub
#lsp
<
2021-04-06
>
snoe17:04:37

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.

ericdallo18:04:01

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

snoe19:04:49

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.

ericdallo19:04:18

I see now, it makes sense indeed

ericdallo19:04:28

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?

snoe19:04:40

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

snoe19:04:24

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

ericdallo19:04:26

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

snoe19:04:44

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

ericdallo19:04:36

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

ericdallo19:04:06

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

borkdude19:04:17

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?

ericdallo19:04:19

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

snoe19:04:20

right, we want definitely want it to learn.

borkdude19:04:58

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

yes 3
borkdude19:04:16

or at least all of your own sources probably

👍 3
borkdude19:04:26

as libraries don't tend to change

ericdallo19:04:45

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

snoe19:04:46

right, and we can checksum and reset if those do

borkdude19:04:07

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

snoe19:04:34

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

borkdude19:04:35

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

ericdallo19:04:25

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

snoe19:04:08

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

borkdude19:04:59

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

borkdude19:04:34

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

☝️ 3
stopa19:04:34

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!

ericdallo19:04:28

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

👍 3
dharrigan19:04:18

Sure, as an example of course 😉

stopa19:04:53

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

ericdallo19:04:53

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

stopa20:04:36

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?

stopa20:04:22

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

stopa20:04:00

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.

ericdallo20:04:49

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

ericdallo20:04:16

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

rafaeldelboni20:04:56

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

thanks 6
stopa20:04:15

oo I see!

yes 6
stopa20:04:38

Okay, one more noob question: Say I have

nnoremap <silent> crml :call CocRequest('clojure-lsp', 'workspace/executeCommand', {'command': 'move-to-let', 'arguments': [Expand('%:p'), line('.') - 1, col('.') - 1, input('Binding name: ')]})<CR>
Could I do above with a codeAction? If I do @UMMMKKADU 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

ericdallo20:04:43

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

ericdallo20:04:21

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

👍 3
ericdallo20:04:33

if not, only calling manually indeed

stopa20:04:45

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

ericdallo20:04:06

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

stopa20:04:07

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:

ericdallo20:04:18

yeah, that one too 😂

❤️ 3
stopa20:04:40

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.

ericdallo20:04:27

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

❤️ 3
stopa20:04:26

Okay, one final noob q for the day:

stopa20:04:05

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

ericdallo20:04:18

are you with the cursor inside the ( ?

stopa20:04:42

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

stopa20:04:12

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

ericdallo20:04:36

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

👍 3
walterl21:04:41

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

❤️ 6
stopa21:04:08

ah, awesome @UJY23QLS1! Thanks

👍 3
stopa20:04:51

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?

ericdallo20:04:44

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

👍 3