Fork me on GitHub
#clj-kondo
<
2020-01-13
>
mikerod16:01:47

How can kondo be made to understand macros that define new symbols/vars?

bfabry16:01:29

"def" would be a macro that creates and binds new vars. "let" would be a macro that binds symbols

borkdude16:01:21

@mikerod Any macro in particular?

mikerod16:01:34

@borkdude no, custom macros

mikerod16:01:51

@bfabry I don’t know that I see how that can work for that symbol then being recognized as available

mikerod16:01:58

it can be worse too though really

mikerod16:01:15

(def-my-thing Foo) could define a var like AutoFoo

borkdude16:01:18

@mikerod what does the macro usage look like

mikerod16:01:41

which is somewhat similar to perhaps the way a defrecord Foo makes fn’s map->Foo & ->Foo

mikerod16:01:04

macro usage is like above

mikerod16:01:39

(def-auto-gen foo)

;; later
(auto-foo :hi)

borkdude16:01:48

search for hugsql in the docs, there's a way how you can fix this with declare

mikerod16:01:56

yeah, I see the declare option

mikerod17:01:06

that’s ok, I suppose. would be a lot to write

borkdude17:01:32

you can also use a local namespace config which excludes those symbols from being reported, but that would be almost the same amount of work as the declare

mikerod17:01:33

Basically I have huge list of def-thing that makes a wrapper type

borkdude17:01:38

or you can just turn the linter off in that namespace

mikerod17:01:40

it also defines a “raw” type under an auto gen name

mikerod17:01:43

and there’s just a lot of them

mikerod17:01:49

so it’d be like 30 repeats

mikerod17:01:04

I don’t use all 30 of these things

borkdude17:01:10

(ns foo {:clj-kondo/config '{:linters {:unresolved-symbol {:level :off}}})

mikerod17:01:14

so so far I’ve just blacklisted the ones I do use in the config

mikerod17:01:24

since that is less

mikerod17:01:41

I didn’t know that was an option - it is appealing from within the ns for sure

mikerod17:01:51

typically no other ns will try to use these autogenerated ones

mikerod17:01:56

but they can still

borkdude17:01:10

in that case they won't get reported, if they are coming from another namespace

mikerod17:01:31

oh, it ignores things like other/auto-foo ?

mikerod17:01:51

that certainly improves the situation for me

mikerod17:01:11

I’m a little surprised I guess since perhaps people may want to know if they are referring to bogus symbols in other ns’s though

mikerod17:01:15

guess it’s just a tradeoff

mikerod17:01:01

other/typo-foo ;; <-- uh oh

mikerod17:01:13

is it just that the compiler will tell you that anyways?

borkdude17:01:22

there is an issue for it to make this work: https://github.com/borkdude/clj-kondo/issues/634 it's just not there yet and I'm not sure if we should ever do this. feel free to respond in that ticket with your opinion

borkdude17:01:58

given that clj-kondo might not have a complete picture of your "other-ns", it will probably lead to false positives

mikerod17:01:27

Yeah in my case with this sort of macro I think it’d be pretty bad for me on false positives now that I think of it.

mikerod17:01:42

Thanks for the issue link. Will post any more thoughts there.

alidlorenzo20:01:57

could clj-kondo be used to configure code completion? i ask b/c what think i'll miss about Typescript/Static Typing isn't necessarily error detection but improve Intellisense

borkdude20:01:01

I believe @sogaiu has developed some tooling for emacs using the clj-kondo analysis output

borkdude20:01:15

but in general runtime tooling like CIDER/orchard can do this as well

borkdude20:01:54

maybe sogaiu could post a link to his work

sogaiu20:01:27

the following instructions are for use with emacs: https://gist.github.com/sogaiu/6cb947b00ae13d00d4ae16ab7aaf97e4 but there is a piece that can generate either a TAGS (etags) or tags (ctags) file. i have used the ctags version successfully with vscode (but i needed to add an appropriate plugin for it). i've also used it with atom, but there the built-in "jump-to" functionality appears to be on the broken side.

sogaiu20:01:21

i haven't tried to get the generated content to work with completion (on vscode and atom) -- i'm not sure what is involved.

sogaiu20:01:59

so to be clear, the focus so far has been on navigation.

borkdude20:01:13

@sogaiu why not add that gist to the README of the repo?

sogaiu20:01:30

because i have not received enough feedback 🙂

sogaiu20:01:01

does the clj-kondo lsp stuff do code completion?

borkdude20:01:17

no only linting, same as the .exe

alidlorenzo20:01:13

the linked file is only navigation, correct? also, i'm using vscode so maybe I'd be more appropriate for me to continue discussion there? just thought that clj-kondo might be a more generic way of adding this feature since calva already uses it for linting

borkdude20:01:53

@alidcastano calva only bundles the clj-kondo vscode plugin, but doesn't really interact with it on a program level

🆗 1
sogaiu20:01:19

the link is to a description that explains how to get navigation to work for emacs (though as a side effect, it may allow other things). there are both #calva-dev and #vscode if interested in discussing in other places 🙂

👍 1
sogaiu05:01:49

fwiw, i got a bare-bones vscode extension that uses the generated ctags file to provide completion. the main drawback currently is that this uses node-ctags which is a native node module.

borkdude22:01:23

Small "critical" update with regards to with-redefs: https://github.com/borkdude/clj-kondo/releases/tag/v2020.01.13