Fork me on GitHub
#lsp
<
2022-01-14
>
practicalli-johnny14:01:39

Looking at the Clojure LSP built-in snippets, it seems Clojure code can be used to help generate the snippet. For example https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/feature/completion_snippet.clj#L26-L31 uses format function. Is there anything stopping this approach when defining :additional-snippets for my own custom snippets? I assume if Clojure code is included, it should be simple code for performance sake.

ericdallo14:01:57

it's a valid idea but not sure would be easy to implement since the code is already compiled

ericdallo14:01:54

the format on this built-in script being is calling during compilation, so it's not dynamic code being executed

ericdallo14:01:21

if user provide custom clojure-code, how we would run that on a running clojure procces (specially graalvm one)

practicalli-johnny14:01:25

So if defn- snipped was not buit-in, then the following snippet would not work

{:name "defn-"
  :detail "Create private function"
  :snippet (format "(defn%s ${1:name} [$2]\n  ${0:body})"
                   (if (:use-metadata-for-privacy? settings)
                     " ^:private"
                     "-"))}

practicalli-johnny14:01:46

Ah, its because clojure-lsp is compiled by Graal... I forgot that 🙂

ericdallo14:01:46

yes, that wouldn't work

practicalli-johnny14:01:03

So if there was a useful case for including a bit of Clojure code, I should submit a PR to add a built-in snippet and then it would work (assuming the snippet pr is approved)

ericdallo14:01:36

I think a feature to add custom clojure would be great, I just have no idea how we could achieve that 😅 , feel free to start with a issue where we can discuss the problem and ways to solve it

practicalli-johnny14:01:23

I'll try and think of some more snippets that would benefit from custom code. I'm just writing a blog and migrating my yasnippets snippets at the moment. I'll raise an issue later today. Thank you.

ericdallo14:01:40

awesome, thanks!

Lukas Domagala16:01:46

this looks nice. should this be working in vscode/calva? haven’t seen any of the snippets yet and they don’t show up in the “insert snippet” command we were talking about adding something similar into calva, but helping with LSP would make more sense if the “custom clojure” part can work out somehow

ericdallo16:01:34

Clojure-lsp already have a lot of snippets via completion https://clojure-lsp.io/features/#snippets

Lukas Domagala16:01:58

yeah I just saw those for the first time. My question is: does this work in calva out of the box? it seems to be broken for me

ericdallo16:01:08

It follows the LSP completion snippet spec, so it should work OOTB AFAIK

Lukas Domagala16:01:00

so I’d just type in defn- hit ctrl+space and should see a snippet in my autocompletions? than its broken.

2022-01-16T16:33:21.967Z  DEBUG [clojure-lsp.server:?] - :codeAction 49ms
2022-01-16T16:33:27.329Z  DEBUG [clojure-lsp.server:?] - :completion 171ms
2022-01-16T16:33:27.396Z  DEBUG [clojure-lsp.server:?] - :resolveCompletionItem 42ms
the logs indicate it working i think, but there are no snippets in my completions

ericdallo16:01:33

Maybe calva should opt-in something on vscode API? Not sure, maybe @U9A1RLFNV may know more about it

Lukas Domagala16:01:43

yeah maybe, I’ll look into it more. was just wondering if my install is broken or if it never worked

ericdallo16:01:08

you can check that on initialize request log on calva

Lukas Domagala16:01:26

thank you, i’ll check

Lukas Domagala16:01:38

yeah there seems to be no integration for this in calva unless I’m blind, but I also checked in source. Am I missing something @U0ETXRFEW?

ericdallo16:01:36

If there is anything about that integration with lsp, should be on lsp/main on calva IIRC

ericdallo16:01:07

maybe there is a missing opt-in that need to be done on calva side, like adda supportSnippets somewhere via the VScode lsp api

bringe19:01:44

That sounds likely ^

bringe19:01:21

@U02EMBDU2JU Feel free to create an issue for this. A PR is welcome too.

Lukas Domagala19:01:28

thanks @U9A1RLFNV, I’ll do that. just wanted to make sure its actually a missing link not a bug in something that should already work:)

👍 1
Lukas Domagala14:01:27

puh finally got around to creating a ticket at least: https://github.com/BetterThanTomorrow/calva/issues/1483

👍 2