Fork me on GitHub
#lsp
<
2022-01-18
>
practicalli-johnny03:01:06

I am not finding additional snippets I have defined, although I am able to use the built-in snippets. In the project .lsp/config.edn I defined a snippet (taken from the http://clojure-lsp.io docs)

{:source-paths ["src" "test" "develop"]
 :additional-snippets [{:name "wrap-let-sexpr"
                        :detail "Wrap current sexpr in let"
                        :snippet "(let [$1] $0$current-form)"}]}
However, typing wrap in a Clojure buffer finds no matches (I'm using Emacs (Spacemacs)) I can see the custom source paths in the clojure-lsp-log, so it seems the configuration is being read, but nothing is reported about snippets or any obvious errors. I also defined a snippet in the global configuration file, which also does not show.

practicalli-johnny03:01:25

I have restarted the LSP workspace and Emacs itself (several times over) to no avail. Using M-x lsp-clojure-server-info I can see the additional snippet information

:project-root-uri
 "file:///home/practicalli/projects/practicalli/clojure-through-code",
 :port "NREPL only available on :debug profile (`make debug-bin`)",
 :project-settings
 {:additional-snippets
  [{:name "def-",
    :detail "def with private metadata",
    :snippet "(def $0$current-form)"}
   {:name "wrap-let-sexpr",
    :detail "Wrap current sexpr in let",
    :snippet "(let [$1] $0$current-form)"}],
  :source-paths ["src" "test" "develop"]},
 :server-version "2022.01.03-19.46.10",
 :clj-kondo-version "2021.12.20-SNAPSHOT",
 :log-path "/tmp/clojure-lsp.6572465795358753227.out",
 :classpath-settings nil}

practicalli-johnny03:01:47

I experienced the same results with a fresh install of Doom Emacs with clojure and lsp modules added. Same clojure-lsp server and clj-kondo versions, no other configuration

ericdallo12:01:19

I'll take a look

ericdallo12:01:05

it's working but probably need some UX enhancement, for now when a snippet contains $current-form , we require it to have a expression after it otherwise it won't work, so to your snippets work it would need to be triggered on something like:

(let [a 1]
  |(+ a 2))
if you type wrap and call completion with the cursor on | it should bring the snippet

ericdallo12:01:55

maybe we should improve to check for next form excluding spaces and new lines, so this would work as well:

(let [a 1]
  | (+ a 2))
or
(let [a 1]
  |
  (+ a 2))

practicalli-johnny16:01:07

Unfortunately using wrap before a form doesn't work for me either. I added a snippet without a $current-form and no match for the snippet is found

{:source-paths ["src" "test" "develop"]
 :additional-snippets [{:name "practicalli"
                        :detail "really simple snippet"
                        :snippet "(let [:foo :bar] (+ 1 2 3 4 5))"}
                       {:name "wrap-let-sexpr"
                        :detail "Wrap current sexpr in let"
                        :snippet "(let [$1] $0$current-form)"}]}
I'll try on the basic Doom emacs setup next

ericdallo16:01:10

Hum, this is how I'm testing it:

ericdallo16:01:22

and the one without the $current-form

ericdallo16:01:33

it's odd that the built-in snippets work but additional not

ericdallo16:01:03

(BTW, you don't need to restart LSP if changing any snippets, clojure-lsp hot reload most configs including snippets)

practicalli-johnny16:01:54

I am doing the same and only get [No match] in the mini-buffer. I wonder if there is an issue with how completion is set up. I get confusing entries in the completion popup - references act as snippets, what seems to be snippets look like the yasnippet snippets rather than the Clojure snippets. Should I disable yasnippets for clojure-mode ? I wonder if there is a conflict there.

practicalli-johnny16:01:42

In Doom Emacs, when I try TAB complete practicalli I get

user-error: No matching item found on the current line

practicalli-johnny16:01:07

M-/ at the end of practicalli reports

No dynamic expansion for 'practicall' found
Not sure what the right key is for Clojure LSP snippet expansion...

ericdallo16:01:54

I don't have any custom completion config, AFAIK doom handle that very well. check your company-backends config, mine is:

((:separate company-capf company-yasnippet)
 company-yasnippet)

ericdallo16:01:37

The only relevant config I see is https://github.com/ericdallo/dotfiles/blob/master/.doom.d/config.el#L75, regarding disabling cider completion in favor of lsp one

practicalli-johnny17:01:16

I'm afraid I havent found a way to make additional snippets work. I'll try again another time. Thanks for the suggestions.

👍 1
practicalli-johnny18:01:02

I can occasionally get a few of the :additional-snippets to work in Spacemacs, although only when pressing TAB in Evil normal mode. When the snippets expand, the last character of the snippet name remains after the snippet has expanded. I assume because its normal mode and the cursor is on the last character of the snippet name rather than after it. Sometimes a snippet will work once and then stop, other times the snippet will work over and over again. I'll keep trying, but it seems like something is interfering with the snippet completion. I haven't got additional-snippets to work in Doom Emacs at all though

ericdallo19:01:42

yeah, it really sounds like emacs config, I don't know too much about yasnipets on emacs but I already saw a lot of people with issues like that because of wrong config or some package that was changing that behavior

ericdallo19:01:58

as last resource, try the emacs-lsp discord

dharrigan19:01:21

You know when starting clojure-lsp, I have this: :classpath-cmd ["clojure" "-Spath"] in order for it to parse my deps

dharrigan19:01:08

Is there something special that needs to be done in order for it to also parse test dependencies (that are under an alias, i.e., :test)?

dharrigan19:01:30

The reason why I ask, is that whilst in a test file, I can goto definition of a macro, function, whatever, provided it's in the -Spath set. But if I try to jump to definition of a (macro in this case), defexpect then no defintion is found (since the test library isn't in the -Spath output).

dharrigan19:01:35

Curious if this has been solved?

ericdallo19:01:42

yes, let me ask first why you did you override :classpath-cmd ? clojure-lsp already has https://github.com/clojure-lsp/clojure-lsp/blob/master/lib/src/clojure_lsp/settings.clj#L73-L84 that works for most projects, including adding the dev and test aliases

dharrigan19:01:25

oh, well, there you go. I shouldn't have overrode it. Perhaps something I did the the far distant past 🙂

dharrigan19:01:08

I shall expunge forthwith!

dharrigan19:01:46

I think actually, I should override it, as I don't have a dev, but a local-dev

dharrigan19:01:23

but you've given me the magical incantation to create my own one 🙂

ericdallo19:01:34

yes, actually there is a recommended setting for what you want

ericdallo19:01:42

use :source-aliases

ericdallo19:01:19

:source-aliases #{:local-dev :test}

ericdallo19:01:48

this should be enough!

dharrigan19:01:59

and remove the classpath-cmd? right?

ericdallo19:01:13

only override the project-specs as last resource

dharrigan20:01:42

works a charm btw 🙂

dharrigan20:01:56

A follow on question, does it support finding the definition for java sources? If I have, say (UUID/randomUUID) and I jump to defintion on the randomUUID, no definition is found. In my .lsp/config.edn I now have :source-aliases #{:java-sources :base :local-dev :test} with java-sources defined in my deps.edn as :java-sources {:extra-deps {openjdk/java-sources {:local/root "/usr/lib/jvm/java-17-openjdk/lib/src.zip"}}} Any thoughts on if this should work?

ericdallo20:01:49

unfortunately clojure-lsp doesn't support java source analysis, there is a issue for that, to improve kondo analysis to support that, so most features won't work on java interop

dharrigan20:01:18

okaydokey, good to know 🙂

dharrigan20:01:37

interesting discussion on clojureverse about it all

dharrigan20:01:41

I'll be keeping an eye

👍 1