Fork me on GitHub
#clj-kondo
<
2020-10-06
>
fiddlerwoaroof16:10:00

Has anyone used the clj-kondo analysis output to implement jump to definition in emacs?

fiddlerwoaroof16:10:16

(and eldoc 🙂 )

didibus08:10:19

I have jump-to-definition on my to-do. That and eldoc are my next two, but I got kind of stuck with trying to make the analysis async so it doesn't freeze emacs first time you open a file from a project 😝 and that was a lot of work, so then I chocked and I put the whole thing on back burner haha. Thinking of getting back into it soon

fiddlerwoaroof06:10:58

Could you piggieback on the data produced during the linting run @? I figure the .clj-kondo cache directory ought to have all sorts of useful data that I just don’t have an interface into.

fiddlerwoaroof06:10:19

This project looks great, by the way.

didibus03:10:47

Yup, clj-kondo analysis data has everything I'd need. The row/col location of each var in each file and their name and doc is all there

didibus03:10:05

And I maintain my own cache of it on a per-project basis in Emacs

fiddlerwoaroof18:10:44

Is there a way to configure it to just re-use the cache I already have? It's not a huge deal, but it'd be a bit nicer to only actually compute that data once

borkdude18:10:09

anakondo uses its own cache. the format in .clj-kondo/.cache is an implementation detail which is not supposed to be used by other tools since it can change (it doesn't change often, but it could happen)

fiddlerwoaroof19:10:57

That makes sense, it'd be nice if there was a canonical database of analysis data that other tools could hook into.

borkdude19:10:29

I think it's better if tools keep their own caches, caching is hard enough as it is

borkdude19:10:53

But it's likely that when you use anakondo to build up its cache, clj-kondo's cache will be populated as a side effect as well

didibus23:10:57

I can also say that in practice, I've not seen any performance impact even on a 10 year old laptop that can't even run Google Chrome without crashing. The biggest issue for me right now is the initial time to analyse a project, and the fact that it blocks Emacs while doing that initial analysis. Most of the time there is taken by the Java analysis, not clj-kondo, so even then I don't think from clj-kondo's perspective its that big a problem for now.

didibus23:10:44

Also, syncing Emacs with a file based cache wouldn't be that simple, probably requiring its own cache for it 😛

didibus23:10:46

What I have wondered though is more, if I decide to save my own cache to a file, so on Emacs restart you don't need to re-analyse the project, if I should re-use the clj-kondo's folder, or have my own folder, or store it within Emacs's own folder, etc.

borkdude07:10:20

You can save it in .clj-kondo for sure

fiddlerwoaroof17:10:42

I guess I was thinking more in terms of a database with an API that tools can be written against. I'd like to be able to query for code construvts with datalog or SQL, for example.

fiddlerwoaroof17:10:37

Anyways, my grand vision for programming is more smalltalk-image shaped and less file shaped

borkdude18:10:28

totally possible to make a tool which puts clj-kondo's data into a SQL db: https://github.com/borkdude/babashka/blob/master/examples/hsqldb_unused_vars.clj

didibus20:10:04

The downsides of that is for an Emacs editing environment you now have to manage long lived subprocesses and that comes with its own issues.

borkdude20:10:19

@ babashka + hsqldb is pretty fast, and not long lived, milliseconds

borkdude20:10:49

I haven't tested the feasibility of this, but you can try out the example in your own machine to see how it performs

didibus20:10:21

Hum... like if I didn't maintain a cache? It means clj-kondo would need to re-analyse all files every edit and re-initialize hsqldb and insert all vars and then run the query.

didibus20:10:56

I don't know maybe clj-kondo and hsqldb are that fast

borkdude20:10:10

this is just an example of how to use hsqldb. I mean: you could maintain your own cache in a hsqldb

borkdude20:10:24

I'm not sure either

didibus20:10:25

Right, that's what I meant by long lived process

borkdude20:10:43

no, it's persisted to disk?

didibus20:10:46

If I maintain my cache in a DB, that's a seperate process that Emacs as to start and manage

didibus20:10:00

Oh, is it?

didibus20:10:29

So you start hsql run some query over a a file based table and then kill it?

borkdude20:10:31

yeah. you can use it with babashka to create ad hoc databases on your file system, just like sqlite

borkdude20:10:18

sqlite is also an option btw, if emacs has support for that somehow

didibus20:10:21

Ok, that's interesting then, I'll think about it. Could make my code easier, querying data-structures in Emacs is alright but that would make it much nicer

borkdude20:10:27

so, the support for hsqldb from within babashka comes from here: https://github.com/babashka/babashka-sql-pods/

didibus20:10:16

There's the downside of having users need to install one more binary, but I guess they are already expected to install clj-kondo

borkdude20:10:55

That's for sure. Of course you could also make your own anakondo binary with GraalVM and use clj-kondo from there.

borkdude20:10:07

and include whatever database / EDN / EQL stuff you want

borkdude20:10:45

Postgres and HSQLDB (embedded) are the only databases I've gotten to work with GraalVM

didibus20:10:38

Hum, ya that could be an option as well. I'll hammock on it all. Though at this point I wouldn't really see myself making a major refactor of that sort unless it really helped me down the road. But I like the ideas.

fiddlerwoaroof05:10:05

My ideal would be a standardized “database” of analysis information that could be populated by tools like clj-kondo and cider and used by various editor plugins as well as by ad-hoc user queries

fiddlerwoaroof05:10:51

Of course, as someone who isn’t writing code (and doesn’t have time to) I'm grateful for the work y'all do

sogaiu22:10:46

@fiddlerwoaroof this branch uses a much more recent clj-kondo fwiw: https://github.com/sogaiu/alc.index-defs/tree/update-clj-kondo