Skip to content

Commit

Permalink
Update READNE
Browse files Browse the repository at this point in the history
  • Loading branch information
anqiansong committed Apr 29, 2022
1 parent 7007af0 commit 9e2432d
Show file tree
Hide file tree
Showing 28 changed files with 242 additions and 61 deletions.
21 changes: 21 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# 2022-04-29(1.1.0)
* rpc 代码生成支持 `goctl rpc protoc`
* 新增支持弹窗选择 `style`,`output`,`proto_path`,`goclt home` 等信息填写
* 支持快速代码生成
* 新增支持 `timeout` 语法
* 新增支持 Java 风格文档注释
* 修复部分语法错误

# 2022-01-20(1.0.0)
* 支持跨文件跳转

# 2021-11-25(v0.7.18)
* 修复多个 `prefix` 值重复问题
*
# 2021-10-22(v0.7.17)
* 支持绝对路径
* 支持 `prefix`

# 2021-10-05(v0.7.16)
* 优化 goctl not found 问题

# 2020-10-18(v0.6.8)
* 新增支持import语法
* 新增支持@handler语法
Expand Down
106 changes: 63 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Go-Zero Plugin
# goctl intellij Plugin
中文简体 | [English](README_EN.md)

[![go-zero](https://img.shields.io/badge/Github-go--zero-brightgreen?logo=github)](https://github.com/tal-tech/go-zero)
[![license](https://img.shields.io/badge/License-MIT-blue)](https://github.com/zeromicro/goctl-intellij/blob/main/LICENSE)
[![license](https://img.shields.io/badge/Release-0.7.14-red)](https://github.com/zeromicro/goctl-intellij/releases)
[![Java CI with Gradle](https://github.com/zeromicro/goctl-intellij/workflows/Java%20CI%20with%20Gradle/badge.svg)](https://github.com/zeromicro/goctl-intellij/actions)
[![license](https://img.shields.io/badge/Release-1.1.0-red)](https://github.com/zeromicro/goctl-intellij/releases)

# 介绍
一款支持go-zero api语言结构语法高亮、检测以及api、rpc、model快捷生成的插件工具。
Expand Down Expand Up @@ -37,32 +37,74 @@

# 新建 Api file

在工程区域目标文件夹`右键->New-> New Api File ->Empty File/Api Template`,如图:
在工程区域目标文件夹`右键 -> New -> New Api File -> Empty File/Api Template`,如图:

![preview](./src/main/resources/static/api_new.png)
![preview](./src/main/resources/static/new.png)

# 新建 Proto File
在工程区目标文件夹`右键->New-> New Proto File -> Empty File/Proto Template`,如图:

在工程区目标文件夹`右键 -> New -> New Proto File -> Empty File/Proto Template`,如图:
![preview](./src/main/resources/static/new_proto.png)
![preview](./src/main/resources/static/proto.png)

# 快速生成api/rpc服务
在目标文件夹`右键->New->Go Zero -> Api Greet Service/Rpc Greet Service`
在目标文件夹`右键 -> New -> Go Zero -> Api Greet Service/Rpc Greet Service`

![preview](./src/main/resources/static/service.png)

# Api/Rpc/Model Code生成

## 方法一(工程区域)

对应文件(api、proto、sql)`右键->New->Go Zero-> Api/Rpc/Model Code`,如图:

![preview](./src/main/resources/static/project_generate_code.png)

## 方法二(编辑区域)
对应文件(api、proto、sql)`右键-> Generate-> Api/Rpc/Model Code`


# Api 代码生成
## 1. api 文件右键生成
![preview](./src/main/resources/static/project_api_code_gen.png)

## 2. api 文件编辑区右键生成
![preview](./src/main/resources/static/editor_api_code_gen.png)

## Api 代码生成说明
`API Code Generation``API Quick Code Generation` 的区别是:
- `API Code Generation``goctl` 的相关指令参数均使用指定值,其代码生成指令内容如下:
```shell
$ goctl api go --api=${API 文件路径} --style=gozero --home="~/.goctl" --dir=${API 文件所在文件夹}
```
- `API Quick Code Generation` 会打开弹窗让使用者填写 `--style``-- dir``--home` 等信息
![preview](./src/main/resources/static/api_code_gen_dialog.png)

# zRPC 代码生成
## 1. proto 文件右键生成
![preview](./src/main/resources/static/project_zrpc_code_gen.png)

## 2. proto 文件编辑区右键生成
![preview](./src/main/resources/static/editor_zrpc_code_gen.png)

## zRPC 代码生成说明
`ZRPC Code Generation``ZRPC Quick Code Generation` 的区别是:
- `ZRPC Code Generation``goctl` 的相关指令参数均使用指定值,其代码生成指令内容如下:
```shell
$ goctl rpc protoc ${proto 文件路径} --style=gozero --home="~/.goctl" --go_out=${API 文件所在文件夹} --grpc-go_out=${API 文件所在文件夹} --zrpc_out=${API 文件所在文件夹}
```
- `ZRPC Quick Code Generation` 会打开弹窗让使用者填写 `--style``-- dir``--home`,`proto_path`(如果有 import 其他 proto 文件) 等信息
- 无 import 情况
![preview](./src/main/resources/static/api_code_gen_dialog.png)
- 有 import 情况,proto_path 目前只支持但文件选择,因此 **不支持 import 自不同文件夹的 proto**
![preview](./src/main/resources/static/rpc_code_gen_dialog.png)

# Model 代码生成
## 1. sql 文件右键生成
![preview](./src/main/resources/static/project_model_code_gen.png)

## 2. sql 文件编辑区右键生成
![preview](./src/main/resources/static/editor_model_code_gen.png)

## Model 代码生成说明
**Model 代码生成默认都是带缓存的。**

`Model Code Generation``Model Quick Code Generation` 的区别是:
- `Model Code Generation``goctl` 的相关指令参数均使用指定值,其代码生成指令内容如下:
```shell
$ goctl model mysql ddl --src=${sql 文件路径} --dir=${sql 文件所在文件夹} --style=gozero -c --home="~/.goctl"
```
- `Model Quick Code Generation` 会打开弹窗让使用者填写 `--style``-- dir``--home``--cache` 等信息
![preview](./src/main/resources/static/api_code_gen_dialog.png)
-
# 错误提示
![context menu](./src/main/resources/static/alert.png)

Expand All @@ -78,10 +120,7 @@ func main(){
![context menu](./src/main/resources/static/go_live_template.png)

下面就进入今天api语法中的模板使用说明吧,我们先来看看service模板的效果
![context menu](./src/main/resources/static/live_template.gif)

首先上一张图了解一下api文件中几个模板生效区域(psiTree元素区域)
![context menu](./src/main/resources/static/psiTree.png)
![context menu](./src/main/resources/static/live_preview.gif)

#### 预设模板及生效区域
| 模板关键字 | psiTree生效区域 |描述
Expand All @@ -104,23 +143,4 @@ func main(){
| json | Tag|Tag literal |tag模板|
| xml | Tag|Tag literal |tag模板|
| path | Tag|Tag literal |tag模板|
| form | Tag|Tag literal |tag模板|

关于每个模板对应内容可在`Goland(mac Os)->Preference->Editor->Live Templates-> Api|Api Tags`中查看详细模板内容,如json tag模板内容为
```golang
json:"$FIELD_NAME$"
```
![context menu](./src/main/resources/static/json_tag.png)

> 注意: 关键字区分大小写


# 注意事项
目前api文件中,仅type block支持单行注释,但目前idea并没有对其他block单行注释进行报错,这个是需要后期完善的功能。后续陆续将api文件中都支持单行注释。

# 待完善功能
* 语法、语义检测优化
* 完善高亮优化
* 完善智能提示
* Find Usages
| form | Tag|Tag literal |tag模板|
150 changes: 150 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# goctl intellij Plugin
[中文简体](README.md) | English

[![go-zero](https://img.shields.io/badge/Github-go--zero-brightgreen?logo=github)](https://github.com/tal-tech/go-zero)
[![license](https://img.shields.io/badge/License-MIT-blue)](https://github.com/zeromicro/goctl-intellij/blob/main/LICENSE)
[![license](https://img.shields.io/badge/Release-1.1.0-red)](https://github.com/zeromicro/goctl-intellij/releases)

# Introduction
A plugin tool that supports go-zero api language structure syntax highlighting, detection, and api, rpc, and model shortcut generation.


# idea version requirements

No less than 193.0 (2019.3)

# Version features

* api syntax highlighting
* api syntax, semantic detection
* struct, route, handler duplicate definition detection
* type jump to type declaration location
* context menu support api, rpc, mode related menu options
* Code formatting (option+command+L)
* Code hinting

# Installation methods

## Way 1
Find the latest zip package in the github release, download and install it locally. (No need to decompress)

## Way 2
In the plugin store, just search for `Goctl` and install it (currently the adopted version in the store is relatively low.)


## Preview
![preview](./src/main/resources/static/api_colorful.png)

# New Api file

In the project area target folder ` Right click -> New -> New Api File -> Empty File/Api Template`, as shown in the figure.

![preview](./src/main/resources/static/api_new.png)
![preview](./src/main/resources/static/new.png)

# New Proto File
In the project area target folder `Right click -> New -> New Proto File -> Empty File/Proto Template`, as shown in the figure.
![preview](./src/main/resources/static/new_proto.png)
![preview](./src/main/resources/static/proto.png)

# Quickly generate api/rpc service
In the target folder ` Right click -> New -> Go Zero -> Api Greet Service/Rpc Greet Service`

![preview](./src/main/resources/static/service.png)

# Api code generation
## 1. api file right click to generate
![preview](./src/main/resources/static/project_api_code_gen.png)

## 2. api file edit area right-click generation
![preview](./src/main/resources/static/editor_api_code_gen.png)

## Api code generation instructions
The difference between `API Code Generation` and `API Quick Code Generation` is that
- `API Code Generation` in `goctl` uses the specified values for the relevant command parameters, and its code generation instructions read as follows
```shell
$ goctl api go --api=${API file path} --style=gozero --home="~/.goctl" --dir=${API file folder}
```
- `API Quick Code Generation` will open a popup for the user to fill in `--style`, `-- dir`, `--home`, etc.
![preview](./src/main/resources/static/api_code_gen_dialog.png)

# zRPC code generation
## 1. proto file right click generation
![preview](./src/main/resources/static/project_zrpc_code_gen.png)

## 2. proto file edit area right-click generation
![preview](./src/main/resources/static/editor_zrpc_code_gen.png)

## zRPC Code Generation Instructions
The difference between `ZRPC Code Generation` and `ZRPC Quick Code Generation` is that
- `ZRPC Code Generation` uses the specified values for the relevant command parameters of `goctl`, and its code generation instructions read as follows
```shell
$ goctl rpc protoc ${proto file path} --style=gozero --home="~/.goctl" --go_out=${API file folder} --grpc-go_out=${API file folder} --zrpc_out=${API file folder }
```
- `ZRPC Quick Code Generation` will open a popup window for users to fill in `--style`, `-- dir`, `--home`, `proto_path` (if there are other proto files imported), etc.
- No import case
![preview](./src/main/resources/static/api_code_gen_dialog.png)
- With import, proto_path currently only supports but file selection, so **importing proto from a different folder is not supported**.
![preview](./src/main/resources/static/rpc_code_gen_dialog.png)

# Model code generation
## 1. sql file right click generation
![preview](./src/main/resources/static/project_model_code_gen.png)

## 2. sql file edit area right-click generation
![preview](./src/main/resources/static/editor_model_code_gen.png)

## Model code generation instructions
**Model code generation is cached by default. **

The difference between `Model Code Generation` and `Model Quick Code Generation` is that
- `Model Code Generation` uses the specified values for the `goctl` command parameters, and the code generation commands are as follows
```shell
$ goctl model mysql ddl --src=${sql file path} --dir=${sql file folder} --style=gozero -c --home="~/.goctl"
```
- `Model Quick Code Generation` will open a popup for the user to fill in `--style`, `-- dir`, `--home`, `--cache`, etc.
![preview](./src/main/resources/static/api_code_gen_dialog.png)
-
# Error message
![context menu](./src/main/resources/static/alert.png)


# Live Template
Live Template can speed up the writing of api files, for example, if we type `main` keyword in a go file and enter it according to tip, a template code will be inserted
```golang
func main(){
}
```
Or maybe you'll be more familiar with the following image, where you defined the template once upon a time
![context menu](./src/main/resources/static/go_live_template.png)
Let's get into the template usage instructions in today's api syntax, and let's see the effect of the service template
![context menu](./src/main/resources/static/live_preview.gif)

#### Preset templates and effective areas
| Template keywords | psiTree effect area | description
| ---- | ---- | ---- |
| @doc | ApiService |doc annotation template |
| doc | ApiService |doc annotation template|
| struct |struct |struct declaration template|
| info | ApiFile |info block template|
| type | ApiFile |type group template|
| handler | ApiService |handler filename template|
| get | ApiService |get method routing template|
| head | ApiService |head method routing template|
| post | ApiService |post method routing template|
| put | ApiService |put method routing template|
| delete | ApiService |delete method routing template|
| connect | ApiService |connect method routing template|
| options | ApiService |options method routing template|
| trace | ApiService |trace method routing template|
| service | ApiFile |service service block template|
| json | Tag|Tag literal |tag template|
| xml | Tag|Tag literal |tag template|
| path | Tag|Tag literal |tag template|
| form | Tag|Tag literal |tag template|

About each template corresponding content can be seen in `Goland(mac Os)->Preference->Editor->Live Templates-> Api|Api Tags` in the detailed template content, such as json tag template content for

Translated with www.DeepL.com/Translator (free version)
26 changes: 8 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'cn.xiaoheiban'
version '1.0.0'
version '1.1.0'

repositories {
mavenCentral()
Expand Down Expand Up @@ -35,24 +35,14 @@ intellij {
patchPluginXml {
sinceBuild '193.0'
changeNotes """
<h1># 2022-01-20(1.0.0)</h1>
<h1># 2022-04-29(1.1.0)</h1>
<ul>
<li>Add completion keys</li>
<li>Support to go to declaration cross files</li>
</ul>
<h1># 2021-11-25(v0.7.18)</h1>
<ul>
<li>Fix duplicate routes error if there declared 'prefix' </li>
</ul>
<h1># 2021-10-22(v0.7.17)</h1>
<ul>
<li>Syntax support root path</li>
</ul>
<h1># 2021-10-05(v0.7.16)</h1>
<ul>
<li>Fixed goctl not found</li>
<li> rpc code generation support `goctl rpc protoc`</li>
<li> New support for popups with `style`, `output`, `proto_path`, `goctl home`, etc.</li>
<li> Support for quick code generation</li>
<li> New support for `timeout` syntax</li>
<li> Add support for Java style documentation comments</li>
<li> Fix some syntax errors</li>
</ul>
"""
}
Binary file modified src/main/resources/static/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/api_code_gen_dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/static/api_colorful.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/api_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/static/editor-menu.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/static/go_live_template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/static/goctl.png
Binary file not shown.
Binary file removed src/main/resources/static/json_tag.png
Binary file not shown.
Binary file added src/main/resources/static/live_preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/static/live_template.gif
Binary file not shown.
Binary file modified src/main/resources/static/new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/new_proto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/static/project_generate_code.png
Binary file not shown.
Binary file removed src/main/resources/static/project_menu.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/static/proto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/static/psiTree.png
Binary file not shown.
Binary file added src/main/resources/static/rpc_code_gen_dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/static/service.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9e2432d

Please sign in to comment.