After Save Hooks Follow
Answered
It may sound crazy, but I want to implement a plugin that does something everytime I save. But not before the file is actually saved I need to know when it is saved. I tried to find the documentation on what happens (what events are fired) when the user saves a document. But I didn't find what I was looking for. This post: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206377699-After-save-hook?input_string=After%20Save%20Hooks Doesn't help me. I don't even want to trigger something external.
I hope my question is clear
Donut
Please sign in to leave a comment.
Check out com.intellij.openapi.fileEditor.FileDocumentManagerListener.
I have done that. The only method I came across, that hopefully does what I need is fileContentReloaded. Is every document reloaded after it was saved?
I think you can only get an event before file is saved currently.
I found a "solution". It might not be the correct/efficient way or best practice, but it works for me. I directly register a VirtualFileListener to the VirtualFileManager
Any thoughts on this workaround?
The solution above is quite correct. Hope you aren't going to modify files on a disk after the save, aren't you?
> But not before the file is actually saved I need to know when it is saved.
This part is somewhat obscure; could you please clarify?
> Hope you aren't going to modify files on a disk after the save, aren't you?
Of course not. What do you think of me? :-)
The idea (pun not intended) is to run a specific task every time I save "something". This something might get more and more defined over the next iterations, but for now it is just any document. The task I want to run is a test runner (e.g jUnit). This is why I think I need to run it right after everything was saved. I don't want to run with an outdated version of the file.
OK :)
For this use case, the solution is definitely correct.
Thank you for the feedback. :-)
I will continue developing and might have some other questions (about run configurations etc.) in other threads.