fix: TreeUI should be accessed only from EDT fixed #89

This commit is contained in:
林万程
2025-11-30 14:50:15 +08:00
parent 5c33174791
commit caa9f17454
8 changed files with 13 additions and 25 deletions

View File

@@ -29,7 +29,7 @@ public class ReloadExtDocAction extends CopyReferenceAction {
if (project == null) { if (project == null) {
return; return;
} }
FileLoader.EPN.getExtensionList().forEach(fileLoader -> fileLoader.loadAll(project)); FileLoader.loadAll(project);
} catch (Throwable t) { } catch (Throwable t) {
LOG.info("ReloadExtDocAction catch Throwable but log to record.", t); LOG.info("ReloadExtDocAction catch Throwable but log to record.", t);
} }

View File

@@ -3,8 +3,8 @@ package io.github.linwancen.plugin.show.ext.action;
import com.intellij.ide.actions.CopyReferenceAction; import com.intellij.ide.actions.CopyReferenceAction;
import com.intellij.ide.projectView.ProjectView; import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.util.concurrency.EdtExecutorService;
import io.github.linwancen.plugin.show.ext.listener.FileLoader; import io.github.linwancen.plugin.show.ext.listener.FileLoader;
import io.github.linwancen.plugin.show.settings.ShowBundle; import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -33,8 +33,7 @@ public class ResetExtDocAction extends CopyReferenceAction {
if (project == null) { if (project == null) {
return; return;
} }
ApplicationManager.getApplication().invokeLater(() -> EdtExecutorService.getInstance().execute(() -> ProjectView.getInstance(project).refresh());
ProjectView.getInstance(project).refresh());
} catch (Throwable t) { } catch (Throwable t) {
LOG.info("ConfFileChangeListener catch Throwable but log to record.", t); LOG.info("ConfFileChangeListener catch Throwable but log to record.", t);
} }

View File

@@ -1,6 +1,5 @@
package io.github.linwancen.plugin.show.ext.conf; package io.github.linwancen.plugin.show.ext.conf;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FilenameIndex; import com.intellij.psi.search.FilenameIndex;
@@ -149,9 +148,6 @@ public class ConfCache extends FileLoader {
if (files.isEmpty()) { if (files.isEmpty()) {
return; return;
} }
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
LOG.info("Ext doc conf load all complete {} files\n{}", files.size(), sb); LOG.info("Ext doc conf load all complete {} files\n{}", files.size(), sb);
} }

View File

@@ -25,7 +25,7 @@ public class FileLoadInitListener implements DumbService.DumbModeListener, Proje
@NotNull Project[] projects = ProjectManager.getInstance().getOpenProjects(); @NotNull Project[] projects = ProjectManager.getInstance().getOpenProjects();
for (@NotNull Project project : projects) { for (@NotNull Project project : projects) {
PROJECT_LOAD_MAP.computeIfAbsent(project, k -> { PROJECT_LOAD_MAP.computeIfAbsent(project, k -> {
FileLoader.EPN.getExtensionList().forEach(fileLoader -> fileLoader.loadAll(project)); FileLoader.loadAll(project);
return true; return true;
}); });
} }

View File

@@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor; import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.intellij.util.concurrency.EdtExecutorService;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -67,10 +68,14 @@ public abstract class FileLoader {
*/ */
protected abstract void loadFileImpl(@NotNull VirtualFile file, @Nullable Project project); protected abstract void loadFileImpl(@NotNull VirtualFile file, @Nullable Project project);
public void loadAll(@NotNull Project project) { public static void loadAll(@NotNull Project project) {
ApplicationManager.getApplication().executeOnPooledThread(() -> ApplicationManager.getApplication().executeOnPooledThread(() ->
DumbService.getInstance(project).runReadActionInSmartMode(() DumbService.getInstance(project).runReadActionInSmartMode(() -> {
-> loadAllImpl(project))); if (!project.isDisposed()) {
FileLoader.EPN.getExtensionList().forEach(fileLoader -> fileLoader.loadAllImpl(project));
EdtExecutorService.getInstance().execute(() -> ProjectView.getInstance(project).refresh());
}
}));
} }
public void visitChildrenRecursively(@NotNull Project project, @NotNull VirtualFile dir, @NotNull StringBuilder sb) { public void visitChildrenRecursively(@NotNull Project project, @NotNull VirtualFile dir, @NotNull StringBuilder sb) {
@@ -94,7 +99,7 @@ public abstract class FileLoader {
ApplicationManager.getApplication().runReadAction(() -> { ApplicationManager.getApplication().runReadAction(() -> {
loadFileImpl(file, project); loadFileImpl(file, project);
if (project != null && !project.isDisposed()) { if (project != null && !project.isDisposed()) {
ProjectView.getInstance(project).refresh(); EdtExecutorService.getInstance().execute(() -> ProjectView.getInstance(project).refresh());
} }
})); }));
} }

View File

@@ -4,7 +4,6 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
@@ -36,9 +35,6 @@ public class OllamaModelsCache extends FileLoader {
} }
@NotNull StringBuilder sb = new StringBuilder(); @NotNull StringBuilder sb = new StringBuilder();
visitChildrenRecursively(project, dir, sb); visitChildrenRecursively(project, dir, sb);
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
LOG.info("ollama manifests load all complete files\n{}", sb); LOG.info("ollama manifests load all complete files\n{}", sb);
} }

View File

@@ -1,6 +1,5 @@
package io.github.linwancen.plugin.show.ext.sql; package io.github.linwancen.plugin.show.ext.sql;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FilenameIndex; import com.intellij.psi.search.FilenameIndex;
@@ -66,9 +65,6 @@ public class SqlCache extends FileLoader {
if (files.isEmpty()) { if (files.isEmpty()) {
return; return;
} }
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
LOG.info("SQL doc load all complete {} files\n{}", files.size(), sb); LOG.info("SQL doc load all complete {} files\n{}", files.size(), sb);
} }

View File

@@ -1,6 +1,5 @@
package io.github.linwancen.plugin.show.lang.vue; package io.github.linwancen.plugin.show.lang.vue;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.lang.ecmascript6.psi.ES6ImportCall; import com.intellij.lang.ecmascript6.psi.ES6ImportCall;
import com.intellij.lang.ecmascript6.psi.ES6ImportedBinding; import com.intellij.lang.ecmascript6.psi.ES6ImportedBinding;
import com.intellij.lang.javascript.psi.JSArrayLiteralExpression; import com.intellij.lang.javascript.psi.JSArrayLiteralExpression;
@@ -62,9 +61,6 @@ public class VueRouterCache extends FileLoader {
if (files.isEmpty()) { if (files.isEmpty()) {
return; return;
} }
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
LOG.info("Vue Router load all complete {} files\n{}", files.size(), sb); LOG.info("Vue Router load all complete {} files\n{}", files.size(), sb);
} }