summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/diagnostics/init.lua4
-rw-r--r--script/parser/luadoc.lua20
-rw-r--r--script/vm/getDocs.lua25
-rw-r--r--test/diagnostics/init.lua33
5 files changed, 72 insertions, 11 deletions
diff --git a/changelog.md b/changelog.md
index 895dbc33..f966aa35 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 1.18.0
+* `NEW` `LuaDoc`: supports `---@diagnostic disable`
* `CHG` `Windows`: dose not provide `ucrt` any more
* `CHG` `Lua.workspace.library`: use `path[]` instead of `<path, true>`
* `FIX` missed syntax error `local a <const>= 1`
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
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 6374b4b7..0ee558af 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -1062,3 +1062,36 @@ r.x = 1
return r.x
]]
+
+TEST [[
+---@diagnostic disable-next-line
+x = 1
+]]
+
+TEST [[
+---@diagnostic disable-next-line: lowercase-global
+x = 1
+]]
+
+TEST [[
+---@diagnostic disable-next-line: unused-local
+<!x!> = 1
+]]
+
+TEST [[
+---@diagnostic disable
+x = 1
+]]
+
+TEST [[
+---@diagnostic disable
+---@diagnostic enable
+<!x!> = 1
+]]
+
+TEST [[
+---@diagnostic disable
+---@diagnostic disable
+---@diagnostic enable
+x = 1
+]]