feat(cache): 2.13 Cache to Support 2023.3 | 注释缓存以支持新版 fix Slow ... EDT
This commit is contained in:
@@ -112,6 +112,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.13 ★ Cache for 2023.3
|
||||
<li>2.12 Add project-view-tree support Markdown and Asciidoc
|
||||
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
|
||||
<li>2.10 Add line-end-comment not doc comment
|
||||
@@ -153,6 +154,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.13 ★ 缓存用于支持 2023.3
|
||||
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
|
||||
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
|
||||
<li>2.10 增加 行末注释 非文档注释
|
||||
|
||||
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'io.github.linwancen'
|
||||
version '2.12.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
version '2.13.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -87,6 +87,7 @@ patchPluginXml {
|
||||
changeNotes = """
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.13 ★ Cache for 2023.3
|
||||
<li>2.12 Add project-view-tree support Markdown and Asciidoc
|
||||
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
|
||||
<li>2.10 Add line-end-comment not doc comment
|
||||
@@ -128,6 +129,7 @@ patchPluginXml {
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.13 ★ 缓存用于支持 2023.3
|
||||
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
|
||||
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
|
||||
<li>2.10 增加 行末注释 非文档注释
|
||||
|
||||
@@ -2,15 +2,19 @@ package io.github.linwancen.plugin.show;
|
||||
|
||||
import com.intellij.json.JsonFileType;
|
||||
import com.intellij.json.json5.Json5FileType;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorLinePainter;
|
||||
import com.intellij.openapi.editor.LineExtensionInfo;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import io.github.linwancen.plugin.show.bean.FileInfo;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.cache.LineEndCacheUtils;
|
||||
import io.github.linwancen.plugin.show.ext.LineExt;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
@@ -22,7 +26,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LineEnd extends EditorLinePainter {
|
||||
@@ -41,8 +44,8 @@ public class LineEnd extends EditorLinePainter {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static List<LineExtensionInfo> getLineExtensionInfos(@NotNull Project project,
|
||||
@NotNull VirtualFile file, int lineNumber) {
|
||||
private static Collection<LineExtensionInfo> getLineExtensionInfos(@NotNull Project project,
|
||||
@NotNull VirtualFile file, int lineNumber) {
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
if (!settings.showLineEndComment) {
|
||||
return null;
|
||||
@@ -63,23 +66,32 @@ public class LineEnd extends EditorLinePainter {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (DumbService.isDumb(project)) {
|
||||
return null;
|
||||
}
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
@Nullable LineInfo info = LineInfo.of(file, project, lineNumber);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
if (settings.lineEndCache) {
|
||||
return LineEndCacheUtils.get(info);
|
||||
} else {
|
||||
@Nullable LineExtensionInfo lineExt = lineExt(info);
|
||||
if (lineExt == null) {
|
||||
return null;
|
||||
}
|
||||
return Collections.singleton(lineExt);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static LineExtensionInfo lineExt(@NotNull LineInfo info) {
|
||||
@Nullable String doc = lineDocSkipHave(info);
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
@NotNull TextAttributes textAttr = file.getFileType().equals(JsonFileType.INSTANCE)
|
||||
|| file.getFileType().equals(Json5FileType.INSTANCE)
|
||||
? settings.lineEndJsonTextAttr
|
||||
: settings.lineEndTextAttr;
|
||||
@NotNull LineExtensionInfo lineExt = new LineExtensionInfo(settings.lineEndPrefix + doc, textAttr);
|
||||
return Collections.singletonList(lineExt);
|
||||
@NotNull TextAttributes textAttr = info.file.getFileType().equals(JsonFileType.INSTANCE)
|
||||
|| info.file.getFileType().equals(Json5FileType.INSTANCE)
|
||||
? info.appSettings.lineEndJsonTextAttr
|
||||
: info.appSettings.lineEndTextAttr;
|
||||
return new LineExtensionInfo(info.appSettings.lineEndPrefix + doc, textAttr);
|
||||
}
|
||||
|
||||
public static void textWithDoc(@NotNull FileInfo fileInfo, int startLine, int endLine,
|
||||
@@ -110,8 +122,11 @@ public class LineEnd extends EditorLinePainter {
|
||||
func.accept(sb.toString());
|
||||
}
|
||||
|
||||
private static @Nullable String lineDocSkipHave(@Nullable LineInfo info) {
|
||||
@Nullable String doc = lineDoc(info);
|
||||
private static @Nullable String lineDocSkipHave(@NotNull LineInfo info) {
|
||||
@Nullable String doc = LineExt.doc(info);
|
||||
if (doc == null) {
|
||||
doc = BaseLangDoc.langDoc(info);
|
||||
}
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -121,16 +136,4 @@ public class LineEnd extends EditorLinePainter {
|
||||
}
|
||||
return trimDoc;
|
||||
}
|
||||
|
||||
private static @Nullable String lineDoc(@Nullable LineInfo info) {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
// override some text
|
||||
@Nullable String doc = LineExt.doc(info);
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
return BaseLangDoc.langDoc(info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public class LineEndAdd extends DumbAwareAction {
|
||||
new Task.Backgroundable(project, "Show LineEndAdd " + list.size() + " " + list.get(0)) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
indicator.setIndeterminate(false);
|
||||
WriteCommandAction.runWriteCommandAction(project, () -> {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
VirtualFile file = list.get(i);
|
||||
|
||||
@@ -52,6 +52,7 @@ public class LineEndCopy extends DumbAwareAction {
|
||||
new Task.Backgroundable(project, "Show LineEndCopy " + info.file.getName()) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
indicator.setIndeterminate(false);
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
int startLine = 0;
|
||||
int endLine = info.document.getLineCount() - 1;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.ide.projectView.ProjectViewNodeDecorator;
|
||||
import com.intellij.ide.util.treeView.PresentableNodeDescriptor.ColoredFragment;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.packageDependencies.ui.PackageDependenciesNode;
|
||||
@@ -13,6 +14,7 @@ import com.intellij.ui.ColoredTreeCellRenderer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import io.github.linwancen.plugin.show.bean.FuncEnum;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.cache.TreeCacheUtils;
|
||||
import io.github.linwancen.plugin.show.ext.TreeExt;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
@@ -33,20 +35,30 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
public void decorate(@NotNull ProjectViewNode node, @NotNull PresentationData data) {
|
||||
try {
|
||||
decorateImpl(node, data);
|
||||
} catch (ProcessCanceledException ignore) {
|
||||
// ignore
|
||||
} catch (Throwable e) {
|
||||
LOG.info("Tree catch Throwable but log to record.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void decorateImpl(@NotNull ProjectViewNode<?> node, @NotNull PresentationData data) {
|
||||
if (!AppSettingsState.getInstance().showTreeComment) {
|
||||
@NotNull AppSettingsState state = AppSettingsState.getInstance();
|
||||
if (!state.showTreeComment) {
|
||||
return;
|
||||
}
|
||||
@Nullable Project project = node.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
if (DumbService.isDumb(project)) {
|
||||
@Nullable String extDoc = TreeExt.doc(node);
|
||||
if (extDoc != null) {
|
||||
addText(data, extDoc);
|
||||
return;
|
||||
}
|
||||
if (state.treeCache) {
|
||||
@Nullable String doc = TreeCacheUtils.treeDoc(node, project);
|
||||
addText(data, doc);
|
||||
return;
|
||||
}
|
||||
DumbService.getInstance(project).runReadActionInSmartMode(() ->
|
||||
@@ -68,11 +80,7 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String treeDoc(@NotNull ProjectViewNode<?> node, @NotNull Project project) {
|
||||
@Nullable String doc = TreeExt.doc(node);
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
public static String treeDoc(@NotNull ProjectViewNode<?> node, @NotNull Project project) {
|
||||
@NotNull SettingsInfo info = SettingsInfo.of(project, FuncEnum.TREE);
|
||||
@Nullable String relFileDoc = RelFileDoc.relFileDoc(node, info);
|
||||
if (relFileDoc != null) {
|
||||
|
||||
59
src/main/java/io/github/linwancen/plugin/show/cache/CacheUpdateEditorListener.java
vendored
Normal file
59
src/main/java/io/github/linwancen/plugin/show/cache/CacheUpdateEditorListener.java
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
package io.github.linwancen.plugin.show.cache;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
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;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* call ConfCache.loadFile
|
||||
*/
|
||||
public class CacheUpdateEditorListener implements FileEditorManagerListener {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CacheUpdateEditorListener.class);
|
||||
|
||||
@Override
|
||||
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
|
||||
@NotNull Project project = event.getManager().getProject();
|
||||
@Nullable VirtualFile file = event.getNewFile();
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
ApplicationManager.getApplication().executeOnPooledThread(() -> {
|
||||
if (project.isDisposed()) {
|
||||
LineEndCacheUtils.cache.remove(project);
|
||||
return;
|
||||
}
|
||||
@Nullable Map<VirtualFile, Map<Integer, LineEndCache>> fileMap = LineEndCacheUtils.cache.get(project);
|
||||
if (fileMap == null) {
|
||||
return;
|
||||
}
|
||||
@Nullable Map<Integer, LineEndCache> lineMap = fileMap.get(file);
|
||||
if (lineMap == null) {
|
||||
return;
|
||||
}
|
||||
lineMap.forEach((integer, lineEndCache) -> lineEndCache.selectChanged = true);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
|
||||
@NotNull Project project = source.getProject();
|
||||
ApplicationManager.getApplication().executeOnPooledThread(() -> {
|
||||
if (project.isDisposed()) {
|
||||
LineEndCacheUtils.cache.remove(project);
|
||||
return;
|
||||
}
|
||||
Map<VirtualFile, Map<Integer, LineEndCache>> fileMap = LineEndCacheUtils.cache.get(project);
|
||||
fileMap.remove(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
22
src/main/java/io/github/linwancen/plugin/show/cache/CacheUpdateProjectListener.java
vendored
Normal file
22
src/main/java/io/github/linwancen/plugin/show/cache/CacheUpdateProjectListener.java
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
package io.github.linwancen.plugin.show.cache;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManagerListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CacheUpdateProjectListener implements ProjectManagerListener {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CacheUpdateProjectListener.class);
|
||||
|
||||
@Override
|
||||
public void projectClosed(@NotNull Project project) {
|
||||
try {
|
||||
LineEndCacheUtils.cache.remove(project);
|
||||
TreeCacheUtils.cache.remove(project);
|
||||
} catch (Throwable e) {
|
||||
LOG.info("CacheUpdateProjectListener catch Throwable but log to record.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/main/java/io/github/linwancen/plugin/show/cache/LineEndCache.java
vendored
Normal file
27
src/main/java/io/github/linwancen/plugin/show/cache/LineEndCache.java
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
package io.github.linwancen.plugin.show.cache;
|
||||
|
||||
import com.intellij.openapi.editor.LineExtensionInfo;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LineEndCache {
|
||||
@NotNull public String code;
|
||||
@NotNull public List<LineExtensionInfo> lineExtList;
|
||||
public boolean selectChanged = false;
|
||||
/** null if updated */
|
||||
@Nullable public volatile LineInfo info;
|
||||
|
||||
public LineEndCache(@NotNull String code, @NotNull List<LineExtensionInfo> right, @NotNull LineInfo info) {
|
||||
this.code = code;
|
||||
this.lineExtList = right;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void updated() {
|
||||
selectChanged = false;
|
||||
info = null;
|
||||
}
|
||||
}
|
||||
97
src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
vendored
Normal file
97
src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
package io.github.linwancen.plugin.show.cache;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.LineExtensionInfo;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.concurrency.AppExecutorUtil;
|
||||
import io.github.linwancen.plugin.show.LineEnd;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class LineEndCacheUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LineEndCacheUtils.class);
|
||||
|
||||
public static final Map<Project, Map<VirtualFile, Map<Integer, LineEndCache>>> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public static @Nullable Collection<LineExtensionInfo> get(@NotNull LineInfo info) {
|
||||
try {
|
||||
@NotNull LineEndCache lineCache = cache
|
||||
.computeIfAbsent(info.project, a -> new ConcurrentHashMap<>())
|
||||
.computeIfAbsent(info.file, a -> new ConcurrentHashMap<>())
|
||||
.computeIfAbsent(info.lineNumber, a -> new LineEndCache(info.text, new ArrayList<>(1), info));
|
||||
if (lineCache.selectChanged || !info.text.equals(lineCache.code)) {
|
||||
lineCache.lineExtList.clear();
|
||||
lineCache.info = info;
|
||||
}
|
||||
checkScheduleAndInit();
|
||||
return lineCache.lineExtList;
|
||||
} catch (Throwable e) {
|
||||
LOG.info("LineEndCache catch Throwable but log to record.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static volatile boolean isRun = false;
|
||||
|
||||
private static void checkScheduleAndInit() {
|
||||
if (!isRun) {
|
||||
synchronized (LineEndCacheUtils.class) {
|
||||
if (!isRun) {
|
||||
isRun = true;
|
||||
AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
ApplicationManager.getApplication().runReadAction(LineEndCacheUtils::cacheUpdate);
|
||||
} catch (Exception e) {
|
||||
LOG.info("LineEndCache checkScheduleAndInit catch Throwable but log to record.", e);
|
||||
}
|
||||
}, 0L, 1L, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void cacheUpdate() {
|
||||
cache.forEach((project, fileMap) -> {
|
||||
try {
|
||||
if (project.isDisposed()) {
|
||||
cache.remove(project);
|
||||
return;
|
||||
}
|
||||
if (DumbService.isDumb(project)) {
|
||||
return;
|
||||
}
|
||||
fileMap.forEach((file, lineMap) ->
|
||||
lineMap.forEach((lineNumber, lineEndCache) -> {
|
||||
try {
|
||||
@Nullable LineInfo info = lineEndCache.info;
|
||||
if (info == null) {
|
||||
return;
|
||||
}
|
||||
@Nullable LineExtensionInfo lineExt = LineEnd.lineExt(info);
|
||||
lineEndCache.updated();
|
||||
lineEndCache.code = info.text;
|
||||
if (lineExt == null) {
|
||||
return;
|
||||
}
|
||||
lineEndCache.lineExtList.add(lineExt);
|
||||
} catch (Exception e) {
|
||||
LOG.info("LineEndCache lineMap.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
}));
|
||||
} catch (Exception e) {
|
||||
LOG.info("LineEndCache cache.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
9
src/main/java/io/github/linwancen/plugin/show/cache/TreeCache.java
vendored
Normal file
9
src/main/java/io/github/linwancen/plugin/show/cache/TreeCache.java
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
package io.github.linwancen.plugin.show.cache;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TreeCache {
|
||||
@Nullable
|
||||
public String doc;
|
||||
public volatile boolean needUpdate = true;
|
||||
}
|
||||
85
src/main/java/io/github/linwancen/plugin/show/cache/TreeCacheUtils.java
vendored
Normal file
85
src/main/java/io/github/linwancen/plugin/show/cache/TreeCacheUtils.java
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
package io.github.linwancen.plugin.show.cache;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.concurrency.AppExecutorUtil;
|
||||
import io.github.linwancen.plugin.show.Tree;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TreeCacheUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TreeCacheUtils.class);
|
||||
|
||||
public static final Map<Project, Map<ProjectViewNode<?>, TreeCache>> cache = new ConcurrentHashMap<>();
|
||||
|
||||
@Nullable
|
||||
public static String treeDoc(@NotNull ProjectViewNode<?> node, @NotNull Project project) {
|
||||
try {
|
||||
@NotNull TreeCache treeCache = cache
|
||||
.computeIfAbsent(project, a -> new ConcurrentHashMap<>())
|
||||
.computeIfAbsent(node, a -> new TreeCache());
|
||||
treeCache.needUpdate = true;
|
||||
checkScheduleAndInit();
|
||||
return treeCache.doc;
|
||||
} catch (Throwable e) {
|
||||
LOG.info("LineEndCache catch Throwable but log to record.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static volatile boolean isRun = false;
|
||||
|
||||
private static void checkScheduleAndInit() {
|
||||
if (!isRun) {
|
||||
synchronized (TreeCacheUtils.class) {
|
||||
if (!isRun) {
|
||||
isRun = true;
|
||||
AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
ApplicationManager.getApplication().runReadAction(TreeCacheUtils::cacheUpdate);
|
||||
} catch (Exception e) {
|
||||
LOG.info("TreeCacheUtils checkScheduleAndInit catch Throwable but log to record.", e);
|
||||
}
|
||||
}, 0L, 1L, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void cacheUpdate() {
|
||||
cache.forEach((project, nodeCache) -> {
|
||||
try {
|
||||
if (project.isDisposed()) {
|
||||
cache.remove(project);
|
||||
return;
|
||||
}
|
||||
if (DumbService.isDumb(project)) {
|
||||
return;
|
||||
}
|
||||
nodeCache.forEach((node, treeCache) -> {
|
||||
try {
|
||||
if (treeCache.needUpdate) {
|
||||
treeCache.needUpdate = false;
|
||||
treeCache.doc = Tree.treeDoc(node, project);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.info("TreeCacheUtils nodeCache.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LOG.info("TreeCacheUtils cache.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.search.FilenameIndex;
|
||||
@@ -13,7 +12,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -123,14 +126,16 @@ public class ConfCache {
|
||||
new Task.Backgroundable(project, "Show Load xxx.tree/key/doc/json.tsv") {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
indicator.setIndeterminate(false);
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
@NotNull Collection<VirtualFile> files = FilenameIndex.getAllFilesByExt(project, TsvLoader.EXT);
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
int i = 0;
|
||||
double i = 0;
|
||||
for (@NotNull VirtualFile file : files) {
|
||||
indicator.setText(file.getName());
|
||||
load(file);
|
||||
indicator.setFraction((double) ++i /files.size());
|
||||
i++;
|
||||
indicator.setFraction(i / files.size());
|
||||
sb.append(file.getName()).append("\n");
|
||||
}
|
||||
if (files.isEmpty()) {
|
||||
|
||||
@@ -17,20 +17,22 @@ public class AppSettingsComponent {
|
||||
private final JPanel myMainPanel;
|
||||
private final JBCheckBox showTreeComment = new JBCheckBox(ShowBundle.message("show.tree.comment"));
|
||||
private final JBCheckBox compact = new JBCheckBox(ShowBundle.message("compact"));
|
||||
private final JBCheckBox treeCache = new JBCheckBox(ShowBundle.message("tree.cache"));
|
||||
private final JBTextField treeTags = new JBTextField();
|
||||
private final JBCheckBox showLineEndComment = new JBCheckBox(ShowBundle.message("show.line.end.comment"));
|
||||
private final JBCheckBox showLineEndCommentJava = new JBCheckBox("Java ");
|
||||
private final JBCheckBox lineEndCache = new JBCheckBox(ShowBundle.message("line.end.cache"));
|
||||
private final JBCheckBox showLineEndCommentJava = new JBCheckBox(" Java ");
|
||||
private final JBCheckBox showLineEndCommentJavaBase = new JBCheckBox("// Java ");
|
||||
private final JBCheckBox showLineEndCommentKotlin = new JBCheckBox("Kotlin ");
|
||||
private final JBCheckBox showLineEndCommentKotlin = new JBCheckBox(" Kotlin ");
|
||||
private final JBCheckBox showLineEndCommentKotlinBase = new JBCheckBox("// Kotlin ");
|
||||
private final JBCheckBox showLineEndCommentJs = new JBCheckBox("js ");
|
||||
private final JBCheckBox showLineEndCommentJs = new JBCheckBox(" js ");
|
||||
private final JBCheckBox showLineEndCommentJsBase = new JBCheckBox("// js ");
|
||||
private final JBCheckBox showLineEndCommentPy = new JBCheckBox("Python ");
|
||||
private final JBCheckBox showLineEndCommentPy = new JBCheckBox(" Python ");
|
||||
private final JBCheckBox showLineEndCommentPyBase = new JBCheckBox("# Python ");
|
||||
private final JBCheckBox showLineEndCommentGo = new JBCheckBox("Go ");
|
||||
private final JBCheckBox showLineEndCommentGo = new JBCheckBox(" Go ");
|
||||
private final JBCheckBox showLineEndCommentGoBase = new JBCheckBox("// Go ");
|
||||
private final JBCheckBox showLineEndCommentSql = new JBCheckBox("sql ");
|
||||
private final JBCheckBox showLineEndCommentJson = new JBCheckBox("json ");
|
||||
private final JBCheckBox showLineEndCommentSql = new JBCheckBox(" sql ");
|
||||
private final JBCheckBox showLineEndCommentJson = new JBCheckBox(" json ");
|
||||
private final JBTextField lineTags = new JBTextField();
|
||||
private final JBCheckBox getToSet = new JBCheckBox("get --> set ");
|
||||
private final JBCheckBox fromNew = new JBCheckBox("java new ");
|
||||
@@ -56,17 +58,18 @@ public class AppSettingsComponent {
|
||||
@NotNull
|
||||
private JPanel showPanel() {
|
||||
JPanel comment = FormBuilder.createFormBuilder()
|
||||
.addComponent(JPanelFactory.of(showTreeComment, compact), 1)
|
||||
.addComponent(JPanelFactory.of(showLineEndComment,
|
||||
.addComponent(JPanelFactory.of(showTreeComment, treeCache, compact), 1)
|
||||
.addComponent(JPanelFactory.of(showLineEndComment, lineEndCache), 1)
|
||||
.addComponent(JPanelFactory.of(
|
||||
showLineEndCommentJava,
|
||||
showLineEndCommentKotlin,
|
||||
showLineEndCommentJs,
|
||||
showLineEndCommentPy,
|
||||
showLineEndCommentGo
|
||||
showLineEndCommentGo,
|
||||
showLineEndCommentSql,
|
||||
showLineEndCommentJson
|
||||
), 1)
|
||||
.addComponent(JPanelFactory.of(
|
||||
showLineEndCommentSql,
|
||||
showLineEndCommentJson,
|
||||
showLineEndCommentJavaBase,
|
||||
showLineEndCommentKotlinBase,
|
||||
showLineEndCommentJsBase,
|
||||
@@ -120,6 +123,14 @@ public class AppSettingsComponent {
|
||||
compact.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getTreeCache() {
|
||||
return treeCache.isSelected();
|
||||
}
|
||||
|
||||
public void setTreeCache(boolean newStatus) {
|
||||
treeCache.setSelected(newStatus);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTreeTags() {
|
||||
return treeTags.getText();
|
||||
@@ -138,6 +149,14 @@ public class AppSettingsComponent {
|
||||
showLineEndComment.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getLineEndCache() {
|
||||
return lineEndCache.isSelected();
|
||||
}
|
||||
|
||||
public void setLineEndCache(boolean newStatus) {
|
||||
lineEndCache.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getShowLineEndCommentJava() {
|
||||
return showLineEndCommentJava.isSelected();
|
||||
}
|
||||
|
||||
@@ -37,8 +37,10 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
|
||||
modified |= mySettingsComponent.getCompact() != settings.compact;
|
||||
modified |= mySettingsComponent.getTreeCache() != settings.treeCache;
|
||||
|
||||
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
|
||||
modified |= mySettingsComponent.getLineEndCache() != settings.lineEndCache;
|
||||
modified |= mySettingsComponent.getShowLineEndCommentJava() != settings.showLineEndCommentJava;
|
||||
modified |= mySettingsComponent.getShowLineEndCommentKotlin() != settings.showLineEndCommentKotlin;
|
||||
modified |= mySettingsComponent.getShowLineEndCommentJs() != settings.showLineEndCommentJs;
|
||||
@@ -73,8 +75,10 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
|
||||
settings.compact = mySettingsComponent.getCompact();
|
||||
settings.treeCache = mySettingsComponent.getTreeCache();
|
||||
|
||||
settings.showLineEndComment = mySettingsComponent.getShowLineEndComment();
|
||||
settings.lineEndCache = mySettingsComponent.getLineEndCache();
|
||||
settings.showLineEndCommentJava = mySettingsComponent.getShowLineEndCommentJava();
|
||||
settings.showLineEndCommentKotlin = mySettingsComponent.getShowLineEndCommentKotlin();
|
||||
settings.showLineEndCommentJs = mySettingsComponent.getShowLineEndCommentJs();
|
||||
@@ -112,8 +116,10 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
static void reset(@NotNull AppSettingsState settings, @NotNull AppSettingsComponent mySettingsComponent) {
|
||||
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
|
||||
mySettingsComponent.setCompact(settings.compact);
|
||||
mySettingsComponent.setTreeCache(settings.treeCache);
|
||||
|
||||
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
|
||||
mySettingsComponent.setLineEndCache(settings.lineEndCache);
|
||||
mySettingsComponent.setShowLineEndCommentJava(settings.showLineEndCommentJava);
|
||||
mySettingsComponent.setShowLineEndCommentKotlin(settings.showLineEndCommentKotlin);
|
||||
mySettingsComponent.setShowLineEndCommentJs(settings.showLineEndCommentJs);
|
||||
|
||||
@@ -25,8 +25,10 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
|
||||
|
||||
public boolean showTreeComment = true;
|
||||
public boolean compact = true;
|
||||
public boolean treeCache = true;
|
||||
|
||||
public boolean showLineEndComment = true;
|
||||
public boolean lineEndCache = true;
|
||||
public boolean showLineEndCommentJava = true;
|
||||
public boolean showLineEndCommentJavaBase = false;
|
||||
public boolean showLineEndCommentKotlin = true;
|
||||
|
||||
@@ -123,11 +123,15 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
topic="com.intellij.openapi.vfs.newvfs.BulkFileListener"/>
|
||||
<listener class="io.github.linwancen.plugin.show.ext.conf.listener.ConfFileChangeListener"
|
||||
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
|
||||
<listener class="io.github.linwancen.plugin.show.cache.CacheUpdateEditorListener"
|
||||
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
|
||||
</applicationListeners>
|
||||
|
||||
<projectListeners>
|
||||
<listener class="io.github.linwancen.plugin.show.ext.conf.listener.ConfFileInitListener"
|
||||
topic="com.intellij.openapi.project.ProjectManagerListener"/>
|
||||
<listener class="io.github.linwancen.plugin.show.cache.CacheUpdateProjectListener"
|
||||
topic="com.intellij.openapi.project.ProjectManagerListener"/>
|
||||
</projectListeners>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
@@ -4,8 +4,10 @@ reset.default=Reset default
|
||||
show=Show
|
||||
show.tree.comment=Show tree comment
|
||||
compact=Support compact
|
||||
tree.cache=Tree Comment Cache
|
||||
|
||||
show.line.end.comment=Show line end comment
|
||||
line.end.cache=Line End Comment Cache for 2023.3 Slow EDT
|
||||
only.select.line=Only Select Line
|
||||
|
||||
skip.anno=skip @
|
||||
|
||||
@@ -4,8 +4,10 @@ reset.default=\u6062\u590D\u9ED8\u8BA4
|
||||
show=\u663E\u793A
|
||||
show.tree.comment=\u663E\u793A\u6587\u4EF6\u6811\u6CE8\u91CA
|
||||
compact=\u652F\u6301\u538B\u7F29\u7A7A\u7684\u4E2D\u95F4\u5305
|
||||
tree.cache=\u6587\u4EF6\u6811\u6CE8\u91CA\u7F13\u5B58
|
||||
|
||||
show.line.end.comment=\u663E\u793A\u884C\u672B\u6CE8\u91CA
|
||||
line.end.cache=\u884C\u672B\u6CE8\u91CA\u7F13\u5B58\u7528\u4E8E 2023.3 Slow EDT
|
||||
only.select.line=\u53EA\u663E\u793A\u9009\u62E9\u884C
|
||||
|
||||
line.tags=\u884C\u6CE8\u91CA @ \u6807\u7B7E | \u5206\u9694
|
||||
|
||||
Reference in New Issue
Block a user