Virtual File changes only occur when clicking off Intellij
Hi,
So I'm creating a plugin which utilizes the VFS changes listener, however I find that when debugging, I make a change and the event for the change is only triggered when I click off intellij. So for example, in the community instance running my plugin, I type some changes in the editor, nothing. Click off the editor and onto a components such as a tool window, still nothing. Then I click off the community edition window and onto my web browser, or different intellij window which I am using to code the plugin, and the change event is triggered. However, at this point the before and after methods are both exactly the same, there is no difference between them.
I've tried using VirtualFileManager.addVirtualFileListener() and using BulkFileListener, both yield the same results. When trying to implement AsyncFileListener, I can't find that exact class, only AsyncVfsEventsListener. However it seems I cant subscribe to VFSChanges topic with this, and nor can I use it with VirtualFileManager.addVirtualFileListener(). I've also tried using both application and project level message busses.
Can anyone provide some direction in how to get events fired exactly when they happen?
Thanks,
Alex
请先登录再写评论。
VFS events are fired when files are changed on disk (more precise: when IDE realizes that they are changed and syncs its state).
Typing in Editor modifies corresponding in-memory structure - Document.
These changes are saved on disk on "Save All" action, by "Save files on frame deactivation" option, before Make, etc.
You can listen for these changes using DocumentListener (either for specific document - Document.addDocumentListener or in bulk - EditorFactory.getEventMulticaster.addDocumentListener).
See also BulkAwareDocumentListener that can help improve performance during intensive modifications.
https://www.jetbrains.org/intellij/sdk/docs/basics/virtual_file_system.html
https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/documents.html
Ahh OK, that makes sense. Thanks!
>However, at this point the before and after methods are both exactly the same, there is no difference between them.
The difference is the order in which they are invoked (ex: you can't access newly created file in "before" event, as it does not yet exist).
What difference would you expect here?
Ah yeah, true. Thank you