Hi, is there a place to configure clojure-lsp and clj-kondo? I'm not getting all the warnings and also it doesnt look like in the docs.
I'm still having some problems with clj-kondo and lsp.
I have an example file with 1 error and 3 warnings.
I manually run clj-kondo
which gets the config that I placed in ~/.clj-kondo/config.edn
on that file and I get the 3 warnings and the error.
When I open that example.clj file with emacs and lsp, I'm only getting 3 warnings and no errors.
$ clj-kondo --lint example.clj
example.clj:4:5: warning: Unsorted namespace: clojure.set
example.clj:4:5: warning: namespace clojure.set is required but never used
example.clj:11:12: warning: unused binding x
example.clj:15:3: error: clojure.string/join is called with 0 args but expects 1 or 2
linting took 12ms, errors: 1, warnings: 3
My clj-kondo config looks like this:
{:skip-comments true
:linters {:unused-namespace {:exclude [clojure.test.check]}
:unused-referred-var {:exclude {clojure.test [is deftest testing]}}
:unsorted-required-namespaces {:level :warning}} }
This is what I have in my init.el:
(use-package lsp-mode
:ensure t
:hook ((clojure-mode . lsp)
(clojurec-mode . lsp)
(clojurescript-mode . lsp))
:config
;; add paths to your local installation of project mgmt tools, like lein
(setenv "PATH" (concat
"/usr/local/bin" path-separator
(getenv "PATH")))
(dolist (m '(clojure-mode
clojurec-mode
clojurescript-mode
clojurex-mode))
(add-to-list 'lsp-language-id-configuration `(,m . "clojure")))
(setq lsp-clojure-server-command '("bash" "-c" "clojure-lsp"))
(setq gc-cons-threshold 100000000)
(setq read-process-output-max (* 1024 1024))
(setq lsp-completion-provider :capf)
(setq lsp-headerline-breadcrumb-enable nil))
Previously I was using flycheck-clj-kondo
but I removed it. When I had`flycheck-clj-kondo`
and lsp-mode
at the same time I saw the 3 warnings and 1 error for 1 or 2 seconds until lsp-mode connected to the clojure-lsp server. When it connected, lsp-mode
overrode the error.
And emacs shows the example file like this:Hum, I could not reproduce that, could you try remove .lsp/sqlite.db
?
back, I was eating. Let me check if I have that file
~/.lsp/sqlite.db
?
AHh, inside the project
yes
ahh that made the trick!
Nice 🙂
thanks eric
You're welcome 😉
btw, is there a way to check if semantic-tokens are active?
This is my ~/.lsp/config.edn
{
:auto-add-ns-to-new-files? true
:semantic-tokens? true
}
but as you can see in the screenshot I sent before, comment isn't colored. It gets colored once I turn on cider and eval the buffer.you need to enable it manually on lsp-mode too
lsp-semantic-tokens-enable t
ah ! great, Ill try it now. You helped me a lot! Thanks.
Yes, the lint is done by clj-kondo
Check this: https://clojure-lsp.github.io/clojure-lsp/settings/#lint
yes
like i said, lsp works for me in .clj and .cljs but not .cljc
Thanks, Ill try it.
Another quick question, do I need company-lsp? In the https://emacs-lsp.github.io/lsp-mode/ I read it was no longer supported. https://clojure-lsp.github.io/clojure-lsp/clients/ it recommends it.
No, it's deprecated, you should use company-capf, I'll update the docs, thanks!
Done!
kk ty! 😄
lol, a bit weird that https://github.com/tonsky/FiraCode is in there too
:man-shrugging::skin-tone-2: https://github.com/hlissner/doom-emacs/blob/develop/modules/lang/clojure/config.el#L18...L23
thanks @ericdallo for all of your work. the new github pages layout, the emacs guide, and all of the support I’ve seen in this channel are much appreciated
Glad to hear it's helping :D, thank you!
If you experience slowness in clojure-lsp with emacs, consider bumping company-idle-delay
to a positive non-zero value
Another thing that maybe can help is increase the company-min-length too Also I'll improve 0 length completion peerformance on clojure-lsp
I tend to abuse the 0 min-length completion in Typescript 😅 to see which exports a module has 😅
Yeah, that feature added this performance issue haha we can improve the results to show more important items and discard others
I just wonder what to drop
Oh right, yea I can imagine how much more inefficient it can get with everything showing up as a candidate. Is it possible to asynchronously load the candidates in chunks? Not sure how TS LSP does it but I'm willing to bet they do something like this
we can certainly improve some things like don't return the docs for all items and use resolveItem LSP method
Emacs is single thread in the end 😅
rewrite in clojure
BTW @borkdude just FYI, doom-emacs default of company-idle-delay is 0.5 and the company package default is 0.2
resolveItem
= only return candidates that fit the current context?
> Emacs is single thread in the end
The comm with the LSP server is done async, right? So do you mean, the inefficiency is from Emacs rendering the candidates? (I'm just guessing)
There is https://github.com/emacs-ng/emacs-ng in rust, that make emacs use js and is 30x better in performance 🙂
Oh yea. Is this backwards-compatible with Elisp packages?
> Oh yea. Is this backwards-compatible with Elisp packages? I think so 😅 > The comm with the LSP server is done async, right? So do you mean, the inefficiency is from Emacs rendering the candidates? (I'm just guessing) (edited) I don't know that much about client completion, but the size of json matters a lot, but yeah, completion performance on emacs is worst than vscode for example AFAIK
Right
Oh wait, emacs-ng is not the rust port of emacs. You're probably talking about remacs
. Seems like emacs-ng
is from the native-comp branch that supports Deno (Typescript) for writing packages
@ericdallo thanks for fixing the keyword search, works perfectly now.
yep, remacs is kind of stuck AFAIK, emacs-ng is also written using rust
Oh right, I see a rust_src
dir, yea
but yeah, emacs-ng is the native-comp branch with improvements in rust
Can we support other languages like Clojure too maybe via a running JVM server or possibly babashka? Is this emacs-ng extensible?
I guess you can already kind of do this by shelling out in elisp
yeah, probably 🙂 This is the maintainers channel: https://gitter.im/emacsng/community
@borkdude @nicdaoraf do you see any items from this "All completions items" that we could remove from the 0 length completion? https://pastebin.com/U4zH4jYD
There are, clojure.core symbols, java.lang and util symbols, other ns symbols, current ns symbols
@ericdallo When I type 1s, why would lsp be interested in symbols not starting with 1 at all?
Good question, but we don't return any completion for 1s
you can check the request/response from logs
If I don't get any completions for 1s, why did it make the request and why did it take so long?
I can see a bunch of keyword labels like these: Are these meant to be candidates?
(I have to sleep now, past midnight here in Aus 😴 )
They are from the clj-kondo (the project I was testing it), I think makes sense to keep it
Also the response size is not big, I'll let remove completion items as a last resource if needed
@ericdallo When do you get all these completions, out of the blue without a context (a starting letter, for example)?
when I just hit C-SPC
in the start of a line (to get all completion items, without any prefix)
right
makes sense
When I have lsp enabled in emacs, using clojure-lsp, the editor slows to a crawl, forward-char, backward-char, previous-line and next-line take about a second to run. Is this normal?
see above
☝️
oh the company-idle-delay? Thanks
Yes @danieleneal, Also I'm improving that on clojure-lsp side, soon changing that setting will not be necessary anymore
great, thanks 🙂
is there any way to make lsp eldoc work identically to cider eldoc?
what do you mean exactly?
oh, yes
when I use cider alone, in addition to the function name I also have the required arguments
set show-docs-arity-on-same-line?
to true
❤️
Just trying out Doom Emacs with clojure-lsp and having some trouble with autocompletion hints. It doesn't seem to work on expanding ns aliases unless I type some standard form first (like defn
). But then it still isn't working for deps that are in an extra deps.edn alias. For example, [datomic.dev-local :as dev-local]
in a :dev alias. Typing "(dev-local)" doesn't show any hints. Running the actual code works with dev-local as intended.
It appears my .lsp/config.edn in the project root is being ignored.
clj-kondo only works with source code, not bytecode
I see, it makes sense, Probably Cursive decompile the class or something
Is that even legal on projects like datomic?
Just the completion I think it is
Ask Rich in your company slack ;)
actually not sure it's ilegal decompile the class
Thanks for confirming, but that really puts a damper on using it for me
:/ I'm sorry, I can't see a easier way to fix that, only using cider probably you will get that completion
I couldn't get it to work there either
The code itself runs fine, but the completion doesn't work
yeah, not sure Cider completion doesn't work for jars without source code, I suggest you ask in #emacs
I think that should work since cider looks at the vars at runtime
Check the logs running lsp-clojure-server-info
, via the log-path
property
Do you have a minimal repro?
Check the logs if your classpath was scanned properly
hey all! thanks so much for making clojure-lsp
, it's wonderful
is there a way to turn off tooltips/intellisense on words in strings?
thank you! What editor are you using? tooltips/intellisense you mean the diagnostics/lint?
sorry, the pop-up window that displays function argument lists and docstrings. i use vim 8.1 and coc.nvim
as you can see, it's suggesting apply
even tho I'm in the middle of typing applicable
lol
Checked them and there's nothing indicating an issue
We implemente support for signatureHelp on latest release, probably now it's enable by default on vim
you need to disable on your vim LSP client, maybe @dharrigan knows how to do that, I'm a :emacs: user 😛
could you test if moving the config to ~/.lsp/config.edn
works?
also what is the config you added that is not working?
coolio, i'll look into the coc.nvim config. thank you!
Ok so I checked lsp-clojure-server-info
and there is :project-settings, which shows what I have and :client-settings, which does not include my alias and :project-specs is nil
so, let me see if I understand your issue, you have a deps in your deps.edn in a custom alias, and the completion feature doesn't show the completion for that deps, right?
if so, you need to tell clojure-lsp to use a custom project-spec
classpath-cmd
Right
these are the defaults https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/crawler.clj#L53-L60
if you need a different classpath different from clojure -Spath
, then you need to configure the project-spec
I have
:project-specs [{:project-path "deps.edn"
:classpath-cmd ["clj" "-A:dev" "-Spath"]}]
Running that command manually shows the correct path
But it seems to be using the settings in :client-settings vs :project-settings
I see, it looks correct Indeed
If you add that config in ~/.lsp/config.edn it works?
It shows the same output in the server info and still doesn't work
the :client-settings are settings sent from emacs, your config should be in :project-settings
oh, make sure you remove your project/.lsp/sqlite*
probably that's the issue....
Recreated the sqlite db and no change
My config is in :project-settings, but it's not being applied
that's odd..
Would you mind create a minimal project repro that?
This project is early on
I just installed Doom Emacs today
I use doom too
So how do you include additional aliases?
let me try what you did
But how do you personally do it?
adding a project-spec to rpoject config
I use on ~/.lsp/config.edn
I don't need to add custom project-specs
So how do you handle per-project aliases?
You include dev deps with prod deps?
the projects I work have custom alias but none change the deps
Could you share your dev alias?
:dev {:extra-paths ["dev"]
:extra-deps {com.datomic/dev-local {:mvn/version "0.9.225"}
org.clojure/tools.namespace {:mvn/version "1.1.0"}}}
so tools.namespace completion doesn't work too, right?
I'll test with that
Right
Oddly enough moving dev-local to main deps still doesn't work
It works for me
only when adding the project/.lsp/config.edn
so your problem is something else not right
What is your config?
do you have clj
on your emacs path? try changing to clojure
instead of clj
sample-project/.lsp/config.edn
{:project-specs [{:project-path "deps.edn"
:classpath-cmd ["clj" "-A:dev" "-Spath"]}]}
sample-project/deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.10.2"}}
:paths ["src" "resource"]
:aliases {:dev {:extra-paths ["dev"]
:extra-deps {org.clojure/tools.namespace {:mvn/version "1.1.0"}}}}}
and when I require [clojure.tools.namespace.file :as tools.ns]
and try to complete tools.ns/
I get the results
I'll probably improve the classpath scanning log, to help with cases like that
try removing .lsp/sqlite.db
and .clj-kondo/.cache
I tried that already. And .clj-kondo doesn't exist
oh, that odd
what's your clojure --version
?
Ok, so when require the tools.namespace.repl with an alias it does work. But typing out the FQDN doesn't
1.10.2
sorry, clojure-lsp --version
2021.02.21-21.02.51
your project should contain a .clj-kondo
folder
clojure-lsp scan the classpath using clj-kondo under the hood
and we cache the results on that .clj-kondo/.cache
Doesn't exist
do you have any clj-kondo
config in your home or something that could mess with that?
Nope
damm, that's really odd
what means "But typing out the FQDN doesn't"?
Type out the FQDN and autocomplete doesn't work
So like clojure.tools.namespace.repl
ohhh I see
you are trying to complete something like clojure.tools.namespace.file/
?
.repl/, but yes
yeah, we don't support that ATM, and it should not be hard to implement it, please open a feature request issue, sorry for the bad comumnication 🙂
Hmm, ok. That's a significant missing piece since there are times to prefer the FQDN
But I still can't get dev-local to work
But the code itself runs normal
what is the dev-local?
the deps on your dev alias, right?
com.datomic/dev-local
let me try that one
That one is a bit more complicated because you have to have a mvn config for the repo
BTW, is your code on dev
or src
folder?
hum, I thought it was public
My dev helper code is in dev and the main stuff is in src
It's free to use, but you still have to sign up for access
oh, did you add the dev
folder to source-paths
?
Yes
we use a default source-paths of src
and test
I mean, clojure-lsp source-paths
:source-paths #{"src" "dev"}
so only that datomic deps is not working
but the clojure.tools.namespace
work?
yes
What disables being able to insert spaces?
probably clj-kondo is not scanning correctly that deps so
we could check the transit file, like this for example:
project/.clj-kondo/.cache/2021.02.14-SNAPSHOT/clj/clojure.tools.namespace.file.transit.json
but your project has no .clj-kondo
is really weird
So I don't know why that dir doesn't exist
I have clj-kondo installed
any permission issue with your project folder?
nope
you don't need clj-kondo installed, clojure-lsp use clj-kondo via JVM
but if you have a custom .clj-kondo/config.edn somewhere, it could mess that
if you change the cache-dir
manually
I uninstalled the system clj-kondo and no difference
it should not make any difference indeed, but any ~/.clj-kondo/config.edn
or something like that changing the cache dir can cause a issue
but I don't think that's the issue here
That file doesn't exist either
anything on clojure-lsp logs? /tmp/clojure-lsp.*.out
Nope
yeah, that's sad. Please open an issue following the issue template, it'd be good to use a external deps easy to debug and a minimal project with all those files configured if you don't mind
Also I created this: https://github.com/clojure-lsp/clojure-lsp/issues/337
I also can't get REBL to work with Doom either so this is looking less appealing as I go
😕 did you enable the (clojure +lsp)
in your init.el?
yes
lsp is working for deps other than dev-local
It could be a permission issue with your pc
Nah
It works fine in Cursive
yeah, really weird
Including autocompleting dev-local
I like Cursive a lot. I just wanted to see what this side looked like. I don't know how it's so popular with how much trouble it is to get right
Normally it works, your case really looks a corner case
But not really. Even with the regular alias deps it was inconsistent in autocompleting
Why inconsistent?
What I don't understand is that the jar is in my .m2/repository for dev-local so Cursive can scan it fine. I don't know why clojure-lsp is having this trouble
It could be a clj-kondo issue
The autocomplete wouldn't always work for the working completions. Sometimes nothing would show up and just deleting the text repeatedly it would sometimes work
But if clj -Spath works and you can cat the file in m2, it should work
But if I grabbed the latest doom emacs and simply enabled clojure and lsp then there shouldn't be an issue
Exactly. And it does show up in the -Spath
And Cursive reads it fine
But you can easily sign up for datomic dev-local and grab the jar yourself. It's just an email sign-up and .m2/settings.xml credentials given
Oh, check if kondo recognizes the namespace, hover under the datomic.dev require and call lsp-clojure-cursor-info
Nope. And thus going to definition also doesn't work
I honestly wonder if it's an issue with the hyphen
None of my other deps have one to test
Wait, yes there is one. com.datomic/client-cloud
And that one autocompletes and goes to definition
Hold on. I'm derping. I'm thinking of the on-prem dev tools. dev-local is just a regular dep: https://docs.datomic.com/cloud/dev-local.html#using
So you can pull that and test
Yes, I can test it in a some minutes, I'm on mobile right now
I'm also noticing that enabling parinfer makes lsp not start automatically. And it doesn't work either
Hahaha that doesnt makes any sense, but it's a lsp-mode side issue or related