Perform write action after compiling the project

I am getting the following exception when trying to perform write action(changing documents) in compile callback.

Write access is allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality state (not "any"). See TransactionGuard documentation for details.

public class CustomRenameHandler implements RenameHandler {
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
CompilerManager.getInstance(project).make((aborted, errors, warnings, compileContext) -> {
FileDocumentManager.getInstance().saveAllDocuments();
// perform write action
});
}
}

Any suggestions how to achieve this?

1 comment
Comment actions Permalink

Please check javadoc for com.intellij.openapi.application.TransactionGuard class. Is there any specific part of it that needs further clarification?

0

Please sign in to leave a comment.