Skip to content

Commit

Permalink
Formatting proto files (#8)
Browse files Browse the repository at this point in the history
* 🚀 Add more code snippets

Add more code snippets

* ✨ proto3 snippets && syntaxes

* 📝add image

* 📝update image

* Update package.json

 set language `proto3`

* 🚧  Add some features

🚧 Add some features

* ✨  代码高亮&代码提示

调整了生成样式

* 🚧  #1 CompletionItemProvider

CompletionItemProvider

* 🔧

丰富设置

* Create LICENSE

* Update package.json

* ✨ #2 proto file to markdown

:sparkles: #2 proto file to markdown

* 📝 enrich documentation

* ✨ #2 假设工具已安装后代码执行逻辑

* ✨ #2

支持语言设置

* ⚗️  #2

安装生成文档工具测试代码

* ✨ Automatic installation of generation tools

* #3 using clang-format

* #4 fixed: The request is abandoned.

* #4 remove @

* remove @, fixed #5

* #2 proto-doc download link is redirected.

* format code

* Fix the problem of downloading file failure,  close #2

* feat: update readme

* #3 feat: clang-format options config

* #3 feat: installation tips and parameter options

* update readme

Update version (#9)

* update version

update readme (#10)

* update version

update version
  • Loading branch information
kalifun committed Feb 4, 2024
1 parent c615bc8 commit a4229de
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.vscode-test/
*.vsix
*.proto
.DS_Store
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- snippets
- syntaxes

## [0.1.2]

- Gen Api Doc

## [0.1.3]

- format code
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ I'm sure you're no stranger to api documentation, but when there's no common pla

![](images/doc.png)

### Format

![](images/format.gif)

## Todo

- [x] Snippets
- [x] Syntaxes
- [x] Gen Api Doc
- [x] Format code

# Acknowledgement

Expand Down
Binary file added images/format.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
303 changes: 168 additions & 135 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,143 +1,176 @@
{
"name": "vscode-proto3-tools",
"displayName": "Proto3 Tools",
"version": "0.1.1",
"description": "proto3 language service",
"engines": {
"vscode": "^1.71.0"
},
"categories": [
"Programming Languages",
"Snippets",
"Linters",
"Formatters"
],
"license": "MIT",
"icon": "images/logo.png",
"repository": {
"type": "git",
"url": "https://github.com/kalifun/vscode-proto3-tools"
},
"author": {
"name": "kalifun"
},
"publisher": "kalifun",
"contributors": [
{
"name": "kalifun",
"email": "[email protected]",
"url": "https://github.com/kalifun"
}
],
"activationEvents": [
"onCommand:proto3.gendoc",
"onLanguage:proto3"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "proto3.gendoc",
"title": "proto3 to doc"
},
{
"command": "proto3.menus_gendoc",
"title": "proto gen markdown"
}
],
"languages": [
{
"id": "proto3",
"aliases": [
"ProtoBuf",
"protobuf"
],
"extensions": [
".proto"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "proto3",
"scopeName": "source.proto",
"path": "./syntaxes/protobuf.tmLanguage.json"
}
],
"snippets": [
{
"language": "proto3",
"path": "./snippets/snippets.json"
}
"name": "vscode-proto3-tools",
"displayName": "Proto3 Tools",
"version": "0.1.4",
"description": "proto3 language service",
"engines": {
"vscode": "^1.71.0"
},
"categories": [
"Programming Languages",
"Snippets",
"Linters",
"Formatters"
],
"menus": {
"editor/context": [
"license": "MIT",
"icon": "images/logo.png",
"repository": {
"type": "git",
"url": "https://github.com/kalifun/vscode-proto3-tools"
},
"author": {
"name": "kalifun"
},
"publisher": "kalifun",
"contributors": [
{
"when": "resourceExtname == .proto",
"command": "proto3.menus_gendoc",
"group": "6_test"
"name": "kalifun",
"email": "[email protected]",
"url": "https://github.com/kalifun"
}
]
},
"configuration": {
"title": "Proto3 Tools Config",
"properties": {
"proto3.outputpath": {
"type": "string",
"default": "doc",
"description": "Path to the generated document(Based on current path)"
],
"activationEvents": [
"onCommand:proto3.gendoc",
"onLanguage:proto3"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "proto3.gendoc",
"title": "proto3 to doc"
},
{
"command": "proto3.menus_gendoc",
"title": "proto gen markdown"
}
],
"languages": [
{
"id": "proto3",
"aliases": [
"ProtoBuf",
"protobuf"
],
"extensions": [
".proto"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "proto3",
"scopeName": "source.proto",
"path": "./syntaxes/protobuf.tmLanguage.json"
}
],
"snippets": [
{
"language": "proto3",
"path": "./snippets/snippets.json"
}
],
"menus": {
"editor/context": [
{
"when": "resourceExtname == .proto",
"command": "proto3.menus_gendoc",
"group": "6_test"
}
]
},
"proto3.template_language": {
"type": "string",
"default": "en",
"enum": [
"zh",
"en"
],
"enumDescriptions": [
"Generated text titles, etc. are in Chinese",
"Generated text titles, etc. are in English"
]
"configuration": {
"title": "Proto3 Tools Config",
"properties": {
"proto3.outputpath": {
"type": "string",
"default": "doc",
"description": "Path to the generated document(Based on current path)"
},
"proto3.template_language": {
"type": "string",
"default": "en",
"enum": [
"zh",
"en"
],
"enumDescriptions": [
"Generated text titles, etc. are in Chinese",
"Generated text titles, etc. are in English"
]
},
"proto3.disable_rules": {
"type": "array",
"enum": [
"core::0140::lower-snake",
"core::0131::request-name-field"
],
"default": [
"core::0123::resource-annotation"
],
"description": "Set the check rule to be cancelled(https://linter.aip.dev/)"
},
"proto3.clang-format_BasedOnStyle": {
"type": "string",
"default": "Google",
"enum": [
"Google",
"LLVM"
],
"description": "Specify the code style to use for clang-format"
},
"proto3.clang-format_IndentWidth": {
"type": "number",
"default": 2,
"enum": [
2,
4
],
"description": "Specify the indentation width for clang-format"
},
"proto3.clang-format_TabWidth": {
"type": "number",
"default": 2,
"enum": [
2,
4
],
"description": "Specify the tab width for clang-format"
}
}
},
"proto3.disable_rules": {
"type": "array",
"enum": [
"core::0140::lower-snake",
"core::0131::request-name-field"
],
"default": [
"core::0123::resource-annotation"
],
"description": "Set the check rule to be cancelled(https://linter.aip.dev/)"
}
}
"documentFormattingProviders": [
{
"language": "proto3",
"provider": "extension.clangFormat"
}
]
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.1",
"@types/node": "16.x",
"@types/tar": "^6.1.11",
"@types/vscode": "^1.71.0",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"@vscode/test-electron": "^2.1.5",
"eslint": "^8.20.0",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"typescript": "^4.7.4"
},
"dependencies": {
"compressing": "^1.10.0",
"tar": "^6.2.0"
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.1",
"@types/node": "16.x",
"@types/tar": "^6.1.11",
"@types/vscode": "^1.71.0",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"@vscode/test-electron": "^2.1.5",
"eslint": "^8.20.0",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"typescript": "^4.7.4"
},
"dependencies": {
"compressing": "^1.10.0",
"tar": "^6.2.0"
}
}
8 changes: 5 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cp = require('child_process');
import { Proto3CompletionItemProvider } from './api/completion/completion';
import { Proto3 } from './conf/config';
import { generateMarkdown, rightClickGenDoc } from './repo/doc/doc';
import {formatFile, isClangFormat} from "./repo/format/format";



Expand All @@ -25,9 +26,10 @@ export function activate(context: vscode.ExtensionContext) {

vscode.languages.registerDocumentFormattingEditProvider('proto3', {
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
let filePath = document.uri.fsPath;
let stdout = cp.execFileSync('clang-format', [filePath]);
return [new vscode.TextEdit(document.validateRange(new vscode.Range(0, 0, Infinity, Infinity)), stdout ? stdout.toString() : '')];
if (!isClangFormat) {
return [];
}
return formatFile(document);
},
});

Expand Down
Loading

0 comments on commit a4229de

Please sign in to comment.