Project Component wait for indexed directories

in my custom language plugin I want to attach a changeListener to three certain documents. I thought the best time to attach the listeners would be in a Project or Module Component.

I added the following code in the moduleAdded respective the projectOpened method of the components:

final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);                 document.addDocumentListener(new DocumentAdapter() {                     @Override                     public void documentChanged(DocumentEvent e) {                         super.documentChanged(e);                         System.out.println("I was changed");                     }                 });

However, the PsiFile is null. I get the message : ERROR - .roots.impl.DirectoryIndexImpl - Directory index is not initialized yet for Project
So when is the right time to attach listeners to documents. Is there a action I can hook in that is called after all directories are indexed?
Thanks in advance,

1 comment

Refer class DumbService, especially methods: runWhenSmart, smartInvokeLater - this may help.


Please sign in to leave a comment.