Skip to content

Commit bced7c4

Browse files
committed
2.12 Markdown and Asciidoc | 文件内容正则注释
1 parent b3c84d9 commit bced7c4

15 files changed

+302
-151
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Show doc comment at the Project view Tree, line End, json, other
112112

113113
<h2>English Change Notes:</h2>
114114
<ul>
115+
<li>2.12 Add project-view-tree support Markdown and Asciidoc
115116
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
116117
<li>2.10 Add line-end-comment not doc comment
117118
<li>2.09 Add line-end-comment support Python doc strings
@@ -152,6 +153,7 @@ Show doc comment at the Project view Tree, line End, json, other
152153

153154
<h2>中文更新说明:</h2>
154155
<ul>
156+
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
155157
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
156158
<li>2.10 增加 行末注释 非文档注释
157159
<li>2.09 增加 行末注释 支持 Python 文档字符串

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'io.github.linwancen'
7-
version '2.11.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
7+
version '2.12.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
88

99
repositories {
1010
mavenCentral()
@@ -87,6 +87,7 @@ patchPluginXml {
8787
changeNotes = """
8888
<h2>English Change Notes:</h2>
8989
<ul>
90+
<li>2.12 Add project-view-tree support Markdown and Asciidoc
9091
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
9192
<li>2.10 Add line-end-comment not doc comment
9293
<li>2.09 Add line-end-comment support Python doc strings
@@ -127,6 +128,7 @@ patchPluginXml {
127128
128129
<h2>中文更新说明:</h2>
129130
<ul>
131+
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
130132
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
131133
<li>2.10 增加 行末注释 非文档注释
132134
<li>2.09 增加 行末注释 支持 Python 文档字符串

src/main/java/io/github/linwancen/plugin/show/Tree.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.github.linwancen.plugin.show.ext.TreeExt;
1717
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
1818
import io.github.linwancen.plugin.show.settings.AppSettingsState;
19-
import io.github.linwancen.plugin.show.tree.ProjectDoc;
19+
import io.github.linwancen.plugin.show.tree.RelFileDoc;
2020
import org.jetbrains.annotations.NotNull;
2121
import org.jetbrains.annotations.Nullable;
2222
import org.slf4j.Logger;
@@ -49,7 +49,7 @@ private void decorateImpl(@NotNull ProjectViewNode node, @NotNull PresentationDa
4949
if (DumbService.isDumb(project)) {
5050
return;
5151
}
52-
DumbService.getInstance(project).smartInvokeLater(() ->
52+
DumbService.getInstance(project).runReadActionInSmartMode(() ->
5353
ApplicationManager.getApplication().runReadAction(() -> {
5454
@Nullable String doc = treeDoc(node, project);
5555
if (doc == null) {
@@ -59,13 +59,7 @@ private void decorateImpl(@NotNull ProjectViewNode node, @NotNull PresentationDa
5959
if (coloredText.isEmpty()) {
6060
data.addText(data.getPresentableText(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
6161
}
62-
@NotNull String text = " " + doc;
63-
for (@NotNull ColoredFragment fragment : coloredText) {
64-
if (text.equals(fragment.getText())) {
65-
return;
66-
}
67-
}
68-
data.addText(text, SimpleTextAttributes.GRAY_ATTRIBUTES);
62+
data.addText(" " + doc, SimpleTextAttributes.GRAY_ATTRIBUTES);
6963
}));
7064
}
7165

@@ -76,9 +70,9 @@ private String treeDoc(@NotNull ProjectViewNode<?> node, @NotNull Project projec
7670
return doc;
7771
}
7872
@NotNull SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.TREE);
79-
@Nullable String projectDoc = ProjectDoc.projectDoc(node, settingsInfo);
80-
if (projectDoc != null) {
81-
return projectDoc;
73+
@Nullable String relFileDoc = RelFileDoc.relFileDoc(node, settingsInfo);
74+
if (relFileDoc != null) {
75+
return relFileDoc;
8276
}
8377
Object value = node.getValue();
8478
if (value instanceof PsiElement) {

src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public abstract class AbstractSettingsComponent {
2424

2525
private final JBCheckBox docGetEffect = new JBCheckBox("");
2626
private final JBTextField docGet = new JBTextField();
27-
private final JBCheckBox projectDocEffect = new JBCheckBox("");
28-
private final JBTextArea projectDoc = new JBTextArea();
27+
private final JBCheckBox dirDocEffect = new JBCheckBox("");
28+
private final JBTextArea dirDoc = new JBTextArea();
29+
private final JBCheckBox fileDocEffect = new JBCheckBox("");
30+
private final JBTextArea fileDoc = new JBTextArea();
2931

3032
@NotNull
3133
protected JPanel commonPanel() {
@@ -57,9 +59,12 @@ protected JPanel lineEndPanel() {
5759

5860
@NotNull
5961
private JPanel treePanel() {
60-
@NotNull JPanel label = JPanelFactory.of(projectDocEffect, new JBLabel(ShowBundle.message("project.doc.regexp")));
62+
@NotNull JPanel dirLabel = JPanelFactory.of(dirDocEffect, new JBLabel(ShowBundle.message("dir.doc.regexp")));
63+
@NotNull JPanel fileLabel = JPanelFactory.of(fileDocEffect, new JBLabel(ShowBundle.message("file.doc.regexp")));
6164
JPanel panel = FormBuilder.createFormBuilder()
62-
.addLabeledComponent(label, projectDoc, 1, true).getPanel();
65+
.addLabeledComponent(dirLabel, dirDoc, 1, true)
66+
.addLabeledComponent(fileLabel, fileDoc, 1, true)
67+
.getPanel();
6368
panel.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("tree.comment")));
6469
return panel;
6570
}
@@ -137,20 +142,38 @@ public void setDocGet(@NotNull String newText) {
137142
}
138143

139144

140-
public boolean getProjectEffect() {
141-
return projectDocEffect.isSelected();
145+
public boolean getDirEffect() {
146+
return dirDocEffect.isSelected();
147+
}
148+
149+
public void setDirEffect(boolean newStatus) {
150+
dirDocEffect.setSelected(newStatus);
151+
}
152+
153+
@NotNull
154+
public String getDirDoc() {
155+
return dirDoc.getText();
156+
}
157+
158+
public void setDirDoc(@NotNull String newText) {
159+
dirDoc.setText(newText);
160+
}
161+
162+
163+
public boolean getFileEffect() {
164+
return fileDocEffect.isSelected();
142165
}
143166

144-
public void setProjectEffect(boolean newStatus) {
145-
projectDocEffect.setSelected(newStatus);
167+
public void setFileEffect(boolean newStatus) {
168+
fileDocEffect.setSelected(newStatus);
146169
}
147170

148171
@NotNull
149-
public String getProjectDoc() {
150-
return projectDoc.getText();
172+
public String getFileDoc() {
173+
return fileDoc.getText();
151174
}
152175

153-
public void setProjectDoc(@NotNull String newText) {
154-
projectDoc.setText(newText);
176+
public void setFileDoc(@NotNull String newText) {
177+
fileDoc.setText(newText);
155178
}
156179
}

src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ static boolean isModified(@NotNull AbstractSettingsState settings, @NotNull Abst
1616
modified |= !component.getDocExclude().equals(settings.getDocExclude());
1717
modified |= component.getDocGetEffect() != settings.docGetEffect;
1818
modified |= !component.getDocGet().equals(settings.getDocGet());
19-
modified |= component.getProjectEffect() != settings.projectDocEffect;
20-
modified |= !component.getProjectDoc().equals(settings.getProjectDoc());
19+
modified |= component.getDirEffect() != settings.dirDocEffect;
20+
modified |= !component.getDirDoc().equals(settings.getDirDoc());
21+
modified |= component.getFileEffect() != settings.fileDocEffect;
22+
modified |= !component.getFileDoc().equals(settings.getFileDoc());
2123
return modified;
2224
}
2325

@@ -34,8 +36,10 @@ static void apply(@NotNull AbstractSettingsState settings, @NotNull AbstractSett
3436
settings.setDocExclude(component.getDocExclude());
3537
settings.docGetEffect = component.getDocGetEffect();
3638
settings.setDocGet(component.getDocGet());
37-
settings.projectDocEffect = component.getProjectEffect();
38-
settings.setProjectDoc(component.getProjectDoc());
39+
settings.dirDocEffect = component.getDirEffect();
40+
settings.setDirDoc(component.getDirDoc());
41+
settings.fileDocEffect = component.getFileEffect();
42+
settings.setFileDoc(component.getFileDoc());
3943
}
4044

4145
static void reset(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) {
@@ -47,7 +51,9 @@ static void reset(@NotNull AbstractSettingsState settings, @NotNull AbstractSett
4751
component.setDocExclude(settings.getDocExclude());
4852
component.setDocGetEffect(settings.docGetEffect);
4953
component.setDocGet(settings.getDocGet());
50-
component.setProjectEffect(settings.projectDocEffect);
51-
component.setProjectDoc(settings.getProjectDoc());
54+
component.setDirEffect(settings.dirDocEffect);
55+
component.setDirDoc(settings.getDirDoc());
56+
component.setFileEffect(settings.fileDocEffect);
57+
component.setFileDoc(settings.getFileDoc());
5258
}
5359
}

src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import org.jetbrains.annotations.NotNull;
44

5-
import java.util.function.Function;
5+
import java.util.LinkedHashMap;
6+
import java.util.Map;
67
import java.util.regex.Pattern;
7-
import java.util.stream.Collectors;
8-
import java.util.stream.Stream;
98

109
public abstract class AbstractSettingsState {
1110

1211
public int lineEndCount = 2;
1312
public int lineEndLen = 0;
1413
public boolean onlySelectLine = false;
14+
1515
@NotNull
1616
public transient Pattern lineInclude = Pattern.compile("");
1717
@NotNull
@@ -20,21 +20,32 @@ public abstract class AbstractSettingsState {
2020
public transient Pattern docInclude = Pattern.compile("");
2121
@NotNull
2222
public transient Pattern docExclude = Pattern.compile("");
23+
2324
public boolean docGetEffect = false;
2425
@NotNull
2526
public transient Pattern docGet = Pattern.compile(".+?(?:[。\\r\\n]|\\. )");
26-
public boolean projectDocEffect = true;
27+
28+
public boolean dirDocEffect = true;
2729
@NotNull
28-
public transient Pattern[][] projectDoc = {
29-
{
30-
Pattern.compile("pom.xml"),
31-
Pattern.compile("<description>([^<]++)</description>"),
32-
Pattern.compile("<name>\\$\\{[^}]*+\\}([^<]++)</name>"),
33-
},
34-
{Pattern.compile("build.gradle"), Pattern.compile("^description[^'\"]*+['\"]([^'\"]++)['\"]")},
35-
{Pattern.compile("build.gradle.kts"), Pattern.compile("^description[^'\"]*+['\"]([^'\"]++)['\"]")},
36-
{Pattern.compile("README.md"), Pattern.compile("^# (.*)")},
37-
};
30+
public transient Map<String, Pattern[]> dirDoc = new LinkedHashMap<>() {{
31+
put("pom.xml", new Pattern[]{
32+
Pattern.compile("<description>([^<]++)</description>"),
33+
Pattern.compile("<name>\\$\\{[^}]*+\\}([^<]++)</name>"),
34+
});
35+
put("build.gradle", new Pattern[]{Pattern.compile("(?m)^description[^'\"]*+['\"]([^'\"]++)['\"]")});
36+
put("build.gradle.kts", new Pattern[]{Pattern.compile("(?m)^description[^'\"]*+['\"]([^'\"]++)['\"]")});
37+
put("README.md", new Pattern[]{Pattern.compile("(?m)^#++ (.*)")});
38+
}};
39+
40+
public boolean fileDocEffect = true;
41+
@NotNull
42+
public transient Map<String, Pattern[]> fileDoc = new LinkedHashMap<>() {{
43+
put("md", new Pattern[]{Pattern.compile("(?m)^#++ (.*)")});
44+
put("ad", new Pattern[]{Pattern.compile("(?m)^=++ (.*)")});
45+
put("adoc", new Pattern[]{Pattern.compile("(?m)^=++ (.*)")});
46+
put("asciidoc", new Pattern[]{Pattern.compile("(?m)^=++ (.*)")});
47+
}};
48+
3849

3950
public String getLineInclude() {
4051
return lineInclude.pattern();
@@ -79,30 +90,21 @@ public void setDocGet(@NotNull String docExclude) {
7990
}
8091

8192

82-
public static final Function<Pattern[], String> TO_LINE = patterns -> Stream.of(patterns)
83-
.map(Pattern::pattern)
84-
.collect(Collectors.joining("||"));
93+
@NotNull
94+
public String getDirDoc() {
95+
return PatternMapUtils.toString(dirDoc);
96+
}
8597

86-
public String getProjectDoc() {
87-
return Stream.of(projectDoc)
88-
.map(TO_LINE)
89-
.collect(Collectors.joining("\n"));
98+
public void setDirDoc(@NotNull String dirDoc) {
99+
this.dirDoc = PatternMapUtils.toMap(dirDoc);
100+
}
101+
102+
@NotNull
103+
public String getFileDoc() {
104+
return PatternMapUtils.toString(fileDoc);
90105
}
91106

92-
private static final Pattern LINE_PATTERN = Pattern.compile("[\\r\\n]++");
93-
94-
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\|\\|");
95-
96-
public void setProjectDoc(@NotNull String projectDoc) {
97-
String[] projectDocLines = LINE_PATTERN.split(projectDoc);
98-
@NotNull Pattern[][] patterns = new Pattern[projectDocLines.length][];
99-
for (int i = 0; i < projectDocLines.length; i++) {
100-
String[] projectDocs = SPLIT_PATTERN.split(projectDocLines[i]);
101-
patterns[i] = new Pattern[projectDocs.length];
102-
for (int j = 0; j < projectDocs.length; j++) {
103-
patterns[i][j] = Pattern.compile(projectDocs[j]);
104-
}
105-
}
106-
this.projectDoc = patterns;
107+
public void setFileDoc(@NotNull String fileDoc) {
108+
this.fileDoc = PatternMapUtils.toMap(fileDoc);
107109
}
108110
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.github.linwancen.plugin.show.settings;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import java.util.ArrayList;
8+
import java.util.LinkedHashMap;
9+
import java.util.Map;
10+
import java.util.function.Consumer;
11+
import java.util.regex.Pattern;
12+
import java.util.stream.Collectors;
13+
import java.util.stream.Stream;
14+
15+
public class PatternMapUtils {
16+
private static final Logger LOG = LoggerFactory.getLogger(PatternMapUtils.class);
17+
18+
public static final Pattern LINE_PATTERN = Pattern.compile("[\\r\\n]++");
19+
public static final Pattern SPLIT_PATTERN = Pattern.compile("\\|\\|");
20+
21+
@NotNull
22+
public static Map<String, Pattern[]> toMap(@NotNull String fileDoc) {
23+
String[] lines = LINE_PATTERN.split(fileDoc);
24+
@NotNull Map<String, Pattern[]> map = new LinkedHashMap<>(lines.length, 1);
25+
for (String line : lines) {
26+
String[] split = SPLIT_PATTERN.split(line);
27+
if (split.length > 1) {
28+
@NotNull ArrayList<Pattern> patterns = new ArrayList<>(split.length - 1);
29+
for (int i = 1; i < split.length; i++) {
30+
try {
31+
patterns.add(Pattern.compile(split[i]));
32+
} catch (Exception ignore) {}
33+
}
34+
map.put(split[0], patterns.toArray(new Pattern[0]));
35+
}
36+
}
37+
return map;
38+
}
39+
40+
@NotNull
41+
public static String toString(@NotNull Map<String, Pattern[]> patternMap) {
42+
return patternMap.entrySet().stream().map(entry ->
43+
entry.getKey() + "||" + Stream.of(entry.getValue())
44+
.map(Pattern::pattern)
45+
.collect(Collectors.joining("||"))
46+
).collect(Collectors.joining("\n"));
47+
}
48+
}

src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsState.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.jetbrains.annotations.NotNull;
99
import org.jetbrains.annotations.Nullable;
1010

11+
import java.util.Collections;
1112
import java.util.regex.Pattern;
1213

1314
@State(
@@ -18,8 +19,10 @@ public class ProjectSettingsState extends AbstractSettingsState implements Persi
1819

1920
public ProjectSettingsState() {
2021
this.lineExclude = Pattern.compile("");
21-
this.projectDocEffect = false;
22-
this.projectDoc = new Pattern[][]{};
22+
this.dirDocEffect = false;
23+
this.dirDoc = Collections.emptyMap();
24+
this.fileDocEffect = false;
25+
this.fileDoc = Collections.emptyMap();
2326
}
2427

2528
public static final ProjectSettingsState DEFAULT_SETTING = new ProjectSettingsState();

0 commit comments

Comments
 (0)