diff --git a/3rd/EmmyLuaCodeStyle b/3rd/EmmyLuaCodeStyle index 081b623d0..28bff899e 160000 --- a/3rd/EmmyLuaCodeStyle +++ b/3rd/EmmyLuaCodeStyle @@ -1 +1 @@ -Subproject commit 081b623d03627b281d5744ab53c420667573b955 +Subproject commit 28bff899e7590f594b15146ea5f3a791268d1427 diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua index a354ff0b4..48cde197c 100644 --- a/locale/en-us/setting.lua +++ b/locale/en-us/setting.lua @@ -269,6 +269,8 @@ Read [formatter docs](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/doc ]] config.spell.dict = 'Custom words for spell checking.' +config.nameStyle.config = +'Set name style config' config.telemetry.enable = [[ 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'] = 'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.' config.diagnostics['spell-check'] = 'Enable diagnostics for typos in strings.' +config.diagnostics['name-style-check'] = +'Enable diagnostics for name style.' config.diagnostics['unbalanced-assignments']= 'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).' config.diagnostics['undefined-doc-class'] = diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua index c38f0ff06..ea1bfddd6 100644 --- a/locale/pt-br/setting.lua +++ b/locale/pt-br/setting.lua @@ -269,6 +269,8 @@ Read [formatter docs](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/doc ]] config.spell.dict = -- TODO: need translate! 'Custom words for spell checking.' +config.nameStyle.config = -- TODO: need translate! +'Set name style config' config.telemetry.enable = -- TODO: need translate! [[ 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! 'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.' config.diagnostics['spell-check'] = -- TODO: need translate! 'Enable diagnostics for typos in strings.' +config.diagnostics['name-style-check'] = -- TODO: need translate! +'Enable diagnostics for name style.' config.diagnostics['unbalanced-assignments']= -- TODO: need translate! 'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).' config.diagnostics['undefined-doc-class'] = -- TODO: need translate! diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua index 9dbd961d3..1755d76fa 100644 --- a/locale/zh-cn/setting.lua +++ b/locale/zh-cn/setting.lua @@ -268,6 +268,8 @@ config.format.defaultConfig = ]] config.spell.dict = '拼写检查的自定义单词。' +config.nameStyle.config = +'设定命名风格检查的配置' config.telemetry.enable = [[ 启用遥测,通过网络发送你的编辑器信息与错误日志。在[此处](https://github.com/LuaLS/lua-language-server/wiki/Home#privacy)阅读我们的隐私声明。 @@ -400,6 +402,8 @@ config.diagnostics['return-type-mismatch'] = -- TODO: need translate! 'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.' config.diagnostics['spell-check'] = -- TODO: need translate! 'Enable diagnostics for typos in strings.' +config.diagnostics['name-style-check'] = -- TODO: need translate! +'Enable diagnostics for name style.' config.diagnostics['unbalanced-assignments']= -- TODO: need translate! 'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).' config.diagnostics['undefined-doc-class'] = -- TODO: need translate! diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua index 7cf932973..6c2c04893 100644 --- a/locale/zh-tw/setting.lua +++ b/locale/zh-tw/setting.lua @@ -268,6 +268,8 @@ config.format.defaultConfig = ]] config.spell.dict = '拼寫檢查的自訂單詞。' +config.nameStyle.config = -- TODO: need translate! +'Set name style config' config.telemetry.enable = [[ 啟用遙測,透過網路發送你的編輯器資訊與錯誤日誌。在[此處](https://github.com/LuaLS/lua-language-server/wiki/Home#privacy)閱讀我們的隱私聲明。 @@ -400,6 +402,8 @@ config.diagnostics['return-type-mismatch'] = -- TODO: need translate! 'Enable diagnostics for return values whose type does not match the type declared in the corresponding return annotation.' config.diagnostics['spell-check'] = -- TODO: need translate! 'Enable diagnostics for typos in strings.' +config.diagnostics['name-style-check'] = -- TODO: need translate! +'Enable diagnostics for name style.' config.diagnostics['unbalanced-assignments']= -- TODO: need translate! 'Enable diagnostics on multiple assignments if not all variables obtain a value (e.g., `local x,y = 1`).' config.diagnostics['undefined-doc-class'] = -- TODO: need translate! diff --git a/make/code_format.lua b/make/code_format.lua index 4d0764db1..c36a6b4fb 100644 --- a/make/code_format.lua +++ b/make/code_format.lua @@ -19,6 +19,7 @@ lm:source_set 'code_format' { "Util/src/StringUtil.cpp", "Util/src/Utf8.cpp", "Util/src/SymSpell/*.cpp", + "Util/src/InfoTree/*.cpp", --CodeService "CodeService/src/**/*.cpp", }, diff --git a/script/config/template.lua b/script/config/template.lua index 3d2a8d35d..436f5e1a4 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -385,6 +385,8 @@ local template = { auto_complete_table_sep = "true" }, ['Lua.spell.dict'] = Type.Array(Type.String), + ['Lua.nameStyle.config'] = Type.Hash(Type.String, Type.Or(Type.String, Type.Array(Type.Hash(Type.String, Type.String)))) + >> {}, ['Lua.misc.parameters'] = Type.Array(Type.String), ['Lua.misc.executablePath'] = Type.String, ['Lua.type.castNumberToInteger'] = Type.Boolean >> true, diff --git a/script/core/diagnostics/name-style-check.lua b/script/core/diagnostics/name-style-check.lua new file mode 100644 index 000000000..4bdb068f2 --- /dev/null +++ b/script/core/diagnostics/name-style-check.lua @@ -0,0 +1,35 @@ +local files = require 'files' +local converter = require 'proto.converter' +local log = require 'log' +local nameStyle = require 'provider.name-style' + + +---@async +return function (uri, callback) + local state = files.getState(uri) + if not state then + return + end + local text = state.originText + + local status, diagnosticInfos = nameStyle.nameStyleCheck(uri, text) + + if not status then + if diagnosticInfos ~= nil then + log.error(diagnosticInfos) + end + + return + end + + if diagnosticInfos then + for _, diagnosticInfo in ipairs(diagnosticInfos) do + callback { + start = converter.unpackPosition(state, diagnosticInfo.range.start), + finish = converter.unpackPosition(state, diagnosticInfo.range["end"]), + message = diagnosticInfo.message, + data = diagnosticInfo.data + } + end + end +end diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua index 34f3646f3..bd10b7f7c 100644 --- a/script/proto/diagnostic.lua +++ b/script/proto/diagnostic.lua @@ -125,6 +125,14 @@ m.register { status = 'None', } +m.register { + 'name-style-check' +} { + group = 'codestyle', + severity = 'Warning', + status = 'None', +} + m.register { 'newline-call', 'newfield-call', diff --git a/script/provider/name-style.lua b/script/provider/name-style.lua new file mode 100644 index 000000000..bdb20d80d --- /dev/null +++ b/script/provider/name-style.lua @@ -0,0 +1,28 @@ +local suc, codeFormat = pcall(require, 'code_format') +if not suc then + return +end + +local config = require 'config' + +local m = {} + +m.loaded = false + +function m.nameStyleCheck(uri, text) + if not m.loaded then + local value = config.get(nil, "Lua.nameStyle.config") + codeFormat.update_name_style_config(value) + m.loaded = true + end + + return codeFormat.name_style_analysis(uri, text) +end + +config.watch(function (uri, key, value) + if key == "Lua.nameStyle.config" then + codeFormat.update_name_style_config(value) + end +end) + +return m