Fork me on GitHub
#lsp
<
2022-11-11
>
borkdude17:11:59

@ericdallo @mkvlr I and I were discussing the following:

(require '[clojure.test])
(def foo 'clojure.test/is)
Technically, the symbol clojure.test/is is just an arbitary thing, it doesn't need (load or refer) the clojure.test/is var or clojure.test namespace and as such clj-kondo doesn't emit a var usage for that. But as a user of lsp, it would still be nice to be able to navigate to clojure.test/is when you're on that symbol. 🧵

borkdude17:11:35

I think it would be possible to infer the var just by looking at the namespace / alias and name of the symbol, just for navigation, perhaps.

borkdude17:11:06

And perhaps only allow navigation (or even completion?) for qualified symbols

ericdallo17:11:37

yes, as a final user that sounds good. Not that easy I think to support that, as we don't have any analysis of symbols 'clojure.test/is for example, so we would need to do hacky things like if no analysis is present try to infer that with the logic you mentioned

borkdude17:11:39

Why is that hacky? Btw, Cursive supports this

mkvlr17:11:52

@U04V15CAJ thanks for starting this conversation! @ericdallo some context if you’re interested: in Clerk a render-fn is a quoted form defined in Clojure that’s then transmitted to the browser. In cursive you can use jump to definition for a symbol like https://github.com/nextjournal/clerk/blob/edd0c2fc22bd0207cc8d3762f00f239ce63ee87f/src/nextjournal/clerk/viewer.cljc#L733 and I’d love it if lsp users could also do that

mkvlr17:11:29

one level up would be to resolve ns-aliases for a quoted form so when you see a quoted symbol like v/html to first try to resolve it as-is, and if there’s an ns-alias defined for this, also try with that resolved

ericdallo17:11:46

I agreed that for user this makes sense, I'm just saying that it'd be something hacky to support on clojure-lsp as ATM we completely rely on analysis and we are saying we would for cases where we don't find a analysis we would introduce a new logic to find a definition

mkvlr17:11:57

https://github.com/nextjournal/clerk/pull/276 is even more context if you’re interested

ericdallo17:11:00

Yeah, that makes sense, we would need to have some kind of resolver for symbols with fallbacking to use rewrite-clj on that code and parse because ATM we receive on server: URI line col

ericdallo17:11:30

so we would need to parse the code on that uri line and col with rewrite-clj, check that is a symbol and try to find analysis for that ns or alias

mkvlr17:11:06

ah so currently this is fully handled by clj-kondo and you don’t even see the symbol?

ericdallo17:11:23

yes, ATM we find any element from kondo analysis that are inside the range checking name locations

👍 1
mkvlr17:11:47

alright, I have to run now but happy to take a look and see if I can implement this next week if you agree having this makes sense in general

ericdallo17:11:46

Sure, feel free to create a issue where we can discuss the implementation better, the feature support makes sense, but is not clear to me if we can support it without lots of hacky code

👍 1
lassemaatta17:11:11

This would be a really nice feature 👍 I remember thinking about opening a ticket about this when I was playing around with lazy loading functions with requiring-resolve

borkdude18:11:30

that's a good example!

borkdude18:11:19

I think just looking at the aliases / used namespaces and using the full namespace name as fallback should be sufficient to navigate to the var (or to do completions)

ericdallo12:12:50

The dev jar is a one time only mostly, you build and the connect to the running nrepl port, there is even a lsp-clojure-nrepl-connect command that does automatically for you :)

ericdallo12:12:17

Then you can change how clojure-lsp works and build your feature without restarting or re-building anything

borkdude12:12:54

@ericdallo That works, but why even go through the jar? You can just start a -main function in the script directly?

ericdallo12:12:13

Yeah, works too, there is run deps alias which runs the main, it's just that was never a issue, as bb debug-cli takes a few seconds and usually you don't need to re-build that anymore

👍 1
ericdallo19:12:21

Merged the first @U04V15CAJ's PR 🎉 it should be available a nightly build soon on #C032YH7P0R2 @mkvlr in case you want to give it a try

pizzaspin 1
ericdallo19:12:08

Oh, I meant related to this thread 😅 but yeah, you already helped a lot in the past!

borkdude19:12:44

oh you meant that 😅

mkvlr19:12:51

@ericdallo @U04V15CAJ awesome, thanks a ton to both of you!

👍 2