Skip to content

Commit 5997feb

Browse files
committed
feature: support enable/disable code formatter.
1 parent 6bc3227 commit 5997feb

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "LuaCoderAssist",
44
"description": "lua编程助手,包括代码补全、符号预览&跳转、函数特征帮助、符号类型推导、静态检查、格式化、代码度量等功能",
55
"icon": "images/icon.png",
6-
"version": "2.5.0",
6+
"version": "2.5.1",
77
"publisher": "liwangqian",
88
"engines": {
99
"vscode": "^1.25.0"
@@ -207,6 +207,11 @@
207207
"default": true,
208208
"description": "Keep diagnostic information after document closed."
209209
},
210+
"LuaCoderAssist.format.enable": {
211+
"type": "boolean",
212+
"default": true,
213+
"description": "Enable/Disable code formatting."
214+
},
210215
"LuaCoderAssist.format.lineWidth": {
211216
"type": "integer",
212217
"default": 120,

server/coder.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ class Coder {
2929
this.settings = {
3030
enable: true,
3131
debug: false,
32-
preloads:[],
32+
preloads: [],
3333
useLove: false,
3434
useJit: false,
3535
symbol: {
3636
showAnonymousFunction: true,
3737
showFunctionOnly: false,
3838
},
39-
luaPath:"",
39+
luaPath: "",
4040
luacheck: {
4141
enable: true,
4242
onSave: true,
@@ -60,6 +60,7 @@ class Coder {
6060
allowDefined: false
6161
},
6262
format: {
63+
enable: true,
6364
lineWidth: 120,
6465
indentCount: 4,
6566
quotemark: "single"

server/providers/format-provider.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class FormatProvider {
2525
let uri = params.textDocument.uri;
2626
let opt = this.coder.settings.format;
2727

28+
if (!opt.enable) {
29+
return [];
30+
}
31+
2832
let document = yield this.coder.document(uri);
2933

3034
let text
@@ -48,7 +52,13 @@ class FormatProvider {
4852
}
4953

5054
_formatOptions(userOptions) {
55+
let formatEnable = true;
56+
if (!userOptions.enable) {
57+
formatEnable = false;
58+
}
59+
5160
return {
61+
enable: formatEnable,
5262
lineWidth: userOptions.lineWidth || 120,
5363
indentCount: userOptions.indentCount || 4,
5464
quotemark: userOptions.quotemark || 'single'

0 commit comments

Comments
 (0)