From 33a2f127c11e5efbf81da5b5ef5f786be9a27089 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=97=E4=B8=87=E7=A8=8B?= <1498425439@qq.com>
Date: Sun, 30 Oct 2022 19:42:08 +0800
Subject: [PATCH] =?UTF-8?q?2.05=20json=20doc=20from=20xxx.json.tsv=20|=20?=
=?UTF-8?q?=E4=BB=8E=20=E9=94=AE=E5=90=8D.tsv=20=E4=B8=AD=E8=AF=BB?=
=?UTF-8?q?=E5=8F=96=20json=20=E7=9A=84=E5=AD=97=E5=85=B8=E6=B3=A8?=
=?UTF-8?q?=E9=87=8A=20fixed=20#13?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +
build.gradle | 4 +-
.../plugin/show/ext/GetFromDocMap.java | 4 +-
.../plugin/show/ext/conf/ConfCache.java | 14 +++++++
.../plugin/show/lang/JsonLangDoc.java | 40 +++++++++++--------
.../linwancen/plugin/show/demo/dict.tsv | 2 +
.../plugin/show/demo/json/array-Pojo.json5 | 3 +-
.../plugin/show/demo/json/base-Pojo.json | 3 +-
.../linwancen/plugin/show/demo/json/dict.tsv | 3 +-
.../plugin/show/demo/json/ext.json.tsv | 1 +
.../plugin/show/demo/json/list-Pojo.json | 3 +-
.../plugin/show/demo/json/nested-Pojo.json | 3 +-
12 files changed, 56 insertions(+), 26 deletions(-)
create mode 100644 src/test/java/io/github/linwancen/plugin/show/demo/dict.tsv
create mode 100644 src/test/java/io/github/linwancen/plugin/show/demo/json/ext.json.tsv
diff --git a/README.md b/README.md
index a472cf9..edda20e 100644
--- a/README.md
+++ b/README.md
@@ -62,6 +62,7 @@ Show doc comment at the Project view Tree, line End, json etc.
English Change Notes:
+- 2.05 Add line-end-comment json doc from xxx.json.tsv
- 2.04 Add line-end-comment json dict doc from (key).tsv
- 2.03 Add live-templates input `doc` `docc` -> /** */
- 2.02 Add line-end-comment show before doc for `isA(xxx)` and `a.set(b.get)`
@@ -95,6 +96,7 @@ Show doc comment at the Project view Tree, line End, json etc.
中文更新说明:
+- 2.05 增加 行末注释 从 xxx.json.tsv 中读取注释
- 2.04 增加 行末注释 从 键名.tsv 中读取 json 的字典注释
- 2.03 增加 活动模板 输入 doc / docc 等生成 /** */
- 2.02 增加 行末注释 `isA(xxx)` 和 `a.set(b.get)` 显示前一个注释
diff --git a/build.gradle b/build.gradle
index c44894e..1c10588 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'io.github.linwancen'
-version '2.04.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
+version '2.05.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
repositories {
mavenCentral()
@@ -87,6 +87,7 @@ patchPluginXml {
changeNotes = """
English Change Notes:
+- 2.05 Add line-end-comment json doc from xxx.json.tsv
- 2.04 Add line-end-comment json dict doc from (key).tsv
- 2.03 Add live-templates input `doc` `docc` -> /** */
- 2.02 Add line-end-comment show before doc for `isA(xxx)` and `a.set(b.get)`
@@ -120,6 +121,7 @@ patchPluginXml {
中文更新说明:
+- 2.05 增加 行末注释 从 xxx.json.tsv 中读取注释
- 2.04 增加 行末注释 从 键名.tsv 中读取 json 的字典注释
- 2.03 增加 活动模板 输入 doc / docc 等生成 /** */
- 2.02 增加 行末注释 `isA(xxx)` 和 `a.set(b.get)` 显示前一个注释
diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java b/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java
index 62f4015..81c2deb 100644
--- a/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java
+++ b/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java
@@ -7,12 +7,12 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-class GetFromDocMap {
+public class GetFromDocMap {
private GetFromDocMap() {}
@Nullable
- static String get(@NotNull Map>> docMap, @NotNull String... words) {
+ public static String get(@NotNull Map>> docMap, @NotNull String... words) {
@NotNull List keywordDoc = list(docMap, words);
if (keywordDoc.size() >= 2) {
return keywordDoc.get(1);
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 e8dc96d..e3811a6 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
@@ -24,11 +24,13 @@ public class ConfCache {
static final String KEY_MID_EXT = ".key";
static final String DOC_MID_EXT = ".doc";
static final String TREE_MID_EXT = ".tree";
+ static final String JSON_MID_EXT = ".json";
private static final ConcurrentSkipListSet EXT_IN_KEY_CACHE = new ConcurrentSkipListSet<>();
private static final Map>> KEY_CACHE = new ConcurrentHashMap<>();
private static final Map>> DOC_CACHE = new ConcurrentHashMap<>();
private static final Map>> TREE_CACHE = new ConcurrentHashMap<>();
+ private static final Map>> JSON_CACHE = new ConcurrentHashMap<>();
private ConfCache() {}
@@ -62,11 +64,17 @@ public class ConfCache {
return ConfCacheGetUtils.filterPath(TREE_CACHE, path);
}
+ @NotNull
+ public static Map>> jsonMap(@NotNull String path) {
+ return ConfCacheGetUtils.filterPath(JSON_CACHE, path);
+ }
+
static void clearAll() {
EXT_IN_KEY_CACHE.clear();
KEY_CACHE.clear();
DOC_CACHE.clear();
TREE_CACHE.clear();
+ JSON_CACHE.clear();
}
static void remove(@NotNull VirtualFile file, @Nullable String name) {
@@ -82,6 +90,8 @@ public class ConfCache {
DOC_CACHE.remove(file);
} else if (name.endsWith(TREE_MID_EXT)) {
TREE_CACHE.remove(file);
+ } else if (name.endsWith(JSON_MID_EXT)) {
+ JSON_CACHE.remove(file);
}
}
@@ -93,6 +103,8 @@ public class ConfCache {
copyCache(file, newFile, DOC_CACHE);
} else if (name.endsWith(TREE_MID_EXT)) {
copyCache(file, newFile, TREE_CACHE);
+ } else if (name.endsWith(JSON_MID_EXT)) {
+ copyCache(file, newFile, JSON_CACHE);
}
}
@@ -144,6 +156,8 @@ public class ConfCache {
DOC_CACHE.put(file, TsvLoader.buildMap(file, false));
} else if (name.endsWith(TREE_MID_EXT)) {
TREE_CACHE.put(file, TsvLoader.buildMap(file, false));
+ } else if (name.endsWith(JSON_MID_EXT)) {
+ JSON_CACHE.put(file, TsvLoader.buildMap(file, false));
}
}
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java
index ab58033..6a8f5aa 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java
@@ -10,13 +10,18 @@ import com.intellij.psi.PsiReference;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import io.github.linwancen.plugin.show.bean.LineInfo;
+import io.github.linwancen.plugin.show.ext.GetFromDocMap;
+import io.github.linwancen.plugin.show.ext.conf.ConfCache;
import io.github.linwancen.plugin.show.ext.conf.ConfCacheGetUtils;
import io.github.linwancen.plugin.show.ext.conf.TsvLoader;
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.*;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
import java.util.concurrent.ConcurrentHashMap;
public class JsonLangDoc extends BaseLangDoc {
@@ -52,9 +57,9 @@ public class JsonLangDoc extends BaseLangDoc {
return null;
}
@NotNull JsonProperty jsonProperty = (JsonProperty) ref;
- @Nullable String dictDoc = dictDoc(lineInfo, jsonProperty);
- if (dictDoc != null) {
- return dictDoc;
+ @Nullable String extDoc = extDoc(lineInfo, jsonProperty);
+ if (extDoc != null) {
+ return extDoc;
}
@NotNull PsiReference[] references = jsonProperty.getNameElement().getReferences();
for (@NotNull PsiReference reference : references) {
@@ -76,21 +81,28 @@ public class JsonLangDoc extends BaseLangDoc {
}
@Nullable
- private static String dictDoc(@NotNull LineInfo lineInfo, @NotNull JsonProperty prop) {
+ private static String extDoc(@NotNull LineInfo lineInfo, @NotNull JsonProperty prop) {
@Nullable JsonValue value = prop.getValue();
if (value == null || value instanceof JsonArray || value instanceof JsonObject) {
return null;
}
@NotNull GlobalSearchScope scope = GlobalSearchScope.allScope(lineInfo.project);
- String jsonKey = prop.getName();
+ @NotNull String jsonKey = prop.getName();
String jsonValue = value.getText();
// Read the json.path before if needed
- return jsonDictDoc(lineInfo, scope, jsonKey, jsonValue);
+ @Nullable String dictDoc = jsonDictDoc(lineInfo, scope, jsonKey, jsonValue);
+ if (dictDoc != null) {
+ return dictDoc;
+ }
+ @NotNull Map>> jsonMap = ConfCache.jsonMap(lineInfo.file.getPath());
+ return GetFromDocMap.get(jsonMap, jsonKey);
}
@Nullable
- private static String jsonDictDoc(@NotNull LineInfo lineInfo, @NotNull GlobalSearchScope scope, String fileName, String jsonValue) {
- @NotNull Collection files = FilenameIndex.getVirtualFilesByName(lineInfo.project, fileName + ".tsv", scope);
+ private static String jsonDictDoc(@NotNull LineInfo lineInfo,
+ @NotNull GlobalSearchScope scope, String jsonKey, String jsonValue) {
+ @NotNull String name = jsonKey + ".tsv";
+ @NotNull Collection files = FilenameIndex.getVirtualFilesByName(lineInfo.project, name, scope);
// one file
if (files.size() < 2) {
for (@NotNull VirtualFile file : files) {
@@ -109,13 +121,7 @@ public class JsonLangDoc extends BaseLangDoc {
fileMap.put(file, map);
}
@NotNull String path = lineInfo.file.getPath();
- @NotNull SortedMap>> treeMap = ConfCacheGetUtils.filterPath(fileMap, path);
- for (@NotNull Map.Entry>> entry : treeMap.entrySet()) {
- List list = entry.getValue().get(jsonValue);
- if (list != null && list.size() > 1) {
- return list.get(1);
- }
- }
- return null;
+ @NotNull SortedMap>> sortedMap = ConfCacheGetUtils.filterPath(fileMap, path);
+ return GetFromDocMap.get(sortedMap, jsonValue);
}
}
diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/dict.tsv b/src/test/java/io/github/linwancen/plugin/show/demo/dict.tsv
new file mode 100644
index 0000000..d59f597
--- /dev/null
+++ b/src/test/java/io/github/linwancen/plugin/show/demo/dict.tsv
@@ -0,0 +1,2 @@
+0 should_not_show_this
+1 dict_1
\ No newline at end of file
diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/json/array-Pojo.json5 b/src/test/java/io/github/linwancen/plugin/show/demo/json/array-Pojo.json5
index 7bc9f71..0b43a21 100644
--- a/src/test/java/io/github/linwancen/plugin/show/demo/json/array-Pojo.json5
+++ b/src/test/java/io/github/linwancen/plugin/show/demo/json/array-Pojo.json5
@@ -3,7 +3,8 @@
{
"nestedClass2": {
"a": "",
- "dict": 0
+ "dict": 0,
+ "extKey": 0
}
},
[
diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/json/base-Pojo.json b/src/test/java/io/github/linwancen/plugin/show/demo/json/base-Pojo.json
index be7daea..36f4c22 100644
--- a/src/test/java/io/github/linwancen/plugin/show/demo/json/base-Pojo.json
+++ b/src/test/java/io/github/linwancen/plugin/show/demo/json/base-Pojo.json
@@ -3,5 +3,6 @@
"str": "",
"date": "2022-03-04 21:34:01",
"bool": false,
- "dict": 0
+ "dict": 0,
+ "extKey": 0
}
\ No newline at end of file
diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/json/dict.tsv b/src/test/java/io/github/linwancen/plugin/show/demo/json/dict.tsv
index 4171e5b..878b568 100644
--- a/src/test/java/io/github/linwancen/plugin/show/demo/json/dict.tsv
+++ b/src/test/java/io/github/linwancen/plugin/show/demo/json/dict.tsv
@@ -1,2 +1 @@
-0 dict_0
-1 dict_1
\ No newline at end of file
+0 dict_0
\ No newline at end of file
diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/json/ext.json.tsv b/src/test/java/io/github/linwancen/plugin/show/demo/json/ext.json.tsv
new file mode 100644
index 0000000..63afc7f
--- /dev/null
+++ b/src/test/java/io/github/linwancen/plugin/show/demo/json/ext.json.tsv
@@ -0,0 +1 @@
+extKey ext doc
\ No newline at end of file
diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/json/list-Pojo.json b/src/test/java/io/github/linwancen/plugin/show/demo/json/list-Pojo.json
index 8375b91..c3b11bc 100644
--- a/src/test/java/io/github/linwancen/plugin/show/demo/json/list-Pojo.json
+++ b/src/test/java/io/github/linwancen/plugin/show/demo/json/list-Pojo.json
@@ -3,7 +3,8 @@
{
"nestedClass2": {
"a": "",
- "dict": 0
+ "dict": 0,
+ "extKey": 0
}
},
{
diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/json/nested-Pojo.json b/src/test/java/io/github/linwancen/plugin/show/demo/json/nested-Pojo.json
index 20e2ff0..15dbf47 100644
--- a/src/test/java/io/github/linwancen/plugin/show/demo/json/nested-Pojo.json
+++ b/src/test/java/io/github/linwancen/plugin/show/demo/json/nested-Pojo.json
@@ -2,7 +2,8 @@
"nestedClass": {
"nestedClass2": {
"a": "",
- "dict": 0
+ "dict": 0,
+ "extKey": 0
},
"dict": 1
}