javaintellij-ideaintellij-pluginintellij-14

Programmatically refresh/synchronize an IntelliJ IDEA project via a plugin


Is there a way to programmatically refresh/synchronize an IntelliJ IDEA project via a plugin?

I'm working on an IntelliJ IDEA plugin that creates a file within the active project. And I want to refresh/synchronize the project automatically via the plugin so that the user can see the changes immediately. Is this possible in IntelliJ IDEA?


Solution

  • After digging a bit more I came through the following solution and it worked.

    public void actionPerformed(AnActionEvent e) {
    
        // Create/Modify files
    
        // Get the project from the ActionEvent
        Project project = e.getData(PlatformDataKeys.PROJECT);
    
        // Get the Base Dir and refresh with the following parameters
        // 'asynchronous' set to false and 'recursive' set to true
        project.getBaseDir().refresh(false,true);
    
    }