fix load ext *.tsv doc exception when close project

This commit is contained in:
林万程
2023-12-12 18:39:19 +08:00
parent bced7c4805
commit 7129f0031c
2 changed files with 10 additions and 3 deletions

View File

@@ -128,7 +128,9 @@ public class ConfCache {
if (files.isEmpty()) {
return;
}
ProjectView.getInstance(project).refresh();
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
LOG.info("Ext doc conf load all complete {} files\n{}", files.size(), sb);
});
}
@@ -136,7 +138,7 @@ public class ConfCache {
static void loadFile(@NotNull VirtualFile file, @Nullable Project project) {
ApplicationManager.getApplication().invokeLater(() -> {
ConfCache.load(file);
if (project != null) {
if (project != null && !project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
});

View File

@@ -2,6 +2,7 @@ package io.github.linwancen.plugin.show.ext.conf;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -17,13 +18,17 @@ public class ConfFileChangeListener implements FileEditorManagerListener {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
@NotNull Project project = event.getManager().getProject();
if (project.isDisposed()) {
return;
}
@Nullable VirtualFile file = event.getOldFile();
if (file == null) {
return;
}
if (file.exists()) {
try {
ConfCache.loadFile(file, event.getManager().getProject());
ConfCache.loadFile(file, project);
} catch (Throwable e) {
LOG.info("ConfFileChangeListener catch Throwable but log to record.", e);
}