Skip to content

Commit b422860

Browse files
authored
Merge pull request #2091 from CppCXY/master
name-style-check support
2 parents 7318bbb + 6a81d83 commit b422860

File tree

10 files changed

+91
-1
lines changed

10 files changed

+91
-1
lines changed

3rd/EmmyLuaCodeStyle

Submodule EmmyLuaCodeStyle updated 45 files

locale/en-us/setting.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ Read [formatter docs](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/doc
269269
]]
270270
config.spell.dict =
271271
'Custom words for spell checking.'
272+
config.nameStyle.config =
273+
'Set name style config'
272274
config.telemetry.enable =
273275
[[
274276
Enable telemetry to send your editor information and error logs over the network. Read our privacy policy [here](https://github.com/LuaLS/lua-language-server/wiki/Home#privacy).
@@ -401,6 +403,8 @@ config.diagnostics['return-type-mismatch'] =
401403
'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.'
402404
config.diagnostics['spell-check'] =
403405
'Enable diagnostics for typos in strings.'
406+
config.diagnostics['name-style-check'] =
407+
'Enable diagnostics for name style.'
404408
config.diagnostics['unbalanced-assignments']=
405409
'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).'
406410
config.diagnostics['undefined-doc-class'] =

locale/pt-br/setting.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ Read [formatter docs](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/doc
269269
]]
270270
config.spell.dict = -- TODO: need translate!
271271
'Custom words for spell checking.'
272+
config.nameStyle.config = -- TODO: need translate!
273+
'Set name style config'
272274
config.telemetry.enable = -- TODO: need translate!
273275
[[
274276
Enable telemetry to send your editor information and error logs over the network. Read our privacy policy [here](https://github.com/LuaLS/lua-language-server/wiki/Home#privacy).
@@ -401,6 +403,8 @@ config.diagnostics['return-type-mismatch'] = -- TODO: need translate!
401403
'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.'
402404
config.diagnostics['spell-check'] = -- TODO: need translate!
403405
'Enable diagnostics for typos in strings.'
406+
config.diagnostics['name-style-check'] = -- TODO: need translate!
407+
'Enable diagnostics for name style.'
404408
config.diagnostics['unbalanced-assignments']= -- TODO: need translate!
405409
'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).'
406410
config.diagnostics['undefined-doc-class'] = -- TODO: need translate!

locale/zh-cn/setting.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ config.format.defaultConfig =
268268
]]
269269
config.spell.dict =
270270
'拼写检查的自定义单词。'
271+
config.nameStyle.config =
272+
'设定命名风格检查的配置'
271273
config.telemetry.enable =
272274
[[
273275
启用遥测,通过网络发送你的编辑器信息与错误日志。在[此处](https://github.com/LuaLS/lua-language-server/wiki/Home#privacy)阅读我们的隐私声明。
@@ -400,6 +402,8 @@ config.diagnostics['return-type-mismatch'] = -- TODO: need translate!
400402
'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.'
401403
config.diagnostics['spell-check'] = -- TODO: need translate!
402404
'Enable diagnostics for typos in strings.'
405+
config.diagnostics['name-style-check'] = -- TODO: need translate!
406+
'Enable diagnostics for name style.'
403407
config.diagnostics['unbalanced-assignments']= -- TODO: need translate!
404408
'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).'
405409
config.diagnostics['undefined-doc-class'] = -- TODO: need translate!

locale/zh-tw/setting.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ config.format.defaultConfig =
268268
]]
269269
config.spell.dict =
270270
'拼寫檢查的自訂單詞。'
271+
config.nameStyle.config = -- TODO: need translate!
272+
'Set name style config'
271273
config.telemetry.enable =
272274
[[
273275
啟用遙測,透過網路發送你的編輯器資訊與錯誤日誌。在[此處](https://github.com/LuaLS/lua-language-server/wiki/Home#privacy)閱讀我們的隱私聲明。
@@ -400,6 +402,8 @@ config.diagnostics['return-type-mismatch'] = -- TODO: need translate!
400402
'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.'
401403
config.diagnostics['spell-check'] = -- TODO: need translate!
402404
'Enable diagnostics for typos in strings.'
405+
config.diagnostics['name-style-check'] = -- TODO: need translate!
406+
'Enable diagnostics for name style.'
403407
config.diagnostics['unbalanced-assignments']= -- TODO: need translate!
404408
'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).'
405409
config.diagnostics['undefined-doc-class'] = -- TODO: need translate!

make/code_format.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ lm:source_set 'code_format' {
1919
"Util/src/StringUtil.cpp",
2020
"Util/src/Utf8.cpp",
2121
"Util/src/SymSpell/*.cpp",
22+
"Util/src/InfoTree/*.cpp",
2223
--CodeService
2324
"CodeService/src/**/*.cpp",
2425
},

script/config/template.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ local template = {
385385
auto_complete_table_sep = "true"
386386
},
387387
['Lua.spell.dict'] = Type.Array(Type.String),
388+
['Lua.nameStyle.config'] = Type.Hash(Type.String, Type.Or(Type.String, Type.Array(Type.Hash(Type.String, Type.String))))
389+
>> {},
388390
['Lua.misc.parameters'] = Type.Array(Type.String),
389391
['Lua.misc.executablePath'] = Type.String,
390392
['Lua.type.castNumberToInteger'] = Type.Boolean >> true,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local files = require 'files'
2+
local converter = require 'proto.converter'
3+
local log = require 'log'
4+
local nameStyle = require 'provider.name-style'
5+
6+
7+
---@async
8+
return function (uri, callback)
9+
local state = files.getState(uri)
10+
if not state then
11+
return
12+
end
13+
local text = state.originText
14+
15+
local status, diagnosticInfos = nameStyle.nameStyleCheck(uri, text)
16+
17+
if not status then
18+
if diagnosticInfos ~= nil then
19+
log.error(diagnosticInfos)
20+
end
21+
22+
return
23+
end
24+
25+
if diagnosticInfos then
26+
for _, diagnosticInfo in ipairs(diagnosticInfos) do
27+
callback {
28+
start = converter.unpackPosition(state, diagnosticInfo.range.start),
29+
finish = converter.unpackPosition(state, diagnosticInfo.range["end"]),
30+
message = diagnosticInfo.message,
31+
data = diagnosticInfo.data
32+
}
33+
end
34+
end
35+
end

script/proto/diagnostic.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ m.register {
125125
status = 'None',
126126
}
127127

128+
m.register {
129+
'name-style-check'
130+
} {
131+
group = 'codestyle',
132+
severity = 'Warning',
133+
status = 'None',
134+
}
135+
128136
m.register {
129137
'newline-call',
130138
'newfield-call',

script/provider/name-style.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
local suc, codeFormat = pcall(require, 'code_format')
2+
if not suc then
3+
return
4+
end
5+
6+
local config = require 'config'
7+
8+
local m = {}
9+
10+
m.loaded = false
11+
12+
function m.nameStyleCheck(uri, text)
13+
if not m.loaded then
14+
local value = config.get(nil, "Lua.nameStyle.config")
15+
codeFormat.update_name_style_config(value)
16+
m.loaded = true
17+
end
18+
19+
return codeFormat.name_style_analysis(uri, text)
20+
end
21+
22+
config.watch(function (uri, key, value)
23+
if key == "Lua.nameStyle.config" then
24+
codeFormat.update_name_style_config(value)
25+
end
26+
end)
27+
28+
return m

0 commit comments

Comments
 (0)