clj-kondo

https://github.com/clj-kondo/clj-kondo
fiddlerwoaroof 2020-10-06T16:55:00.100900Z

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

fiddlerwoaroof 2020-10-06T16:55:16.101100Z

(and eldoc ๐Ÿ™‚ )

fiddlerwoaroof 2020-10-06T17:08:31.101400Z

Ok, I found jump-to-definition: https://github.com/sogaiu/alc.index-defs

borkdude 2020-10-06T17:37:33.101700Z

@fiddlerwoaroof also: https://github.com/didibus/anakondo

๐Ÿ‘ 1
2020-10-07T08:06:19.105400Z

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

fiddlerwoaroof 2020-10-08T06:31:58.118100Z

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

fiddlerwoaroof 2020-10-08T06:32:19.118600Z

This project looks great, by the way.

2020-10-09T03:06:47.132600Z

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

2020-10-09T03:07:05.132800Z

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

fiddlerwoaroof 2020-10-09T18:41:44.133Z

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

borkdude 2020-10-09T18:43:09.133200Z

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)

fiddlerwoaroof 2020-10-09T19:14:57.133500Z

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

borkdude 2020-10-09T19:16:29.133700Z

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

borkdude 2020-10-09T19:17:53.133900Z

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

2020-10-09T23:20:57.134100Z

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.

2020-10-09T23:21:44.134300Z

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

2020-10-09T23:22:46.134500Z

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.

borkdude 2020-10-10T07:00:20.135200Z

You can save it in .clj-kondo for sure

fiddlerwoaroof 2020-10-10T17:14:42.147200Z

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.

fiddlerwoaroof 2020-10-10T17:16:37.147400Z

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

borkdude 2020-10-10T18:14:28.147600Z

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

2020-10-10T20:16:04.148Z

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.

borkdude 2020-10-10T20:17:19.148300Z

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

borkdude 2020-10-10T20:19:49.148500Z

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

2020-10-10T20:22:21.148700Z

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.

2020-10-10T20:22:56.148900Z

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

borkdude 2020-10-10T20:23:10.149100Z

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

borkdude 2020-10-10T20:23:24.149300Z

I'm not sure either

2020-10-10T20:23:25.149500Z

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

borkdude 2020-10-10T20:23:43.149700Z

no, it's persisted to disk?

2020-10-10T20:23:46.149900Z

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

2020-10-10T20:24:00.150200Z

Oh, is it?

2020-10-10T20:24:29.150400Z

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

borkdude 2020-10-10T20:24:31.150600Z

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

borkdude 2020-10-10T20:25:18.150800Z

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

2020-10-10T20:25:21.151Z

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

borkdude 2020-10-10T20:26:27.151200Z

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

2020-10-10T20:27:16.151400Z

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

borkdude 2020-10-10T20:27:55.151600Z

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

borkdude 2020-10-10T20:28:07.151800Z

and include whatever database / EDN / EQL stuff you want

borkdude 2020-10-10T20:28:45.152Z

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

2020-10-10T20:29:38.152200Z

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.

fiddlerwoaroof 2020-10-11T05:07:05.154600Z

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

fiddlerwoaroof 2020-10-11T05:07:51.155700Z

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

2020-10-11T05:26:23.156Z

there is also this project: https://github.com/jpmonettas/clindex

๐Ÿ‘ 1
2020-10-06T22:47:46.102400Z

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

fiddlerwoaroof 2020-10-06T22:48:00.102600Z

Thanks @sogaiu

๐Ÿ‘ 1