Made a video about clojure-lsp (my initial experiences after using it for 1 week) https://youtu.be/WMnVv63ezFQ A little bit chaotic, apologies ;)
@ericdallo Unfortunately I had to remove a section about renaming since that didn't work at all :(
And you can also see how I have some problems with auto-complete... but I explained this yesterday.
But overall, good stuff ;)
Really good video @borkdude, thank you for that!
:)
Your completion issue is really odd indeed, I'll try to reproduce with a clean emacs later
@ericdallo You can try my entire emacs setup here: https://github.com/borkdude/prelude It even contains all elpa packages ;)
Hi folks, I often edit .cljc
files with reader conditionals in the ns
:require
block:
(ns my-app.core
(:require
[my-app.foo :as foo]
#?@(:cljs
[[my-app.bar :as bar]])))
This seems to break the add-missing-libspec
action. Should this work, or is it too much of a unique use-case to support?
It's indeed a bug @jkrasnay π Please, open an issue with that minimal repro, clojure-lsp should know how to handle that IMO
Iβm trying to create a repro but add-missing-libspec
has seemed to stop working for me at all, even for plain .clj
files. Iβve tried clearing out .lsp/sqlite.db
and restarting but itβs no help. Unfortunately I donβt see any logs under /tmp
either. Any ideas?
Are you running arr-missing-libspec
via code actions or manually executing lsp-clojure-add-missing-libspec
?
you can try lsp-clojure-server-info
and find the log-path
where it will point to the clojure-lsp log path
Iβm running Neovim with this mapping from @snoeβs vimrc: nnoremap <silent> cram :call CocRequest('clojure-lsp', 'workspace/executeCommand', {'command': 'add-missing-libspec', 'arguments': [Expand('%:p'), line('.') - 1, col('.') - 1]})<CR>
Other similarly mapped commands are working, e.g. introduce-let
Not sure how to run the equivalent of lsp-clojure-server-info
in Neovim (that looks like an Emacs command to me). Let me try to figure that one out.
I see, the issue with manually calling the commands is that you need to know if for that ns is supported, that's way I recommend calling code actions instead
it's the same of your mapping but change add-missing-libspec
-> server-info
I'd suggest using code actions instead of manually calling refactor commands (that may not be available all the time, depending on your code)
@dharrigan knows how to call code actions in vim π
Got it. Yeah, @dharrigan was giving me some help on the #vim channel. add-missing-libspec
wasnβt showing in my code actions either, but now Iβve found the log!
FYI I guess MacOS has some fancy ideas on where to put temp files. My log was in /var/folders/6k/qwsbhrf9291gjy8vs1nyyq7h0000gn/T/clojure-lsp.13565201280854705473.out
yeah, @snoe had the same issue, is like JVM save the log on createTempFile
, not sure there is a better way to improve that without messing with user folders permissions
The problem was that I was trying to resolve str/lower-case
. string/lower-case
resolves fine. Obvious in retrospect π
yeah, that's why code actions are more reliable π If there is any way to add that require/import, it'll return the code action, otherwise not
Thanks for your help!
you are welcome π
Out of curiosity, would it then be your advice not to use mappings such as "noremap <silent> cram :call CocRequest('clojure-lsp', 'workspace/executeCommand', {'command': 'add-missing-libspec', 'arguments': [Expand('%:p'), line('.') - 1, col('.') - 1]})<CR>" and only rely upon the codeaction (menu)?
The issue is that add-missing-libspec is a command that will only work if the namespace can be imported otherwise will do nothing. The add-missing-* code actions are already returned if it's confirmed that could be imported, so it's a better UI IMO
makes sense
I shall update my vimrc π
The only two I now have are clean-ns
and cycle-privacy
cycle privacy is available via code action too, and not make sense call in a non function, but it's your choice, is not a huge difference
true, I'm normally "in" a function when I do crcp
to quickly toggle the privacy. Yes, using a code action would achieve the same π
As an aside, does clojure-lsp
know if the thing on a doHover
is a Java import?
I'm curious to know if it might be possible to show javadoc on a known Java interop method
i.e., if I press K
(a well-known show me the source binding), then if I'm on a, say for example a .javaMethod
it would pop up and show the javadoc for javaMethod
Yeah we know but clj-kondo analysis doesn't has that yet π
np π
Is there a way to configure the command to generate classpaths for each project?
What do you mean? What's your issue?
I have a clojurescript project that outputs cljs files (for source maps I think) to a directory nested under the resources
directory of my project. Is there a way to make clojure-lsp ignore this directory? Sometimes when I try to navigate to a var definition, it jumps me to a file under this directory when the preferred file exists under my source directory.
Hrm, that might be a bug, we should only save jar analysis in the db, no matter the flag.
@ericdallo If you look at your classpath, there's basically three types of things in there. A) jar files, B) target directories (`output/:target/`) C) source directories (`src/)`. If you set that flag to true, LSP should only walk the jar files from the classpath (A), if the flag is false, then directories (B) would also be analyzed (but should not be stored) and then (as always) we analyze source-paths
based on settings and independent from classpath source paths (C). I'm guessing we messed up what we store in the db when switching to kondo
So if set that flag to true it'll stop walking that jar files? is that make sence? I think we just need a flag to not check the target directories, right?
No, jars always get walked, if true the directories don't get walked
Alright, I see the point of the boolean now, I saw that the code ignore directories if true, but that won't ignore source paths that are directories too?
yeah, source-paths get added on after directories are stripped iirc
Honestly, true
should be the default behaviour, I just wasn't comfortable changing it before.
I tried setting ignore-classpath-directories
to true but that didn't seem to solve my problem
I have a project that needs aliases to generate the correct dev classpath. As in clojure -A:dev -Spath
@mynomoto This is what I have in .lsp/config.edn at work:
{:project-specs [{:project-path "deps.edn"
:classpath-cmd ["clojure" "-A:frontend:backend" "-Spath"]}]}
So what I would think that could work is a project specific project-specs
.
Got it, you can configure a custom project-specs
for that
yes, like that βοΈ
Oh, this is great! Thank you @borkdude and @ericdallo.
Yeah, the ignore-classpath-directories
is exactly for that, but I don't know exactly how it works, it's odd to me that it's a boolean, if true it'll ignore what folders?
@snoe should that be a set of files/folders? otherwise, how that does work?
I'm currently attempting force lsp to start with a fresh late by deleting the sqlite.db file. Maybe it held onto some stuff when I set that ignore-classpath-directories
thing
I'm trying to explore the https://github.com/furkan3ayraktar/clojure-polylith-realworld-example-app using lsp to navigate between the files. But the navigation works in several cases only after entering manually on the destination file. Should it work without that?
Yes, with the classpath scan when starting the project
check /tmp/clojure-lsp.*.out
log when initializing the server
@mynomoto since it's a project with not default folders src test
, you should configure it
with source-paths
: https://clojure-lsp.github.io/clojure-lsp/settings/
or import the specific project instead of the root, like clojure-polylith-realworld-example-app/rest-api
on the first time you open the project (lsp-mode should prompt for you to chosse the root, then you should choose the subproject if you wanna try this way)
So, those are on the :dev
alias under :extra-paths
and they apear on the classpath generated using clojure -A:dev -Spath
I'm using coc, I think it doesn't work the same as lsp-mode.
but are they on source-paths
?
No, they are not. Just to make it clear to me, it won't work with :extra-paths
?
OK, will do
And it has to be on the top-level of deps.edn? I renamed the extra-paths to source-paths on the alias (as there is no top-level source-paths) and got the same result.
no, they are different things, extra-paths
is something you tell clj
what are the extra-paths for your classpath, but clojure-lsp
doesn't know that (or is not smarter enough, not sure that would be possible or could be confusing), so you need to tell clojure-lsp what are the dirs that contains the clojrue code of your project, the default are src
and test
the source-paths
need to be specified on .lsp/config.edn
not in any deps.edn π
thank you!
Oh, got it, thanks! Let me try that.
For most common clojure projects, the default is enough, since this project use a different folders arch, you need to specify that
Sorry for missing the file where :source-paths
should go, now everything is working. Thank you!
I wonder if the classpath information (that considers the :extra-path
configuration on deps.edn
) should not be enough for analysis since that is what clj-kondo
uses. I'm sure there is a reason why this is necessary and I just don't know what it is.
Thank you for your work on clojure-lsp, I think is an amazing project!
I am unsure if I've fixed it. I deleted the sqlite.db file, I ran lein clean
on my project (which cleaned up the extra cljs files in resources). I'm not jumping into that directory anymore. We will see if it holds.
Nice! Yeah, that something to improve probably, but we need to take care to not mess with already working source-paths, but I agree that should be cool feature to have, for leon projects too checking the project.el Feel free to open a feature request issue :)
Has anyone had any luck using clojure-lsp
with Instaparse? Instaparse appears to define may of its symbols via a macro: defclone
. This appears to confuse clojure-lsp
triggering unresolved-vars
errors. I tried fixing this by adding instaparse.macros/defclone clojure.core/def
under the :lint-as
key in .clj-kondo/config.edn
, but that didnβt work.
Hey, I don't know what is Instaparse, but I imagine it has a custom macro, right?
If so, the correct way to fix the macro lint error is to configure via clj-kondo indeed with :lint-as
The config you mention should work
@zane past here the exact config
You will probably need to re-crawl your sources after adding that config
{:lint-as {clojure.test.check.clojure-test/defspec clojure.core/def
clojure.test.check.properties/for-all clojure.core/let
instaparse.macros/defclone clojure.core/def
metaprob.generative-functions/gen clojure.core/fn}}
I see. How do I trigger a re-crawl?
I tried just making a small edit and saving.
@zane rm -rf .lsp/sqlite* and then re-open the project
Let me try that.
@ericdallo Maybe the crawler should take into account a hash of the clj-kondo config for caching?
@borkdude That fixed it. Cheers!
:thumbsup:
I was thinking exactly that @borkdude, we could hash the clj-config used
@borkdude By the way, Iβm giving clojure-lsp
another go because of your recent video, so thanks for that as well. π:skin-tone-2: π
π :)
Created this to improve that behavior π https://github.com/clojure-lsp/clojure-lsp/issues/331
Iβm experiencing something a bit strange with completion. In one of the files in my project completion isnβt available before a certain line, but is available after it. The only significant thing about the line in question is that it has a .cljc
reader conditional on it. :thinking_face:
could you show a little repro?
Would it help to create a repro project?
Or do you want the code around the line in question?
A repro project would be perfect, could you open an issue linking that project?
Will do (if Iβm successful at creating the repro project!).