diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/config/template.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/name-style-check.lua | 35 | ||||
-rw-r--r-- | script/proto/diagnostic.lua | 8 | ||||
-rw-r--r-- | script/provider/name-style.lua | 28 |
4 files changed, 73 insertions, 0 deletions
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 |