Fork me on GitHub
#lsp
<
2022-01-27
>
jacob.maine00:01:34

I’d like to re-record a refactoring gif. What Emacs theme do you use @ericdallo?

ericdallo02:01:23

That'd help a lot! I use dracula on https://github.com/ericdallo/dotfiles

1
ericdallo03:01:41

Also I use "peek" to record my gifs

jacob.maine14:01:26

Well, that’s a very thorough answer! Thanks! I’ve been thinking about trying out NixOS… /goes down a rabbit hole

ericdallo14:01:47

Yeah, NixOS is awesome, but I already spent a lot of time indeed with that 😅

jacob.maine01:01:00

Here’s the re-recorded gif. The MacOS tools for optimizing aren’t great, so it’s still pretty large (463K vs the original which was shorter but only 137K). @ericdallo would you like me to add it to the https://github.com/clojure-lsp/clojure-lsp/pull/716 or do you want to record it on your machine?

ericdallo13:01:58

Sure! Feel free to add tot he PR

ericdallo13:01:49

@U07M2C8TT I intend to do a release this week, do you think we should wait to include your PR?

jacob.maine19:01:26

Up to you. I’ve been using it regularly and it’s been fine, but I know you wanted to do a bit more testing on it. There’s no rush.

👍 1
dpsutton16:01:34

I’m having an issue with some lsp highlighting on unused public vars. We have a macro called defendpoint that creates our routes. clj-kondo/lsp consider this an unused public var which is fine I guess, I can ignore that. But the problem is that when my cursor is in the form it highlights it for me and makes it hard to read.

dpsutton16:01:40

Point outside of the form:

dpsutton16:01:00

point inside the form:

dpsutton16:01:22

Is there a way to prevent this highlighting until we can correct the analysis?

ericdallo16:01:31

oh that's quite odd, seems like some lsp-mode/emacs configuration

ericdallo16:01:05

is this project open so I can test that?

borkdude16:01:20

this is because defendpoint is linted using a config macro and all warnings appear on the opening paren, but perhaps this doesn't work nicely with the public var linter

ericdallo16:01:45

I think this could happen if you didn't configure the hook for that macro to use the proper row/col/end-row/end-col right @U04V15CAJ?

borkdude16:01:27

this just uses the :macroexpand :hook which is a simplified way of writing hooks with the trade-off that you lose your locations for warnings and all of them are propagated to the top

dpsutton16:01:43

makes sense

ericdallo16:01:06

hum, I see, that's bad, I was not aware that could cause those highlight issues

dpsutton16:01:09

i’d be fine if it just highlighted the macro’s form api/defendpoint rather than the entire form

borkdude16:01:13

you can already see that there are 0 references for this var, so maybe disable the public var linter locally as this is basically the same info

👍 1
ericdallo16:01:24

I suspect this will happen for every linter that uses macroexpand, not only unused-var

ericdallo16:01:44

@U11BV7MTK you can disable the linter for specific namespaces or vars as well

dpsutton16:01:12

seems like all of our api namespaces will have an issue. Its also finding some unused bindings > src/metabase/api/email.clj:68:1: warning: unused binding p1__19760#

borkdude16:01:12

a better way is to write an :analyze-call hook but this takes more time :)

☝️ 1
ericdallo16:01:07

yeah, I already wrote some hooks for metabase, so probably take that as examples :)

dpsutton16:01:15

@ericdallo that’s an lsp feature not clj-kondo? The config you sent me is for lsp but i’m reading the warnings from clj-kondo --lint src:shared/src

dpsutton16:01:18

:clojure-lsp/unused-public-var

borkdude16:01:39

this linter is only available in clojure-lsp

👍 1
ericdallo16:01:58

@U11BV7MTK :clojure-lsp/unused-public-var`` is a custom lint fn that clojure-lsp has using clj-kondo custom lint feature

dpsutton16:01:06

oh right. clj-kondo only mentions unused private vars

dpsutton16:01:24

thank you both

dpsutton16:01:05

should i file an issue about the macro warning line information? or is that just a user problem because i am not providing a hook?

ericdallo16:01:11

I don't see nothing wrong on clojure-lsp side, and kondo can't know for sure the correct location, so probably this is a user problem indeed

👍 1
borkdude16:01:52

it's a "do I want to pay the time for writing a better hook vs getting a slightly worse editor experience" problem

👍 1
ericdallo16:01:53

I'd go with writing the hook, but this is your call @U11BV7MTK 😄

borkdude16:01:23

@ericdallo FYI, I recently brought down the errors on metabase to 0 in one day :)

ericdallo16:01:32

(I didn't even know this :macroexpand feature)

borkdude16:01:33

And I wrote that macro to get it done within a day

ericdallo16:01:43

yeah, I saw that, really neat! 👏

dpsutton16:01:32

:linters {:clojure-lsp/unused-public-var {:level :warning
                                           :exclude-when-defined-by #{metabase.api.common/defendpoint}}}
should do it then?

dpsutton16:01:50

if that does what i think it does, exclude-when-defined-by is a very thoughtful addition.

ericdallo16:01:04

yeah, I added that for those cases :)

dpsutton16:01:24

that’s really thoughtful. Really nice

gratitude 1
dpsutton17:01:07

it is not working for me though 😞

dpsutton17:01:18

i’ve restarted the workspace twice.

ericdallo17:01:39

oh, the highlight issue is not related with any linter :(

ericdallo17:01:55

it's a clojure-lsp feature called hover, that show the symbol location

dpsutton17:01:10

it might be a clj-kondo error inside of the macro and the line information is the entire form then

ericdallo17:01:10

since the location is wrong, there is no way to disable that unless fixing the hook

ericdallo17:01:27

I can confirm that later tonight

borkdude17:01:36

the location is not wrong, it's just propagated to the top. any linter can display information at the top (first paren)

ericdallo17:01:09

@U04V15CAJ the issue is not the linter, but the row/col on the analysis or the name-row/col

ericdallo17:01:22

I'll try to show that later tonight

borkdude17:01:47

the location of every node in the macro-expansion will be the location of the outer expr

borkdude17:01:50

with macroexpand

dpsutton17:01:44

yeah i think it knows there are several errors and they are all at the same place

borkdude17:01:35

Perhaps we'll just have to enhance this linter

👍 1
borkdude17:01:00

:macroexpand is usually used for simple things like (declare foo bar baz) where nothing can go wrong, but this macro is a bit involved

👍 1
☝️ 1
ericdallo17:01:26

I confirmed the behavior on metabase local @U11BV7MTK, it's indeed multiple elements at same outer position:

[{:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :ns metabase.api.util,
    :name GET_stats,
    :defined-by clojure.core/def,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :col 1,
    :name-col 1,
    :end-col 33,
    :doc "foo",
    :bucket :var-definitions,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :ns metabase.api.util,
    :name GET_stats,
    :defined-by clojure.core/def,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :col 1,
    :name-col 1,
    :end-col 33,
    :doc "foo",
    :bucket :var-definitions,
    :row 25},
   :semantic-tokens
   [{:token-type :function, :token-modifier [:definition]}]}
  {:element
   {:fixed-arities #{1},
    :end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name defendpoint*,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :macro true,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :arity 1,
    :bucket :var-usages,
    :row 25,
    :to metabase.api.common},
   :definition
   {:fixed-arities #{1},
    :end-row 257,
    :name-end-col 23,
    :name-end-row 247,
    :name-row 247,
    :ns metabase.api.common,
    :name defendpoint*,
    :defined-by clojure.core/defmacro,
    :filename "/home/greg/dev/metabase/src/metabase/api/common.clj",
    :macro true,
    :col 1,
    :name-col 11,
    :end-col 16,
    :arglist-strs
    ["[{:keys [method route fn-name docstr args body]}]"],
    :doc "Impl macro for `defendpoint`; don't use this directly.",
    :bucket :var-definitions,
    :row 247},
   :semantic-tokens [{:token-type :macro, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name do,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :var-usages,
    :row 25,
    :to clojure.core},
   :semantic-tokens [{:token-type :function, :token-modifier []}]}
  {:element
   {:fixed-arities #{0},
    :end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name check-superuser,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :alias api,
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :arity 0,
    :bucket :var-usages,
    :row 25,
    :to metabase.api.common},
   :definition
   {:fixed-arities #{0},
    :end-row 95,
    :name-end-col 22,
    :name-end-row 92,
    :name-row 92,
    :ns metabase.api.common,
    :name check-superuser,
    :defined-by clojure.core/defn,
    :filename "/home/greg/dev/metabase/src/metabase/api/common.clj",
    :col 1,
    :name-col 7,
    :end-col 31,
    :arglist-strs ["[]"],
    :doc
    "Check that `*current-user*` is a superuser or throw a 403. This doesn't require a DB call.",
    :bucket :var-definitions,
    :row 92},
   :semantic-tokens
   [{:token-type :type, :token-modifier []}
    {:token-type :event, :token-modifier []}
    {:token-type :function, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name anonymous-usage-stats,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :alias stats,
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :arity 0,
    :bucket :var-usages,
    :row 25,
    :to metabase.analytics.stats},
   :definition
   {:fixed-arities #{0},
    :end-row 389,
    :name-end-col 28,
    :name-end-row 369,
    :name-row 369,
    :ns metabase.analytics.stats,
    :name anonymous-usage-stats,
    :defined-by clojure.core/defn,
    :filename
    "/home/greg/dev/metabase/src/metabase/analytics/stats.clj",
    :col 1,
    :name-col 7,
    :end-col 53,
    :arglist-strs ["[]"],
    :doc "generate a map of the usage stats for this instance",
    :bucket :var-definitions,
    :row 369},
   :semantic-tokens
   [{:token-type :type, :token-modifier []}
    {:token-type :event, :token-modifier []}
    {:token-type :function, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name do,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :arity 2,
    :bucket :var-usages,
    :row 25,
    :to clojure.core},
   :semantic-tokens [{:token-type :function, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name GET,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :arity 6,
    :bucket :var-usages,
    :row 25,
    :to compojure.core},
   :semantic-tokens [{:token-type :function, :token-modifier []}]}
  {:element
   {:fixed-arities #{1 3 2},
    :end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name def,
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :macro true,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :arity 2,
    :bucket :var-usages,
    :row 25,
    :to clojure.core},
   :semantic-tokens [{:token-type :macro, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "line",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "line",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "column",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "column",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "doc",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "doc",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "is-endpoint?",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "is-endpoint?",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "line",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "line",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "column",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "column",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "line",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "line",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}
  {:element
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "column",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :definition
   {:end-row 30,
    :name-end-col 33,
    :name-end-row 30,
    :name-row 25,
    :name "column",
    :filename "/home/greg/dev/metabase/src/metabase/api/util.clj",
    :from metabase.api.util,
    :col 1,
    :name-col 1,
    :context {},
    :from-var GET_stats,
    :end-col 33,
    :bucket :keywords,
    :row 25},
   :semantic-tokens [{:token-type :keyword, :token-modifier []}]}]

ericdallo17:01:05

(BTW this is a really handful tricky when debugging kondo analysis, lsp-clojure-cursor-info)

dpsutton17:01:40

i was looking for something like that. thanks

ericdallo17:01:33

Useful tip when you want to debug kondo analysis used by clojure-lsp 🧵

👍 1
ericdallo17:01:46

there is a custom request called clojure/cursorInfo which brings information about the element at cursor position like kondo analysis, element definition and semantic tokens for that element!

ericdallo17:01:03

emacs For emacs user this is already available via lsp-clojure-cursor-info

Lukas Domagala17:01:21

uh nice, I’ll have to build that into Calva. Thanks!

ericdallo17:01:31

I was about to suggest exactly that @U02EMBDU2JU :)

NoahTheDuke17:01:39

available in coc-clojure as a CocCommand too!

nice 1
vim 1