diff --git a/build.gradle b/build.gradle
index 3fad938..2c7126d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'io.github.linwancen'
-version '2.26.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
+version '2.27.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
patchPluginXml {
// The performance of 2019.3 has been greatly improved.
@@ -15,6 +15,7 @@ patchPluginXml {
changeNotes = """
English Change Notes:
+- 2.27 Add project-view-tree use 1st or 2nd line to file comment
- 2.26 Add External Comment load *.sql ddl comment
- 2.25 Add project-view-tree use xml/html/vue 1st or 2nd line comment
- 2.24 Add line-end-comment Maven pom.xml \${} doc
@@ -70,6 +71,7 @@ patchPluginXml {
中文更新说明:
+- 2.27 增加 文件树注释 用第 1 或第 2 行注释当文件注释
- 2.26 增加 外部注释 读取 *.sql ddl 注释
- 2.25 增加 文件树注释 用 xml/html/vue 第 1 或第 2 行注释当文件注释
- 2.24 增加 行末注释 Maven pom.xml \${} 注释
diff --git a/src/main/java/io/github/linwancen/plugin/show/Tree.java b/src/main/java/io/github/linwancen/plugin/show/Tree.java
index 79f883e..bd1a967 100644
--- a/src/main/java/io/github/linwancen/plugin/show/Tree.java
+++ b/src/main/java/io/github/linwancen/plugin/show/Tree.java
@@ -19,6 +19,7 @@ import io.github.linwancen.plugin.show.ext.TreeExt;
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.tree.RelFileDoc;
+import io.github.linwancen.plugin.show.tree.first.FirstDoc;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@@ -104,7 +105,7 @@ public class Tree implements ProjectViewNodeDecorator {
return s;
}
}
- return null;
+ return FirstDoc.firstDoc(node, info);
}
@Override
diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/XmlLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/XmlLangDoc.java
index 45e2a86..e57ebb0 100644
--- a/src/main/java/io/github/linwancen/plugin/show/lang/XmlLangDoc.java
+++ b/src/main/java/io/github/linwancen/plugin/show/lang/XmlLangDoc.java
@@ -1,21 +1,13 @@
package io.github.linwancen.plugin.show.lang;
-import com.intellij.ide.projectView.ProjectViewNode;
import com.intellij.lang.xml.XMLLanguage;
-import com.intellij.openapi.editor.Document;
import com.intellij.openapi.extensions.ExtensionPointName;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.FileViewProvider;
-import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiManager;
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.bean.SettingsInfo;
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
-import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -37,53 +29,6 @@ public class XmlLangDoc extends BaseLangDoc {
return true;
}
- @Override
- public @Nullable String treeDoc(@NotNull T info, @NotNull ProjectViewNode> node,
- @NotNull Project project) {
- @Nullable VirtualFile virtualFile = node.getVirtualFile();
- if (virtualFile == null || virtualFile.isDirectory()) {
- return null;
- }
- @Nullable FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(virtualFile);
- if (viewProvider == null) {
- return null;
- }
- @Nullable PsiElement psiElement = viewProvider.findElementAt(0);
- if (psiElement == null || !"
+ "|.*.*"
);
private static final Pattern LINE_SEPARATOR_PATTERN = Pattern.compile("[\r\n]");
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 68de3c3..1c2746f 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
@@ -18,6 +18,7 @@ public class AppSettingsComponent {
private final JBCheckBox showTreeComment = new JBCheckBox(ShowBundle.message("show.tree.comment"));
private final JBCheckBox compact = new JBCheckBox(ShowBundle.message("compact"));
private final JBCheckBox treeCache = new JBCheckBox(ShowBundle.message("tree.cache"));
+ private final JBCheckBox treeFirst = new JBCheckBox(ShowBundle.message("tree.first"));
private final JBCheckBox showLineEndComment = new JBCheckBox(ShowBundle.message("show.line.end.comment"));
private final JBCheckBox lineEndCache = new JBCheckBox(ShowBundle.message("line.end.cache"));
private final JBCheckBox showLineEndCommentJava = new JBCheckBox(" Java ");
@@ -57,86 +58,7 @@ public class AppSettingsComponent {
private final ColorPanel lineEndJsonColor = new ColorPanel();
private final JBTextField lineEndPrefix = new JBTextField();
- public AppSettingsComponent() {
- @NotNull JButton resetDefault = new JButton(ShowBundle.message("reset.default"));
- resetDefault.addActionListener(e -> AppSettingsConfigurable.reset(AppSettingsState.DEFAULT_SETTING, this));
- myMainPanel = FormBuilder.createFormBuilder()
- .addComponent(JPanelFactory.of(resetDefault), 1)
- .addComponent(showPanel(), 1)
- .addComponent(lineEndFilterPanel(), 1)
- .addComponentFillVertically(new JPanel(), 0)
- .getPanel();
- }
-
- @NotNull
- private JPanel showPanel() {
- JPanel comment = FormBuilder.createFormBuilder()
- .addComponent(JPanelFactory.of(showTreeComment, treeCache, compact), 1)
- .addComponent(JPanelFactory.of(showLineEndComment, lineEndCache), 1)
- .addComponent(JPanelFactory.of(
- showLineEndCommentJava,
- showLineEndCommentKotlin,
- showLineEndCommentScala,
- showLineEndCommentGroovy
- ), 1)
- .addComponent(JPanelFactory.of(
- showLineEndCommentJavaBase,
- showLineEndCommentKotlinBase,
- showLineEndCommentScalaBase,
- showLineEndCommentGroovyBase
- ), 1)
- .addComponent(JPanelFactory.of(
- showLineEndCommentJs,
- showLineEndCommentPhp,
- showLineEndCommentPy,
-
- showLineEndCommentGo,
- showLineEndCommentSql,
- showLineEndCommentJson,
- showLineEndCommentYaml
- ), 1)
- .addComponent(JPanelFactory.of(
- showLineEndCommentJsBase,
- showLineEndCommentPhpBase,
- showLineEndCommentPyBase,
-
- showLineEndCommentRustBase,
- showLineEndCommentCBase,
- showLineEndCommentSwiftBase,
- showLineEndCommentHtml
- ), 1)
- .addLabeledComponent(new JBLabel(ShowBundle.message("tree.tags")), treeTags, 1, true)
- .addLabeledComponent(new JBLabel(ShowBundle.message("line.tags")), lineTags, 1, true)
- .getPanel();
- comment.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("show")));
- return comment;
- }
-
- @NotNull
- protected JPanel lineEndFilterPanel() {
- @NotNull JPanel text = JPanelFactory.of(
- new JBLabel(ShowBundle.message("text.color")), lineEndColor,
- new JBLabel(ShowBundle.message("text.color.json")), lineEndJsonColor,
- new JBLabel(ShowBundle.message("prefix")), lineEndPrefix);
- FormBuilder formBuilder = FormBuilder.createFormBuilder()
- .addSeparator()
- .addComponent(JPanelFactory.of(skipAscii, skipBlank, skipAnnotation, getToSet), 1)
- .addComponent(JPanelFactory.of(fromNew, fromParam, enumDoc), 1)
- .addSeparator()
- .addComponent(text)
- .addSeparator();
- return formBuilder.getPanel();
- }
-
- public JPanel getPanel() {
- return myMainPanel;
- }
-
- @NotNull
- public JComponent getPreferredFocusedComponent() {
- return showTreeComment;
- }
-
+ // move get set near field for AI
public boolean getShowTreeComment() {
return showTreeComment.isSelected();
@@ -162,6 +84,14 @@ public class AppSettingsComponent {
treeCache.setSelected(newStatus);
}
+ public boolean getTreeFirst() {
+ return treeFirst.isSelected();
+ }
+
+ public void setTreeFirst(boolean newStatus) {
+ treeFirst.setSelected(newStatus);
+ }
+
@NotNull
public String getTreeTags() {
return treeTags.getText();
@@ -473,4 +403,85 @@ public class AppSettingsComponent {
public void setLineEndPrefix(@NotNull String newText) {
lineEndPrefix.setText(newText);
}
+
+
+ public AppSettingsComponent() {
+ @NotNull JButton resetDefault = new JButton(ShowBundle.message("reset.default"));
+ resetDefault.addActionListener(e -> AppSettingsConfigurable.reset(AppSettingsState.DEFAULT_SETTING, this));
+ myMainPanel = FormBuilder.createFormBuilder()
+ .addComponent(JPanelFactory.of(resetDefault), 1)
+ .addComponent(showPanel(), 1)
+ .addComponent(lineEndFilterPanel(), 1)
+ .addComponentFillVertically(new JPanel(), 0)
+ .getPanel();
+ }
+
+ @NotNull
+ private JPanel showPanel() {
+ JPanel comment = FormBuilder.createFormBuilder()
+ .addComponent(JPanelFactory.of(showTreeComment, treeCache, compact, treeFirst), 1)
+ .addComponent(JPanelFactory.of(showLineEndComment, lineEndCache), 1)
+ .addComponent(JPanelFactory.of(
+ showLineEndCommentJava,
+ showLineEndCommentKotlin,
+ showLineEndCommentScala,
+ showLineEndCommentGroovy
+ ), 1)
+ .addComponent(JPanelFactory.of(
+ showLineEndCommentJavaBase,
+ showLineEndCommentKotlinBase,
+ showLineEndCommentScalaBase,
+ showLineEndCommentGroovyBase
+ ), 1)
+ .addComponent(JPanelFactory.of(
+ showLineEndCommentJs,
+ showLineEndCommentPhp,
+ showLineEndCommentPy,
+
+ showLineEndCommentGo,
+ showLineEndCommentSql,
+ showLineEndCommentJson,
+ showLineEndCommentYaml
+ ), 1)
+ .addComponent(JPanelFactory.of(
+ showLineEndCommentJsBase,
+ showLineEndCommentPhpBase,
+ showLineEndCommentPyBase,
+
+ showLineEndCommentRustBase,
+ showLineEndCommentCBase,
+ showLineEndCommentSwiftBase,
+ showLineEndCommentHtml
+ ), 1)
+ .addLabeledComponent(new JBLabel(ShowBundle.message("tree.tags")), treeTags, 1, true)
+ .addLabeledComponent(new JBLabel(ShowBundle.message("line.tags")), lineTags, 1, true)
+ .getPanel();
+ comment.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("show")));
+ return comment;
+ }
+
+ @NotNull
+ protected JPanel lineEndFilterPanel() {
+ @NotNull JPanel text = JPanelFactory.of(
+ new JBLabel(ShowBundle.message("text.color")), lineEndColor,
+ new JBLabel(ShowBundle.message("text.color.json")), lineEndJsonColor,
+ new JBLabel(ShowBundle.message("prefix")), lineEndPrefix);
+ FormBuilder formBuilder = FormBuilder.createFormBuilder()
+ .addSeparator()
+ .addComponent(JPanelFactory.of(skipAscii, skipBlank, skipAnnotation, getToSet), 1)
+ .addComponent(JPanelFactory.of(fromNew, fromParam, enumDoc), 1)
+ .addSeparator()
+ .addComponent(text)
+ .addSeparator();
+ return formBuilder.getPanel();
+ }
+
+ public JPanel getPanel() {
+ return myMainPanel;
+ }
+
+ @NotNull
+ public JComponent getPreferredFocusedComponent() {
+ return showTreeComment;
+ }
}
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 d9d8417..91012c6 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
@@ -38,6 +38,7 @@ public class AppSettingsConfigurable implements Configurable {
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
modified |= mySettingsComponent.getCompact() != settings.compact;
modified |= mySettingsComponent.getTreeCache() != settings.treeCache;
+ modified |= mySettingsComponent.getTreeFirst() != settings.treeFirst;
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
modified |= mySettingsComponent.getLineEndCache() != settings.lineEndCache;
@@ -90,6 +91,7 @@ public class AppSettingsConfigurable implements Configurable {
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
settings.compact = mySettingsComponent.getCompact();
settings.treeCache = mySettingsComponent.getTreeCache();
+ settings.treeFirst = mySettingsComponent.getTreeFirst();
settings.showLineEndComment = mySettingsComponent.getShowLineEndComment();
settings.lineEndCache = mySettingsComponent.getLineEndCache();
@@ -145,6 +147,7 @@ public class AppSettingsConfigurable implements Configurable {
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
mySettingsComponent.setCompact(settings.compact);
mySettingsComponent.setTreeCache(settings.treeCache);
+ mySettingsComponent.setTreeFirst(settings.treeFirst);
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
mySettingsComponent.setLineEndCache(settings.lineEndCache);
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 82495c7..0c12c1e 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
@@ -26,6 +26,7 @@ public class AppSettingsState implements PersistentStateComponent node, @NotNull SettingsInfo info) {
+ if (!info.appSettings.treeFirst) {
+ return null;
+ }
+ @Nullable VirtualFile virtualFile = node.getVirtualFile();
+ if (virtualFile == null || virtualFile.isDirectory()) {
+ return null;
+ }
+ Project project = node.getProject();
+ if (project == null) {
+ return null;
+ }
+ @Nullable FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(virtualFile);
+ if (viewProvider == null) {
+ return null;
+ }
+ @Nullable PsiElement psiElement = viewProvider.findElementAt(0);
+ if (psiElement == null || notDoc(psiElement)) {
+ @Nullable Document document = viewProvider.getDocument();
+ if (document == null) {
+ return null;
+ }
+ int lineCount = document.getLineCount();
+ // lineNumber start 0, as 1 <= 1 should return
+ if (lineCount <= 1) {
+ return null;
+ }
+ // because in HTML 1st line must
+ int i = document.getLineStartOffset(1);
+ psiElement = viewProvider.findElementAt(i);
+ if (psiElement == null || notDoc(psiElement)) {
+ return null;
+ }
+ }
+ if (!(psiElement instanceof PsiComment)) {
+ psiElement = psiElement.getParent();
+ if (!(psiElement instanceof PsiComment)) {
+ return null;
+ }
+ }
+ @NotNull String doc = PsiUnSaveUtils.getText(psiElement);
+ // Copyright or copyright
+ //noinspection SpellCheckingInspection
+ if (doc.contains("opyright")) {
+ return null;
+ }
+ String cutDoc = DocFilter.cutDoc(doc, info, true);
+ FirstDocToDirCache.indexDocToDirDoc(virtualFile, cutDoc);
+ return cutDoc;
+ }
+
+ private static final Pattern COMMENT_PATTERN = Pattern.compile("