summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-05-11 11:32:12 +0800
committerGitHub <noreply@github.com>2023-05-11 11:32:12 +0800
commitb422860aedb390744a566063991d57ccc829deb2 (patch)
tree07c8b91a0657e6e39d68778f230abbf3d2c4a489
parent7318bbba9808b94c59202d301ac4faf4dc7f1f5a (diff)
parent6a81d83e80db51e8e2736074bd6f0039e898b6c4 (diff)
downloadlua-language-server-b422860aedb390744a566063991d57ccc829deb2.zip
Merge pull request #2091 from CppCXY/master
name-style-check support
m---------3rd/EmmyLuaCodeStyle0
-rw-r--r--locale/en-us/setting.lua4
-rw-r--r--locale/pt-br/setting.lua4
-rw-r--r--locale/zh-cn/setting.lua4
-rw-r--r--locale/zh-tw/setting.lua4
-rw-r--r--make/code_format.lua1
-rw-r--r--script/config/template.lua2
-rw-r--r--script/core/diagnostics/name-style-check.lua35
-rw-r--r--script/proto/diagnostic.lua8
-rw-r--r--script/provider/name-style.lua28
10 files changed, 90 insertions, 0 deletions
diff --git a/3rd/EmmyLuaCodeStyle b/3rd/EmmyLuaCodeStyle
-Subproject 081b623d03627b281d5744ab53c420667573b95
+Subproject 28bff899e7590f594b15146ea5f3a791268d142
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/make/code_format.lua b/make/code_format.lua
index 4d0764db..c36a6b4f 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 3d2a8d35..436f5e1a 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 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/proto/diagnostic.lua b/script/proto/diagnostic.lua
index 34f3646f..bd10b7f7 100644
--- a/script/proto/diagnostic.lua
+++ b/script/proto/diagnostic.lua
@@ -126,6 +126,14 @@ m.register {
}
m.register {
+ 'name-style-check'
+} {
+ group = 'codestyle',
+ severity = 'Warning',
+ status = 'None',
+}
+
+m.register {
'newline-call',
'newfield-call',
'ambiguity-1',
diff --git a/script/provider/name-style.lua b/script/provider/name-style.lua
new file mode 100644
index 00000000..bdb20d80
--- /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