summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/init.lua4
-rw-r--r--script/parser/luadoc.lua20
-rw-r--r--script/vm/getDocs.lua25
3 files changed, 38 insertions, 11 deletions
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index 87afd4af..a164437f 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -2,6 +2,7 @@ local files = require 'files'
local define = require 'proto.define'
local config = require 'config'
local await = require 'await'
+local vm = require "vm.vm"
-- 把耗时最长的诊断放到最后面
local diagSort = {
@@ -38,6 +39,9 @@ local function check(uri, name, results)
local severity = define.DiagnosticSeverity[level]
local clock = os.clock()
require('core.diagnostics.' .. name)(uri, function (result)
+ if vm.isDiagDisabledAt(uri, result.start, name) then
+ return
+ end
result.level = severity or result.level
result.code = name
results[#results+1] = result
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 0eddda7a..a78039ba 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -887,6 +887,16 @@ local function parseDiagnostic()
result.mode = mode
result.start = getStart()
result.finish = getFinish()
+ if mode ~= 'disable-next-line'
+ and mode ~= 'disable-line'
+ and mode ~= 'disable'
+ and mode ~= 'enable' then
+ pushError {
+ type = 'LUADOC_ERROR_DIAG_NAME',
+ start = result.start,
+ finish = result.finish,
+ }
+ end
if checkToken('symbol', ':', 1) then
nextToken()
@@ -902,16 +912,6 @@ local function parseDiagnostic()
return result
end
result.names[#result.names+1] = name
- if name ~= 'disable-next-line'
- and name ~= 'disable-line'
- and name ~= 'disable'
- and name ~= 'enable' then
- pushError {
- type = 'LUADOC_ERROR_DIAG_NAME',
- start = name.start,
- finish = name.finish,
- }
- end
if not checkToken('symbol', ',', 1) then
break
end
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua
index 05ecfdd3..1bf27859 100644
--- a/script/vm/getDocs.lua
+++ b/script/vm/getDocs.lua
@@ -245,7 +245,8 @@ local function makeDiagRange(uri, doc, results)
if doc.names then
names = {}
for i, nameUnit in ipairs(doc.names) do
- names[i] = nameUnit[1]
+ local name = nameUnit[1]
+ names[name] = true
end
end
local row = guide.positionOf(lines, doc.start)
@@ -318,4 +319,26 @@ function vm.isDiagDisabledAt(uri, offset, name)
return a.offset < b.offset
end)
end
+ if #cache.diagnosticRanges == 0 then
+ return false
+ end
+ local stack = {}
+ for _, range in ipairs(cache.diagnosticRanges) do
+ if range.offset <= offset then
+ if not range.names or range.names[name] then
+ if range.mode == 'disable' then
+ stack[#stack+1] = range
+ elseif range.mode == 'enable' then
+ stack[#stack] = nil
+ end
+ end
+ else
+ break
+ end
+ end
+ local current = stack[#stack]
+ if not current then
+ return false
+ end
+ return true
end