feat(PhpLangDoc): support PHP | 支持 PHP

This commit is contained in:
林万程
2024-02-08 10:07:41 +08:00
parent 10074b3ac7
commit 62c52fa93d
12 changed files with 155 additions and 12 deletions

View File

@@ -13,7 +13,7 @@ Show doc comment at the Project view Tree, line End, json, other
<h2>English Note</h2>
<ul>
<li>support Java Kotlin JS/TS Python Go Rust SQL
<li>support Java Kotlin JS/TS PHP Python Go Rust SQL
<li>tree doc from lang or README.md pom .gradle etc. by settings
<li>input `doc` `docc` -> /** */
<li>json doc from xxx.json.tsv
@@ -33,7 +33,7 @@ Show doc comment at the Project view Tree, line End, json, other
<li>In path, "doc" can replace any, and can use % like in SQL, effect at previous layer when folder named -1
<li>The lines in key.tsv will be concatenated with `|` to regexp; longer str should in front; startWith `?` to exclude
<li>Chang tsv file in find pop window would not reload!
<li>The tsv conf file must could be search in "Go to File"(Ctrl + Shift + N)
<li>The tsv conf file must could be search in "Go to File" (Ctrl + Shift + N)
</ul>
<h3>My Project</h3>
@@ -41,6 +41,9 @@ Show doc comment at the Project view Tree, line End, json, other
<li>Show doc comment at the Project view Tree, line End, json etc.:
<a href="https://plugins.jetbrains.com/plugin/18553-show-comment">Show Comment</a>
</li>
<li>show line count for file / method, show children count for dir in project view (tree on the left):
<a href="https://plugins.jetbrains.com/plugin/23300-line-num">Line Num</a>
</li>
<li>Method call usage graph and maven dependency graph:
<a href="https://plugins.jetbrains.com/plugin/21242-draw-graph">Draw Graph</a>
</li>
@@ -53,7 +56,7 @@ Show doc comment at the Project view Tree, line End, json, other
<hr>
<h2>中文说明</h2>
<ul>
<li>在行末尾显示 引用对象的文档注释,支持 Java Kotlin JS/TS Python Go Rust SQL
<li>在行末尾显示 引用对象的文档注释,支持 Java Kotlin JS/TS PHP Python Go Rust SQL
<li>在结构树显示 文件注释 或 项目说明 (README.md pom.xml 等,可设置)
<li>输入 doc / docc 等生成 /** */
<li>json 字段注释从 xxx.json.tsv 读取
@@ -82,6 +85,9 @@ Show doc comment at the Project view Tree, line End, json, other
<li>在文件树、行末、JSON 显示注释:
<a href="https://plugins.jetbrains.com/plugin/18553-show-comment">Show Comment</a>
</li>
<li>在文件树显示行数、文件数:
<a href="https://plugins.jetbrains.com/plugin/23300-line-num">Line Num</a>
</li>
<li>生成 方法调用图 和 Maven 依赖图:
<a href="https://plugins.jetbrains.com/plugin/21242-draw-graph">Draw Graph</a>
</li>
@@ -114,7 +120,7 @@ Show doc comment at the Project view Tree, line End, json, other
<h2>English Change Notes:</h2>
<ul>
<li>2.16 Add line-end-comment support Rust
<li>2.16 Add line-end-comment support Rust, PHP
<li>2.15 Add line-end-comment java anno doc
<li>2.14 Add line-end-comment java enum doc for Yes(1, "Yes")
<li>2.13 ★ Cache for 2023.3
@@ -159,7 +165,7 @@ Show doc comment at the Project view Tree, line End, json, other
<h2>中文更新说明:</h2>
<ul>
<li>2.16 增加 行末注释 支持 Rust
<li>2.16 增加 行末注释 支持 Rust, PHP
<li>2.15 增加 行末注释 java 注解注释
<li>2.14 增加 行末注释 java 枚举注释用于 Yes(1, "是")
<li>2.13 ★ 缓存用于支持 2023.3

View File

@@ -29,9 +29,11 @@ intellij {
}
// see https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-plugins
plugins = [
'PsiViewer:201.6251.22-EAP-SNAPSHOT.3', // only for runIde when dev
'Pythonid:201.6668.121',
'org.rust.lang:0.3.131.3366-201',
'org.toml.lang:0.2.131.3366-201',
'com.jetbrains.php:201.6668.153',
// 'com.jetbrains.rust:232.9921.46',
// 'Pythonid:212.5284.44',
]
@@ -91,7 +93,7 @@ patchPluginXml {
changeNotes = """
<h2>English Change Notes:</h2>
<ul>
<li>2.16 Add line-end-comment support Rust
<li>2.16 Add line-end-comment support Rust, PHP
<li>2.15 Add line-end-comment java anno doc
<li>2.14 Add line-end-comment java enum doc for Yes(1, "Yes")
<li>2.13 ★ Cache for 2023.3
@@ -136,7 +138,7 @@ patchPluginXml {
<h2>中文更新说明:</h2>
<ul>
<li>2.16 增加 行末注释 支持 Rust
<li>2.16 增加 行末注释 支持 Rust, PHP
<li>2.15 增加 行末注释 java 注解注释
<li>2.14 增加 行末注释 java 枚举注释用于 Yes(1, "是")
<li>2.13 ★ 缓存用于支持 2023.3

View File

@@ -0,0 +1,71 @@
package io.github.linwancen.plugin.show.lang;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.php.lang.PhpLanguage;
import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment;
import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocRef;
import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag;
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
import com.jetbrains.php.lang.psi.elements.PhpReference;
import io.github.linwancen.plugin.show.bean.LineInfo;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import io.github.linwancen.plugin.show.lang.base.BaseTagLangDoc;
import io.github.linwancen.plugin.show.lang.base.DocFilter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class PhpLangDoc extends BaseTagLangDoc<PhpDocComment> {
static {
LANG_DOC_MAP.put(PhpLanguage.INSTANCE.getID(), new PhpLangDoc());
}
@Override
public @NotNull List<Class<? extends PsiElement>> getRefClass() {
return List.of(PhpReference.class, PhpDocRef.class);
}
@Override
public boolean show(@NotNull LineInfo info) {
return info.appSettings.showLineEndCommentPhp;
}
@Override
protected <T extends SettingsInfo> boolean parseBaseComment(@NotNull T info) {
return info.appSettings.showLineEndCommentPhpBase;
}
@Nullable
@Override
protected <T extends SettingsInfo> PhpDocComment toDocElement(@NotNull T info, @NotNull PsiElement resolve) {
if (resolve instanceof PhpNamedElement) {
@NotNull PhpNamedElement phpNamedElement = (PhpNamedElement) resolve;
return phpNamedElement.getDocComment();
}
return null;
}
@NotNull
@Override
protected <T extends SettingsInfo> String descDoc(@NotNull T info, @NotNull PhpDocComment phpDocComment) {
String text = phpDocComment.getText();
return DocFilter.cutDoc(text, info, true);
}
@Override
protected <T extends SettingsInfo> void appendTag(@NotNull T info, @NotNull StringBuilder tagStrBuilder,
@NotNull PhpDocComment phpDocComment, @NotNull String name) {
@Nullable PhpDocTag[] tags = PsiTreeUtil.getChildrenOfType(phpDocComment, PhpDocTag.class);
if (tags == null) {
return;
}
for (@NotNull PhpDocTag tag : tags) {
if (("@" + name).equals(tag.getName())) {
tagStrBuilder.append(tag.getTagValue());
}
}
}
}

View File

@@ -90,6 +90,10 @@ public class Prev {
public static @Nullable <T extends SettingsInfo> PsiElement prevCompactElement(
@SuppressWarnings("unused") @NotNull T info, @NotNull PsiElement resolve, @NotNull Document document) {
@Nullable PsiElement element = PsiTreeUtil.prevVisibleLeaf(resolve);
@Nullable PsiComment psiComment = PsiTreeUtil.getParentOfType(element, PsiComment.class);
if (psiComment != null) {
return psiComment;
}
if (element == null) {
return null;
}

View File

@@ -67,7 +67,7 @@ public class ResolveDoc {
if (document == null) {
return null;
}
@Nullable PsiElement psiElement = PsiTreeUtil.getChildOfType(resolve, PsiComment.class);
@Nullable PsiElement psiElement = PsiTreeUtil.findChildOfType(resolve, PsiComment.class);
if (psiElement == null) {
psiElement = Prev.prevCompactElement(info, resolve, document);
}

View File

@@ -27,6 +27,8 @@ public class AppSettingsComponent {
private final JBCheckBox showLineEndCommentKotlinBase = new JBCheckBox("// Kotlin ");
private final JBCheckBox showLineEndCommentJs = new JBCheckBox(" js ");
private final JBCheckBox showLineEndCommentJsBase = new JBCheckBox("// js ");
private final JBCheckBox showLineEndCommentPhp = new JBCheckBox(" php ");
private final JBCheckBox showLineEndCommentPhpBase = new JBCheckBox("// php ");
private final JBCheckBox showLineEndCommentPy = new JBCheckBox(" Python ");
private final JBCheckBox showLineEndCommentPyBase = new JBCheckBox("# Python ");
private final JBCheckBox showLineEndCommentGo = new JBCheckBox(" Go ");
@@ -66,6 +68,7 @@ public class AppSettingsComponent {
showLineEndCommentJava,
showLineEndCommentKotlin,
showLineEndCommentJs,
showLineEndCommentPhp,
showLineEndCommentPy,
showLineEndCommentGo,
showLineEndCommentSql,
@@ -75,6 +78,7 @@ public class AppSettingsComponent {
showLineEndCommentJavaBase,
showLineEndCommentKotlinBase,
showLineEndCommentJsBase,
showLineEndCommentPhpBase,
showLineEndCommentPyBase,
showLineEndCommentRustBase
), 1)
@@ -184,6 +188,14 @@ public class AppSettingsComponent {
showLineEndCommentJs.setSelected(newStatus);
}
public boolean getShowLineEndCommentPhp() {
return showLineEndCommentPhp.isSelected();
}
public void setShowLineEndCommentPhp(boolean newStatus) {
showLineEndCommentPhp.setSelected(newStatus);
}
public boolean getShowLineEndCommentPy() {
return showLineEndCommentPy.isSelected();
}
@@ -224,6 +236,14 @@ public class AppSettingsComponent {
showLineEndCommentJsBase.setSelected(newStatus);
}
public boolean getShowLineEndCommentPhpBase() {
return showLineEndCommentPhpBase.isSelected();
}
public void setShowLineEndCommentPhpBase(boolean newStatus) {
showLineEndCommentPhpBase.setSelected(newStatus);
}
public boolean getShowLineEndCommentPyBase() {
return showLineEndCommentPyBase.isSelected();
}

View File

@@ -44,11 +44,13 @@ public class AppSettingsConfigurable implements Configurable {
modified |= mySettingsComponent.getShowLineEndCommentJava() != settings.showLineEndCommentJava;
modified |= mySettingsComponent.getShowLineEndCommentKotlin() != settings.showLineEndCommentKotlin;
modified |= mySettingsComponent.getShowLineEndCommentJs() != settings.showLineEndCommentJs;
modified |= mySettingsComponent.getShowLineEndCommentPhp() != settings.showLineEndCommentPhp;
modified |= mySettingsComponent.getShowLineEndCommentPy() != settings.showLineEndCommentPy;
modified |= mySettingsComponent.getShowLineEndCommentGo() != settings.showLineEndCommentGo;
modified |= mySettingsComponent.getShowLineEndCommentJavaBase() != settings.showLineEndCommentJavaBase;
modified |= mySettingsComponent.getShowLineEndCommentKotlinBase() != settings.showLineEndCommentKotlinBase;
modified |= mySettingsComponent.getShowLineEndCommentJsBase() != settings.showLineEndCommentJsBase;
modified |= mySettingsComponent.getShowLineEndCommentPhpBase() != settings.showLineEndCommentPhpBase;
modified |= mySettingsComponent.getShowLineEndCommentPyBase() != settings.showLineEndCommentPyBase;
modified |= mySettingsComponent.getShowLineEndCommentGoBase() != settings.showLineEndCommentGoBase;
modified |= mySettingsComponent.getShowLineEndCommentRustBase() != settings.showLineEndCommentRustBase;
@@ -84,11 +86,13 @@ public class AppSettingsConfigurable implements Configurable {
settings.showLineEndCommentJava = mySettingsComponent.getShowLineEndCommentJava();
settings.showLineEndCommentKotlin = mySettingsComponent.getShowLineEndCommentKotlin();
settings.showLineEndCommentJs = mySettingsComponent.getShowLineEndCommentJs();
settings.showLineEndCommentPhp = mySettingsComponent.getShowLineEndCommentPhp();
settings.showLineEndCommentPy = mySettingsComponent.getShowLineEndCommentPy();
settings.showLineEndCommentGo = mySettingsComponent.getShowLineEndCommentGo();
settings.showLineEndCommentJavaBase = mySettingsComponent.getShowLineEndCommentJavaBase();
settings.showLineEndCommentKotlinBase = mySettingsComponent.getShowLineEndCommentKotlinBase();
settings.showLineEndCommentJsBase = mySettingsComponent.getShowLineEndCommentJsBase();
settings.showLineEndCommentPhpBase = mySettingsComponent.getShowLineEndCommentPhpBase();
settings.showLineEndCommentPyBase = mySettingsComponent.getShowLineEndCommentPyBase();
settings.showLineEndCommentGoBase = mySettingsComponent.getShowLineEndCommentGoBase();
settings.showLineEndCommentRustBase = mySettingsComponent.getShowLineEndCommentRustBase();
@@ -127,11 +131,13 @@ public class AppSettingsConfigurable implements Configurable {
mySettingsComponent.setShowLineEndCommentJava(settings.showLineEndCommentJava);
mySettingsComponent.setShowLineEndCommentKotlin(settings.showLineEndCommentKotlin);
mySettingsComponent.setShowLineEndCommentJs(settings.showLineEndCommentJs);
mySettingsComponent.setShowLineEndCommentPhp(settings.showLineEndCommentPhp);
mySettingsComponent.setShowLineEndCommentPy(settings.showLineEndCommentPy);
mySettingsComponent.setShowLineEndCommentGo(settings.showLineEndCommentGo);
mySettingsComponent.setShowLineEndCommentJavaBase(settings.showLineEndCommentJavaBase);
mySettingsComponent.setShowLineEndCommentKotlinBase(settings.showLineEndCommentKotlinBase);
mySettingsComponent.setShowLineEndCommentJsBase(settings.showLineEndCommentJsBase);
mySettingsComponent.setShowLineEndCommentPhpBase(settings.showLineEndCommentPhpBase);
mySettingsComponent.setShowLineEndCommentPyBase(settings.showLineEndCommentPyBase);
mySettingsComponent.setShowLineEndCommentGoBase(settings.showLineEndCommentGoBase);
mySettingsComponent.setShowLineEndCommentRustBase(settings.showLineEndCommentRustBase);

View File

@@ -35,6 +35,8 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
public boolean showLineEndCommentKotlinBase = false;
public boolean showLineEndCommentJs = true;
public boolean showLineEndCommentJsBase = false;
public boolean showLineEndCommentPhp = true;
public boolean showLineEndCommentPhpBase = false;
public boolean showLineEndCommentPy = true;
public boolean showLineEndCommentPyBase = false;
public boolean showLineEndCommentGo = true;

View File

@@ -0,0 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<editor.linePainter implementation="io.github.linwancen.plugin.show.lang.PhpLangDoc"/>
</extensions>
</idea-plugin>

View File

@@ -11,7 +11,7 @@ Show doc comment at the Project view Tree, line End, json, other
<h2>English Note</h2>
<ul>
<li>support Java Kotlin JS/TS Python Go Rust SQL
<li>support Java Kotlin JS/TS PHP Python Go Rust SQL
<li>tree doc from lang or README.md pom .gradle etc. by settings
<li>input `doc` `docc` -> /** */
<li>json doc from xxx.json.tsv
@@ -31,7 +31,7 @@ Show doc comment at the Project view Tree, line End, json, other
<li>In path, "doc" can replace any, and can use % like in SQL, effect at previous layer when folder named -1
<li>The lines in key.tsv will be concatenated with `|` to regexp; longer str should in front; startWith `?` to exclude
<li>Chang tsv file in find pop window would not reload!
<li>The tsv conf file must could be search in "Go to File"(Ctrl + Shift + N)
<li>The tsv conf file must could be search in "Go to File" (Ctrl + Shift + N)
</ul>
<h3>My Project</h3>
@@ -39,6 +39,9 @@ Show doc comment at the Project view Tree, line End, json, other
<li>Show doc comment at the Project view Tree, line End, json etc.:
<a href="https://plugins.jetbrains.com/plugin/18553-show-comment">Show Comment</a>
</li>
<li>show line count for file / method, show children count for dir in project view (tree on left):
<a href="https://plugins.jetbrains.com/plugin/23300-line-num">Line Num</a>
</li>
<li>Method call usage graph and maven dependency graph:
<a href="https://plugins.jetbrains.com/plugin/21242-draw-graph">Draw Graph</a>
</li>
@@ -51,7 +54,7 @@ Show doc comment at the Project view Tree, line End, json, other
<hr>
<h2>中文说明</h2>
<ul>
<li>在行末尾显示 引用对象的文档注释,支持 Java Kotlin JS/TS Python Go Rust SQL
<li>在行末尾显示 引用对象的文档注释,支持 Java Kotlin JS/TS PHP Python Go Rust SQL
<li>在结构树显示 文件注释 或 项目说明 (README.md pom.xml 等,可设置)
<li>输入 doc / docc 等生成 /** */
<li>json 字段注释从 xxx.json.tsv 读取
@@ -80,6 +83,9 @@ Show doc comment at the Project view Tree, line End, json, other
<li>在文件树、行末、JSON 显示注释:
<a href="https://plugins.jetbrains.com/plugin/18553-show-comment">Show Comment</a>
</li>
<li>在文件树显示行数、文件数:
<a href="https://plugins.jetbrains.com/plugin/23300-line-num">Line Num</a>
</li>
<li>生成 方法调用图 和 Maven 依赖图:
<a href="https://plugins.jetbrains.com/plugin/21242-draw-graph">Draw Graph</a>
</li>
@@ -118,8 +124,9 @@ Show doc comment at the Project view Tree, line End, json, other
<depends optional="true" config-file="python.xml">com.intellij.modules.python</depends>
<depends optional="true" config-file="go.xml">org.jetbrains.plugins.go</depends>
<!-- old version -->
<depends optional="true" config-file="rust.xml">org.rust.lang</depends>
<depends optional="true" config-file="rust_old.xml">org.rust.lang</depends>
<depends optional="true" config-file="rust.xml">com.jetbrains.rust</depends>
<depends optional="true" config-file="php.xml">com.jetbrains.php</depends>
<!--suppress PluginXmlValidity, MybatisMapperXmlInspection -->
<!--<depends optional="true" config-file="cs.xml">com.intellij.modules.rider</depends>-->

View File

@@ -0,0 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<editor.linePainter implementation="io.github.linwancen.plugin.show.lang.RustLangDoc"/>
</extensions>
</idea-plugin>

View File

@@ -0,0 +1,15 @@
<?php
/*
* file tree doc at first
*/
fun();
/**
* fun
* {@link fun}
* @author author
*/
function fun() {
return 'Hello';
}