Fork me on GitHub
#lsp
<
2021-04-06
>
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 🙂

👍 1
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 2
stopa20:04:15

oo I see!

yes 2
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

👍 1
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 😂

❤️ 1
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 🙂

❤️ 1
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

👍 1
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

❤️ 2
stopa21:04:08

ah, awesome @UJY23QLS1! Thanks

👍 1
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

👍 1