Fork me on GitHub

Hi folks, I often edit .cljc files with reader conditionals in the ns :require block:

(ns my-app.core
    [ :as foo]
    #[email protected](:cljs
      [[ :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


OK, will do


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 @U0BUV7XSA’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)


@U11EL3P9U knows how to call code actions in vim 🙂


Got it. Yeah, @U11EL3P9U 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!

nice 3

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, @U0BUV7XSA 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


I shall update my vimrc 🙂

nice 3

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 😕


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 project that needs aliases to generate the correct dev classpath. As in clojure -A:dev -Spath


@U05094X3J 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 @U04V15CAJ and @UKFSJSM38.

👍 6

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.


I tried setting ignore-classpath-directories to true but that didn't seem to solve my problem


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? @U0BUV7XSA 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

👍 3

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 3

Hrm, that might be a bug, we should only save jar analysis in the db, no matter the flag. @UKFSJSM38 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'm trying to explore the 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


@U05094X3J since it's a project with not default folders src test , you should configure it


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?


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 😅


Oh, got it, thanks! Let me try that.

👍 3

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!


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

👍 3

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


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


@U050CT4HR rm -rf .lsp/sqlite* and then re-open the project


Let me try that.


@UKFSJSM38 Maybe the crawler should take into account a hash of the clj-kondo config for caching?


@U04V15CAJ That fixed it. Cheers!


I was thinking exactly that @U04V15CAJ, we could hash the clj-config used


@U04V15CAJ By the way, I’m giving clojure-lsp another go because of your recent video, so thanks for that as well. 👍:skin-tone-2: 🙂

nice 3
🎉 3

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

👍 3

How do I retrieve the client <-> server log?