Skip to content

Commit 38adf62

Browse files
committed
提供代码风格诊断
1 parent c8d9a89 commit 38adf62

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local files = require("files")
2+
local codeFormat = require "code_format"
3+
local converter = require("proto.converter")
4+
local log = require("log")
5+
local config = require("config")
6+
7+
8+
---@async
9+
return function(uri, callback)
10+
local text = files.getText(uri)
11+
if not text then
12+
return
13+
end
14+
15+
local status, diagnosticInfos = codeFormat.diagnose_file(uri, text)
16+
17+
if not status then
18+
if diagnosticInfos ~= nil then
19+
log.error(diagnosticInfos)
20+
end
21+
22+
return
23+
end
24+
25+
if diagnosticInfos then
26+
for _, diagnosticInfo in pairs(diagnosticInfos) do
27+
callback {
28+
start = converter.unpackPosition(uri, diagnosticInfo.range.start),
29+
finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]),
30+
message = diagnosticInfo.message
31+
}
32+
end
33+
end
34+
end

script/proto/define.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ m.DiagnosticDefaultSeverity = {
5858
['doc-field-no-class'] = 'Warning',
5959
['duplicate-doc-field'] = 'Warning',
6060
['unknown-diag-code'] = 'Waiting',
61+
['codestyle-check'] = "Warning",
6162
}
6263

6364
---@alias DiagnosticDefaultNeededFileStatus

test/crossfile/diagnostic.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ local config = require 'config'
55
local platform = require 'bee.platform'
66
local catch = require 'catch'
77

8+
89
config.get(nil, 'Lua.diagnostics.neededFileStatus')['deprecated'] = 'Any'
910
config.get(nil, 'Lua.diagnostics.neededFileStatus')['type-check'] = 'Any'
11+
config.get(nil, 'Lua.diagnostics.neededFileStatus')['codestyle-check'] = 'None'
1012

1113
rawset(_G, 'TEST', true)
1214

0 commit comments

Comments
 (0)