plugin development | changed file reload


I'm developing IntelliJ Plugin.
kotlin code : 
val file = File(fullPath)

file.copyTo(File(targetFullPath), true)

Copy file successfully with above code.

Question : If the file is already displayed on the IDE screen, Is there a way to put the file on the screen as soon as it is changed?

If you know, please check and reply. :)


Could you please elaborate more? Your use case is unclear to me.

Do I understand correctly, that you display a file in the editor, change its content and you want to refresh the content in the visible editor? Or maybe you want to activate the editor with the changed file? Or maybe you want to open a new copy of the file in the new editor? Please clarify.


Karol Lewandowski  Hi!

That situation.

1. The IDE screen displays the a.txt file.
All of them.
2. Click the button to copy the contents of the b.txt file to a.txt.
3. The contents of a.txt have changed, but will not appear immediately on the IDE screen.

I hope the a.txt will be reloaded immediately and displayed on the IDE screen.


Thanks for the clarification.

It is important to understand the Virtual File System used by IntelliJ Platform:
If you work on the physical files level, then it takes time for the platform to detect changes and refresh VFS.

Try to use Virtual File System API, e.g. copy files with VfsUtil.copy*() methods instead of standard files API.


Karol Lewandowski

Thank you for your kind reply!


Is it not good to create a file and refresh it with the code below?

val currentFilePath: VirtualFile? = event.getData(PlatformDataKeys.VIRTUAL_FILE)
VfsUtil.markDirtyAndRefresh(false, true, false, currentFilePath);



You can use markDirtyAndRefresh(), but the recommended approach is to use VFS API to operate on files, if possible.



I understood through VFS related documents and searches.
The VirtualFile concept is difficult but fascinating!
Successfully reloaded file after making changes via VirtualFile!

Thank you for your help.


Please sign in to leave a comment.