My plugin has a VirtualFileManager.VFS_CHANGES listener that performs various post-processing tasks when source files change in certain ways. It has some specific behavior when source files are deleted.
One of my users logged a bug where using the IDE’s file copy/paste-for-overwrite functionality is triggering that delete logic incorrectly given that it’s effectively a contents change event. This is because CopyFilesOrDirectoriesHandler.handleExistingFiles() actually deletes the existing file before copying the new file:
ThrowableRunnable<RuntimeException> doCopy = () -> {
if (progressIndicator != null) {
progressIndicator.setText2(InspectionsBundle.message("processing.progress.text", existing.getName()));
}
existing.delete();
((PsiDirectoryImpl)targetDirectory).executeWithUpdatingAddedFilesDisabled(() -> ContainerUtil.addIfNotNull(added, tDirectory.copyFileFrom(name, replacement)));
};
Is there a good way to detect that a VFS delete is occurring in this context so that it can be safely ignored or handled differently? I already have event filtering for things like VirtualFileEvent.isFromRefresh() and UndoManager.isUndoInProgress(). I’m hoping that there’s something similar for this specific instance of virtual file removal.