summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/parser/guide.lua4
-rw-r--r--script/parser/luadoc.lua10
-rw-r--r--script/vm/getDocs.lua81
-rw-r--r--test/completion/init.lua4
4 files changed, 97 insertions, 2 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index fbb59f31..81adf890 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -637,8 +637,8 @@ end
--- 获取偏移对应的坐标
---@param lines table
----@return integer {name = 'row'}
----@return integer {name = 'col'}
+---@return integer row
+---@return integer col
function m.positionOf(lines, offset)
if offset < 1 then
return 0, 0
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index c5ac3a1e..0eddda7a 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -902,6 +902,16 @@ 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 e5a6d865..05ecfdd3 100644
--- a/script/vm/getDocs.lua
+++ b/script/vm/getDocs.lua
@@ -238,3 +238,84 @@ function vm.isDeprecated(value, deep)
return isDeprecated(value)
end
end
+
+local function makeDiagRange(uri, doc, results)
+ local lines = files.getLines(uri)
+ local names
+ if doc.names then
+ names = {}
+ for i, nameUnit in ipairs(doc.names) do
+ names[i] = nameUnit[1]
+ end
+ end
+ local row = guide.positionOf(lines, doc.start)
+ if doc.mode == 'disable-next-line' then
+ if lines[row+1] then
+ results[#results+1] = {
+ mode = 'disable',
+ names = names,
+ offset = lines[row+1].start,
+ source = doc,
+ }
+ results[#results+1] = {
+ mode = 'enable',
+ names = names,
+ offset = lines[row+1].finish,
+ source = doc,
+ }
+ end
+ elseif doc.mode == 'disable-line' then
+ results[#results+1] = {
+ mode = 'disable',
+ names = names,
+ offset = lines[row].start,
+ source = doc,
+ }
+ results[#results+1] = {
+ mode = 'enable',
+ names = names,
+ offset = lines[row].finish,
+ source = doc,
+ }
+ elseif doc.mode == 'disable' then
+ if lines[row+1] then
+ results[#results+1] = {
+ mode = 'disable',
+ names = names,
+ offset = lines[row+1].start,
+ source = doc,
+ }
+ end
+ elseif doc.mode == 'enable' then
+ if lines[row+1] then
+ results[#results+1] = {
+ mode = 'enable',
+ names = names,
+ offset = lines[row+1].start,
+ source = doc,
+ }
+ end
+ end
+end
+
+function vm.isDiagDisabledAt(uri, offset, name)
+ local status = files.getAst(uri)
+ if not status then
+ return false
+ end
+ if not status.ast.docs then
+ return false
+ end
+ local cache = files.getCache(uri)
+ if not cache.diagnosticRanges then
+ cache.diagnosticRanges = {}
+ for _, doc in ipairs(status.ast.docs) do
+ if doc.type == 'doc.diagnostic' then
+ makeDiagRange(uri, doc, cache.diagnosticRanges)
+ end
+ end
+ table.sort(cache.diagnosticRanges, function (a, b)
+ return a.offset < b.offset
+ end)
+ end
+end
diff --git a/test/completion/init.lua b/test/completion/init.lua
index bd3aca25..e0ac1a2d 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -1596,6 +1596,10 @@ end
label = 'meta',
kind = define.CompletionItemKind.Event,
},
+ {
+ label = 'diagnostic',
+ kind = define.CompletionItemKind.Event,
+ }
}
TEST [[