Fork me on GitHub
#clj-kondo
<
2021-07-09
>
West16:07:22

So I’m using a music creation library overtone.live. The examples tend to add it into the namespace with :use or :refer :all. It makes sense to do this since there isn’t likely to be any collisions with clojure.core and it’s the only library I tend to use in overtone projects. I already got clj-kondo to stop linting :use and :refer :all by adding :linters {:refer-all {:exclude [overtone.live]}} to my kondo config.edn. Now it gives me “Unresolved symbol” when I see why all symbols in the namespace are underlined red. What can I do about this?

borkdude17:07:10

@c.westrom What you can do about this is lint the overtone library while also having a .clj-kondo directory

West18:07:45

I don’t understand. Do you mean clone overtone.live and then run clj-kondo in a separate terminal to lint it? @borkdude

borkdude18:07:31

@c.westrom You are not using overtone.live as a dependency in a clojure project?

borkdude18:07:59

project.clj?

West18:07:04

Deps.edn, everything works fine when I require overtone.live :as ol or something like that. I just don’t want to have to write ol/ before everything.

borkdude18:07:46

@c.westrom ok, then try as documented in the link I gave you:

mkdir -p .clj-kondo
clj-kondo --lint $(clojure -Spath) --dependencies 

borkdude18:07:56

and then try again in your editor

West18:07:46

unfortunately that did not work, I’m suspecting it might be an issue with lsp

borkdude18:07:14

oh, you're using LSP, you didn't mention that :)

borkdude18:07:38

In that case, try removing .lsp/sqlite.db and restart your editor

borkdude18:07:17

If that helps, let me know. If that does not help, I'll have another suggestion.

West18:07:22

Still a sea of red.

borkdude18:07:45

ok, another attempt. Remove .lsp/sqlite.db and remove .clj-kondo/.cache

borkdude18:07:49

and then restart your editor

borkdude18:07:23

oh, I think I see the issue with this. overtone uses a custom macro to import its vars... https://github.com/overtone/overtone/blob/master/src/overtone/live.clj so unfortunately the combination of :use + that namespace won't work very well. you might as well disable the unresolved symbol linter in this namespace :/

ericdallo18:07:07

overtone could have a hook for its macros right? then it would work for clj-kondo if user configure to use the hook, right?

borkdude18:07:36

that's correct, but the macro doesn't give very much to go by. it's basically "copy that namespace to here"

ericdallo18:07:44

yeah, it's hard to make it work for every corner case indeed 😅

borkdude18:07:20

well, what you could do is write a hook for this macro and just hard-code the var defs

West18:07:39

Oh, so it’s an overtone thing. I even tried intellij to see if it was just emacs jank causing the issue.

ericdallo18:07:14

just curious, what happens with intellij/cursive? does it works?

borkdude18:07:33

if cursive uses only static analysis, I expect it to be have similarly

West18:07:00

For all the symbols that were red before, I get x cannot be resolved.

borkdude18:07:31

you could write a hook which generates

(declare osc chance ...)
from the macro call. All the vars are here: https://github.com/overtone/overtone/blob/02f8cdd2817bf810ff390b6f91d3e84d61afcc85/src/overtone/api.clj#L53

West18:07:23

I could look into hooks I guess

borkdude18:07:39

so you would write a hook that expands a call to

(overtone.api/immigrate-overtone-api)
into
(declare osc chance ...)
, then you re-initialize lsp by throwing away .lsp/sqlite.db and .clj-kondo/.cache + editor restart

borkdude18:07:45

and then it should work 😅

borkdude18:07:15

you're welcome to PR the hook to overtone itself

borkdude18:07:20

or to the clj-kondo/config project on github

West19:07:08

thanks guys