Provide a way to track the external changes and make that an undo action

 
I am developing a custom language plugin, which also provides rename feature.
To rename, plugin starts a new process and the newly created process changes files in project externally.
But Intellij doesn't recognize the changes which are made externally,
So, to update documents in intellij, I used the following code
ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run
() {
        CommandProcessor.getInstance().executeCommand(project, new Runnable() {
            @Override
            public void run
() {
                  VirtualFileManager.getInstance().syncRefresh();
            
}
        }, name, name);
    
}
});


The above code refreshes all the documents but doesn't provide undo.
So, Is there any other way to track the external changes and make that an undo action ?

4 comments
Comment actions Permalink

Why exactly do you need to perform rename through an external process? Once you have Find Usages working, adding Rename to that requires very little additional code in your plugin. Also, using the standard IntelliJ IDEA rename logic allows you to provide features such as updating non-code usages with preview which are much more difficult to implement when you perform this through an external process.

0
Comment actions Permalink

The Intellij plugin is just to support the external process and the code for rename is already there in external proceess.

0
Comment actions Permalink

As I said, this will not provide the optimum user experience for the users of your plugin. But that's your decision, of course.

As far as I understand there is no easy way to undo external changes. One fairly simple option need to store the changes performed by the external process in separate files, and then update the content of the real files being refactored from the plugin code. Another possibility is to use local history, to put a label on the project before you invoke the refactoring, and then to push a custom UndoableAction that would revert to that label on the undo stack.

0
Comment actions Permalink

I was trying to use the local history by putting the label

LocalHistory.getInstance().putUserLabel(project, "LABEL");
 

But I am stuck how to revert back to the label?

Can you give some directions on how to do that?

0

Please sign in to leave a comment.