diff options
author | CppCXY <812125110@qq.com> | 2022-01-24 15:14:15 +0800 |
---|---|---|
committer | CppCXY <812125110@qq.com> | 2022-01-24 15:14:15 +0800 |
commit | 38adf62e8dec279ef76073a807989dd8b7669afc (patch) | |
tree | ca3a9a55d1fcfe5d7a5c4eb49975d2a944739a43 /script/core/diagnostics/codestyle-check.lua | |
parent | c8d9a8966b41288ff8a3e3fdf9e89bb1a1aee167 (diff) | |
download | lua-language-server-38adf62e8dec279ef76073a807989dd8b7669afc.zip |
提供代码风格诊断
Diffstat (limited to 'script/core/diagnostics/codestyle-check.lua')
-rw-r--r-- | script/core/diagnostics/codestyle-check.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/script/core/diagnostics/codestyle-check.lua b/script/core/diagnostics/codestyle-check.lua new file mode 100644 index 00000000..16623eca --- /dev/null +++ b/script/core/diagnostics/codestyle-check.lua @@ -0,0 +1,34 @@ +local files = require("files") +local codeFormat = require "code_format" +local converter = require("proto.converter") +local log = require("log") +local config = require("config") + + +---@async +return function(uri, callback) + local text = files.getText(uri) + if not text then + return + end + + local status, diagnosticInfos = codeFormat.diagnose_file(uri, text) + + if not status then + if diagnosticInfos ~= nil then + log.error(diagnosticInfos) + end + + return + end + + if diagnosticInfos then + for _, diagnosticInfo in pairs(diagnosticInfos) do + callback { + start = converter.unpackPosition(uri, diagnosticInfo.range.start), + finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]), + message = diagnosticInfo.message + } + end + end +end |