Fork me on GitHub
#clj-kondo
<
2019-11-04
>
martinklepsch11:11:29

@borkdude did you see tree-sitter? https://www.youtube.com/watch?v=Jes3bD6P0To, maybe it’s interesting to clj-kondo somehow

borkdude11:11:34

I haven't seen it, but added it to my watch list. Thanks!

martinklepsch11:11:45

Some very cool stuff going on there. To provoke some more interest: the system they built can parse code incrementally, maintaining a full syntax tree by incorporating edits from the user as they come in. It can also parse invalid code, recovering from syntax issues in subtrees/leaves of the AST.

borkdude11:11:44

It seems LSP can also do that (parse incrementally)

martinklepsch11:11:58

Yeah, he also references LSP but considers that both complement each other, tree-sitter sitting at the super low-latency spectrum needed for anything that requires “as you type” kind of interactivity

borkdude11:11:43

true, I guess LSP is only a high level protocol. using LSP you can pass the text to a parser, which could be tree-sitter

dominicm12:11:25

LSP is considered too high latency for the things tree sitter is achieving. E.g. Syntax highlighting

borkdude12:11:07

I guess it depends what you're doing with your LSP events. LSP itself is just a network/REST thing using JSON, which is fast.

borkdude12:11:50

How do they define low latency, which threshold in ms are we talking about?

martinklepsch12:11:01

I guess 60fps? i.e. double digit ms

martinklepsch12:11:21

(in an ideal world 😛)

dominicm12:11:38

> - The LSP probably isn't well suited to general syntax highlighting due to computation cost and communication chattiness concerns, but the LSP may eventually support semantic syntax highlighting [1]. This could, for example, allow an editor to color all singletons hotpink, which requires a semantic understanding of the code. Semantic highlighting would augment the base highlighting provided by tree-sitter or by a TextMate grammar. Syntax highlighting targets instant. as plugins will be using it to make decisions.

dominicm12:11:16

10k loc buffer needs to be re-sent and received on every change with LSP IS implied.

dominicm12:11:02

Editors can implement the incremental part based on their buffer data structures to provide instant highlighting

dominicm12:11:59

The key thing here is that most toolchains aren't incremental by default.

borkdude12:11:09

@dominicm LSP can send incremental changes

dominicm12:11:17

I think that the implied problem is that most compilers aren't capable of handling incremental changes. Maybe they are stateless, or simply not designed that way because it isn't useful for their language.

borkdude12:11:38

it's definitely harder. kondo doesn't support it 😉

borkdude12:11:35

kondo does try to stay within double digits latency though for single files

borkdude12:11:59

if the linter becomes too slow that's also feedback: split up your file in multiple namespaces 😛

dominicm12:11:41

Sometimes there's no real logical way to do that.

dominicm12:11:13

E.g. A model layer for a graph database. You can't split by entity, because your queries operate across many of them.

whilo12:11:53

incremental compilation is a very interesting research field

borkdude12:11:25

@dominicm it's kind of a similar problem that clj-kondo has I think. I do that by passing main functions as arguments to sub-functions. it's a bit of a hack maybe. clojure.core does it with in-ns I think

borkdude12:11:10

(I also tried in-ns briefly, but it's less linter-friendly and also it gave weird problems with graalvm / AOT)

borkdude12:11:31

also multi-methods may help there

dominicm13:11:46

I don't understand at all, sorry

borkdude13:11:12

Splitting in multiple files can be achieved with multi-methods, passing functions around as arguments or using in-ns

borkdude13:11:53

unless I don't understand the problem you described, then I'm sorry 😉

dominicm14:11:53

Oh, I just meant that it is sometimes unclear in which dimension to slice up a namespace.

souenzzo15:11:04

@borkdude how do I find all (:require [...]) in my src/main ?

borkdude15:11:35

@souenzzo You mean all referred namespaces? What is the background of your question?

souenzzo15:11:55

I want to programmatic access all :requires in my project I will use it to create assertions like datomic.api should always be aliased as d or do not use refer inside my test suite

borkdude15:11:19

btw @dominicm I think you asked for this feature once, it's now released

dominicm15:11:49

Hmm. I wanted the config in that situation to be generated from the project.

borkdude15:11:36

Let me rephrase my previous comment. You might be able to use the analysis data to generate a config. It's hard to infer it while linting, since there can be multiple competing aliases and it also depends on how many files you are linting, so it wasn't a clear cut thing to do

borkdude15:11:42

Also the set of namespaces that you want to force a consistent alias for, might not contain every single namespace

souenzzo17:11:19

cool thing https://gist.github.com/souenzzo/5a15947ce3449a2a084d7b81d9cb1efd helped me clean up unused dependencies in a project. the output is a hint. Dynamic things like io.pedestal/pedestal.jetty may be wrongly reported.

👍 4
souenzzo17:11:57

.class things like datomic-pro also wrongly reported but I think that it can be handled

dominicm17:11:38

Oh, that's awesome

souenzzo17:11:05

deps from project that aren't used (remove deps-from-requires deps-from-project) deps from requires that arent explicit dependencies (this one is nice as a linter!) (remove deps-from-project deps-from-requires)

borkdude17:11:55

can you give an example of the latter?

borkdude18:11:04

aaah, you are parsing project.clj

borkdude18:11:01

there's also one other check which @dominicm has suggested: when you use a qualified var without a require you should get a warning

borkdude18:11:14

(if I remember correctly)

borkdude18:11:40

e.g. (ns foo) (clojure.string/trim ...)

souenzzo15:11:39

(kondo/run! {:lint ["src/main"]
             :config {:output {:analysis true}}})
Nice 🙂

borkdude15:11:31

"do not use refer" isn't included in the analysis data, but it could be an option for the alias-consistency linter maybe

borkdude15:11:50

maybe that data could also be added to the analysis data

borkdude15:11:13

the relevant data is now in :namespace-usages