summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/completion.lua51
-rw-r--r--script/parser/guide.lua3
-rw-r--r--script/parser/luadoc.lua49
3 files changed, 100 insertions, 3 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 407a0e98..613ca062 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -21,6 +21,13 @@ local furi = require 'file-uri'
local rpath = require 'workspace.require-path'
local lang = require 'language'
+local DiagnosticModes = {
+ 'disable-next-line',
+ 'disable-line',
+ 'disable',
+ 'enable',
+}
+
local stackID = 0
local stacks = {}
local function stack(callback)
@@ -1467,6 +1474,7 @@ local function tryLuaDocCate(word, results)
'meta',
'version',
'see',
+ 'diagnostic',
} do
if matchKey(word, docType) then
results[#results+1] = {
@@ -1568,6 +1576,35 @@ local function tryLuaDocBySource(ast, offset, source, results)
end
end
return true
+ elseif source.type == 'doc.diagnostic' then
+ for _, mode in ipairs(DiagnosticModes) do
+ if matchKey(source.mode, mode) then
+ results[#results+1] = {
+ label = mode,
+ kind = define.CompletionItemKind.Enum,
+ textEdit = {
+ start = source.start,
+ finish = source.start + #source.mode - 1,
+ newText = mode,
+ },
+ }
+ end
+ end
+ return true
+ elseif source.type == 'doc.diagnostic.name' then
+ for name in pairs(define.DiagnosticDefaultSeverity) do
+ if matchKey(source[1], name) then
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Value,
+ textEdit = {
+ start = source.start,
+ finish = source.start + #source[1] - 1,
+ newText = name,
+ },
+ }
+ end
+ end
end
return false
end
@@ -1632,6 +1669,20 @@ local function tryLuaDocByErr(ast, offset, err, docState, results)
}
end
end
+ elseif err.type == 'LUADOC_MISS_DIAG_MODE' then
+ for _, mode in ipairs(DiagnosticModes) do
+ results[#results+1] = {
+ label = mode,
+ kind = define.CompletionItemKind.Enum,
+ }
+ end
+ elseif err.type == 'LUADOC_MISS_DIAG_NAME' then
+ for name in pairs(define.DiagnosticDefaultSeverity) do
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Value,
+ }
+ end
end
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 4ce241c7..fbb59f31 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -105,7 +105,8 @@ m.childMap = {
['doc.type.typeliteral'] = {'node'},
['doc.type.arg'] = {'extends'},
['doc.overload'] = {'overload', 'comment'},
- ['doc.see'] = {'name', 'field'},
+ ['doc.see'] = {'name', 'field', 'comment'},
+ ['doc.diagnostic'] = {'#names', 'comment'},
}
m.actionMap = {
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 7684ac1f..c5ac3a1e 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -12,7 +12,7 @@ Sp <- %s+
X16 <- [a-fA-F0-9]
Word <- [a-zA-Z0-9_]
Token <- Name / String / Symbol
-Name <- ({} {[a-zA-Z0-9_] [a-zA-Z0-9_.*]*} {})
+Name <- ({} {[a-zA-Z0-9_] [a-zA-Z0-9_.*-]*} {})
-> Name
String <- ({} StringDef {})
-> String
@@ -871,6 +871,49 @@ local function parseSee()
return result
end
+local function parseDiagnostic()
+ local result = {
+ type = 'doc.diagnostic',
+ }
+ local nextTP, mode = nextToken()
+ if nextTP ~= 'name' then
+ pushError {
+ type = 'LUADOC_MISS_DIAG_MODE',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ return nil
+ end
+ result.mode = mode
+ result.start = getStart()
+ result.finish = getFinish()
+
+ if checkToken('symbol', ':', 1) then
+ nextToken()
+ result.names = {}
+ while true do
+ local name = parseName('doc.diagnostic.name', result)
+ if not name then
+ pushError {
+ type = 'LUADOC_MISS_DIAG_NAME',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ return result
+ end
+ result.names[#result.names+1] = name
+ if not checkToken('symbol', ',', 1) then
+ break
+ end
+ nextToken()
+ end
+ end
+
+ result.finish = getFinish()
+
+ return result
+end
+
local function convertTokens()
local tp, text = nextToken()
if not tp then
@@ -878,7 +921,7 @@ local function convertTokens()
end
if tp ~= 'name' then
pushError {
- type = 'LUADOC_MISS_CATE_NAME',
+ type = 'LUADOC_MISS_CATE_NAME',
start = getStart(),
finish = getFinish(),
}
@@ -910,6 +953,8 @@ local function convertTokens()
return parseVersion()
elseif text == 'see' then
return parseSee()
+ elseif text == 'diagnostic' then
+ return parseDiagnostic()
end
end