summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2023-04-26 20:50:43 +0800
committerCppCXY <812125110@qq.com>2023-04-26 20:50:43 +0800
commitf6e103f10acd4b20fd73cd7a5b9b76fa0a676810 (patch)
tree6d5958fb51aaf543b72790c0610d05a26ee01ff9
parent19906a977c517b1e6edfd3ada60e20b2f9179e43 (diff)
downloadlua-language-server-f6e103f10acd4b20fd73cd7a5b9b76fa0a676810.zip
complete namestyle provider
-rw-r--r--make/code_format.lua1
-rw-r--r--script/config/template.lua2
-rw-r--r--script/core/diagnostics/name-style.lua35
-rw-r--r--script/proto/diagnostic.lua8
-rw-r--r--script/provider/name-style.lua21
5 files changed, 67 insertions, 0 deletions
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..2b40f1a2 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.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.lua b/script/core/diagnostics/name-style.lua
new file mode 100644
index 00000000..4bdb068f
--- /dev/null
+++ b/script/core/diagnostics/name-style.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..5ee21638 100644
--- a/script/proto/diagnostic.lua
+++ b/script/proto/diagnostic.lua
@@ -126,6 +126,14 @@ m.register {
}
m.register {
+ 'namestyle-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..f9c5c756
--- /dev/null
+++ b/script/provider/name-style.lua
@@ -0,0 +1,21 @@
+local suc, codeFormat = pcall(require, 'code_format')
+if not suc then
+ return
+end
+
+local config = require 'config'
+
+
+local m = {}
+
+function m.nameStyleCheck(uri, text)
+ 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