Cannot capture file changes from refactorings


I am building a plugin that listens to all the text changes performed by refactorings.

I am using:

  • a VirtualFileListener to listen to file adds / deletes
  • a DocumentListener to listen to the changes on all the opened files (using a FileEditorManagerListener to hook up the DocumentListeners when files are opened and closed)

My problem is that, if a refactoring touches files that are not opened in editors (e.g. a rename refactoring that writes into other unopened files), then its changes into the unopened files do not seem to fire any events whatsoever, anywhere:

  • no file opened / closed events are generated, therefore no Document listeners can be attached
  • no VirtualFileListener.contentsChanged() is triggered, so I cannot listen to the change even at the VirtualFile level. (not even a file save event is fired ... how can this be?)

My question is, what listeners do I need to hookup and where in order to capture text changes performed by Idea in files that are not opened in UI editors?


Comment actions Permalink

EditorFactory.getEventMulticaster().addDocumentListener() will add an IDE-wide document change listener.

Comment actions Permalink

Thanks. That one gives me all the text edits. Including some strange "IntellijIdeaRulezzz" hack edits (which I've tracked down as a really really really bad IJ programming design decision). I've noticed that the hack edits appear in a different file than the original one, so I filter out all the edits on these auxiliary copies.

Comment actions Permalink

I wouldn't call it a bad decision, it helps tremendously when writing completion stuff. :)
You may probably check !(FileDocumentManager.getFile(document) instanceof LightVirtualFile)


Please sign in to leave a comment.