Skip to content

Commit

Permalink
1. 树列表渲染
Browse files Browse the repository at this point in the history
2. 完善注释展示
3. 支持编辑行注释
4. 修改 Dubbo 上传 YApi 支持
  • Loading branch information
liuzhihang committed Aug 6, 2021
1 parent c090567 commit 11bafb0
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 43 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ Doc View
特征
----

- Controller/Dubbo 接口文档生成
- 支持 validation、swagger 等注解
- Markdown 接口查看、预览、复制、导出
- 支持自定义生成接口的 Markdown 模版
- 支持界面编辑文档、注释、并同步保存到代码注释中
- 支持在编辑实体界面, 将实体复制为 Json 字符串
- 支持上传文档到 YApi
- 支持上传文档到 ShowDoc
- 支持自定义配置
- [x] Controller/Dubbo 接口文档生成
- [x] 支持 validation、swagger 等注解
- [x] Markdown 接口查看、预览、复制、导出
- [x] 支持自定义生成接口的 Markdown 模版
- [x] 支持界面编辑文档、注释、并同步保存到代码注释或 Swagger 注解中
- [x] 支持在编辑实体界面, 将实体复制为 Json 字符串
- [x] 支持上传文档到 YApi
- [x] 支持上传文档到 ShowDoc
- [x] 支持自定义配置

演示
----

![1111-l7NaTW](https://cdn.jsdelivr.net/gh/liuzhihang/oss/pic/article/1111-l7NaTW.gif)
![](https://cdn.jsdelivr.net/gh/liuzhihang/oss/pic/article/122-zbZ9ps.gif)
![](https://cdn.jsdelivr.net/gh/liuzhihang/oss/pic/article/0YyY3m-CQdmD6.gif)

[更多截图演示](https://github.com/liuzhihang/doc-view/discussions/17)

Expand Down
16 changes: 15 additions & 1 deletion parts/changeNotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ <h4>English introduction</h4>
<ul>
<li>1.1.7
<ol>
<li>Added support for uploading documents to ShowDoc</li>
<li>Doc Editor UI adjusted to tree list</li>
<li>Doc Editor supports required and description of Swagger annotations</li>
<li>Modify the situation that the Dubbo interface cannot upload YApi</li>
<li>Fix String type field parsing error</li>
<li>Modify the condition that no comment fields are required by default</li>
<li>Support parsing field line comments and converting them to Java Doc comments after editing</li>
<li>Fixes for some other problems</li>
</ol>
</li>
<li><a href="https://github.com/liuzhihang/doc-view/blob/master/doc/ChangeNotes.md">More records</a></li>
Expand All @@ -14,8 +20,16 @@ <h4>中文介绍</h4>
<ul>
<li>1.1.7
<ol>
<li>Doc Editor UI 调整为树列表</li>
<li>Doc Editor 支持 Swagger 注解的必填和描述</li>
<li>修改 Dubbo 接口无法上传 YApi 的情况</li>
<li>修复 String 类型字段解析错误</li>
<li>修改无注释字段默认必填的情况</li>
<li>支持解析字段行注释,并在编辑后转换为 Java Doc 注释</li>
<li>其他一些问题的修复</li>
<li>备注:当前版本使用 swingx-core 依赖生成 TreeTable, 导致插件包占用空间变大, 需要后期调整, 具体可参考:
https://youtrack.jetbrains.com/issue/IDEA-275249 ,如果小伙伴有其他解决方式, 希望可以联系我,或者提 Issue.
</li>
</ol>
</li>
<li><a href="https://github.com/liuzhihang/doc-view/blob/master/doc/ChangeNotes.md">更多记录</a></li>
Expand Down
4 changes: 2 additions & 2 deletions parts/pluginDescription.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>Generate Markdown documents based on the interface</h1>
<br/>
<br/>

The Markdown document is generated based on the interface and can be previewed, edited, and uploaded to YApi.
The Markdown document is generated based on the interface and can be previewed, edited, and uploaded to YApi or ShowDoc.
<br/>
<br/>

Expand All @@ -32,7 +32,7 @@ <h1>Generate Markdown documents based on the interface</h1>
<br/>
<br/>

基于接口生成 Markdown 文档, 支持预览、编辑以及上传到YApi。
基于接口生成 Markdown 文档, 支持预览、编辑以及上传到YApi、ShowDoc
<br/>
<br/>
<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class YApiSettings implements PersistentStateComponent<YApiSettings> {

private String token;


public static YApiSettings getInstance(@NotNull Project project) {
return ServiceManager.getService(project, YApiSettings.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void upload(@NotNull Project project, @NotNull DocView docView) {

if (docView.getMethod().equals("Dubbo")) {
// dubbo 接口处理
save.setPath("/Dubbo/" + docView.getName());
save.setPath("/Dubbo/" + docView.getPsiMethod().getName());
save.setMethod("POST");
} else {
save.setMethod(docView.getMethod());
Expand All @@ -95,7 +95,7 @@ public void upload(@NotNull Project project, @NotNull DocView docView) {
save.setReqQuery(buildReqQuery(docView.getReqParamList()));
save.setResBodyType("json");
save.setResBody(buildJsonSchema(docView.getRespRootBody().getChildList()));
save.setDesc(buildDesc(docView));
save.setMarkdown(buildDesc(docView));
save.setTitle(docView.getName());

if (docView.getReqExampleType().equals("json")) {
Expand All @@ -109,7 +109,7 @@ public void upload(@NotNull Project project, @NotNull DocView docView) {

DocViewNotification.notifyInfo(project, DocViewBundle.message("notify.yapi.upload.success", yapiInterfaceUrl));
} catch (Exception e) {
DocViewNotification.notifyError(project, DocViewBundle.message("notify.yapi.upload.error"));
DocViewNotification.notifyError(project, DocViewBundle.message("notify.yapi.upload.error", e.getMessage()));
log.error("上传单个文档失败:{}", docView, e);
}

Expand All @@ -125,9 +125,11 @@ public void upload(@NotNull Project project, @NotNull DocView docView) {
private String buildDesc(DocView docView) {


return "**接口描述:**\n"
return "**接口名称:**\n\n"
+ docView.getName() + "\n\n"
+ "**接口描述:**\n\n"
+ docView.getDesc() + "\n\n"
+ "**请求示例:**\n"
+ "**请求示例:**\n\n"
+ docView.getReqExample() + "\n\n"
+ "**返回示例:**\n\n"
+ docView.getRespExample();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void popup() {
.setCancelOnClickOutside(false)
// 在其他窗口打开时取消
.setCancelOnOtherWindowOpen(false)
.setMinSize(new Dimension(600, 380))
.setCancelOnWindowDeactivation(false)
.createPopup();
popup.showCenteredInCurrentWindow(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void popup() {
.setCancelOnClickOutside(false)
// 在其他窗口打开时取消
.setCancelOnOtherWindowOpen(false)
.setMinSize(new Dimension(600, 380))
.setCancelOnWindowDeactivation(false)
.createPopup();
popup.showCenteredInCurrentWindow(project);
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/liuzhihang/doc/view/ui/ParamDocEditorForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ParamDocEditorForm {
private final Editor editor;
private final PsiClass psiClass;

private ParamTreeTableModel treeTableModel;
private JXTreeTable treeTable;

private JPanel rootPanel;
private JPanel headToolbarPanel;
Expand Down Expand Up @@ -118,6 +118,7 @@ public void popup() {
.setCancelOnClickOutside(false)
// 在其他窗口打开时取消
.setCancelOnOtherWindowOpen(false)
.setMinSize(new Dimension(600, 380))
.setCancelOnWindowDeactivation(false)
.createPopup();
popup.showCenteredInCurrentWindow(project);
Expand Down Expand Up @@ -206,7 +207,11 @@ public void actionPerformed(@NotNull AnActionEvent e) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {

DocViewUtils.writeComment(project, treeTableModel.getModifiedMap());
if (treeTable.isEditing()) {
treeTable.getCellEditor().stopCellEditing();
}

DocViewUtils.writeComment(project, ((ParamTreeTableModel) treeTable.getTreeTableModel()).getModifiedMap());
popup.cancel();
}
});
Expand Down Expand Up @@ -243,9 +248,7 @@ private void initParamTable() {
DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(paramData);
ParamTreeTableUtils.createTreeData(rootNode, dataList);

treeTableModel = new ParamTreeTableModel(rootNode);

JXTreeTable treeTable = new JXTreeTable(treeTableModel);
treeTable = new JXTreeTable(new ParamTreeTableModel(rootNode));

ParamTreeTableUtils.render(treeTable);

Expand All @@ -254,6 +257,4 @@ private void initParamTable() {
}




}
1 change: 1 addition & 0 deletions src/main/java/com/liuzhihang/doc/view/ui/PreviewForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void popup() {
.setCancelOnClickOutside(false)
// 在其他窗口打开时取消
.setCancelOnOtherWindowOpen(false)
.setMinSize(new Dimension(600, 380))
.setCancelOnWindowDeactivation(false)
.createPopup();
popup.showCenteredInCurrentWindow(project);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.liuzhihang.doc.view.utils;

import com.google.common.collect.Lists;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocTag;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class CustomPsiCommentUtils {
* @return
*/
@NotNull
public static String getComment(PsiDocComment docComment, String tagName) {
public static String getDocComment(PsiDocComment docComment, String tagName) {

if (docComment != null) {
for (PsiElement element : docComment.getChildren()) {
Expand All @@ -57,7 +58,7 @@ public static String getComment(PsiDocComment docComment, String tagName) {
* @return
*/
@NotNull
public static String getComment(PsiDocComment docComment) {
public static String getDocComment(PsiDocComment docComment) {

StringBuilder sb = new StringBuilder();

Expand All @@ -75,6 +76,19 @@ public static String getComment(PsiDocComment docComment) {
return sb.toString();
}

@NotNull
public static String getComment(PsiComment psiComment) {


if (psiComment != null && StringUtils.isNotBlank(psiComment.getText())) {
// 原注释中的换行符移除
return psiComment.getText().replace("/", StringUtils.EMPTY).trim();

}
return "";
}


/**
* 保留换行
*
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/com/liuzhihang/doc/view/utils/DocViewUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.liuzhihang.doc.view.config.Settings;
import com.liuzhihang.doc.view.constant.SwaggerConstant;
import com.liuzhihang.doc.view.dto.DocViewParamData;
Expand Down Expand Up @@ -47,7 +48,7 @@ public static String getTitle(@NotNull PsiClass psiClass) {

if (settings.getTitleUseCommentTag()) {
// 注释 @DocView.Title
String docTitleTagValue = CustomPsiCommentUtils.getComment(psiClass.getDocComment(), settings.getTitleTag());
String docTitleTagValue = CustomPsiCommentUtils.getDocComment(psiClass.getDocComment(), settings.getTitleTag());

if (StringUtils.isNotBlank(docTitleTagValue)) {
return docTitleTagValue;
Expand All @@ -57,7 +58,7 @@ public static String getTitle(@NotNull PsiClass psiClass) {
if (settings.getTitleClassComment()) {
// 获取类注释

String comment = CustomPsiCommentUtils.getComment(psiClass.getDocComment());
String comment = CustomPsiCommentUtils.getDocComment(psiClass.getDocComment());

if (StringUtils.isNotBlank(comment)) {
return comment;
Expand Down Expand Up @@ -120,7 +121,7 @@ public static String getName(@NotNull PsiMethod psiMethod) {

// 注释上的 tag
if (settings.getNameUseCommentTag()) {
String comment = CustomPsiCommentUtils.getComment(psiMethod.getDocComment(), settings.getNameTag());
String comment = CustomPsiCommentUtils.getDocComment(psiMethod.getDocComment(), settings.getNameTag());

if (StringUtils.isNotBlank(comment)) {
return comment;
Expand All @@ -130,7 +131,7 @@ public static String getName(@NotNull PsiMethod psiMethod) {
if (settings.getNameMethodComment()) {
// 获取类注释

String comment = CustomPsiCommentUtils.getComment(psiMethod.getDocComment());
String comment = CustomPsiCommentUtils.getDocComment(psiMethod.getDocComment());

if (StringUtils.isNotBlank(comment)) {
return comment;
Expand Down Expand Up @@ -175,7 +176,7 @@ public static String getMethodDesc(@NotNull PsiMethod psiMethod) {
}
// 最后从注释中获取

return CustomPsiCommentUtils.getComment(psiMethod.getDocComment());
return CustomPsiCommentUtils.getDocComment(psiMethod.getDocComment());
}


Expand Down Expand Up @@ -326,12 +327,16 @@ public static String fieldDesc(@NotNull PsiField psiField) {
}
}

PsiDocComment docComment = psiField.getDocComment();

if (docComment != null) {
PsiComment comment = PsiTreeUtil.findChildOfType(psiField, PsiComment.class);

if (comment != null) {
// param.setExample();
// 参数举例, 使用 tag 判断
return CustomPsiCommentUtils.getComment(docComment);
if (comment instanceof PsiDocComment) {
return CustomPsiCommentUtils.getDocComment((PsiDocComment) comment);
}
return CustomPsiCommentUtils.getComment(comment);
}
return "";
}
Expand All @@ -343,7 +348,7 @@ public static void writeComment(Project project, @NotNull Map<PsiElement, DocVie

for (PsiElement element : modifyBodyMap.keySet()) {
DocViewParamData data = modifyBodyMap.get(element);
String comment;
String docComment;

PsiField psiField = (PsiField) element;

Expand Down Expand Up @@ -399,20 +404,27 @@ public static void writeComment(Project project, @NotNull Map<PsiElement, DocVie

// 不修改原有注解
if (!DocViewUtils.isRequired(psiField) && data.getRequired()) {
comment = "/** "
docComment = "/** "
+ data.getDesc() + "\n"
+ "* @" + Settings.getInstance(project).getRequired()
+ " */";
} else {
comment = "/** "
docComment = "/** "
+ data.getDesc()
+ " */";
}

PsiComment comment = PsiTreeUtil.findChildOfType(psiField, PsiComment.class);

if (comment != null && !(comment instanceof PsiDocComment)) {
WriteCommandAction.runWriteCommandAction(project, comment::delete);
}

PsiElementFactory factory = PsiElementFactory.getInstance(project);
PsiDocComment psiDocComment = factory.createDocCommentFromText(comment);
PsiDocComment psiDocComment = factory.createDocCommentFromText(docComment);
ServiceManager.getService(WriterService.class).write(project, element, psiDocComment);


}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.liuzhihang.doc.view.utils;

import com.liuzhihang.doc.view.dto.DocViewData;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
Expand Down Expand Up @@ -41,7 +40,7 @@ public static String convert(String template, DocViewData data) {
velocityContext.put("DocView", data);
boolean isSuccess = engine.evaluate(velocityContext, writer, VM_LOG_TAG, template);
if (!isSuccess) {

return "ERROR";
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages/DocViewBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ notify.dubbo.error.no.method=\u5F53\u524D\u63A5\u53E3\u4E2D\u6CA1\u6709\u65B9\u6
notify.spring.error.method=\u5F53\u524D\u65B9\u6CD5\u4E0D\u6EE1\u8DB3\u6761\u4EF6!
notify.spring.error.no.method=\u5F53\u524D Controller \u4E2D\u6CA1\u6709\u6EE1\u8DB3\u6761\u4EF6\u7684\u65B9\u6CD5!
notify.yapi.info.settings=\u8BF7\u6DFB\u52A0 YApi \u76F8\u5173\u914D\u7F6E
notify.yapi.upload.error=\u63A5\u53E3\u4E0A\u4F20 YApi \u5931\u8D25
notify.yapi.upload.error=\u63A5\u53E3\u4E0A\u4F20 YApi \u5931\u8D25:{0}
notify.yapi.upload.success=\u63A5\u53E3\u4E0A\u4F20 YApi \u6210\u529F, \u63A5\u53E3\u5730\u5740\u4E3A: <p><a href={0}>{0}</a>
notify.yapi.project.id=\u9879\u76EE id (projectId) \u8BF7\u8F93\u5165\u6570\u5B57
notify.showdoc.info.settings=\u8BF7\u6DFB\u52A0 ShowDoc \u76F8\u5173\u914D\u7F6E
Expand Down

0 comments on commit 11bafb0

Please sign in to comment.