Fork me on GitHub
#lsp
<
2021-04-11
>
otfrom15:04:11

I did some work recently to make clj-kondo recognise some things in the scicloj datascience world (specifically tablecloth). This has allowed me to suppress clj-kondo warnings in tablecloth by using lint-as, but I'd expected I'd get clojure-lsp help as well. Are there some docs I'm missing or do I need to do more than just a lint-as? eldoc seems to work if I'm jacked into cider

borkdude15:04:03

clojure-lsp should pick up on the same clj-kondo config, if not, then something is wrong

ericdallo15:04:21

@otfrom I just see unused-public-var warnings there that are from clojure-lsp: https://clojure-lsp.github.io/clojure-lsp/settings/#clojure-lsp

borkdude15:04:49

is this because of some potemkin-like macro that imports vars?

ericdallo15:04:44

I don't know how tablecloth macro works @otfrom, could you please share how clj-kondo lint that? or a sample tiny repro?

otfrom15:04:00

@borkdude yeah, it is that export that tablecloth.api uses that I was trying to sort out with the lint-as in my config.edn

otfrom15:04:16

@ericdallo is this ^^ what you mean?

otfrom15:04:57

btw, sending me back to say, "look again at hooks" is a perfectly reasonable response if lint-as isn't sufficient

borkdude15:04:28

@otfrom I think a hook could save you some time here but if you're happy with manually writing the lint-as config that's perfectly fine too

ericdallo15:04:03

yes, if work with clj-kondo, it should work with clojure-lsp, at least from you print I can't see nothing wrong

borkdude15:04:12

maybe @otfrom can you explain what is the unexpected bit?

otfrom15:04:38

sorry, it has been tricky to capture I think this is it:

otfrom15:04:58

eldoc shows what I'd expect in the lsp-ui tooltip

ericdallo15:04:18

I see now, so yeah, only with lint-as will not capture the definition to render correctly the eldoc

ericdallo15:04:29

you will need a hook probably to make that work

otfrom15:04:07

cool, that gives me a place to go then. At least it is behaving as expected, so I've not got that bit wrong.

ericdallo15:04:34

yes, it's tricky but with a hook should work as expected

ericdallo15:04:59

clj-kondo lint-as just really fixes the lint for those cases

borkdude15:04:42

@ericdallo how would a hook fix this?

borkdude15:04:10

e.g. the hook that expands into (def x the-other-x)

borkdude15:04:19

that would still not fix the eldoc I think?

ericdallo15:04:51

the eldoc will work as soon clojure-lsp find correctly the definition of a var, using lint-as will just tell clj-kondo how to lint, but not how to make clojure-lsp find the definition

ericdallo15:04:52

if the hook expands to (def x the-other-x) , the clj-kondo analysis will find that and then clojure-lsp will get the definition correctly, right?

ericdallo15:04:07

@otfrom could you please move your cursor to the separate column and call lsp-clojure-cursor-info ?

otfrom16:04:32

LSP :: {:element
 {:name-end-col 20,
  :name-end-row 9,
  :name-row 9,
  :name separate-column,
  :filename "/home/bld/wip/kixi.large/src/kixi/large.clj",
  :alias tc,
  :from kixi.large,
  :col 2,
  :name-col 2,
  :arity 1,
  :bucket :var-usages,
  :row 9,
  :to tablecloth.api},
 :definition nil}

ericdallo15:04:21

this will help understand how kondo is analysing that

borkdude15:04:25

I have a very old issue here that is probably relevant: https://github.com/clj-kondo/clj-kondo/issues/412

borkdude15:04:21

currently (def x the-other-x) does not make an automatic connection between those vars, but clj-kondo could do this if that issue got implemented

ericdallo15:04:37

and how that affect kondo analysis?

borkdude15:04:56

then x would just be a proxy to the-other-x, similar to how analysis for potemkin works

borkdude15:04:12

so I think @otfrom that a hook won't help you until 412 is implemented

3
borkdude15:04:13

or... you could transform the call into a potemkin call, which clj-kondo knows about

ericdallo15:04:16

oh, it makes sense @borkdude, checking the function https://github.com/scicloj/tablecloth/blob/924d0c10c1862b03a9c18da289151f77a9889653/src/tablecloth/api/join_separate.clj#L82-L86 It seems to be the exactly issue from 412, I imagine that the analysis considering the first export instead of that function

otfrom16:04:32

LSP :: {:element
 {:name-end-col 20,
  :name-end-row 9,
  :name-row 9,
  :name separate-column,
  :filename "/home/bld/wip/kixi.large/src/kixi/large.clj",
  :alias tc,
  :from kixi.large,
  :col 2,
  :name-col 2,
  :arity 1,
  :bucket :var-usages,
  :row 9,
  :to tablecloth.api},
 :definition nil}

ericdallo16:04:20

yes, we can see clojure-lsp is not finding the :definition of that var, probably because of https://github.com/clj-kondo/clj-kondo/issues/412

borkdude16:04:09

no, the definition is not there because clj-kondo doesn't understand the custom import logic in tablecloth.api

borkdude16:04:48

but the docstring of tablecloth.foo.bar isn't automatically connected with tablecloth.api if you do (def x foo.bar/x), which is 412

ericdallo16:04:12

hum, I see, so there are 2 issues there, right?

borkdude16:04:13

so these are two separate issues

borkdude16:04:42

yes. the first one can be solved using a hook. if you write the hook such that it expands into potemkin-like code, it also solved the second issue.

👍 3
ericdallo16:04:56

I imagine it should be hard to clj-kondo support tech.v3.datatype.export-symbols like it does for potemkin?

borkdude16:04:44

not hard, but this can be accomplished using a hook, so I'd rather not stick code for every other macro out in the wild into clj-kondo

ericdallo16:04:08

yes, it makes sense

otfrom16:04:09

so instead of (def x the-other-x) it would be something like (import-vars [other.ns foo-fn])?

borkdude16:04:53

also with the right require clause prepended so it knows import-vars is from potemkin

ericdallo16:04:25

@otfrom you can implement the hook to fix your issue and if you want to solve this problem to everyone else that uses this lib, you can use https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration and add the hook to the tablecloth lib itself 🙂

ericdallo16:04:54

this way any user from tablecloth will just need to add something like :config-paths ["scicloj/tableclothe"] and the hook will just work

ericdallo16:04:19

but first you need to make the hook work, then you can start thinking in migrate it to the tablecloth lib 😄

otfrom16:04:31

yeah, getting it working locally is definitely step 0

otfrom16:04:42

or rather 0+n

otfrom16:04:51

I think n is about 6 or 7 atm

dpsutton16:04:08

i'm not seeing an .lsp folder being created in my project. this indicates that lsp is not working correctly, right?

dpsutton16:04:07

i'm not seeing any logging anywhere either to indicate what's going on

dpsutton16:04:22

and i'm not seeing any /tmp/clojure-lsp.*.out files created

dpsutton16:04:48

interestingly, i reenabled the file watchers thing and it told me there are 48,000 files to be watched. it seems to think that the root of the project is my projects dir that contains all of the projects, rather than this project

ericdallo16:04:00

you can check with lsp-workspace-folders-remove

ericdallo16:04:17

and then lsp again, then lsp-mode should ask what is the project root

ericdallo16:04:33

also you can get the log of your current session with lsp-clojure-server-info

ericdallo16:04:00

there was a recent change on lsp-mode to print the project root @U11BV7MTK maybe it could be related

dpsutton16:04:04

ah nice, i think this is going to work. it asked me if i wanted to import the correct mode

dpsutton16:04:09

not mode, project

👍 3
dpsutton16:04:29

and now have an .lsp folder. thanks so much @ericdallo

ericdallo16:04:50

Also, I suggest you add to your clojure-lso config, :log-path /tmp/clojure-lsp.out to use the same file for any project log

dpsutton16:04:53

somewhere along the line the parent folder got marked as the parent, even though there was no .lsp folder in there

dpsutton16:04:17

i'm wondering where they are by default

dpsutton16:04:27

i'm not seeing any clojure-lsp type files in tmp

ericdallo16:04:28

yeah, it's lsp-mode using projectile/project.el that decides the project root

ericdallo16:04:43

are you a mac user?

ericdallo16:04:10

I think for some OSs JVM use the /var/log/hash folder

ericdallo16:04:26

that's why I suggest you use a :log-path /tmp/clojure-lsp.out

ericdallo16:04:49

we can't set that as default for all users as there are users that don't have write access to /tmp folder

ericdallo16:04:54

you re welcome 🙂