New plugin, and performance question
I'm working on a new plugin that detects some possible errors in calls to printf like functions. It's working pretty well so far. Wondering if anyone would like to alpha test?
Also I have found that the processing can take some time, and i've seen it block auto completion occasionally till it finishes. What is the best way to do this processing without causing potential ide slowdowns? All of the current processing is done in a LocalInspectionTool, including that for the LinePainter because it gets called from the UI thread, and blocking ui threads is a no-no. My best guess is I could put it in a background thread that is triggered from the local inspection tool call, and then somehow triggers a re-run of both the local inspection scanning AND the line painting once its finished. A full reparse is not ideal, as I like storing a cache of my results in the Psi tree itself to avoid having to detect when the cached data is invalid. Storing my cache inside the inspection tool or some kind of service would lead to some hairy code recognizing when i need to invalidate cache entries.
Screenshots:


请先登录再写评论。
Hi,
what kind of preprocessing is this? Local inspections by definition do not check anything outside the current file and thus are supposed to be fast on each element. So probably you need something else but local inspection but in order to evaluate that more details are required
Thanks,
Anna
It only inspects the current file, assuming the reference search sticks to the current scope (it seems to so far).
It scans the file for a specific pattern, for example, a method call expression that has a string argument with a specific name followed by a var arg list. That alone can take a bit of time. not a HUGE amount, but can be noticible.
After that it actually will go and do a really basic "evaluation" of the vararg parameters to the method call to show a dumb preview. That part can take a lot longer. It's limited exclusively to literal expressions, references to literal expressions, assignments to variables including initializations, and basic artithmetic operations. As long as all references evaluate down to basic operations on literals, it can calculate a preview for that argument, othewise it just puts in a simple <placeholder> for the type of the expression.
Hi,
local inspections run together in parallel on different elements, thus it's better if you implement `visitMethodCallExpression` and do not perform search yourself - check for the pattern of method call should be fast, a lot of inspection do that and ±everything is cached.
There is special utils to evaluate constants, it's fast enough to be used inside local inspection without any modification. You may want to check how it works: `com.intellij.psi.impl.ConstantExpressionVisitor`. The corresponding api to call it: `com.intellij.psi.impl.JavaConstantExpressionEvaluator#computeConstantExpression(com.intellij.psi.PsiExpression, boolean)`.
Hope this helps,
Anna
Thank you for the tips, I will check them out! The expression validator would deffinitely simplify a bunch of my plugin.
I really wish there was more documentation for the various apis.
ALSO I'm interested in implementing the same features for multiple languages, including (but not limited to) C/C++, PHP, and Go. I'd really appreciate any guidance there. I've read that there is no supported public api for some of separate IDEs (like goland, and CLion), is that true? Would it be against any TOS to reverse engineer enough of the api to get a plugin like mine to work for C++/PHP/Go ?
Thanks!
OH, I just checked, I am using JavaElementVisitor::visitMethodCallExpression, as it did simplify some things over scanning the entire document(s) myself. But I looked at the code, and it essentially does what I'd do anyhow.
One thing I have noticed is that my code gets called multiple times, on the same "document". I ended up having to cache results in the Psi tree using putUserData to keep from re-doing all the work.