Fork me on GitHub
#lsp
<
2021-02-20
>
jkrasnay17:02:11

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

jkrasnay17:02:30

This seems to break the add-missing-libspec action. Should this work, or is it too much of a unique use-case to support?

ericdallo17:02:44

It's indeed a bug @jkrasnay 😔 Please, open an issue with that minimal repro, clojure-lsp should know how to handle that IMO

jkrasnay19:02:11

OK, will do

jkrasnay13:02:47

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?

ericdallo13:02:51

Are you running arr-missing-libspec via code actions or manually executing lsp-clojure-add-missing-libspec ?

ericdallo13:02:55

you can try lsp-clojure-server-info and find the log-path where it will point to the clojure-lsp log path

jkrasnay13:02:27

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>

jkrasnay13:02:58

Other similarly mapped commands are working, e.g. introduce-let

jkrasnay13:02:23

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.

ericdallo13:02:29

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

ericdallo13:02:58

it's the same of your mapping but change add-missing-libspec -> server-info

ericdallo13:02:27

I'd suggest using code actions instead of manually calling refactor commands (that may not be available all the time, depending on your code)

ericdallo13:02:42

@U11EL3P9U knows how to call code actions in vim 🙂

jkrasnay13:02:15

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
jkrasnay13:02:29

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

ericdallo13:02:31

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

jkrasnay13:02:55

The problem was that I was trying to resolve str/lower-case. string/lower-case resolves fine. Obvious in retrospect 😊

ericdallo14:02:04

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

jkrasnay14:02:41

Thanks for your help!

ericdallo14:02:15

you are welcome 🙂

dharrigan16:02:33

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

ericdallo16:02:05

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

dharrigan16:02:53

I shall update my vimrc 🙂

nice 3
dharrigan16:02:52

The only two I now have are clean-ns and cycle-privacy

ericdallo16:02:48

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

dharrigan16:02:41

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 🙂

dharrigan16:02:11

As an aside, does clojure-lsp know if the thing on a doHover is a Java import?

dharrigan16:02:33

I'm curious to know if it might be possible to show javadoc on a known Java interop method

dharrigan16:02:27

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

ericdallo16:02:36

Yeah we know but clj-kondo analysis doesn't has that yet 😕

mynomoto18:02:24

Is there a way to configure the command to generate classpaths for each project?

ericdallo18:02:22

What do you mean? What's your issue?

mynomoto18:02:11

I have a project that needs aliases to generate the correct dev classpath. As in clojure -A:dev -Spath

borkdude18:02:09

@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"]}]}

mynomoto18:02:10

So what I would think that could work is a project specific project-specs.

ericdallo18:02:22

Got it, you can configure a custom project-specs for that

ericdallo18:02:29

yes, like that ☝️

mynomoto18:02:19

Oh, this is great! Thank you @U04V15CAJ and @UKFSJSM38.

👍 6
lispers-anonymous18:02:37

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.

lispers-anonymous18:02:52

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

ericdallo19:02:58

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?

lispers-anonymous19:02:35

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
lispers-anonymous19:02:29

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
snoe14:02:22

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

ericdallo15:02:45

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?

snoe02:02:59

No, jars always get walked, if true the directories don't get walked

ericdallo03:02:02

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?

snoe04:02:55

yeah, source-paths get added on after directories are stripped iirc

snoe04:02:46

Honestly, true should be the default behaviour, I just wasn't comfortable changing it before.

mynomoto19:02:50

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?

ericdallo19:02:24

Yes, with the classpath scan when starting the project

ericdallo19:02:37

check /tmp/clojure-lsp.*.out log when initializing the server

ericdallo19:02:55

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

ericdallo19:02:25

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)

mynomoto19:02:06

So, those are on the :dev alias under :extra-paths and they apear on the classpath generated using clojure -A:dev -Spath

mynomoto19:02:16

I'm using coc, I think it doesn't work the same as lsp-mode.

ericdallo19:02:29

but are they on source-paths?

mynomoto19:02:36

No, they are not. Just to make it clear to me, it won't work with :extra-paths?

mynomoto19:02:54

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.

ericdallo19:02:21

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

ericdallo19:02:41

the source-paths need to be specified on .lsp/config.edn not in any deps.edn 😅

mynomoto19:02:10

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

👍 3
ericdallo19:02:54

For most common clojure projects, the default is enough, since this project use a different folders arch, you need to specify that

mynomoto19:02:18

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!

ericdallo19:02:07

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
zane22:02:45

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.

ericdallo22:02:47

Hey, I don't know what is Instaparse, but I imagine it has a custom macro, right?

ericdallo22:02:16

If so, the correct way to fix the macro lint error is to configure via clj-kondo indeed with :lint-as

borkdude22:02:21

The config you mention should work

ericdallo22:02:42

@U050CT4HR past here the exact config

borkdude22:02:35

You will probably need to re-crawl your sources after adding that config

zane22:02:02

{: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}}

zane22:02:13

I see. How do I trigger a re-crawl?

zane22:02:26

I tried just making a small edit and saving.

borkdude22:02:28

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

zane22:02:44

Let me try that.

borkdude22:02:40

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

zane22:02:51

@U04V15CAJ That fixed it. Cheers!

ericdallo22:02:06

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

zane22:02:35

@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
zane23:02:09

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:

ericdallo23:02:41

could you show a little repro?

zane23:02:58

Would it help to create a repro project?

zane23:02:04

Or do you want the code around the line in question?

ericdallo23:02:15

A repro project would be perfect, could you open an issue linking that project?

zane23:02:13

Will do (if I’m successful at creating the repro project!).

👍 3
zane00:02:29

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