feat: 2.21 use JS/TS/Vue "export default" doc for tree doc | 用 JS/TS/Vue "export default" 注释当文件注释
This commit is contained in:
@@ -125,6 +125,7 @@ Show doc comment in the Project view Tree, line End, json, other
|
|||||||
|
|
||||||
<h2>English Change Notes:</h2>
|
<h2>English Change Notes:</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>2.21 Add project-view-tree use JS/TS/Vue "export default" doc for tree doc
|
||||||
<li>2.20 Add External Comment support Vue src/router tree doc
|
<li>2.20 Add External Comment support Vue src/router tree doc
|
||||||
<li>2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
|
<li>2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
|
||||||
<li>2.18 Add line-end-comment support injected language like SQL
|
<li>2.18 Add line-end-comment support injected language like SQL
|
||||||
@@ -174,6 +175,7 @@ Show doc comment in the Project view Tree, line End, json, other
|
|||||||
|
|
||||||
<h2>中文更新说明:</h2>
|
<h2>中文更新说明:</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>2.21 增加 文件树注释 用 JS/TS/Vue "export default" 注释当文件注释
|
||||||
<li>2.20 增加 外部注释 支持 Vue 路由标题文件树注释
|
<li>2.20 增加 外部注释 支持 Vue 路由标题文件树注释
|
||||||
<li>2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
|
<li>2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
|
||||||
<li>2.18 增加 行末注释 支持注入语言如 SQL
|
<li>2.18 增加 行末注释 支持注入语言如 SQL
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'io.github.linwancen'
|
group 'io.github.linwancen'
|
||||||
version '2.20.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
version '2.21.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -95,6 +95,7 @@ patchPluginXml {
|
|||||||
changeNotes = """
|
changeNotes = """
|
||||||
<h2>English Change Notes:</h2>
|
<h2>English Change Notes:</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>2.21 Add project-view-tree use JS/TS/Vue "export default" doc for tree doc
|
||||||
<li>2.20 Add External Comment support Vue src/router tree doc
|
<li>2.20 Add External Comment support Vue src/router tree doc
|
||||||
<li>2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
|
<li>2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
|
||||||
<li>2.18 Add line-end-comment support injected language like SQL
|
<li>2.18 Add line-end-comment support injected language like SQL
|
||||||
@@ -144,6 +145,7 @@ patchPluginXml {
|
|||||||
|
|
||||||
<h2>中文更新说明:</h2>
|
<h2>中文更新说明:</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>2.21 增加 文件树注释 用 JS/TS/Vue "export default" 注释当文件注释
|
||||||
<li>2.20 增加 外部注释 支持 Vue 路由标题文件树注释
|
<li>2.20 增加 外部注释 支持 Vue 路由标题文件树注释
|
||||||
<li>2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
|
<li>2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
|
||||||
<li>2.18 增加 行末注释 支持注入语言如 SQL
|
<li>2.18 增加 行末注释 支持注入语言如 SQL
|
||||||
|
|||||||
@@ -64,7 +64,11 @@ public class HtmlLangDoc extends JsLangDoc {
|
|||||||
public @Nullable <T extends SettingsInfo> String treeDoc(@NotNull T info, @NotNull ProjectViewNode<?> node,
|
public @Nullable <T extends SettingsInfo> String treeDoc(@NotNull T info, @NotNull ProjectViewNode<?> node,
|
||||||
@NotNull Project project) {
|
@NotNull Project project) {
|
||||||
@Nullable VirtualFile virtualFile = node.getVirtualFile();
|
@Nullable VirtualFile virtualFile = node.getVirtualFile();
|
||||||
return VueRouterCache.fileDoc(virtualFile);
|
@Nullable String doc = VueRouterCache.fileDoc(virtualFile);
|
||||||
|
if (doc != null) {
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
return super.treeDoc(info, node, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
package io.github.linwancen.plugin.show.lang;
|
package io.github.linwancen.plugin.show.lang;
|
||||||
|
|
||||||
|
import com.intellij.ide.projectView.ProjectViewNode;
|
||||||
|
import com.intellij.lang.ecmascript6.psi.ES6ExportDefaultAssignment;
|
||||||
import com.intellij.lang.javascript.JavascriptLanguage;
|
import com.intellij.lang.javascript.JavascriptLanguage;
|
||||||
import com.intellij.lang.javascript.documentation.JSDocumentationUtils;
|
import com.intellij.lang.javascript.documentation.JSDocumentationUtils;
|
||||||
import com.intellij.lang.javascript.psi.JSPsiReferenceElement;
|
import com.intellij.lang.javascript.psi.JSPsiReferenceElement;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.PsiComment;
|
import com.intellij.psi.PsiComment;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import com.intellij.psi.PsiManager;
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||||
|
import io.github.linwancen.plugin.show.lang.vue.VueRouterCache;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -29,6 +37,32 @@ public class JsLangDoc extends BaseLangDoc {
|
|||||||
return info.appSettings.showLineEndCommentJs;
|
return info.appSettings.showLineEndCommentJs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable <T extends SettingsInfo> String treeDoc(@NotNull T info, @NotNull ProjectViewNode<?> node,
|
||||||
|
@NotNull Project project) {
|
||||||
|
@Nullable VirtualFile virtualFile = node.getVirtualFile();
|
||||||
|
if (virtualFile == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Nullable PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
|
||||||
|
if (psiFile == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Nullable ES6ExportDefaultAssignment export = PsiTreeUtil.findChildOfType(psiFile,
|
||||||
|
ES6ExportDefaultAssignment.class);
|
||||||
|
if (export == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Nullable String doc = resolveDocPrint(info, export);
|
||||||
|
if (doc != null && "index".equals(virtualFile.getNameWithoutExtension())) {
|
||||||
|
VirtualFile parent = virtualFile.getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
VueRouterCache.DOC_CACHE.put(parent, doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable <T extends SettingsInfo> String resolveDocRaw(@NotNull T info, @NotNull PsiElement resolve) {
|
public @Nullable <T extends SettingsInfo> String resolveDocRaw(@NotNull T info, @NotNull PsiElement resolve) {
|
||||||
@Nullable PsiComment psiComment = JSDocumentationUtils.findOwnDocCommentForImplicitElement(resolve);
|
@Nullable PsiComment psiComment = JSDocumentationUtils.findOwnDocCommentForImplicitElement(resolve);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class VueRouterCache extends FileLoader {
|
public class VueRouterCache extends FileLoader {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(VueRouterCache.class);
|
private static final Logger LOG = LoggerFactory.getLogger(VueRouterCache.class);
|
||||||
|
|
||||||
private static final Map<VirtualFile, String> DOC_CACHE = new ConcurrentHashMap<>();
|
public static final Map<VirtualFile, String> DOC_CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String fileDoc(@Nullable VirtualFile virtualFile) {
|
public static String fileDoc(@Nullable VirtualFile virtualFile) {
|
||||||
@@ -157,7 +158,7 @@ public class VueRouterCache extends FileLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
VirtualFile file = parseComponent(obj);
|
@Nullable VirtualFile file = parseComponent(obj);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
virtualFile = file;
|
virtualFile = file;
|
||||||
DOC_CACHE.put(virtualFile, title);
|
DOC_CACHE.put(virtualFile, title);
|
||||||
@@ -186,6 +187,16 @@ public class VueRouterCache extends FileLoader {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Nullable JSExpression value = titleProp.getValue();
|
@Nullable JSExpression value = titleProp.getValue();
|
||||||
|
if (value instanceof JSObjectLiteralExpression) {
|
||||||
|
@NotNull JSObjectLiteralExpression i18n = (JSObjectLiteralExpression) value;
|
||||||
|
// zh_CN
|
||||||
|
@NotNull String lang = Locale.getDefault().toString();
|
||||||
|
@Nullable JSProperty langProp = i18n.findProperty(lang);
|
||||||
|
if (langProp == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
value = langProp.getValue();
|
||||||
|
}
|
||||||
if (value instanceof JSLiteralExpression) {
|
if (value instanceof JSLiteralExpression) {
|
||||||
return ((JSLiteralExpression) value).getStringValue();
|
return ((JSLiteralExpression) value).getStringValue();
|
||||||
}
|
}
|
||||||
@@ -227,7 +238,7 @@ public class VueRouterCache extends FileLoader {
|
|||||||
}
|
}
|
||||||
@NotNull Collection<PsiElement> elements = importCall.resolveReferencedElements();
|
@NotNull Collection<PsiElement> elements = importCall.resolveReferencedElements();
|
||||||
for (PsiElement element : elements) {
|
for (PsiElement element : elements) {
|
||||||
PsiFile psiFile = PsiTreeUtil.getParentOfType(element, PsiFile.class);
|
@Nullable PsiFile psiFile = PsiTreeUtil.getParentOfType(element, PsiFile.class);
|
||||||
if (psiFile != null) {
|
if (psiFile != null) {
|
||||||
return psiFile.getVirtualFile();
|
return psiFile.getVirtualFile();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user