summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/completion.lua30
-rw-r--r--script/core/diagnostics/unknown-operator.lua34
-rw-r--r--script/parser/luadoc.lua4
-rw-r--r--script/proto/diagnostic.lua1
4 files changed, 65 insertions, 4 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 69488e36..ae1d7f9e 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1736,6 +1736,23 @@ local function tryluaDocBySource(state, position, source, results)
end
end
return true
+ elseif source.type == 'doc.operator.name' then
+ for _, name in ipairs(vm.UNARY_OP) do
+ if matchKey(source[1], name) then
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ }
+ end
+ end
+ for _, name in ipairs(vm.BINARY_OP) do
+ if matchKey(source[1], name) then
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ }
+ end
+ end
end
return false
end
@@ -1846,6 +1863,19 @@ local function tryluaDocByErr(state, position, err, docState, results)
}
end
end
+ elseif err.type == 'LUADOC_MISS_OPERATOR_NAME' then
+ for _, name in ipairs(vm.UNARY_OP) do
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ }
+ end
+ for _, name in ipairs(vm.BINARY_OP) do
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ }
+ end
end
end
diff --git a/script/core/diagnostics/unknown-operator.lua b/script/core/diagnostics/unknown-operator.lua
new file mode 100644
index 00000000..29a86eaa
--- /dev/null
+++ b/script/core/diagnostics/unknown-operator.lua
@@ -0,0 +1,34 @@
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
+local vm = require 'vm'
+local await = require 'await'
+local util = require 'utility'
+
+---@async
+return function (uri, callback)
+ local state = files.getState(uri)
+ if not state then
+ return
+ end
+
+ if not state.ast.docs then
+ return
+ end
+
+ for _, doc in ipairs(state.ast.docs) do
+ if doc.type == 'doc.operator' then
+ local op = doc.op
+ if op then
+ if not util.arrayHas(vm.UNARY_OP, op[1])
+ and not util.arrayHas(vm.BINARY_OP, op[1]) then
+ callback {
+ start = doc.op.start,
+ finish = doc.op.finish,
+ message = lang.script('DIAG_UNKNOWN_OPERATOR', op[1])
+ }
+ end
+ end
+ end
+ end
+end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 2237b232..13c34d16 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -148,10 +148,6 @@ Symbol <- ({} {
---@field versions? table[]
---@field names? parser.object[]
-local function trim(str)
- return str:match '^%s*(%S+)%s*$'
-end
-
local function parseTokens(text, offset)
Ci = 0
Offset = offset
diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua
index e5f74ef5..d8312dfe 100644
--- a/script/proto/diagnostic.lua
+++ b/script/proto/diagnostic.lua
@@ -93,6 +93,7 @@ m.register {
'unknown-diag-code',
'unknown-cast-variable',
'cast-type-mismatch',
+ 'unknown-operator',
} {
group = 'luadoc',
severity = 'Warning',