This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-18
Channels
- # announcements (6)
- # aws (1)
- # babashka (47)
- # beginners (50)
- # calva (65)
- # cider (4)
- # clj-commons (17)
- # clj-kondo (44)
- # clojure (150)
- # clojure-europe (41)
- # clojure-nl (4)
- # clojure-spec (1)
- # clojure-sweden (4)
- # clojure-uk (6)
- # clojurescript (15)
- # clr (1)
- # conjure (1)
- # core-async (7)
- # cursive (5)
- # datomic (12)
- # events (2)
- # fulcro (17)
- # graphql (12)
- # introduce-yourself (1)
- # jackdaw (5)
- # jobs (2)
- # lsp (52)
- # malli (5)
- # meander (3)
- # minecraft (2)
- # missionary (2)
- # off-topic (10)
- # other-languages (9)
- # reitit (9)
- # remote-jobs (1)
- # ring (8)
- # rum (7)
- # shadow-cljs (9)
- # sql (2)
- # tools-deps (20)
- # xtdb (12)
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.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}
The additional snippets also appear in the log, on line 117 https://gist.github.com/practicalli-john/4a51e9c6a9752b8647c99329bbb9bdfd
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
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 snippetmaybe 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))
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(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)
company-yasnippet)
I'm looking over https://github.com/ericdallo/dotfiles/blob/master/.doom.d/init.el to see if I can spot any differences
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
I'm afraid I havent found a way to make additional snippets work. I'll try again another time. Thanks for the suggestions.
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
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).
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
oh, well, there you go. I shouldn't have overrode it. Perhaps something I did the the far distant past 🙂
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?