Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronize virtual file to the physical file in the Intellij IDEA plugin

I'm implementing the plugin for Intellij IDEA that needs file to be saved before executing action. Action is shell command, it requires file name to be passed as the command-line parameter.

AFAIK Idea saves (synchronizes) files on frame deactivation, so if I right-click on the file, and click on my action - old version of file will be used. If I go to other window, return to Idea and click my action - current version of the file will be used.

I've read this doc about Virtual File System, and found that I can trigger file to be loaded from file system (e.g. VirtualFileManager.syncRefresh() or VirtualFileManager.asyncRefresh()). I tried this hoping it would work, but it doesn't.

Question is: how to manually (programmatically) save file?

like image 417
Dany Avatar asked Dec 08 '13 23:12

Dany


People also ask

What is VFS IntelliJ?

The Virtual File System (VFS) is a component of the IntelliJ Platform that encapsulates most of its activity for working with files represented as Virtual File.

How do I refresh my IntelliJ workspace?

As we saw earlier, when we do make changes to a build file, we can reload those changes by using ⇧⌘I (macOS), or Ctrl+Shift+O (Windows/Linux). Sometimes we want to force a reload of the whole project, so that IntelliJ IDEA uses the Gradle settings to set up and build the project.


1 Answers

While formatting my question I checked one more time, and this worked for me.

FileDocumentManager.getInstance().saveAllDocuments();

EDIT
Finally came up with the solution

FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getDocument(file);
if (document != null) {
    fileDocumentManager.saveDocument(document);
}
like image 132
Dany Avatar answered Oct 19 '22 23:10

Dany