Stubs not removed when removing PSI

Answered

Hello,

I have an issue with my stub index.
I remove a PSI element that has an associated stub and the stub is then also gone from the index. But when I restart IntelliJ, the stub is again present in the index.

I prepared a simplified project to demonstrate my issue: https://github.com/raddatzk/indexing-issue
To monitor the stub I added an annotator that logs all stubs

`IStubElementType.serialize` is also only called for remaining stubs (not the deleted one), so I don't understand why they are all back after restart

0
5 comments

See https://plugins.jetbrains.com/docs/intellij/stub-indexes.html#keys

Please note also related javadoc from com.intellij.util.indexing.FileBasedIndex#getAllKeys

* Query all the keys in the project. Note that the result may contain keys from other projects, orphan keys and the like,
* but it is guaranteed that it contains at least all the keys from specified project.

0

Many thanks already. Then I guess that I have to check for each item from `getElements` if it still exists in the project, right?

I have an additional question: I have an index that contains the keys for elements of type ClassA. After generating some PSI and restarting IntelliJ the stub also returned keys for elements of type ClassB. Unfortunately I was not yet able to reproduce this behavior, seems like in some edge cases. Is this also related to your answer?

0

I have to check for each item from `getElements` if it still exists in the project

Yes. Iterate all returned keys and try to resolve them in getElements() with proper search scope (e.g., current Project).

0

Related to “additional question”, it is unclear how this could happen and this issue is not known to us ATM. Is it possible that you mixed up some stubs/index access in your code?

0

I am currently reworking that part so maybe this won't occur again

I made sure to only add stubs of the same type in the index. From what I tried to debug it looked like at some point there is something like an ordered list of all stubs in a certain file and the index queries the list with the expected position of the stub

class1 {}
<- generate class2{} here
enum1 {}

Querying the enum index after generation and restart of IntelliJ returned class2. It seemed like the expected position in the file of enum1 was not updated accordingly

 

When I am done with my rework I will try to see if I can reproduce that again

0

Please sign in to leave a comment.