PsiTreeChangeEvent error

Answered

Hello, I am trying to make plugin which shows hints after end of each line. There is already such plugin, but it has same bug i am getting in my experiments.

I made small test plugin which shows balloon with hints information(start offset, end offset, line, description) on each key press.
GitHub: https://github.com/IoaNNUwU/Test/blob/main/src/main/kotlin/com/github/ioannuwu/test/listeners/MyPsiTreeChangeListener.kt

The problem is sometimes i am getting "IndexOutOfBoundsException: Wrong offset" on backspace press.

I think it has to do with multithreading but i don't understand what is the problem.

My questions is what is the correct way to handle such events?

1 comment
Comment actions Permalink

The problem is indeed in multi-threading access. You are accessing HIghlightInfos after the document has changed but before these HighlightInfos are updated,and getStartOffset() returns invalid value. HighlightInfo is a very low-level concept which usually shouldn't be used. Instead, please consider using Annotator or LocalInspectionTool. (please see https://plugins.jetbrains.com/docs/intellij/annotator.html )

0

Please sign in to leave a comment.