2.05 json doc from xxx.json.tsv | 从 键名.tsv 中读取 json 的字典注释 fixed #13
This commit is contained in:
@@ -62,6 +62,7 @@ Show doc comment at the Project view Tree, line End, json etc.
|
||||
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.05 Add line-end-comment json doc from xxx.json.tsv
|
||||
<li>2.04 Add line-end-comment json dict doc from (key).tsv
|
||||
<li>2.03 Add live-templates input `doc` `docc` -> /** */
|
||||
<li>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.
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.05 增加 行末注释 从 xxx.json.tsv 中读取注释
|
||||
<li>2.04 增加 行末注释 从 键名.tsv 中读取 json 的字典注释
|
||||
<li>2.03 增加 活动模板 输入 doc / docc 等生成 /** */
|
||||
<li>2.02 增加 行末注释 `isA(xxx)` 和 `a.set(b.get)` 显示前一个注释
|
||||
|
||||
@@ -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 = """
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.05 Add line-end-comment json doc from xxx.json.tsv
|
||||
<li>2.04 Add line-end-comment json dict doc from (key).tsv
|
||||
<li>2.03 Add live-templates input `doc` `docc` -> /** */
|
||||
<li>2.02 Add line-end-comment show before doc for `isA(xxx)` and `a.set(b.get)`
|
||||
@@ -120,6 +121,7 @@ patchPluginXml {
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.05 增加 行末注释 从 xxx.json.tsv 中读取注释
|
||||
<li>2.04 增加 行末注释 从 键名.tsv 中读取 json 的字典注释
|
||||
<li>2.03 增加 活动模板 输入 doc / docc 等生成 /** */
|
||||
<li>2.02 增加 行末注释 `isA(xxx)` 和 `a.set(b.get)` 显示前一个注释
|
||||
|
||||
@@ -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<String, Map<String, List<String>>> docMap, @NotNull String... words) {
|
||||
public static String get(@NotNull Map<String, Map<String, List<String>>> docMap, @NotNull String... words) {
|
||||
@NotNull List<String> keywordDoc = list(docMap, words);
|
||||
if (keywordDoc.size() >= 2) {
|
||||
return keywordDoc.get(1);
|
||||
|
||||
@@ -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<String> EXT_IN_KEY_CACHE = new ConcurrentSkipListSet<>();
|
||||
private static final Map<VirtualFile, Map<String, List<String>>> KEY_CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<VirtualFile, Map<String, List<String>>> DOC_CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<VirtualFile, Map<String, List<String>>> TREE_CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<VirtualFile, Map<String, List<String>>> JSON_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private ConfCache() {}
|
||||
|
||||
@@ -62,11 +64,17 @@ public class ConfCache {
|
||||
return ConfCacheGetUtils.filterPath(TREE_CACHE, path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<String, Map<String, List<String>>> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, Map<String, List<String>>> 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<VirtualFile> 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<VirtualFile> 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<String, Map<String, List<String>>> treeMap = ConfCacheGetUtils.filterPath(fileMap, path);
|
||||
for (@NotNull Map.Entry<String, Map<String, List<String>>> entry : treeMap.entrySet()) {
|
||||
List<String> list = entry.getValue().get(jsonValue);
|
||||
if (list != null && list.size() > 1) {
|
||||
return list.get(1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@NotNull SortedMap<String, Map<String, List<String>>> sortedMap = ConfCacheGetUtils.filterPath(fileMap, path);
|
||||
return GetFromDocMap.get(sortedMap, jsonValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
0 should_not_show_this
|
||||
1 dict_1
|
||||
|
@@ -3,7 +3,8 @@
|
||||
{
|
||||
"nestedClass2": {
|
||||
"a": "",
|
||||
"dict": 0
|
||||
"dict": 0,
|
||||
"extKey": 0
|
||||
}
|
||||
},
|
||||
[
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
"str": "",
|
||||
"date": "2022-03-04 21:34:01",
|
||||
"bool": false,
|
||||
"dict": 0
|
||||
"dict": 0,
|
||||
"extKey": 0
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
0 dict_0
|
||||
1 dict_1
|
||||
0 dict_0
|
||||
|
@@ -0,0 +1 @@
|
||||
extKey ext doc
|
||||
|
@@ -3,7 +3,8 @@
|
||||
{
|
||||
"nestedClass2": {
|
||||
"a": "",
|
||||
"dict": 0
|
||||
"dict": 0,
|
||||
"extKey": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"nestedClass": {
|
||||
"nestedClass2": {
|
||||
"a": "",
|
||||
"dict": 0
|
||||
"dict": 0,
|
||||
"extKey": 0
|
||||
},
|
||||
"dict": 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user