summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/config/template.lua5
-rw-r--r--script/core/completion/completion.lua25
-rw-r--r--script/core/diagnostics/unknown-operator.lua5
-rw-r--r--script/vm/compiler.lua6
-rw-r--r--script/vm/operator.lua12
-rw-r--r--test/type_inference/init.lua21
6 files changed, 64 insertions, 10 deletions
diff --git a/script/config/template.lua b/script/config/template.lua
index c9ad2f4c..e928db78 100644
--- a/script/config/template.lua
+++ b/script/config/template.lua
@@ -54,8 +54,9 @@ end
---@class config.template
---@field [string] config.template
----@operator shl: config.template
----@operator shr: config.template
+---@operator shl: config.template
+---@operator shr: config.template
+---@operator call: config.template
local Type = setmetatable({}, { __index = function (_, name)
local unit = {}
for k, v in pairs(units[name]) do
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index bc3760d9..c577874f 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1743,7 +1743,7 @@ local function tryluaDocBySource(state, position, source, results)
results[#results+1] = {
label = name,
kind = define.CompletionItemKind.Operator,
- description = ('```lua\n%s\n```'):format(vm.UNARY_MAP[name]),
+ description = ('```lua\n%s\n```'):format(vm.OP_UNARY_MAP[name]),
}
end
end
@@ -1752,10 +1752,20 @@ local function tryluaDocBySource(state, position, source, results)
results[#results+1] = {
label = name,
kind = define.CompletionItemKind.Operator,
- description = ('```lua\n%s\n```'):format(vm.BINARY_MAP[name]),
+ description = ('```lua\n%s\n```'):format(vm.OP_BINARY_MAP[name]),
}
end
end
+ for _, name in ipairs(vm.OTHER_OP) do
+ if matchKey(source[1], name) then
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ description = ('```lua\n%s\n```'):format(vm.OP_OTHER_MAP[name]),
+ }
+ end
+ end
+ return true
end
return false
end
@@ -1871,14 +1881,21 @@ local function tryluaDocByErr(state, position, err, docState, results)
results[#results+1] = {
label = name,
kind = define.CompletionItemKind.Operator,
- description = ('```lua\n%s\n```'):format(vm.UNARY_MAP[name]),
+ description = ('```lua\n%s\n```'):format(vm.OP_UNARY_MAP[name]),
}
end
for _, name in ipairs(vm.BINARY_OP) do
results[#results+1] = {
label = name,
kind = define.CompletionItemKind.Operator,
- description = ('```lua\n%s\n```'):format(vm.BINARY_MAP[name]),
+ description = ('```lua\n%s\n```'):format(vm.OP_BINARY_MAP[name]),
+ }
+ end
+ for _, name in ipairs(vm.OTHER_OP) do
+ results[#results+1] = {
+ label = name,
+ kind = define.CompletionItemKind.Operator,
+ description = ('```lua\n%s\n```'):format(vm.OP_OTHER_MAP[name]),
}
end
end
diff --git a/script/core/diagnostics/unknown-operator.lua b/script/core/diagnostics/unknown-operator.lua
index 5e8177c3..7404b5ef 100644
--- a/script/core/diagnostics/unknown-operator.lua
+++ b/script/core/diagnostics/unknown-operator.lua
@@ -21,8 +21,9 @@ return function (uri, callback)
local op = doc.op
if op then
local opName = op[1]
- if not vm.BINARY_MAP[opName]
- and not vm.UNARY_MAP[opName] then
+ if not vm.OP_BINARY_MAP[opName]
+ and not vm.OP_UNARY_MAP[opName]
+ and not vm.OP_OTHER_MAP[opName] then
callback {
start = doc.op.start,
finish = doc.op.finish,
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index a13f1e3a..a9cd50cd 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1472,6 +1472,9 @@ local compilerSwitch = util.switch()
if not node then
return
end
+ if node:isEmpty() then
+ node = vm.runOperator('call', vararg.node) or node
+ end
vm.setNode(source, node)
end
if vararg.type == 'varargs' then
@@ -1490,6 +1493,9 @@ local compilerSwitch = util.switch()
if not node then
return
end
+ if node:isEmpty() then
+ node = vm.runOperator('call', source.node) or node
+ end
vm.setNode(source, node)
end)
: case 'doc.type'
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index 35910f94..69340648 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -24,6 +24,9 @@ vm.BINARY_OP = {
'shr',
'concat',
}
+vm.OTHER_OP = {
+ 'call',
+}
local unaryMap = {
['-'] = 'unm',
@@ -47,8 +50,13 @@ local binaryMap = {
['..'] = 'concat',
}
-vm.UNARY_MAP = util.revertMap(unaryMap)
-vm.BINARY_MAP = util.revertMap(binaryMap)
+local otherMap = {
+ ['()'] = 'call',
+}
+
+vm.OP_UNARY_MAP = util.revertMap(unaryMap)
+vm.OP_BINARY_MAP = util.revertMap(binaryMap)
+vm.OP_OTHER_MAP = util.revertMap(otherMap)
---@param operators parser.object[]
---@param op string
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 619d7615..065109aa 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -3555,3 +3555,24 @@ TEST 'boolean' [[
local a
local <?b?> = a + true
]]
+
+TEST 'A' [[
+---@class A
+---@operator call: A
+
+---@type A
+local a
+local <?b?> = a()
+]]
+
+TEST 'A' [[
+---@class A
+---@operator call: A
+
+---@type A
+local a
+
+local t = {
+ <?x?> = a(),
+}
+]]