2.09 python doc strings | Python 文档字符串 fixed #41
This commit is contained in:
@@ -113,6 +113,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.09 Add line-end-comment support Python doc strings
|
||||
<li>2.08 Add i18n and chinese
|
||||
<li>2.07 Add global-setting reset default
|
||||
<li>2.06 Add project-view-tree xx-abc.xxx from Abc.java doc
|
||||
@@ -150,6 +151,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.09 增加 行末注释 支持 Python 文档字符串
|
||||
<li>2.08 增加 多语言与中文支持
|
||||
<li>2.07 增加 全局设置 复位默认值
|
||||
<li>2.06 增加 文件树注释 xx-abc.xxx 来自 Abc.java 的文档注释
|
||||
|
||||
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'io.github.linwancen'
|
||||
version '2.08.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
version '2.09.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -87,6 +87,7 @@ patchPluginXml {
|
||||
changeNotes = """
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.09 Add line-end-comment support Python doc strings
|
||||
<li>2.08 Add i18n and chinese
|
||||
<li>2.07 Add global-setting reset default
|
||||
<li>2.06 Add project-view-tree xx-abc.xxx from Abc.java doc
|
||||
@@ -124,6 +125,7 @@ patchPluginXml {
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.09 增加 行末注释 支持 Python 文档字符串
|
||||
<li>2.08 增加 多语言与中文支持
|
||||
<li>2.07 增加 全局设置 复位默认值
|
||||
<li>2.06 增加 文件树注释 xx-abc.xxx 来自 Abc.java 的文档注释
|
||||
|
||||
@@ -2,12 +2,20 @@ package io.github.linwancen.plugin.show.lang;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.PythonLanguage;
|
||||
import com.jetbrains.python.documentation.docstrings.TagBasedDocString;
|
||||
import com.jetbrains.python.psi.PyDocStringOwner;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.StructuredDocString;
|
||||
import com.jetbrains.python.toolbox.Substring;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||
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.apache.commons.lang.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PythonLangDoc extends BaseLangDoc {
|
||||
public class PythonLangDoc extends BaseTagLangDoc<StructuredDocString> {
|
||||
|
||||
static {
|
||||
LANG_DOC_MAP.put(PythonLanguage.INSTANCE.getID(), new PythonLangDoc());
|
||||
@@ -22,4 +30,40 @@ public class PythonLangDoc extends BaseLangDoc {
|
||||
public boolean show(@NotNull LineInfo lineInfo) {
|
||||
return lineInfo.appSettings.showLineEndCommentPy;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected <T extends SettingsInfo> StructuredDocString toDocElement(@NotNull T settingsInfo,
|
||||
@NotNull PsiElement resolve) {
|
||||
if (resolve instanceof PyDocStringOwner) {
|
||||
@NotNull PyDocStringOwner pyDocStringOwner = (PyDocStringOwner) resolve;
|
||||
return pyDocStringOwner.getStructuredDocString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected <T extends SettingsInfo> String descDoc(@NotNull T lineInfo,
|
||||
@NotNull StructuredDocString structuredDocString) {
|
||||
String summary = structuredDocString.getSummary();
|
||||
if (StringUtils.isNotEmpty(summary)) {
|
||||
return summary;
|
||||
}
|
||||
@NotNull String description = structuredDocString.getDescription();
|
||||
return DocFilter.cutDoc(DocFilter.html2Text(description), lineInfo.appSettings, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T extends SettingsInfo> void appendTag(@NotNull T lineInfo, @NotNull StringBuilder tagStrBuilder,
|
||||
@NotNull StructuredDocString structuredDocString,
|
||||
@NotNull String name) {
|
||||
if (structuredDocString instanceof TagBasedDocString) {
|
||||
@Nullable Substring tagValue = ((TagBasedDocString) structuredDocString).getTagValue(name);
|
||||
if (tagValue != null) {
|
||||
@NotNull String cutDoc = DocFilter.cutDoc(tagValue.getValue(), lineInfo.appSettings, false);
|
||||
tagStrBuilder.append(cutDoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,9 +92,14 @@ public class DocFilter {
|
||||
* trim end with space
|
||||
*/
|
||||
public static void addHtml(@NotNull StringBuilder sb, @NotNull String s) {
|
||||
@NotNull String deleteHtml = HTML_PATTERN.matcher(s).replaceAll("").trim();
|
||||
@NotNull String deleteHtml = html2Text(s);
|
||||
if (deleteHtml.length() > 0) {
|
||||
sb.append(deleteHtml).append(" ");
|
||||
sb.append(deleteHtml);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String html2Text(@NotNull String s) {
|
||||
return HTML_PATTERN.matcher(s).replaceAll(" ").trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user