From 49147b0e7bbfaaba07921f763e4c16f8d26f1920 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=97=E4=B8=87=E7=A8=8B?= <1498425439@qq.com>
Date: Wed, 29 Jan 2025 22:25:17 +0800
Subject: [PATCH] =?UTF-8?q?feat:=202.20=20support=20Vue=20src/router=20tre?=
=?UTF-8?q?e=20doc=20|=20=E6=94=AF=E6=8C=81=20Vue=20=E8=B7=AF=E7=94=B1?=
=?UTF-8?q?=E6=A0=87=E9=A2=98=E6=96=87=E4=BB=B6=E6=A0=91=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 +-
build.gradle | 4 +-
.../plugin/show/cache/LineEndCacheUtils.java | 1 +
.../{conf => }/action/ReloadExtDocAction.java | 6 +-
.../{conf => }/action/ResetExtDocAction.java | 6 +-
.../plugin/show/ext/action/package-info.java | 4 +
.../plugin/show/ext/conf/ConfCache.java | 82 +++---
.../ext/conf/SpiltKeyWordPatternFactory.java | 1 -
.../show/ext/conf/action/package-info.java | 4 -
.../show/ext/conf/listener/package-info.java | 4 -
.../FileLoadInitListener.java} | 11 +-
.../plugin/show/ext/listener/FileLoader.java | 71 ++++++
.../FileOptListener.java} | 30 +--
.../FileSelectChangeListener.java} | 11 +-
.../show/ext/listener/package-info.java | 4 +
.../plugin/show/lang/HtmlLangDoc.java | 29 ++-
.../plugin/show/lang/base/BaseLangDoc.java | 4 +-
.../plugin/show/lang/base/DocSkip.java | 4 +-
.../plugin/show/lang/vue/VueRouterCache.java | 237 ++++++++++++++++++
src/main/resources/META-INF/js.xml | 4 +
src/main/resources/META-INF/plugin.xml | 23 +-
.../messages/ShowCommentBundle.properties | 3 +
.../messages/ShowCommentBundle_zh.properties | 3 +
23 files changed, 444 insertions(+), 106 deletions(-)
rename src/main/java/io/github/linwancen/plugin/show/ext/{conf => }/action/ReloadExtDocAction.java (82%)
rename src/main/java/io/github/linwancen/plugin/show/ext/{conf => }/action/ResetExtDocAction.java (87%)
create mode 100644 src/main/java/io/github/linwancen/plugin/show/ext/action/package-info.java
delete mode 100644 src/main/java/io/github/linwancen/plugin/show/ext/conf/action/package-info.java
delete mode 100644 src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/package-info.java
rename src/main/java/io/github/linwancen/plugin/show/ext/{conf/listener/ConfFileInitListener.java => listener/FileLoadInitListener.java} (76%)
create mode 100644 src/main/java/io/github/linwancen/plugin/show/ext/listener/FileLoader.java
rename src/main/java/io/github/linwancen/plugin/show/ext/{conf/listener/ConfFileListener.java => listener/FileOptListener.java} (73%)
rename src/main/java/io/github/linwancen/plugin/show/ext/{conf/listener/ConfFileChangeListener.java => listener/FileSelectChangeListener.java} (71%)
create mode 100644 src/main/java/io/github/linwancen/plugin/show/ext/listener/package-info.java
create mode 100644 src/main/java/io/github/linwancen/plugin/show/lang/vue/VueRouterCache.java
diff --git a/README.md b/README.md
index df98952..502b05f 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ Show doc comment in the Project view Tree, line End, json, other
- Java, Kotlin, Groovy, Scala
- C/C++/OC, Python, Go, Rust, Ruby
-
- JS/TS, PHP, SQL
+
- HTML(Vue), JS/TS, PHP, SQL
- YAML/yml
@@ -125,6 +125,7 @@ Show doc comment in the Project view Tree, line End, json, other
English Change Notes:
+- 2.20 Add External Comment support Vue src/router tree doc
- 2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
- 2.18 Add line-end-comment support injected language like SQL
- 2.17 Add External Comment support *.key.regexp and MyBatis xml demo in Git
@@ -173,6 +174,7 @@ Show doc comment in the Project view Tree, line End, json, other
中文更新说明:
+- 2.20 增加 外部注释 支持 Vue 路由标题文件树注释
- 2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
- 2.18 增加 行末注释 支持注入语言如 SQL
- 2.17 增加 tsv 注释 支持 *.key.regexp 与 Mybatis xml 示例在 Git
diff --git a/build.gradle b/build.gradle
index ab5c97d..ccb4a10 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'io.github.linwancen'
-version '2.19.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
+version '2.20.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
repositories {
mavenCentral()
@@ -95,6 +95,7 @@ patchPluginXml {
changeNotes = """
English Change Notes:
+- 2.20 Add External Comment support Vue src/router tree doc
- 2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
- 2.18 Add line-end-comment support injected language like SQL
- 2.17 Add External Comment support *.key.regexp and MyBatis xml demo in Git
@@ -143,6 +144,7 @@ patchPluginXml {
中文更新说明:
+- 2.20 增加 外部注释 支持 Vue 路由标题文件树注释
- 2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
- 2.18 增加 行末注释 支持注入语言如 SQL
- 2.17 增加 tsv 注释 支持 *.key.regexp 与 Mybatis xml 示例在 Git
diff --git a/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java b/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
index 6b5e046..a9735f9 100644
--- a/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
+++ b/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
@@ -139,6 +139,7 @@ public class LineEndCacheUtils {
}
}).inSmartMode(project).executeSynchronously();
}));
+ } catch (ProcessCanceledException ignored) {
} catch (IllegalStateException ignore) {
// ignore inSmartMode(project) throw:
// @NotNull method com/intellij/openapi/project/impl/ProjectImpl.getEarlyDisposable must not return null
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/action/ReloadExtDocAction.java b/src/main/java/io/github/linwancen/plugin/show/ext/action/ReloadExtDocAction.java
similarity index 82%
rename from src/main/java/io/github/linwancen/plugin/show/ext/conf/action/ReloadExtDocAction.java
rename to src/main/java/io/github/linwancen/plugin/show/ext/action/ReloadExtDocAction.java
index 934a411..ed63a86 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/action/ReloadExtDocAction.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/action/ReloadExtDocAction.java
@@ -1,9 +1,9 @@
-package io.github.linwancen.plugin.show.ext.conf.action;
+package io.github.linwancen.plugin.show.ext.action;
import com.intellij.ide.actions.CopyReferenceAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
-import io.github.linwancen.plugin.show.ext.conf.ConfCache;
+import io.github.linwancen.plugin.show.ext.listener.FileLoader;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,7 +29,7 @@ public class ReloadExtDocAction extends CopyReferenceAction {
if (project == null) {
return;
}
- ConfCache.loadAll(project);
+ FileLoader.EPN.getExtensionList().forEach(fileLoader -> fileLoader.loadAll(project));
} catch (Throwable t) {
LOG.info("ReloadExtDocAction catch Throwable but log to record.", t);
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/action/ResetExtDocAction.java b/src/main/java/io/github/linwancen/plugin/show/ext/action/ResetExtDocAction.java
similarity index 87%
rename from src/main/java/io/github/linwancen/plugin/show/ext/conf/action/ResetExtDocAction.java
rename to src/main/java/io/github/linwancen/plugin/show/ext/action/ResetExtDocAction.java
index 82f56b7..c4d6528 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/action/ResetExtDocAction.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/action/ResetExtDocAction.java
@@ -1,11 +1,11 @@
-package io.github.linwancen.plugin.show.ext.conf.action;
+package io.github.linwancen.plugin.show.ext.action;
import com.intellij.ide.actions.CopyReferenceAction;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
-import io.github.linwancen.plugin.show.ext.conf.ConfCache;
+import io.github.linwancen.plugin.show.ext.listener.FileLoader;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -28,7 +28,7 @@ public class ResetExtDocAction extends CopyReferenceAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
try {
- ConfCache.clearAll();
+ FileLoader.EPN.getExtensionList().forEach(FileLoader::clearAll);
@Nullable Project project = e.getProject();
if (project == null) {
return;
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/action/package-info.java b/src/main/java/io/github/linwancen/plugin/show/ext/action/package-info.java
new file mode 100644
index 0000000..6895df1
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/action/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * call ConfCache clear and loadAll
+ */
+package io.github.linwancen.plugin.show.ext.action;
\ No newline at end of file
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java
index 62fb5d9..4e44251 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java
@@ -1,11 +1,10 @@
package io.github.linwancen.plugin.show.ext.conf;
import com.intellij.ide.projectView.ProjectView;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FilenameIndex;
+import io.github.linwancen.plugin.show.ext.listener.FileLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@@ -23,7 +22,7 @@ import java.util.regex.Pattern;
/**
* call ConfFactory, ConfCacheGetUtils
*/
-public class ConfCache {
+public class ConfCache extends FileLoader {
private static final Logger LOG = LoggerFactory.getLogger(ConfCache.class);
static final String KEY_MID_EXT = ".key";
@@ -74,7 +73,13 @@ public class ConfCache {
return ConfCacheGetUtils.filterPath(JSON_CACHE, path);
}
- public static void clearAll() {
+ @Override
+ public boolean skipExt(@Nullable String extension) {
+ return !TsvLoader.EXT.equals(extension) && !TsvLoader.REGEXP_EXT.equals(extension);
+ }
+
+ @Override
+ public void clearAll() {
EXT_IN_KEY_CACHE.clear();
KEY_CACHE.clear();
DOC_CACHE.clear();
@@ -82,11 +87,15 @@ public class ConfCache {
JSON_CACHE.clear();
}
- public static void remove(@NotNull VirtualFile file, @Nullable String name) {
+ @Override
+ public void remove(@NotNull VirtualFile file, @Nullable String name) {
if (name != null) {
int i = name.lastIndexOf('.');
+ @NotNull String ext = name.substring(i + 1);
+ if (skipExt(ext)) return;
name = name.substring(0, i);
} else {
+ if (skipExt(file.getExtension())) return;
name = file.getNameWithoutExtension();
}
if (name.endsWith(KEY_MID_EXT)) {
@@ -100,8 +109,9 @@ public class ConfCache {
}
}
- public static void copy(@NotNull VirtualFile file, @NotNull VirtualFile newFile) {
- @NotNull String name = file.getNameWithoutExtension();
+ @Override
+ public void copyImpl(@NotNull VirtualFile file, @NotNull VirtualFile newFile) {
+ @NotNull String name = newFile.getNameWithoutExtension();
if (name.endsWith(KEY_MID_EXT)) {
copyCache(file, newFile, KEY_CACHE);
} else if (name.endsWith(DOC_MID_EXT)) {
@@ -121,46 +131,32 @@ public class ConfCache {
}
}
- public static void loadAll(@NotNull Project project) {
- ApplicationManager.getApplication().executeOnPooledThread(() ->
- DumbService.getInstance(project).runReadActionInSmartMode(() ->
- ApplicationManager.getApplication().runReadAction(() -> {
- @NotNull Collection files = FilenameIndex.getAllFilesByExt(project,
- TsvLoader.EXT);
- @NotNull StringBuilder sb = new StringBuilder();
- for (@NotNull VirtualFile file : files) {
- load(file);
- sb.append(file.getName()).append("\n");
- }
- @NotNull Collection files2 = FilenameIndex.getAllFilesByExt(project,
- TsvLoader.REGEXP_EXT);
- for (@NotNull VirtualFile file : files2) {
- load(file);
- sb.append(file.getName()).append("\n");
- }
- if (files.isEmpty()) {
- return;
- }
- if (!project.isDisposed()) {
- ProjectView.getInstance(project).refresh();
- }
- LOG.info("Ext doc conf load all complete {} files\n{}", files.size(), sb);
- })));
- }
-
- public static void loadFile(@NotNull VirtualFile file, @Nullable Project project) {
- if (!TsvLoader.EXT.equals(file.getExtension()) && !TsvLoader.REGEXP_EXT.equals(file.getExtension())) {
+ @Override
+ public void loadAllImpl(@NotNull Project project) {
+ @NotNull Collection files = FilenameIndex.getAllFilesByExt(project,
+ TsvLoader.EXT);
+ @NotNull StringBuilder sb = new StringBuilder();
+ for (@NotNull VirtualFile file : files) {
+ loadFileImpl(file, project);
+ sb.append(file.getName()).append("\n");
+ }
+ @NotNull Collection files2 = FilenameIndex.getAllFilesByExt(project,
+ TsvLoader.REGEXP_EXT);
+ for (@NotNull VirtualFile file : files2) {
+ loadFileImpl(file, project);
+ sb.append(file.getPath()).append("\n");
+ }
+ if (files.isEmpty()) {
return;
}
- ApplicationManager.getApplication().invokeLater(() -> {
- ConfCache.load(file);
- if (project != null && !project.isDisposed()) {
- ProjectView.getInstance(project).refresh();
- }
- });
+ if (!project.isDisposed()) {
+ ProjectView.getInstance(project).refresh();
+ }
+ LOG.info("Ext doc conf load all complete {} files\n{}", files.size(), sb);
}
- private static void load(@NotNull VirtualFile file) {
+ @Override
+ public void loadFileImpl(@NotNull VirtualFile file, @Nullable Project project) {
@NotNull String name = file.getNameWithoutExtension();
if (name.endsWith(KEY_MID_EXT)) {
@NotNull String matchName = name.substring(0, name.length() - KEY_MID_EXT.length());
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/SpiltKeyWordPatternFactory.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/SpiltKeyWordPatternFactory.java
index 5dfe74a..f608be9 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/SpiltKeyWordPatternFactory.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/SpiltKeyWordPatternFactory.java
@@ -46,7 +46,6 @@ class SpiltKeyWordPatternFactory {
}
sb.insert(0, "\n");
sb.insert(0, path);
- sb.insert(0, "\n");
try {
@NotNull Pattern compile = Pattern.compile(regex);
PATTERN_CACHE.put(regex, compile);
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/action/package-info.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/action/package-info.java
deleted file mode 100644
index 87e2843..0000000
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/action/package-info.java
+++ /dev/null
@@ -1,4 +0,0 @@
-/**
- * call ConfCache clear and loadAll
- */
-package io.github.linwancen.plugin.show.ext.conf.action;
\ No newline at end of file
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/package-info.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/package-info.java
deleted file mode 100644
index 87f639d..0000000
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/package-info.java
+++ /dev/null
@@ -1,4 +0,0 @@
-/**
- * call ConfCache.load etc.
- */
-package io.github.linwancen.plugin.show.ext.conf.listener;
\ No newline at end of file
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileInitListener.java b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileLoadInitListener.java
similarity index 76%
rename from src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileInitListener.java
rename to src/main/java/io/github/linwancen/plugin/show/ext/listener/FileLoadInitListener.java
index 925a57e..814b4e6 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileInitListener.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileLoadInitListener.java
@@ -1,10 +1,9 @@
-package io.github.linwancen.plugin.show.ext.conf.listener;
+package io.github.linwancen.plugin.show.ext.listener;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
-import io.github.linwancen.plugin.show.ext.conf.ConfCache;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,11 +12,11 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
- * call ConfCache.loadAll
+ * call FileLoader.loadAll
*/
-public class ConfFileInitListener implements DumbService.DumbModeListener, ProjectManagerListener {
+public class FileLoadInitListener implements DumbService.DumbModeListener, ProjectManagerListener {
- private static final Logger LOG = LoggerFactory.getLogger(ConfFileInitListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(FileLoadInitListener.class);
private static final Map PROJECT_LOAD_MAP = new ConcurrentHashMap<>() {};
@Override
@@ -26,7 +25,7 @@ public class ConfFileInitListener implements DumbService.DumbModeListener, Proje
@NotNull Project[] projects = ProjectManager.getInstance().getOpenProjects();
for (@NotNull Project project : projects) {
PROJECT_LOAD_MAP.computeIfAbsent(project, k -> {
- ConfCache.loadAll(project);
+ FileLoader.EPN.getExtensionList().forEach(fileLoader -> fileLoader.loadAll(project));
return true;
});
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileLoader.java b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileLoader.java
new file mode 100644
index 0000000..a5b34a8
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileLoader.java
@@ -0,0 +1,71 @@
+package io.github.linwancen.plugin.show.ext.listener;
+
+import com.intellij.ide.projectView.ProjectView;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.project.DumbService;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * ExtensionPointName: fileLoader
+ */
+public abstract class FileLoader {
+
+ public static final ExtensionPointName EPN =
+ ExtensionPointName.create("io.github.linwancen.show-comment.fileLoader");
+
+ public abstract void clearAll();
+
+ /**
+ * not need skipFile(file) skipFile(newFile)
+ */
+ public abstract void copyImpl(@NotNull VirtualFile file, @NotNull VirtualFile newFile);
+
+ public abstract void remove(@NotNull VirtualFile file, @Nullable String oldName);
+
+ public boolean skipFile(@NotNull VirtualFile file) {
+ return skipExt(file.getExtension());
+ }
+
+ public boolean skipExt(@Nullable String ext) {
+ return false;
+ }
+
+ /**
+ * protected because not in runReadAction & executeOnPooledThread
+ */
+ protected abstract void loadAllImpl(Project project);
+
+ /**
+ * not need skipFile(file)
+ */
+ protected abstract void loadFileImpl(@NotNull VirtualFile file, @Nullable Project project);
+
+ public void loadAll(@NotNull Project project) {
+ ApplicationManager.getApplication().executeOnPooledThread(() ->
+ DumbService.getInstance(project).runReadActionInSmartMode(() ->
+ ApplicationManager.getApplication().runReadAction(() ->
+ loadAllImpl(project))));
+ }
+
+ void loadFile(@NotNull VirtualFile file, @Nullable Project project) {
+ if (skipFile(file)) return;
+ if (project != null && DumbService.isDumb(project)) return;
+ ApplicationManager.getApplication().executeOnPooledThread(() ->
+ ApplicationManager.getApplication().runReadAction(() -> {
+ loadFileImpl(file, project);
+ if (!project.isDisposed()) {
+ ProjectView.getInstance(project).refresh();
+ }
+ }));
+ }
+
+ public void copy(@NotNull VirtualFile file, @NotNull VirtualFile newFile) {
+ if (skipFile(file)) return;
+ if (skipFile(newFile)) return;
+ copyImpl(file, newFile);
+ }
+}
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileListener.java b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileOptListener.java
similarity index 73%
rename from src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileListener.java
rename to src/main/java/io/github/linwancen/plugin/show/ext/listener/FileOptListener.java
index 770d233..c0e6c2e 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileListener.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileOptListener.java
@@ -1,4 +1,4 @@
-package io.github.linwancen.plugin.show.ext.conf.listener;
+package io.github.linwancen.plugin.show.ext.listener;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
@@ -7,7 +7,6 @@ import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent;
import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent;
-import io.github.linwancen.plugin.show.ext.conf.ConfCache;
import io.github.linwancen.plugin.show.ext.conf.TsvLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -17,11 +16,11 @@ import org.slf4j.LoggerFactory;
import java.util.List;
/**
- * call ConfCache.loadFile, copy, remove
+ * call FileLoader.loadFile, copy, remove
*/
-public class ConfFileListener implements BulkFileListener {
+public class FileOptListener implements BulkFileListener {
- private static final Logger LOG = LoggerFactory.getLogger(ConfFileListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(FileOptListener.class);
@Override
public void after(@NotNull List extends VFileEvent> events) {
@@ -35,6 +34,7 @@ public class ConfFileListener implements BulkFileListener {
}
private static void forEvent(@NotNull VFileEvent event) {
+ @NotNull List list = FileLoader.EPN.getExtensionList();
@Nullable VirtualFile file = event.getFile();
if (file == null) {
return;
@@ -46,17 +46,15 @@ public class ConfFileListener implements BulkFileListener {
@NotNull VFilePropertyChangeEvent changeEvent = (VFilePropertyChangeEvent) event;
if ("name".equals(changeEvent.getPropertyName())) {
String oldName = changeEvent.getOldValue().toString();
- if (oldName.endsWith(TsvLoader.EXT) || oldName.endsWith(TsvLoader.REGEXP_EXT)) {
- // change cache too complicated so remove
- ConfCache.remove(file, oldName);
- }
+ // change cache too complicated so remove
+ list.forEach(fileLoader -> fileLoader.remove(file, oldName));
}
}
if (!TsvLoader.EXT.equals(file.getExtension()) && !TsvLoader.REGEXP_EXT.equals(file.getExtension())) {
return;
}
if (event instanceof VFileDeleteEvent) {
- ConfCache.remove(file, null);
+ list.forEach(fileLoader -> fileLoader.remove(file, null));
return;
}
if (event instanceof VFileCopyEvent) {
@@ -65,15 +63,17 @@ public class ConfFileListener implements BulkFileListener {
if (newFile == null) {
return;
}
- try {
- ConfCache.copy(file, newFile);
- } catch (Exception ignored) {
- // ignore
+ for (@NotNull FileLoader loader : list) {
+ try {
+ loader.copy(file, newFile);
+ } catch (Exception ignored) {
+ // ignore
+ }
}
return;
}
// VFileCreateEvent
// VFileContentChangeEvent
- ConfCache.loadFile(file, null);
+ list.forEach(fileLoader -> fileLoader.loadFile(file, null));
}
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileChangeListener.java b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileSelectChangeListener.java
similarity index 71%
rename from src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileChangeListener.java
rename to src/main/java/io/github/linwancen/plugin/show/ext/listener/FileSelectChangeListener.java
index e15b7ce..3e7fd0c 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/listener/ConfFileChangeListener.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/listener/FileSelectChangeListener.java
@@ -1,21 +1,20 @@
-package io.github.linwancen.plugin.show.ext.conf.listener;
+package io.github.linwancen.plugin.show.ext.listener;
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 io.github.linwancen.plugin.show.ext.conf.ConfCache;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * call ConfCache.loadFile
+ * call FileLoader.loadFile
*/
-public class ConfFileChangeListener implements FileEditorManagerListener {
+public class FileSelectChangeListener implements FileEditorManagerListener {
- private static final Logger LOG = LoggerFactory.getLogger(ConfFileChangeListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(FileSelectChangeListener.class);
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
@@ -29,7 +28,7 @@ public class ConfFileChangeListener implements FileEditorManagerListener {
}
if (file.exists()) {
try {
- ConfCache.loadFile(file, project);
+ FileLoader.EPN.getExtensionList().forEach(fileLoader -> fileLoader.loadFile(file, project));
} catch (Throwable e) {
LOG.info("ConfFileChangeListener catch Throwable but log to record.", e);
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/listener/package-info.java b/src/main/java/io/github/linwancen/plugin/show/ext/listener/package-info.java
new file mode 100644
index 0000000..cb9b7a9
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/listener/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Init and listen file change
+ */
+package io.github.linwancen.plugin.show.ext.listener;
\ No newline at end of file
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java
index 56bb91d..ae71d77 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java
@@ -1,21 +1,27 @@
package io.github.linwancen.plugin.show.lang;
+import com.intellij.ide.projectView.ProjectViewNode;
import com.intellij.lang.html.HTMLLanguage;
import com.intellij.lang.javascript.psi.JSPsiReferenceElement;
import com.intellij.model.psi.PsiSymbolReference;
import com.intellij.model.psi.PsiSymbolReferenceService;
import com.intellij.openapi.progress.ProcessCanceledException;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlTag;
import io.github.linwancen.plugin.show.bean.LineInfo;
+import io.github.linwancen.plugin.show.bean.SettingsInfo;
import io.github.linwancen.plugin.show.lang.base.DocFilter;
import io.github.linwancen.plugin.show.lang.base.DocSkip;
+import io.github.linwancen.plugin.show.lang.vue.VueRouterCache;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -23,15 +29,17 @@ import java.util.List;
public class HtmlLangDoc extends JsLangDoc {
private static final Logger LOG = LoggerFactory.getLogger(HtmlLangDoc.class);
+ @Nullable
public static final Method WEB_DOC_METHOD;
+ @Nullable
public static final Method REF_METHOD;
static {
LANG_DOC_MAP.put(HTMLLanguage.INSTANCE.getID(), new HtmlLangDoc());
- Method method = null;
- Method refMethod = null;
+ @Nullable Method method = null;
+ @Nullable Method refMethod = null;
try {
- Class> clazz = Class.forName("com.intellij.webSymbols.WebSymbol");
+ @NotNull Class> clazz = Class.forName("com.intellij.webSymbols.WebSymbol");
method = clazz.getMethod("getDescription");
// noinspection UnstableApiUsage
refMethod = PsiSymbolReferenceService.class.getMethod("getReferences", PsiElement.class);
@@ -52,6 +60,13 @@ public class HtmlLangDoc extends JsLangDoc {
return info.appSettings.showLineEndCommentJs || info.appSettings.showLineEndCommentHtml;
}
+ @Override
+ public @Nullable String treeDoc(@NotNull T info, @NotNull ProjectViewNode> node,
+ @NotNull Project project) {
+ @Nullable VirtualFile virtualFile = node.getVirtualFile();
+ return VueRouterCache.fileDoc(virtualFile);
+ }
+
/**
* Override like Java/Json/Html
*/
@@ -64,19 +79,19 @@ public class HtmlLangDoc extends JsLangDoc {
if (WEB_DOC_METHOD == null || !info.appSettings.showLineEndCommentHtml) {
return super.refDoc(info, ref);
}
- PsiSymbolReferenceService service = PsiSymbolReferenceService.getService();
- ArrayList references = new ArrayList<>();
+ @NotNull PsiSymbolReferenceService service = PsiSymbolReferenceService.getService();
+ @NotNull ArrayList references = new ArrayList<>();
try {
Object object = REF_METHOD.invoke(service, ref);
if (object instanceof Iterable) {
- Iterable> objects = (Iterable>) object;
+ @NotNull Iterable> objects = (Iterable>) object;
for (Object o : objects) {
if (o instanceof PsiSymbolReference) {
references.add(((PsiSymbolReference) o));
}
}
}
- } catch (ProcessCanceledException ignored) {
+ } catch (ProcessCanceledException | InvocationTargetException ignored) {
return super.refDoc(info, ref);
} catch (Exception e) {
LOG.warn("Web Tag Attr getReferences fail: ", e);
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java
index 2942f3b..3443603 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java
@@ -31,8 +31,8 @@ public abstract class BaseLangDoc extends EditorLinePainter {
static {
try {
// for 2024.2
- Class> clazz = Class.forName("io.github.linwancen.plugin.show.java.KotlinLangDoc");
- BaseLangDoc lang = (BaseLangDoc) clazz.getConstructor().newInstance();
+ @NotNull Class> clazz = Class.forName("io.github.linwancen.plugin.show.java.KotlinLangDoc");
+ @NotNull BaseLangDoc lang = (BaseLangDoc) clazz.getConstructor().newInstance();
LANG_DOC_MAP.put("kotlin", lang);
} catch (Exception ignored) {}
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java
index bf4b99a..c80fef0 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java
@@ -32,12 +32,12 @@ public class DocSkip {
public static boolean skipTagAttr(@NotNull T info, @NotNull PsiElement ref) {
if (ref instanceof XmlTag) {
- String text = ((XmlTag) ref).getName();
+ @NotNull String text = ((XmlTag) ref).getName();
return skipText(info, text,
info.globalSettings.tagInclude, info.globalSettings.tagExclude,
info.projectSettings.tagInclude, info.projectSettings.tagExclude);
} else if (ref instanceof XmlAttribute) {
- String text = ((XmlAttribute) ref).getName();
+ @NotNull String text = ((XmlAttribute) ref).getName();
return skipText(info, text,
info.globalSettings.attrInclude, info.globalSettings.attrExclude,
info.projectSettings.attrInclude, info.projectSettings.attrExclude);
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/vue/VueRouterCache.java b/src/main/java/io/github/linwancen/plugin/show/lang/vue/VueRouterCache.java
new file mode 100644
index 0000000..31ddbec
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/vue/VueRouterCache.java
@@ -0,0 +1,237 @@
+package io.github.linwancen.plugin.show.lang.vue;
+
+import com.intellij.ide.projectView.ProjectView;
+import com.intellij.lang.ecmascript6.psi.ES6ExportDefaultAssignment;
+import com.intellij.lang.ecmascript6.psi.ES6ImportCall;
+import com.intellij.lang.ecmascript6.psi.ES6ImportedBinding;
+import com.intellij.lang.javascript.psi.JSArrayLiteralExpression;
+import com.intellij.lang.javascript.psi.JSExpression;
+import com.intellij.lang.javascript.psi.JSLiteralExpression;
+import com.intellij.lang.javascript.psi.JSObjectLiteralExpression;
+import com.intellij.lang.javascript.psi.JSProperty;
+import com.intellij.lang.javascript.psi.JSReferenceExpression;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.VirtualFileVisitor;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiManager;
+import com.intellij.psi.search.FilenameIndex;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.util.PsiTreeUtil;
+import io.github.linwancen.plugin.show.ext.listener.FileLoader;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * call ConfFactory, ConfCacheGetUtils
+ */
+public class VueRouterCache extends FileLoader {
+ private static final Logger LOG = LoggerFactory.getLogger(VueRouterCache.class);
+
+ private static final Map DOC_CACHE = new ConcurrentHashMap<>();
+
+ @Nullable
+ public static String fileDoc(@Nullable VirtualFile virtualFile) {
+ if (virtualFile == null) {
+ return null;
+ }
+ return DOC_CACHE.get(virtualFile);
+ }
+
+ @Override
+ public void clearAll() {
+ DOC_CACHE.clear();
+ }
+
+ @Override
+ public void remove(@NotNull VirtualFile file, @Nullable String oldName) {
+ if (oldName == null) {
+ DOC_CACHE.remove(file);
+ }
+ }
+
+ @Override
+ public boolean skipFile(@NotNull VirtualFile file) {
+ @Nullable String ext = file.getExtension();
+ return !file.getPath().contains("src/router") && !"js".equals(ext) && !"ts".equals(ext);
+ }
+
+ @Override
+ public void copyImpl(@NotNull VirtualFile file, @NotNull VirtualFile newFile) {
+ String s = DOC_CACHE.get(file);
+ if (s != null) {
+ DOC_CACHE.put(newFile, s);
+ }
+ }
+
+ @Override
+ public void loadAllImpl(@NotNull Project project) {
+ @NotNull Collection files = FilenameIndex.getVirtualFilesByName(project,
+ "package.json", GlobalSearchScope.projectScope(project));
+ @NotNull StringBuilder sb = new StringBuilder();
+ for (@NotNull VirtualFile file : files) {
+ VirtualFile parent = file.getParent();
+ if (parent == null) {
+ continue;
+ }
+ @Nullable VirtualFile src = parent.findChild("src");
+ if (src == null) {
+ continue;
+ }
+ @Nullable VirtualFile router = src.findChild("router");
+ if (router == null) {
+ continue;
+ }
+ VfsUtil.visitChildrenRecursively(router, new VirtualFileVisitor() {
+ @Override
+ public boolean visitFile(@NotNull VirtualFile file) {
+ if (file.isDirectory()) {
+ return super.visitFile(file);
+ }
+ loadFileImpl(file, project);
+ sb.append(file.getPath()).append("\n");
+ return super.visitFile(file);
+ }
+ });
+ }
+ if (files.isEmpty()) {
+ return;
+ }
+ if (!project.isDisposed()) {
+ ProjectView.getInstance(project).refresh();
+ }
+ LOG.info("Vue Router load all complete {} files\n{}", files.size(), sb);
+ }
+
+ @Override
+ public void loadFileImpl(@NotNull VirtualFile file, @Nullable Project project) {
+ if (project == null) {
+ return;
+ }
+ @Nullable PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
+ if (psiFile == null) {
+ return;
+ }
+ @Nullable ES6ExportDefaultAssignment export = PsiTreeUtil.findChildOfType(psiFile,
+ ES6ExportDefaultAssignment.class);
+ if (export == null) {
+ return;
+ }
+ @Nullable JSArrayLiteralExpression arr = PsiTreeUtil.findChildOfAnyType(export, JSArrayLiteralExpression.class);
+ if (arr == null) {
+ return;
+ }
+ parseArr(arr);
+ }
+
+ @Nullable
+ private static VirtualFile parseArr(JSArrayLiteralExpression arr) {
+ @Nullable VirtualFile virtualFile = null;
+ @NotNull List list = PsiTreeUtil.getChildrenOfTypeAsList(arr,
+ JSObjectLiteralExpression.class);
+ for (@NotNull JSObjectLiteralExpression obj : list) {
+ @Nullable String title = parseTitle(obj);
+ @Nullable JSProperty children = obj.findProperty("children");
+ if (children != null) {
+ @Nullable JSExpression value = children.getValue();
+ if (value instanceof JSArrayLiteralExpression) {
+ @NotNull JSArrayLiteralExpression childrenArr = (JSArrayLiteralExpression) value;
+ @Nullable VirtualFile subFile = parseArr(childrenArr);
+ // common component dir
+ if (subFile != null) {
+ VirtualFile file = subFile.getParent();
+ if (file != null && title != null) {
+ virtualFile = file;
+ DOC_CACHE.put(virtualFile, title);
+ }
+ }
+ }
+ }
+ if (title != null) {
+ VirtualFile file = parseComponent(obj);
+ if (file != null) {
+ virtualFile = file;
+ DOC_CACHE.put(virtualFile, title);
+ if ("index.vue".equals(virtualFile.getName())) {
+ virtualFile = virtualFile.getParent();
+ DOC_CACHE.put(virtualFile, title);
+ }
+ }
+ }
+ }
+ return virtualFile;
+ }
+
+ @Nullable
+ private static String parseTitle(@NotNull JSObjectLiteralExpression obj) {
+ @Nullable JSProperty meta = obj.findProperty("meta");
+ if (meta == null) {
+ return null;
+ }
+ @Nullable JSObjectLiteralExpression metaObj = meta.getObjectLiteralExpressionInitializer();
+ if (metaObj == null) {
+ return null;
+ }
+ @Nullable JSProperty titleProp = metaObj.findProperty("title");
+ if (titleProp == null) {
+ return null;
+ }
+ @Nullable JSExpression value = titleProp.getValue();
+ if (value instanceof JSLiteralExpression) {
+ return ((JSLiteralExpression) value).getStringValue();
+ }
+ return null;
+ }
+
+ @Nullable
+ private static VirtualFile parseComponent(@NotNull JSObjectLiteralExpression obj) {
+ @Nullable JSProperty component = obj.findProperty("component");
+ if (component == null) {
+ return null;
+ }
+ @Nullable PsiElement value = component.getValue();
+ if (value instanceof JSReferenceExpression) {
+ @NotNull JSReferenceExpression ref = (JSReferenceExpression) value;
+ @Nullable PsiElement resolve;
+ try {
+ resolve = ref.resolve();
+ } catch (Throwable ignored) {
+ return null;
+ }
+ // import A from ""
+ if (resolve instanceof ES6ImportedBinding) {
+ @NotNull ES6ImportedBinding binding = (ES6ImportedBinding) resolve;
+ @NotNull Collection elements = binding.findReferencedElements();
+ for (@NotNull PsiElement element : elements) {
+ if (element instanceof PsiFile) {
+ return ((PsiFile) element).getVirtualFile();
+ }
+ }
+ }
+ // A = () => import('')
+ value = resolve;
+ }
+ // () => import("")
+ @Nullable ES6ImportCall importCall = PsiTreeUtil.findChildOfType(value, ES6ImportCall.class);
+ if (importCall == null) {
+ return null;
+ }
+ @NotNull Collection elements = importCall.resolveReferencedElements();
+ for (PsiElement element : elements) {
+ PsiFile psiFile = PsiTreeUtil.getParentOfType(element, PsiFile.class);
+ if (psiFile != null) {
+ return psiFile.getVirtualFile();
+ }
+ }
+ return null;
+ }
+}
diff --git a/src/main/resources/META-INF/js.xml b/src/main/resources/META-INF/js.xml
index 21e06a3..8dae7d9 100644
--- a/src/main/resources/META-INF/js.xml
+++ b/src/main/resources/META-INF/js.xml
@@ -3,4 +3,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 9c44d39..64b34a0 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -12,7 +12,7 @@ Show doc comment in the Project view Tree, line End, json, other
- Java, Kotlin, Groovy, Scala
- C/C++/OC, Python, Go, Rust, Ruby
-
- JS/TS, PHP, SQL
+
- HTML(Vue), JS/TS, PHP, SQL
- YAML/yml
@@ -145,23 +145,30 @@ Show doc comment in the Project view Tree, line End, json, other
-
-
-
-
+
+
+
+
+
+
+
@@ -189,13 +196,13 @@ Show doc comment in the Project view Tree, line End, json, other
diff --git a/src/main/resources/messages/ShowCommentBundle.properties b/src/main/resources/messages/ShowCommentBundle.properties
index c015dd5..74ae826 100644
--- a/src/main/resources/messages/ShowCommentBundle.properties
+++ b/src/main/resources/messages/ShowCommentBundle.properties
@@ -45,4 +45,7 @@ reload.ext.doc=\uD83D\uDD04 // Reload External Comment
reset.ext.doc=\uD83C\uDD91 // Clear External Comment
line.end.add=// Add Line Comment
line.end.copy=// Copy With Line Comment
+load.vue.router=Load Vue Router
+reload.vue.router=\uD83D\uDD04 Reload Vue Router
+reset.vue.router=\uD83C\uDD91 Clear Vue Router
copy.class.method.or.file.line=Copy Class.Method / File:LineNum
\ No newline at end of file
diff --git a/src/main/resources/messages/ShowCommentBundle_zh.properties b/src/main/resources/messages/ShowCommentBundle_zh.properties
index 80b33d4..91fe159 100644
--- a/src/main/resources/messages/ShowCommentBundle_zh.properties
+++ b/src/main/resources/messages/ShowCommentBundle_zh.properties
@@ -45,4 +45,7 @@ reload.ext.doc=\uD83D\uDD04 // \u91CD\u65B0\u8BFB\u53D6\u5916\u90E8\u6CE8\u91CA
reset.ext.doc=\uD83C\uDD91 // \u6E05\u7406\u5916\u90E8\u6CE8\u91CA
line.end.add=// \u6DFB\u52A0\u81EA\u52A8\u6CE8\u91CA
line.end.copy=// \u590D\u5236 \u5E26\u81EA\u52A8\u6CE8\u91CA
+load.vue.router=\u8BFB\u53D6 Vue Router
+reload.vue.router=\uD83D\uDD04 \u91CD\u65B0\u8BFB\u53D6 Vue \u8DEF\u7531
+reset.vue.router=\uD83C\uDD91 \u6E05\u7406 Vue \u8DEF\u7531
copy.class.method.or.file.line=\u590D\u5236 \u7C7B.\u65B9\u6CD5 / \u6587\u4EF6:\u884C\u53F7
\ No newline at end of file