I have a custom plugin with three types of stubs (one for the name of the file, one for the imports of other files, and one for the variables declared in the files). You can reference other variables in the definitions of the variables, so I'm trying to use the stubs to quickly retrieve the available variables in a file to resolve the reference. Like this:
The problem is that for files that I have not edited, when I close IntelliJ and re-run the plugin with gradle, all of those references are broken. I've tried debugging it, and I've shown that in fact the variables are not in the stub index. If I make a change to the psi, then the stub index gets updated, but if I undo that change, close the project, then run IntelliJ again, the stub index is back to way it was, and the references are broken... I have to change the psi, then close the project with the changes made and open it up again before the stubs from that file persist.
It's good to know that the stubs are working! And thankfully when I add a new file, the stubs are indexed and persist. But the problem seems to be with files that existed in the project before the stub features were added. I used to not resolve by stub index which was slow, and that's why I added this feature. I'm worried that if I push these changes, all the users of my plugin will have the references in their files be broken, because the psi for those files was built before the stub index was implemented. In some cases, that would mean hundreds of files that the user would have to make trivial changes for no reason other than to get the stubs to be indexed properly.
Is there a graceful way to fix this? Perhaps a way to force the re-indexing of the stubs in a file? Or a way to mark the files that use the old reference resolution functionality? Maybe there's something wrong with the way I implemented the stubs that would cause it to work for some files and not for others?