feat: 2.25 use xml/html/vue 1st or 2nd line comment for tree doc | 用 xml/html/vue 第 1 或第 2 行注释当文件注释
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'io.github.linwancen'
|
||||
version '2.24.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
version '2.25.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
|
||||
patchPluginXml {
|
||||
// The performance of 2019.3 has been greatly improved.
|
||||
@@ -15,10 +15,11 @@ patchPluginXml {
|
||||
changeNotes = """
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.25 Add project-view-tree use xml/html/vue 1st or 2nd line comment
|
||||
<li>2.24 Add line-end-comment Maven pom.xml \${} doc
|
||||
<li>2.23 Add line-end-comment kotlin anno doc
|
||||
<li>2.22 Add project-view-tree ollama models blobs comment from manifests
|
||||
<li>2.21 Add project-view-tree use JS/TS/Vue "export default" doc for tree doc
|
||||
<li>2.21 Add project-view-tree use JS/TS/Vue "export default" 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.18 Add line-end-comment support injected language like SQL
|
||||
@@ -68,6 +69,7 @@ patchPluginXml {
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.21 增加 文件树注释 用 xml/html/vue 第 1 或第 2 行注释当文件注释
|
||||
<li>2.24 增加 行末注释 Maven pom.xml \${} 注释
|
||||
<li>2.23 增加 行末注释 kotlin 注解注释
|
||||
<li>2.22 增加 文件树注释 ollama models 文件夹从 manifests 获取 blobs 文件注释
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package io.github.linwancen.plugin.show.lang;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import io.github.linwancen.plugin.show.ext.listener.FileLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* for html, in here because {@code <!--} is based XML
|
||||
*/
|
||||
public class XmlCache extends FileLoader {
|
||||
|
||||
public static void indexDocToDirDoc(@NotNull VirtualFile virtualFile, @Nullable String doc) {
|
||||
if (doc != null && "index".equals(virtualFile.getNameWithoutExtension())) {
|
||||
VirtualFile parent = virtualFile.getParent();
|
||||
if (parent != null) {
|
||||
@Nullable XmlCache extension = FileLoader.EPN.findExtension(XmlCache.class);
|
||||
if (extension != null) {
|
||||
extension.fileDoc.put(parent, doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllImpl(Project project) {}
|
||||
|
||||
@Override
|
||||
protected void loadFileImpl(@NotNull VirtualFile file, @Nullable Project project) {}
|
||||
}
|
||||
@@ -1,12 +1,19 @@
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -29,6 +36,53 @@ public class XmlLangDoc extends BaseLangDoc {
|
||||
return true;
|
||||
}
|
||||
|
||||
@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 FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(virtualFile);
|
||||
if (viewProvider == null) {
|
||||
return null;
|
||||
}
|
||||
PsiElement psiElement = viewProvider.findElementAt(0);
|
||||
if (psiElement == null || !"<!--".equals(psiElement.getText())) {
|
||||
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 <!DOCTYPE html>
|
||||
int i = document.getLineStartOffset(1);
|
||||
psiElement = viewProvider.findElementAt(i);
|
||||
}
|
||||
if (psiElement == null || !"<!--".equals(psiElement.getText())) {
|
||||
return null;
|
||||
}
|
||||
PsiElement parent = psiElement.getParent();
|
||||
if (!(parent instanceof PsiComment)) {
|
||||
return null;
|
||||
}
|
||||
PsiElement[] children = parent.getChildren();
|
||||
if (children.length < 2) {
|
||||
return null;
|
||||
}
|
||||
String doc = children[1].getText();
|
||||
// Copyright or copyright
|
||||
//noinspection SpellCheckingInspection
|
||||
if (doc == null || doc.contains("opyright")) {
|
||||
return null;
|
||||
}
|
||||
XmlCache.indexDocToDirDoc(virtualFile, doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String findRefDoc(@NotNull LineInfo info, @NotNull FileViewProvider viewProvider, @NotNull PsiElement element) {
|
||||
|
||||
@@ -169,6 +169,7 @@ Show doc comment in the Project view Tree, line End, json, other
|
||||
</extensionPoints>
|
||||
<extensions defaultExtensionNs="io.github.linwancen.show-comment">
|
||||
<fileLoader implementation="io.github.linwancen.plugin.show.ext.conf.ConfCache"/>
|
||||
<fileLoader implementation="io.github.linwancen.plugin.show.lang.XmlCache"/>
|
||||
<fileLoader implementation="io.github.linwancen.plugin.show.ext.ollama.OllamaModelsCache"/>
|
||||
</extensions>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user