lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
2021-04-11T15:26:11.007500Z

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

borkdude 2021-04-11T15:27:03.008200Z

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

ericdallo 2021-04-11T15:28:21.009500Z

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

2021-04-11T15:28:26.009800Z

my, hopefully basic, lint-as https://gist.github.com/otfrom/ab558c8dc40b613b474ce4702abe1695

borkdude 2021-04-11T15:29:49.010200Z

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

ericdallo 2021-04-11T15:30:44.011200Z

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

2021-04-11T15:33:00.011900Z

@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

2021-04-11T15:33:16.012200Z

@ericdallo is this ^^ what you mean?

2021-04-11T15:33:57.012900Z

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

borkdude 2021-04-11T15:34:28.013600Z

@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

ericdallo 2021-04-11T15:35:03.014200Z

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

borkdude 2021-04-11T15:36:12.014600Z

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

2021-04-11T15:37:38.014900Z

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

2021-04-11T15:37:58.015500Z

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

ericdallo 2021-04-11T15:38:18.016100Z

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

ericdallo 2021-04-11T15:38:29.016400Z

you will need a hook probably to make that work

2021-04-11T15:39:07.016900Z

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

ericdallo 2021-04-11T15:39:34.017300Z

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

ericdallo 2021-04-11T15:39:59.017800Z

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

borkdude 2021-04-11T15:42:42.018100Z

@ericdallo how would a hook fix this?

borkdude 2021-04-11T15:43:10.018700Z

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

borkdude 2021-04-11T15:43:19.019100Z

that would still not fix the eldoc I think?

ericdallo 2021-04-11T15:44:51.019800Z

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

ericdallo 2021-04-11T15:45:52.020500Z

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?

borkdude 2021-04-11T15:46:14.020800Z

there are no docstrings in this namespace: https://github.com/scicloj/tablecloth/blob/master/src/tablecloth/api.clj

ericdallo 2021-04-11T15:47:07.021500Z

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

ericdallo 2021-04-11T15:47:21.022200Z

this will help understand how kondo is analysing that

borkdude 2021-04-11T15:47:25.022300Z

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

borkdude 2021-04-11T15:48:21.023300Z

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

ericdallo 2021-04-11T15:48:37.023700Z

and how that affect kondo analysis?

borkdude 2021-04-11T15:48:56.024100Z

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

borkdude 2021-04-11T15:53:12.024500Z

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

1
borkdude 2021-04-11T15:55:13.025200Z

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

ericdallo 2021-04-11T15:56:16.026400Z

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

ericdallo 2021-04-11T16:01:20.027500Z

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

borkdude 2021-04-11T16:02:09.028Z

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

borkdude 2021-04-11T16:02:48.029200Z

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

ericdallo 2021-04-11T16:03:12.029700Z

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

borkdude 2021-04-11T16:03:13.029800Z

so these are two separate issues

borkdude 2021-04-11T16:03:42.030400Z

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.

👍 1
ericdallo 2021-04-11T16:04:56.031100Z

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

borkdude 2021-04-11T16:05:44.031900Z

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

ericdallo 2021-04-11T16:06:08.032500Z

yes, it makes sense

2021-04-11T16:06:09.032700Z

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

borkdude 2021-04-11T16:06:26.033200Z

yes

borkdude 2021-04-11T16:06:53.034100Z

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

ericdallo 2021-04-11T16:07:25.034700Z

@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 🙂

ericdallo 2021-04-11T16:08:54.036400Z

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

ericdallo 2021-04-11T16:09:19.037Z

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

2021-04-11T16:10:31.037300Z

yeah, getting it working locally is definitely step 0

2021-04-11T16:10:42.037500Z

or rather 0+n

2021-04-11T16:10:51.037800Z

I think n is about 6 or 7 atm

dpsutton 2021-04-11T16:12:08.038400Z

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

dpsutton 2021-04-11T16:13:07.038700Z

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

2021-04-11T16:13:24.039Z

thx @borkdude & @ericdallo

👍 1
dpsutton 2021-04-11T16:15:22.039300Z

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

dpsutton 2021-04-11T16:17:48.040300Z

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

ericdallo 2021-04-11T16:19:49.040500Z

yes, maybe

ericdallo 2021-04-11T16:20:00.040700Z

you can check with lsp-workspace-folders-remove

ericdallo 2021-04-11T16:20:17.040900Z

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

dpsutton 2021-04-11T16:20:28.041100Z

👍 1
ericdallo 2021-04-11T16:20:33.041500Z

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

ericdallo 2021-04-11T16:21:00.041800Z

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

dpsutton 2021-04-11T16:21:04.042Z

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

dpsutton 2021-04-11T16:21:09.042200Z

not mode, project

👍 1
dpsutton 2021-04-11T16:21:29.042500Z

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

ericdallo 2021-04-11T16:21:50.042700Z

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

dpsutton 2021-04-11T16:21:53.042900Z

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

dpsutton 2021-04-11T16:22:17.043100Z

i'm wondering where they are by default

dpsutton 2021-04-11T16:22:27.043300Z

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

ericdallo 2021-04-11T16:22:28.043500Z

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

ericdallo 2021-04-11T16:22:43.043700Z

are you a mac user?

ericdallo 2021-04-11T16:23:10.043900Z

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

ericdallo 2021-04-11T16:23:26.044100Z

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

dpsutton 2021-04-11T16:23:31.044300Z

ah i see

dpsutton 2021-04-11T16:23:34.044500Z

thank you

ericdallo 2021-04-11T16:23:49.044700Z

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

ericdallo 2021-04-11T16:23:54.044900Z

you re welcome 🙂