From 1d09f3bd87645e930bf93c14e5790b9297c49075 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Thu, 27 Apr 2023 16:20:06 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rd/EmmyLuaCodeStyle | 2 +- locale/en-us/setting.lua | 4 ++++ locale/pt-br/setting.lua | 4 ++++ locale/zh-cn/setting.lua | 4 ++++ locale/zh-tw/setting.lua | 4 ++++ script/config/template.lua | 2 +- script/core/diagnostics/name-style-check.lua | 35 ++++++++++++++++++++++++++++ script/core/diagnostics/name-style.lua | 35 ---------------------------- script/proto/diagnostic.lua | 2 +- script/provider/name-style.lua | 9 ++++++- 10 files changed, 62 insertions(+), 39 deletions(-) create mode 100644 script/core/diagnostics/name-style-check.lua delete mode 100644 script/core/diagnostics/name-style.lua diff --git a/3rd/EmmyLuaCodeStyle b/3rd/EmmyLuaCodeStyle index 081b623d..00e24b93 160000 --- a/3rd/EmmyLuaCodeStyle +++ b/3rd/EmmyLuaCodeStyle @@ -1 +1 @@ -Subproject commit 081b623d03627b281d5744ab53c420667573b955 +Subproject commit 00e24b9378c5700875899ab310109ca14fb4bc7e diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua index a354ff0b..48cde197 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 c38f0ff0..ea1bfddd 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 9dbd961d..1755d76f 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 7cf93297..6c2c0489 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/script/config/template.lua b/script/config/template.lua index 2b40f1a2..436f5e1a 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -385,7 +385,7 @@ 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.Hash(Type.String, 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, diff --git a/script/core/diagnostics/name-style-check.lua b/script/core/diagnostics/name-style-check.lua new file mode 100644 index 00000000..4bdb068f --- /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/core/diagnostics/name-style.lua b/script/core/diagnostics/name-style.lua deleted file mode 100644 index 4bdb068f..00000000 --- a/script/core/diagnostics/name-style.lua +++ /dev/null @@ -1,35 +0,0 @@ -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 5ee21638..bd10b7f7 100644 --- a/script/proto/diagnostic.lua +++ b/script/proto/diagnostic.lua @@ -126,7 +126,7 @@ m.register { } m.register { - 'namestyle-check' + 'name-style-check' } { group = 'codestyle', severity = 'Warning', diff --git a/script/provider/name-style.lua b/script/provider/name-style.lua index f9c5c756..bdb20d80 100644 --- a/script/provider/name-style.lua +++ b/script/provider/name-style.lua @@ -5,10 +5,17 @@ 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 -- cgit v1.2.3