Fork me on GitHub
#lsp
<
2021-07-09
>
NoahTheDuke15:07:58

Is clojure-lsp sending semantic info to the client?

ericdallo15:07:24

What do you mean with semantic info? the semantic tokens LSP feature?

ericdallo15:07:04

yeah, it has the hability, but you need to enable manually for now

NoahTheDuke15:07:29

how would i enable it?

ericdallo15:07:36

with :semantic-tokens? t on your clojure-lsp config file

ericdallo15:07:54

also, if you use lsp-mode, you need to enable there as well with (setq lsp-semantic-tokens-enable t)

NoahTheDuke15:07:59

interesting. i’m seeing it happen without setting anything in coc.nvim

ericdallo15:07:33

coc..nvim probably has that enabled as default on client side

ericdallo15:07:46

but on server side, this is still disable by default (not for too long)

NoahTheDuke15:07:21

so even tho it’s disabled by default in clojure-lsp, if coc.nvim asks for it, clojure-lsp will provide it?

ericdallo15:07:37

It'll not as it's disabled on server

NoahTheDuke15:07:47

huh i wonder what’s happening then

ericdallo15:07:47

you can confirm that checking client <-> server json log

ericdallo16:07:10

Oh, my bad, it was enabled on server side by default, I changed that a while ago

ericdallo16:07:25

so if you want to disable it you will need to disable on client or server side

ericdallo16:07:40

I'll update the docs fixing it mentioning it's true as default

NoahTheDuke17:07:03

ah perfect, thank you so much. it’s a cool feature, just caught me off guard when all of the colors i’ve meticulously set up suddenly changed, hah

ericdallo17:07:55

They are configurable on client side (at least lsp-mode), so you change for what you want

NoahTheDuke17:07:31

yeah, i found the coc.nvim settings for disabling or configuring it. thanks for the quick responses!

👍 2
NoahTheDuke17:07:45

i have feedback/questions about how the semantic data is generated. is this a good space to ask those questions?

NoahTheDuke17:07:19

cool. i’m referring a defonce map from another namespace into my namespace: (:require ... [web.config :refer [server-config]] ...) and the server-config is being colored as a function (instead of a symbol). i opened the log and found the place where clojure-lsp is sending the info, and coc.nvim is interpreting as a function: "CocSem_function". if i enter the web.config namespace, the (defonce server-config ...) is correctly marked as a normal symbol.

NoahTheDuke17:07:26

is this a bug? should clojure-lsp be finding out the type of a given referred symbol before marking it as a given LSP type?

ericdallo18:07:42

this is definitely clojure-lsp setting it as a function as it's a var-usage from clj-kondo eyes, maybe we can fix that if we somehow know that the server-config is a map and not a function

ericdallo18:07:03

there is a clojure-lsp LSP command to get the info for the current var on point

ericdallo18:07:48

I'm not sure how to call it from vim, but it should bring info for the cursor, so we can debug and understand it

NoahTheDuke18:07:57

lemme see what i can do to call that

NoahTheDuke18:07:05

it seems i can’t send custom commands to the lsp through coc.nvim. is there a way i could send it through the command line?

ericdallo18:07:46

I think that is possible via coc, @U11EL3P9U used to do that

NoahTheDuke18:07:03

hm okay, must not be looking in the right place. thanks

ericdallo18:07:13

but change the cycle-privacy with cursor-info

NoahTheDuke18:07:20

excellent find, thank you

ericdallo18:07:42

(IMO coc/nvim is so hard to configure/understand 😅 and to find docs about it)

NoahTheDuke18:07:51

yeah, it’s really opaque

NoahTheDuke18:07:20

okay, got it working! you’re awesome

NoahTheDuke18:07:22

what info do you need?

ericdallo18:07:33

nice, so, you can move your cursor to the server-config that has the wrong color and call cursor-info

ericdallo18:07:41

then paste the result here

NoahTheDuke18:07:58

{:element
 {:fixed-arities #{1},
  :name-end-col 41,
  :name-end-row 11,
  :name-row 11,
  :name acknowledged?,
  :filename "/Users/noah/Personal/netrunner/src/clj/web/auth.clj",
  :from web.auth,
  :col 28,
  :name-col 28,
  :bucket :var-usages,
  :row 11,
  :to monger.result},
 :definition nil}

NoahTheDuke18:07:18

oops, wrong spot, lol

NoahTheDuke18:07:32

{:element
 {:name-end-col 38,
  :name-end-row 15,
  :name-row 15,
  :name server-config,
  :filename "/Users/noah/Personal/netrunner/src/clj/web/auth.clj",
  :from web.auth,
  :col 25,
  :name-col 25,
  :bucket :var-usages,
  :row 15,
  :to web.config},
 :definition
 {:end-row 13,
  :name-end-col 25,
  :name-end-row 13,
  :name-row 13,
  :ns web.config,
  :name server-config,
  :defined-by clojure.core/defonce,
  :filename "/Users/noah/Personal/netrunner/src/clj/web/config.clj",
  :col 3,
  :name-col 12,
  :end-col 59,
  :bucket :var-definitions,
  :row 13}} 

ericdallo18:07:37

alright, so IMO everything looks correct, from the point of view of the definition, the server-config is a definition of something (it doesn't matter if it's a map or function)

ericdallo18:07:26

and the usage is the same, the color should not change as it's a var-usage, it's not related with the val of the definition, but if it's a usage or not

NoahTheDuke19:07:04

seems like var-usage-element->absolute-tokens is overeager in assigning everything to function?

NoahTheDuke19:07:30

as a demonstration, here’s a portion of my project.clj:

NoahTheDuke19:07:50

and output from hovering differ:

{:element
 {:name-end-col 25,
  :name-end-row 14,
  :name-row 14,
  :name differ,
  :filename "/Users/noah/Personal/netrunner/project.clj",
  :from user,
  :col 19,
  :name-col 19,
  :bucket :var-usages,
  :row 14,
  :to :clj-kondo/unknown-namespace},
 :definition nil}

NoahTheDuke19:07:34

and hovering stylefruits/gniazdo:

{:element nil, :definition nil}

ericdallo19:07:38

Hum, yes, in that case it should return no token or a specific one, maybe requires should be considered as symbols indeed

ericdallo19:07:42

in this case, they are (or should be), namespace-usages, so namespace is a better token for that

ericdallo19:07:21

oh, clj-kondo didn't find the cheshire namespace, that's why it was considered a var-ussage

:to :clj-kondo/unknown-namespace

ericdallo19:07:29

cheshire should be cheshire.core, right?

ericdallo19:07:00

same for differ

ericdallo19:07:38

but agree, clojure-lsp should not return those tokens as var-usages if the :to = :clj-kondo/unknown-namespace . feel free to open an issue related to that

👍 2
ericdallo19:07:43

also I love that semantic-tokens feature, I'd be glad to improve it 🙂

NoahTheDuke19:07:58

if i put the groupId of “cheshire” in so it’s cheshire/cheshire, it stops being highlighted. however, if i change the groupId/namespace to anything a/cheshire, it also stops being highlighted

NoahTheDuke19:07:27

i love it too, and i’d love to see it work better, cuz it could be really powerful

ericdallo19:07:55

Yeah, it's a new feature, I'm sure there are improvements to be made

ericdallo19:07:14

like those corner cases

NoahTheDuke19:07:51

how much detail do you need in this issue?