Fork me on GitHub

Was kind of curious, since Cursive does auto-complete without a running REPL, I think just from its static analysis of the source code. And clj-kondo does static analysis of the source code for linting, how likely is it for it to maybe be used for driving auto-completion as well?


Like, if it can tell that a symbol is used that wasn't defined, or that some function take 3 arguments and not the 2 it's currently called with, doesn't that meant it has the information of all defined functions, macros and vars and their arities?


If so, if it could be queried for it, Cider and Calva et all might be able to ask it for the list of possible completions within some context and maybe also the list of arguments for displaying that as well as you type?


i have written some code that uses clj-kondo as a library to produce index information for identifiers and output as tags / TAGS. i use this to do jump-to-definition like things in various editors. in emacs i think it's supposed to be possible to leverage the info for completion as well. the main downside atm is that the initial indexing takes a while. for more details, you might find the following to be of interest:


@sogaiu @didibus I think the approach that sogaiu takes can be combined with some editor plugin which lints the currently edited file and combines that with the already linted data, so incremental. that would solve the speed problem.


Hum, interesting, but ya, this analyses data does feel like you have everything you need to auto-complete var names, macros, fns, namespaces, show arities and show doc


As well as add jump-to-definition


you can see what sogaiu made with clj-kondo here:


And it would seem, you could even use it for refactoring, since it shows uses of vars and namespaces


looks like github is down


yep. there are currently 4 tools that I know of that build on the analysis export. carve by me: finds unused vars and automatically removes them alc-index by sogaiu two listed here: (morpheus and another one, both visualize dependencies between vars/namespaces)


so yeah, you can build something like this on top of the analysis export


i've been thinking about the incremental approach a bit recently and i took some measurements for just the clj-kondo execution part. for clojure.core, i typically get between 0.7 to 0.8 secs. some post-processing is likely necessary but i'm not sure yet how much that might end up being. in the mean time, i'm trying to see what i can squeeze out of tree-sitter-clojure -- though even if that ends up faster, it's not likely to be nearly as accurate as clj-kondo.


In other news, Sublime Text 3 users can use the LSP server:

👍 12

does anyone have a recommendation on how to set clj-kondo up to run as a pre-commit hook? similar to using lint-staged and husky in your package.json for those familiar with node based project.


@chadhs I quickly whipped this one up:


# To enable this hook, rename this file to "pre-commit".

if git rev-parse --verify HEAD >/dev/null 2>&1
    # Initial commit: diff against an empty tree object
    against=$(git hash-object -t tree /dev/null)

if !(git diff --cached --name-only --diff-filter=AM $against | grep -E '.clj[cs]?$' | xargs clj-kondo --lint)
    echo "Error: new clj-kondo errors found. Please fix them and retry the commit."
    exit 1

exec git diff-index --check --cached $against --


Why not a babashka script 😉


always good to default to plain old /bin/sh unless you need a feature from bash.


the main reason is that I just copied this from existing scripts. another good reason is that bb isn't available on every system and introduces a new dependency


thanks for the idea, I should have done this much earlier 😉


oh wow, cool and thanks; i’ll check this out.


haha no worries. i released v1 of a small project / product in dec, so now i’m spending some time on “tech debt” in the form of tooling, more testing, refactoring before i add features. that sparked “wow i should really try clj-kondo”


you bet, i’m planning to do that tomorrow during the morning.