summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/init.lua43
-rw-r--r--script/core/diagnostics/invisible.lua55
-rw-r--r--script/proto/diagnostic.lua1
3 files changed, 75 insertions, 24 deletions
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index c33de6ce..e3f2c416 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -6,29 +6,6 @@ local vm = require "vm.vm"
local util = require 'utility'
local diagd = require 'proto.diagnostic'
--- 把耗时最长的诊断放到最后面
-local diagSort = {
- ['redundant-value'] = 100,
- ['not-yieldable'] = 100,
- ['deprecated'] = 100,
- ['undefined-field'] = 110,
- ['redundant-parameter'] = 110,
- ['cast-local-type'] = 120,
- ['assign-type-mismatch'] = 120,
- ['param-type-mismatch'] = 120,
- ['missing-return'] = 120,
- ['missing-return-value'] = 120,
- ['redundant-return-value'] = 120,
-}
-
-local diagList = {}
-for k in pairs(define.DiagnosticDefaultSeverity) do
- diagList[#diagList+1] = k
-end
-table.sort(diagList, function (a, b)
- return (diagSort[a] or 0) < (diagSort[b] or 0)
-end)
-
local sleepRest = 0.0
---@async
@@ -165,6 +142,21 @@ local function check(uri, name, isScopeDiag, response)
end
end
+local diagList
+local diagCosts = {}
+local function buildDiagList()
+ if not diagList then
+ diagList = {}
+ for name in pairs(define.DiagnosticDefaultSeverity) do
+ diagList[#diagList+1] = name
+ end
+ end
+ table.sort(diagList, function (a, b)
+ return (diagCosts[a] or 0) < (diagCosts[b] or 0)
+ end)
+ return diagList
+end
+
---@async
---@param uri uri
---@param isScopeDiag boolean
@@ -176,9 +168,12 @@ return function (uri, isScopeDiag, response, checked)
return nil
end
- for _, name in ipairs(diagList) do
+ for _, name in ipairs(buildDiagList()) do
await.delay()
+ local clock = os.clock()
check(uri, name, isScopeDiag, response)
+ local cost = os.clock() - clock
+ diagCosts[name] = (diagCosts[name] or 0) + cost
if checked then
checked(name)
end
diff --git a/script/core/diagnostics/invisible.lua b/script/core/diagnostics/invisible.lua
new file mode 100644
index 00000000..0bd369a4
--- /dev/null
+++ b/script/core/diagnostics/invisible.lua
@@ -0,0 +1,55 @@
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
+local vm = require 'vm.vm'
+local await = require 'await'
+
+local checkTypes = {'getfield', 'setfield', 'getmethod', 'setmethod', 'getindex', 'setindex'}
+
+---@async
+return function (uri, callback)
+ local state = files.getState(uri)
+ if not state then
+ return
+ end
+
+ ---@async
+ guide.eachSourceTypes(state.ast, checkTypes, function (src)
+ local child = src.field or src.method or src.index
+ if not child then
+ return
+ end
+ local key = guide.getKeyName(src)
+ if not key then
+ return
+ end
+ await.delay()
+ local defs = vm.getDefs(src)
+ for _, def in ipairs(defs) do
+ if not vm.isVisible(src.node, def) then
+ if vm.getVisibleType(def) == 'private' then
+ callback {
+ start = child.start,
+ finish = child.finish,
+ uri = uri,
+ message = lang.script('DIAG_INVISIBLE_PRIVATE', {
+ field = key,
+ class = vm.getParentClass(def):getName(),
+ }),
+ }
+ else
+ callback {
+ start = child.start,
+ finish = child.finish,
+ uri = uri,
+ message = lang.script('DIAG_INVISIBLE_PROTECTED', {
+ field = key,
+ class = vm.getParentClass(def):getName(),
+ }),
+ }
+ end
+ break
+ end
+ end
+ end)
+end
diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua
index f6645e89..be30bcec 100644
--- a/script/proto/diagnostic.lua
+++ b/script/proto/diagnostic.lua
@@ -184,6 +184,7 @@ m.register {
'close-non-object',
'deprecated',
'discard-returns',
+ 'invisible',
} {
group = 'strict',
severity = 'Warning',