diff --git a/README.md b/README.md
index 2fd89ad..df98952 100644
--- a/README.md
+++ b/README.md
@@ -125,6 +125,7 @@ Show doc comment in the Project view Tree, line End, json, other
English Change Notes:
+- 2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
- 2.18 Add line-end-comment support injected language like SQL
- 2.17 Add External Comment support *.key.regexp and MyBatis xml demo in Git
- 2.16 Add line-end-comment support Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
@@ -172,6 +173,7 @@ Show doc comment in the Project view Tree, line End, json, other
中文更新说明:
+- 2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
- 2.18 增加 行末注释 支持注入语言如 SQL
- 2.17 增加 tsv 注释 支持 *.key.regexp 与 Mybatis xml 示例在 Git
- 2.16 增加 行末注释 支持 Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
diff --git a/build.gradle b/build.gradle
index e17e748..ab5c97d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'io.github.linwancen'
-version '2.18.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
+version '2.19.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
repositories {
mavenCentral()
@@ -95,6 +95,7 @@ patchPluginXml {
changeNotes = """
English Change Notes:
+- 2.19 ★ line-end-comment support HTML(Vue) Tag/Attr doc since 2022.3.1
- 2.18 Add line-end-comment support injected language like SQL
- 2.17 Add External Comment support *.key.regexp and MyBatis xml demo in Git
- 2.16 Add line-end-comment support Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
@@ -142,6 +143,7 @@ patchPluginXml {
中文更新说明:
+- 2.19 ★ 行末注释 支持 HTML(Vue) 标签/属性 注释从 2022.3.1 起
- 2.18 增加 行末注释 支持注入语言如 SQL
- 2.17 增加 tsv 注释 支持 *.key.regexp 与 Mybatis xml 示例在 Git
- 2.16 增加 行末注释 支持 Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
diff --git a/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java b/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
index 803a379..6b5e046 100644
--- a/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
+++ b/src/main/java/io/github/linwancen/plugin/show/cache/LineEndCacheUtils.java
@@ -79,6 +79,7 @@ public class LineEndCacheUtils {
AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(() -> {
try {
cacheUpdate();
+ } catch (ProcessCanceledException ignored) {
} catch (Throwable e) {
LOG.info("LineEndCacheUtils checkScheduleAndInit catch Throwable but log to record.", e);
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java
index 58fc933..56bb91d 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/HtmlLangDoc.java
@@ -1,17 +1,106 @@
package io.github.linwancen.plugin.show.lang;
import com.intellij.lang.html.HTMLLanguage;
+import com.intellij.lang.javascript.psi.JSPsiReferenceElement;
+import com.intellij.model.psi.PsiSymbolReference;
+import com.intellij.model.psi.PsiSymbolReferenceService;
+import com.intellij.openapi.progress.ProcessCanceledException;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.xml.XmlAttribute;
+import com.intellij.psi.xml.XmlTag;
import io.github.linwancen.plugin.show.bean.LineInfo;
+import io.github.linwancen.plugin.show.lang.base.DocFilter;
+import io.github.linwancen.plugin.show.lang.base.DocSkip;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
public class HtmlLangDoc extends JsLangDoc {
+ private static final Logger LOG = LoggerFactory.getLogger(HtmlLangDoc.class);
+
+ public static final Method WEB_DOC_METHOD;
+ public static final Method REF_METHOD;
static {
LANG_DOC_MAP.put(HTMLLanguage.INSTANCE.getID(), new HtmlLangDoc());
+ Method method = null;
+ Method refMethod = null;
+ try {
+ Class> clazz = Class.forName("com.intellij.webSymbols.WebSymbol");
+ method = clazz.getMethod("getDescription");
+ // noinspection UnstableApiUsage
+ refMethod = PsiSymbolReferenceService.class.getMethod("getReferences", PsiElement.class);
+ } catch (Exception e) {
+ LOG.warn("Web Tag Attr Doc is support since 2022.3, {}", e.getLocalizedMessage());
+ }
+ WEB_DOC_METHOD = method;
+ REF_METHOD = refMethod;
+ }
+
+ @Override
+ public @NotNull List> getRefClass() {
+ return List.of(JSPsiReferenceElement.class, XmlAttribute.class, XmlTag.class);
}
@Override
public boolean show(@NotNull LineInfo info) {
- return info.appSettings.showLineEndCommentJs;
+ return info.appSettings.showLineEndCommentJs || info.appSettings.showLineEndCommentHtml;
+ }
+
+ /**
+ * Override like Java/Json/Html
+ */
+ @SuppressWarnings("UnstableApiUsage")
+ @Nullable
+ protected String refDoc(@NotNull LineInfo info, @NotNull PsiElement ref) {
+ if (DocSkip.skipTagAttr(info, ref)) {
+ return null;
+ }
+ if (WEB_DOC_METHOD == null || !info.appSettings.showLineEndCommentHtml) {
+ return super.refDoc(info, ref);
+ }
+ PsiSymbolReferenceService service = PsiSymbolReferenceService.getService();
+ ArrayList references = new ArrayList<>();
+ try {
+ Object object = REF_METHOD.invoke(service, ref);
+ if (object instanceof Iterable) {
+ Iterable> objects = (Iterable>) object;
+ for (Object o : objects) {
+ if (o instanceof PsiSymbolReference) {
+ references.add(((PsiSymbolReference) o));
+ }
+ }
+ }
+ } catch (ProcessCanceledException ignored) {
+ return super.refDoc(info, ref);
+ } catch (Exception e) {
+ LOG.warn("Web Tag Attr getReferences fail: ", e);
+ }
+ if (references.isEmpty()) {
+ return super.refDoc(info, ref);
+ }
+ try {
+ // v-model:visible should only visible
+ for (Object symbol : references.get(references.size() - 1).resolveReference()) {
+ try {
+ Object doc = WEB_DOC_METHOD.invoke(symbol);
+ if (doc instanceof String) {
+ return DocFilter.html2Text((String) doc);
+ }
+ } catch (ProcessCanceledException ignored) {
+ } catch (Exception e) {
+ LOG.warn("Get Web Tag Attr Doc fail: ", e);
+ }
+ }
+ } catch (ProcessCanceledException ignored) {
+ } catch (Throwable e) {
+ LOG.warn("Web Tag Attr Doc resolveReference fail: ", e);
+ }
+ return super.refDoc(info, ref);
}
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java
index 7cd9568..d8f78e9 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java
@@ -113,6 +113,9 @@ public class DocFilter {
@NotNull
public static String html2Text(@NotNull String s) {
- return HTML_PATTERN.matcher(s).replaceAll(" ").trim();
+ return HTML_PATTERN.matcher(s).replaceAll(" ")
+ .replace("<", "<")
+ .replace(">", ">")
+ .trim();
}
}
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java
index 178c686..bf4b99a 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java
@@ -1,5 +1,8 @@
package io.github.linwancen.plugin.show.lang.base;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.xml.XmlAttribute;
+import com.intellij.psi.xml.XmlTag;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -27,6 +30,21 @@ public class DocSkip {
info.projectSettings.docInclude, info.projectSettings.docExclude);
}
+ public static boolean skipTagAttr(@NotNull T info, @NotNull PsiElement ref) {
+ if (ref instanceof XmlTag) {
+ String text = ((XmlTag) ref).getName();
+ return skipText(info, text,
+ info.globalSettings.tagInclude, info.globalSettings.tagExclude,
+ info.projectSettings.tagInclude, info.projectSettings.tagExclude);
+ } else if (ref instanceof XmlAttribute) {
+ String text = ((XmlAttribute) ref).getName();
+ return skipText(info, text,
+ info.globalSettings.attrInclude, info.globalSettings.attrExclude,
+ info.projectSettings.attrInclude, info.projectSettings.attrExclude);
+ }
+ return false;
+ }
+
static boolean skipText(@NotNull T info, @Nullable String text,
@NotNull Pattern appDocInclude, @NotNull Pattern appDocExclude,
@NotNull Pattern projectDocInclude, @NotNull Pattern projectDocExclude
diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java
index 3276f31..c88450c 100644
--- a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java
+++ b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java
@@ -23,6 +23,12 @@ public abstract class AbstractSettingsComponent {
private final JBTextField docInclude = new JBTextField();
private final JBTextField docExclude = new JBTextField();
+ private final JBTextField tagInclude = new JBTextField();
+ private final JBTextField tagExclude = new JBTextField();
+
+ private final JBTextField attrInclude = new JBTextField();
+ private final JBTextField attrExclude = new JBTextField();
+
private final JBCheckBox docGetEffect = new JBCheckBox("");
private final JBTextField docGet = new JBTextField();
private final JBCheckBox annoDocEffect = new JBCheckBox("");
@@ -52,6 +58,11 @@ public abstract class AbstractSettingsComponent {
.addSeparator()
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.include.regexp")), docInclude, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.exclude.regexp")), docExclude, 1, true)
+ .addSeparator()
+ .addLabeledComponent(new JBLabel(ShowBundle.message("tag.include.regexp")), tagInclude, 1, true)
+ .addLabeledComponent(new JBLabel(ShowBundle.message("tag.exclude.regexp")), tagExclude, 1, true)
+ .addLabeledComponent(new JBLabel(ShowBundle.message("attr.include.regexp")), attrInclude, 1, true)
+ .addLabeledComponent(new JBLabel(ShowBundle.message("attr.exclude.regexp")), attrExclude, 1, true)
.addSeparator();
Border border = docGet.getBorder();
annoDoc.setBorder(border);
@@ -132,6 +143,42 @@ public abstract class AbstractSettingsComponent {
docExclude.setText(newText);
}
+ @NotNull
+ public String getTagInclude() {
+ return tagInclude.getText();
+ }
+
+ public void setTagInclude(@NotNull String newText) {
+ tagInclude.setText(newText);
+ }
+
+ @NotNull
+ public String getTagExclude() {
+ return tagExclude.getText();
+ }
+
+ public void setTagExclude(@NotNull String newText) {
+ tagExclude.setText(newText);
+ }
+
+ @NotNull
+ public String getAttrInclude() {
+ return attrInclude.getText();
+ }
+
+ public void setAttrInclude(@NotNull String newText) {
+ attrInclude.setText(newText);
+ }
+
+ @NotNull
+ public String getAttrExclude() {
+ return attrExclude.getText();
+ }
+
+ public void setAttrExclude(@NotNull String newText) {
+ attrExclude.setText(newText);
+ }
+
public boolean getDocGetEffect() {
return docGetEffect.isSelected();
diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java
index df4caba..eb4d6ec 100644
--- a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java
+++ b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java
@@ -14,6 +14,10 @@ public class AbstractSettingsConfigurable {
modified |= !component.getLineExclude().equals(settings.getLineExclude());
modified |= !component.getDocInclude().equals(settings.getDocInclude());
modified |= !component.getDocExclude().equals(settings.getDocExclude());
+ modified |= !component.getTagInclude().equals(settings.getTagInclude());
+ modified |= !component.getTagExclude().equals(settings.getTagExclude());
+ modified |= !component.getAttrInclude().equals(settings.getAttrInclude());
+ modified |= !component.getAttrExclude().equals(settings.getAttrExclude());
modified |= component.getDocGetEffect() != settings.docGetEffect;
modified |= !component.getDocGet().equals(settings.getDocGet());
modified |= component.getAnnoDocEffect() != settings.annoDocEffect;
@@ -36,6 +40,10 @@ public class AbstractSettingsConfigurable {
settings.setLineExclude(component.getLineExclude());
settings.setDocInclude(component.getDocInclude());
settings.setDocExclude(component.getDocExclude());
+ settings.setTagInclude(component.getTagInclude());
+ settings.setTagExclude(component.getTagExclude());
+ settings.setAttrInclude(component.getAttrInclude());
+ settings.setAttrExclude(component.getAttrExclude());
settings.docGetEffect = component.getDocGetEffect();
settings.setDocGet(component.getDocGet());
settings.annoDocEffect = component.getAnnoDocEffect();
@@ -53,6 +61,10 @@ public class AbstractSettingsConfigurable {
component.setLineExclude(settings.getLineExclude());
component.setDocInclude(settings.getDocInclude());
component.setDocExclude(settings.getDocExclude());
+ component.setTagInclude(settings.getTagInclude());
+ component.setTagExclude(settings.getTagExclude());
+ component.setAttrInclude(settings.getAttrInclude());
+ component.setAttrExclude(settings.getAttrExclude());
component.setDocGetEffect(settings.docGetEffect);
component.setDocGet(settings.getDocGet());
component.setAnnoDocEffect(settings.annoDocEffect);
diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java
index bd6ce50..674ec3e 100644
--- a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java
+++ b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java
@@ -22,6 +22,14 @@ public abstract class AbstractSettingsState {
public transient Pattern docInclude = Pattern.compile("");
@NotNull
public transient Pattern docExclude = Pattern.compile("");
+ @NotNull
+ public transient Pattern tagInclude = Pattern.compile("");
+ @NotNull
+ public transient Pattern tagExclude = Pattern.compile("^(template|script|style)$");
+ @NotNull
+ public transient Pattern attrInclude = Pattern.compile("");
+ @NotNull
+ public transient Pattern attrExclude = Pattern.compile("^(v-[\\w-]*|ref|:?style|:?class|:key|@click|@change|@input)$");
public boolean docGetEffect = false;
@NotNull
@@ -92,6 +100,38 @@ public abstract class AbstractSettingsState {
this.docExclude = Pattern.compile(docExclude);
}
+ public String getTagInclude() {
+ return tagInclude.pattern();
+ }
+
+ public void setTagInclude(@NotNull String tagInclude) {
+ this.tagInclude = Pattern.compile(tagInclude);
+ }
+
+ public String getTagExclude() {
+ return tagExclude.pattern();
+ }
+
+ public void setTagExclude(@NotNull String tagExclude) {
+ this.tagExclude = Pattern.compile(tagExclude);
+ }
+
+ public String getAttrInclude() {
+ return attrInclude.pattern();
+ }
+
+ public void setAttrInclude(@NotNull String attrInclude) {
+ this.attrInclude = Pattern.compile(attrInclude);
+ }
+
+ public String getAttrExclude() {
+ return attrExclude.pattern();
+ }
+
+ public void setAttrExclude(@NotNull String attrExclude) {
+ this.attrExclude = Pattern.compile(attrExclude);
+ }
+
public String getDocGet() {
return docGet.pattern();
diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java
index d8a13ac..68de3c3 100644
--- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java
+++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java
@@ -43,6 +43,7 @@ public class AppSettingsComponent {
private final JBCheckBox showLineEndCommentSql = new JBCheckBox(" SQL ");
private final JBCheckBox showLineEndCommentJson = new JBCheckBox(" JSON ");
private final JBCheckBox showLineEndCommentYaml = new JBCheckBox(" YAML ");
+ private final JBCheckBox showLineEndCommentHtml = new JBCheckBox(" HTML ");
private final JBTextField treeTags = new JBTextField();
private final JBTextField lineTags = new JBTextField();
private final JBCheckBox skipAscii = new JBCheckBox(ShowBundle.message("skip.english"));
@@ -101,7 +102,8 @@ public class AppSettingsComponent {
showLineEndCommentRustBase,
showLineEndCommentCBase,
- showLineEndCommentSwiftBase
+ showLineEndCommentSwiftBase,
+ showLineEndCommentHtml
), 1)
.addLabeledComponent(new JBLabel(ShowBundle.message("tree.tags")), treeTags, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("line.tags")), lineTags, 1, true)
@@ -370,6 +372,14 @@ public class AppSettingsComponent {
showLineEndCommentYaml.setSelected(newStatus);
}
+ public boolean getShowLineEndCommentHtml() {
+ return showLineEndCommentHtml.isSelected();
+ }
+
+ public void setShowLineEndCommentHtml(boolean newStatus) {
+ showLineEndCommentHtml.setSelected(newStatus);
+ }
+
// endregion line end
@NotNull
diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java
index 5b3cc77..d9d8417 100644
--- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java
+++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java
@@ -64,6 +64,7 @@ public class AppSettingsConfigurable implements Configurable {
modified |= mySettingsComponent.getShowLineEndCommentSql() != settings.showLineEndCommentSql;
modified |= mySettingsComponent.getShowLineEndCommentJson() != settings.showLineEndCommentJson;
modified |= mySettingsComponent.getShowLineEndCommentYaml() != settings.showLineEndCommentYaml;
+ modified |= mySettingsComponent.getShowLineEndCommentHtml() != settings.showLineEndCommentHtml;
modified |= !mySettingsComponent.getTreeTags().equals(String.join("|", settings.treeTags));
modified |= !mySettingsComponent.getLineTags().equals(String.join("|", settings.lineTags));
@@ -115,6 +116,7 @@ public class AppSettingsConfigurable implements Configurable {
settings.showLineEndCommentSql = mySettingsComponent.getShowLineEndCommentSql();
settings.showLineEndCommentJson = mySettingsComponent.getShowLineEndCommentJson();
settings.showLineEndCommentYaml = mySettingsComponent.getShowLineEndCommentYaml();
+ settings.showLineEndCommentHtml = mySettingsComponent.getShowLineEndCommentHtml();
settings.treeTags = Splitter.on('|').splitToList(mySettingsComponent.getTreeTags()).toArray(new String[0]);
settings.lineTags = Splitter.on('|').splitToList(mySettingsComponent.getLineTags()).toArray(new String[0]);
@@ -169,6 +171,7 @@ public class AppSettingsConfigurable implements Configurable {
mySettingsComponent.setShowLineEndCommentSql(settings.showLineEndCommentSql);
mySettingsComponent.setShowLineEndCommentJson(settings.showLineEndCommentJson);
mySettingsComponent.setShowLineEndCommentYaml(settings.showLineEndCommentYaml);
+ mySettingsComponent.setShowLineEndCommentHtml(settings.showLineEndCommentHtml);
mySettingsComponent.setTreeTags(String.join("|", settings.treeTags));
mySettingsComponent.setLineTags(String.join("|", settings.lineTags));
diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java
index fbec79e..82495c7 100644
--- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java
+++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java
@@ -52,6 +52,7 @@ public class AppSettingsState implements PersistentStateComponent