File | Synchronize Function in code

Answered

IntelliJ has a function in the menu bar at the top called Synchronize, under File | Synchronize. I'm designing a plugin for practice and in the plugin I am writing to the current file. This all works however it only works if I go into File | Synchronize, then my changes are shown in the current file. 

I've been looking for a way to do this in IntelliJ code (not through the main menu bar) but haven't been successful. I'm really after something like IFile.refreshLocal() in eclipse (but obviously an intellij version). I've also tried looking into the Intellij Community edition source code to find the code which goes with the File | Synchronize but had no success there either. 

Any help would be great.

4 comments
Comment actions Permalink

I use this code:

 

VirtualFileManager.getInstance().syncRefresh()
0
Comment actions Permalink

Ah excellent, this works. Thanks a lot, could I ask how you came to know about this for future? Is it through experience or looking through API or something else?

0
Comment actions Permalink

Yes, you start to get into the API approach. Plus looking at the intellij-community source helps because you get to see how the API was intended to be used. I think that source is the best source of API examples.

0
Comment actions Permalink

Probably, same effect can be achieved in a better way (by performing refresh asynchronously and refreshing only necessary part of file system).
Ex: by using `LocalFileSystem.getInstance().refreshFiles(...)`
(Or `com.intellij.openapi.vfs.VfsUtil#markDirtyAndRefresh`, if files on disk were modified by external tool).

See https://www.jetbrains.org/intellij/sdk/docs/basics/virtual_file_system.html


0

Please sign in to leave a comment.