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 43ffa51..78d6d14 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 @@ -51,17 +51,17 @@ public class ConfCache { // faster than find in KEY_CACHE return Collections.emptyMap(); } - return ConfCacheGetUtils.get(file, KEY_MID_EXT, KEY_CACHE); + return ConfCacheGetUtils.filterPathNameExt(file, KEY_MID_EXT, KEY_CACHE); } @NotNull public static Map>> docMap(@Nullable Project project, @NotNull VirtualFile file) { - return ConfCacheGetUtils.get(file, DOC_MID_EXT, DOC_CACHE); + return ConfCacheGetUtils.filterPathNameExt(file, DOC_MID_EXT, DOC_CACHE); } @NotNull public static Map>> treeMap(@Nullable Project project, @NotNull VirtualFile file) { - return ConfCacheGetUtils.get(file, TREE_MID_EXT, TREE_CACHE); + return ConfCacheGetUtils.filterPath(file, TREE_CACHE); } static void clearAll() { diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java index 285604d..560853f 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java @@ -28,15 +28,12 @@ class ConfCacheGetUtils { * @return {@code } */ @NotNull - static TreeMap get(@NotNull VirtualFile file, - @NotNull String confMidExt, - @NotNull Map cache) { + static TreeMap filterPathNameExt(@NotNull VirtualFile file, + @NotNull String confMidExt, + @NotNull Map cache) { String path = file.getPath(); String name = file.getName(); String ext = file.getExtension(); - if (ext == null) { - ext = ""; - } TreeMap map = new TreeMap<>(); int max = path.length(); int length = String.valueOf(max).length(); @@ -53,15 +50,48 @@ class ConfCacheGetUtils { map.put(levelStr + "\b" + confPath, entry.getValue()); } else if (confName.endsWith((name + confMidExt))) { map.put(levelStr + "\t" + confPath, entry.getValue()); - } else if ((ext + confMidExt).equals(confName)) { - map.put(levelStr + "\n" + confPath, entry.getValue()); - } else if (confName.endsWith((ext + confMidExt))) { - map.put(levelStr + "\f" + confPath, entry.getValue()); + } else if (ext != null) { + if ((ext + confMidExt).equals(confName)) { + map.put(levelStr + "\n" + confPath, entry.getValue()); + } else if (confName.endsWith((ext + confMidExt))) { + map.put(levelStr + "\f" + confPath, entry.getValue()); + } } } return map; } + /** + *
file: + *
a/b/c.ext + *
+ *
configure file priority: + *
a/b/any.tree.tsv + *
a/any.tree.tsv + * + * @return {@code } + */ + @NotNull + static TreeMap filterPath(@NotNull VirtualFile file, + @SuppressWarnings("SameParameterValue") + @NotNull Map cache) { + String path = file.getPath(); + TreeMap map = new TreeMap<>(); + int max = path.length(); + int length = String.valueOf(max).length(); + for (Map.Entry entry : cache.entrySet()) { + VirtualFile confFile = entry.getKey(); + String confPath = confFile.getPath(); + int level = level(path, confPath); + if (level == 0) { + continue; + } + String levelStr = StringUtils.leftPad(String.valueOf(max - level), length, '0'); + map.put(levelStr + confPath, entry.getValue()); + } + return map; + } + private static int level(String path, String confPath) { path = srcPath(path); confPath = srcPath(confPath); diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL-file.tsv.tree.tsv b/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL-file.tsv.tree.tsv index 7b50aea..4c1947d 100644 --- a/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL-file.tsv.tree.tsv +++ b/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL-file.tsv.tree.tsv @@ -2,7 +2,7 @@ COBOL-file.tsv.tree.tsv 📝 COBOL 相关文件注释 COBOL.cbl.key.tsv COBOL 必要【关键字】 -COBOL-struct.cbl.doc.tsv COBOL 文件结构【关键字】 +COBOL-struct.cbl.doc.tsv COBOL 文件结构 COBOL-data.cbl.key.tsv COBOL 数据部必要【关键字】 COBOL-data-layout.cbl.key.tsv COBOL 数据布局【关键字】 @@ -17,4 +17,4 @@ COBOL-loop.cbl.key.tsv COBOL 循环【关键字】(非必要) COBOL-string.cbl.key.tsv COBOL 字符串【关键字】(非必要) COBOL_IDEA.md COBOL IDEA 高亮设置 -COBOL_keyword1.md COBOL COBOL IDEA 高亮 普通关键字 \ No newline at end of file +COBOL_keyword1.md COBOL IDEA 高亮 普通关键字 \ No newline at end of file diff --git a/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL_IDEA.md b/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL_IDEA.md index ab87e4b..34a7aea 100644 --- a/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL_IDEA.md +++ b/src/test/java/io/github/linwancen/plugin/show/demo/ext/cobol/COBOL_IDEA.md @@ -1,4 +1,4 @@ -# IDEA COBOL 高亮配置 +# COBOL IDEA 高亮配置 - File -> Settings -> Editor -> File Types - 文件 -> 设置 -> 编辑器 -> 文件类型