Fork me on GitHub
#clj-kondo
<
2020-04-02
>
didibus08:04:04

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?

didibus08:04:20

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?

didibus08:04:11

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?

sogaiu08:04:55

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: https://github.com/borkdude/clj-kondo/tree/master/analysis

borkdude08:04:01

@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.

didibus20:04:25

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

didibus20:04:47

As well as add jump-to-definition

borkdude20:04:10

you can see what sogaiu made with clj-kondo here: https://github.com/sogaiu/alc.index-defs

didibus20:04:24

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

didibus20:04:00

looks like github is down

borkdude20:04:16

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: https://github.com/clojure/tools.deps.alpha/wiki/Tools (morpheus and another one, both visualize dependencies between vars/namespaces)

borkdude08:04:59

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

sogaiu08:04:23

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.

borkdude09:04:43

In other news, Sublime Text 3 users can use the LSP server: https://github.com/borkdude/clj-kondo/issues/827

👍 12
chadhs11:04:42

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.

borkdude11:04:02

@chadhs I quickly whipped this one up:

#!/bin/sh

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

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

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

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

didibus23:04:46

Why not a babashka script 😉

chadhs14:04:30

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

borkdude15:04:47

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

borkdude11:04:27

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

chadhs11:04:48

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

chadhs11:04:32

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”

chadhs12:04:46

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