Fork me on GitHub

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 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.


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

 :port "NREPL only available on :debug profile (`make debug-bin`)",
  [{: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}


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


I'll take a look


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


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))
(let [a 1]
  (+ a 2))


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


Hum, this is how I'm testing it:


and the one without the $current-form


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


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


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.


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

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


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...


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)


I'm looking over to see if I can spot any differences

👍 1

The only relevant config I see is, regarding disabling cider completion in favor of lsp one


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

👍 1

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


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


as last resource, try the emacs-lsp discord


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


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


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).


Curious if this has been solved?


yes, let me ask first why you did you override :classpath-cmd ? clojure-lsp already has that works for most projects, including adding the dev and test aliases


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


I shall expunge forthwith!


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


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


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


use :source-aliases


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


this should be enough!


and remove the classpath-cmd? right?


only override the project-specs as last resource


works a charm btw 🙂


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/"}}} Any thoughts on if this should work?


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


okaydokey, good to know 🙂


interesting discussion on clojureverse about it all


I'll be keeping an eye

👍 1