cursive

Issues at: https://git.io/cursive-issues
raspasov 2021-05-04T00:35:01.297700Z

This is nothing super critical but I’ve always wondered: why do certain, say, (defn …)’s show as “white”/in use when they are in fact unused? It seems that if the name of the defn is short, then it actually doesn’t autodetect used/unused.

cfleming 2021-05-04T10:57:21.298500Z

Yes, your guess is correct. Basically, this inspection is a best effort - if it says that something it’s unused, then it’s unused, but if it doesn’t it still might be unused. This is because checking references is an expensive operation.

cfleming 2021-05-04T10:59:21.298700Z

So the way this works is that under the hood IntelliJ breaks files down into words, and it has a very fast word search. Generally something like Find Usages will search for all the instances of the word of the name of something, then will check to see if that word is in a string or a comment, and if not it will try to resolve each one to see which are actually references to the thing you’re looking for. This is why a lot of operations are much more expensive for things with short common names.

cfleming 2021-05-04T11:00:25.298900Z

In this case, the inspection has a hard-coded limit (10 IIRC) - if the word appears more than that number of times, we don’t even bother trying to check references since it would slow everything down too much.

cfleming 2021-05-04T11:01:00.299100Z

The moral of the story is, don’t call your functions things like ns, let, or whatever 🙂

raspasov 2021-05-05T00:09:37.301300Z

Understood, thank you for the detailed explanation!

raspasov 2021-05-05T00:12:07.302Z

Does that also apply to (:require [… :as alias1]) ? (I assume, yes)

raspasov 2021-05-05T00:17:45.302400Z

Do you know if there’s a way to tune that from the user perspective to make the search “more accurate”, potentially at the cost of performance? (I am generally pretty happy with the perf. when using a good laptop and charging it)

cfleming 2021-05-07T00:41:46.314700Z

No, there’s no tweakable knob there sorry, I’m using parameters recommended by JetBrains. I’m hesitant to add a config for that since people could inadvertently break the performance of their IDE for non-obvious reasons.

👍 1
raspasov 2021-05-04T00:36:44.298200Z

Actually, maybe not…

wilkerlucio 2021-05-04T20:11:22.299700Z

this is interesting, I made a different try that cause it to mark as unused:

wilkerlucio 2021-05-04T20:11:44.300100Z

seems like it also cares about the tokenized words, if there are small words between tokens, its the same as a full small name

wilkerlucio 2021-05-04T20:12:28.300300Z

on a bit more testing, seems like if "every word" is small, the problem remains, but one part of the symbol is a longer word, them it detects unused

wilkerlucio 2021-05-04T20:13:11.300500Z

raspasov 2021-05-05T00:07:00.301100Z

Yes, it happens frequently enough but I can’t spot a pattern.

raspasov 2021-05-05T00:10:29.301500Z

@cfleming posted an explanation in the other sub-thread https://clojurians.slack.com/archives/C0744GXCJ/p1620088501297700