"Directory index is not initialized yet for Project" at plugin startup
In the plugin I'm developing, I'm needing to get hold of the Vcs Roots when a ProjectComponent starts up. Unfortunately, both the projectOpened and initComponent methods seem to be called before the roots are loaded, because calls to ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs raise an error ("Directory index is not initialized yet for Project") from com.intellij.openapi.roots.impl.DirectoryIndexImpl.checkAvailability.
Is there a better place to put this initialization code, or perhaps a message bus signal that indicates the right time that this kind of initialization can happen?
请先登录再写评论。
is postStartupActivity EP's runActivity called too early?
Forgive my ignorance of your abbreviations, but I'm not quite sure what you meant by EP. That said, you led me down a successful path.
I put the initialization code inside the initComponent() method, inside a registerPostStartupActivity:
public void initComponent() { StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() { public void run() { /* initialization code */ } }); }Thanks for the help.
> what you meant by EP
my apologies Matt,
EP: "Extension Point"
Thank you for sharing your solution. I like it much better than another extension file. I just added some initialization code into my plugin and got the same errors.