2.03 support all JetBrains IDE SQL, JavaScript, Python, Golang, Kotlin; add doc live-templates | 支持所有 JetBrains 软件和主流语言; 增加输入 doc / docc 等生成 /** */
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package io.github.linwancen.plugin.show.ext;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import io.github.linwancen.plugin.show.ext.conf.ConfCache;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,27 +14,42 @@ public class LineExt {
|
||||
|
||||
private LineExt() {}
|
||||
|
||||
public static String extDoc(@Nullable Project project,
|
||||
@NotNull String path, @NotNull String name, @Nullable String ext,
|
||||
@NotNull String text) {
|
||||
public static @Nullable String doc(@NotNull LineInfo lineInfo) {
|
||||
int i = lineInfo.text.indexOf(lineInfo.appSettings.lineEndPrefix);
|
||||
String code = i <= 0 ? lineInfo.text : lineInfo.text.substring(0, i);
|
||||
String extDoc = LineExt.extDoc(lineInfo, code);
|
||||
if (extDoc == null) {
|
||||
return null;
|
||||
}
|
||||
extDoc = extDoc.trim();
|
||||
if (lineInfo.text.endsWith(extDoc)) {
|
||||
return null;
|
||||
}
|
||||
return extDoc;
|
||||
}
|
||||
|
||||
public static String extDoc(@NotNull LineInfo lineInfo, @NotNull String code) {
|
||||
String path = lineInfo.file.getPath();
|
||||
String name = lineInfo.file.getName();
|
||||
String ext = lineInfo.file.getExtension();
|
||||
Map<String, Map<String, List<String>>> keyMap = ConfCache.keyMap(path, name, ext);
|
||||
if (keyMap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Pattern pattern = ConfCache.pattern(project, keyMap, path);
|
||||
Pattern pattern = ConfCache.pattern(lineInfo.project, keyMap, path);
|
||||
if (pattern == null || pattern.pattern().length() == 0) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Map<String, List<String>>> docMap = ConfCache.docMap(path, name, ext);
|
||||
if (docMap.isEmpty()) {
|
||||
Map<String, Map<String, List<String>>> treeMap = ConfCache.treeMap(path, name, ext);
|
||||
if (docMap.isEmpty() && treeMap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Map<String, List<String>>> treeMap = ConfCache.treeMap(path);
|
||||
if (ext == null || "cbl".equals(ext) || "cob".equals(ext) || "cobol".equals(ext)) {
|
||||
text = cblNotAndOr(text);
|
||||
code = cblNotAndOr(code);
|
||||
}
|
||||
String[] words = pattern.split(text);
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
String[] words = pattern.split(code);
|
||||
Matcher matcher = pattern.matcher(code);
|
||||
return extDoc(keyMap, matcher, docMap, words, treeMap);
|
||||
}
|
||||
|
||||
@@ -65,18 +80,15 @@ public class LineExt {
|
||||
@NotNull Map<String, Map<String, List<String>>> docMap, @NotNull String[] words,
|
||||
@NotNull Map<String, Map<String, List<String>>> treeMap) {
|
||||
boolean haveDoc = false;
|
||||
boolean haveKey = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : words) {
|
||||
if (appendDoc(sb, s, docMap, treeMap)) {
|
||||
haveDoc = true;
|
||||
}
|
||||
appendKeyDoc(sb, matcher, keyMap);
|
||||
haveDoc |= appendDoc(sb, s, docMap, treeMap);
|
||||
haveKey = appendKeyDoc(sb, matcher, keyMap);
|
||||
}
|
||||
while (haveKey) {
|
||||
haveKey = appendKeyDoc(sb, matcher, keyMap);
|
||||
}
|
||||
int before;
|
||||
do {
|
||||
before = sb.length();
|
||||
appendKeyDoc(sb, matcher, keyMap);
|
||||
} while (sb.length() != before);
|
||||
if (!haveDoc) {
|
||||
return null;
|
||||
}
|
||||
@@ -100,15 +112,16 @@ public class LineExt {
|
||||
sb.append(treeDoc);
|
||||
return true;
|
||||
}
|
||||
// not word doc ues word
|
||||
sb.append(word);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void appendKeyDoc(@NotNull StringBuilder sb,
|
||||
private static boolean appendKeyDoc(@NotNull StringBuilder sb,
|
||||
@NotNull Matcher matcher,
|
||||
@NotNull Map<String, Map<String, List<String>>> keyMap) {
|
||||
if (!matcher.find()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
String keyword = matcher.group();
|
||||
// "" if no doc
|
||||
@@ -120,5 +133,6 @@ public class LineExt {
|
||||
if (sb.length() != 1) {
|
||||
sb.append(" ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package io.github.linwancen.plugin.show.ext;
|
||||
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -11,8 +13,16 @@ public class TreeExt {
|
||||
|
||||
private TreeExt() {}
|
||||
|
||||
public static @Nullable String doc(ProjectViewNode<?> node) {
|
||||
VirtualFile file = node.getVirtualFile();
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
return TreeExt.extDoc(file);
|
||||
}
|
||||
|
||||
public static String extDoc(@NotNull VirtualFile file) {
|
||||
Map<String, Map<String, List<String>>> docMap = ConfCache.treeMap(file.getPath());
|
||||
Map<String, Map<String, List<String>>> docMap = ConfCache.treeMap(file.getPath(), file.getName(), file.getPath());
|
||||
String[] words = {
|
||||
file.getName(),
|
||||
file.getNameWithoutExtension(),
|
||||
|
||||
@@ -63,8 +63,10 @@ public class ConfCache {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<String, Map<String, List<String>>> treeMap(@NotNull String path) {
|
||||
return ConfCacheGetUtils.filterPath(TREE_CACHE, path);
|
||||
public static Map<String, Map<String, List<String>>> treeMap(@NotNull String path,
|
||||
@NotNull String name,
|
||||
@Nullable String ext) {
|
||||
return ConfCacheGetUtils.filterPath(TREE_CACHE, path, name, ext);
|
||||
}
|
||||
|
||||
static void clearAll() {
|
||||
@@ -113,13 +115,13 @@ public class ConfCache {
|
||||
new NotificationGroup("Ext Doc Conf Load All", NotificationDisplayType.BALLOON, true);
|
||||
|
||||
static void loadAll(@NotNull Project project) {
|
||||
ApplicationManager.getApplication().runReadAction(() ->
|
||||
DumbService.getInstance(project).runReadActionInSmartMode(() -> {
|
||||
DumbService.getInstance(project).runReadActionInSmartMode(() ->
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
Collection<VirtualFile> files = FilenameIndex.getAllFilesByExt(project, EXT);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (VirtualFile file : files) {
|
||||
load(project, file);
|
||||
sb.append(file.getPath()).append("\n");
|
||||
sb.append(file.getName()).append("\n");
|
||||
}
|
||||
if (files.isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -75,7 +75,7 @@ class ConfCacheGetUtils {
|
||||
@NotNull
|
||||
static <T> TreeMap<String, T> filterPath(@SuppressWarnings("SameParameterValue")
|
||||
@NotNull Map<VirtualFile, T> cache,
|
||||
@NotNull String path) {
|
||||
@NotNull String path, String name, String ext) {
|
||||
TreeMap<String, T> map = new TreeMap<>();
|
||||
int max = path.length();
|
||||
int length = String.valueOf(max).length();
|
||||
|
||||
@@ -94,8 +94,6 @@ class ConfFactory {
|
||||
map.put(key, words);
|
||||
}
|
||||
}
|
||||
DATA_LOG.createNotification("Ext doc file load complete", map.size() + " lines",
|
||||
"\n" + path, NotificationType.INFORMATION).notify(project);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user