summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-16 17:50:16 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-16 17:50:16 +0800
commit03a9b0c84b2ea3bd306071860a696f75ac4993d4 (patch)
tree8fd56e5429e9aca88c29fe99403a117f0f67540b /script
parent792afd666c6c43bdbd7e82ec8596755f579dc9ba (diff)
downloadlua-language-server-03a9b0c84b2ea3bd306071860a696f75ac4993d4.zip
call `doc.type.function` always use literal index
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua27
1 files changed, 21 insertions, 6 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index dc34419c..f36b265c 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1301,7 +1301,7 @@ local function pushCallEnumsAndFuncs(defs)
return results
end
-local function getCallEnumsAndFuncs(source, index)
+local function getCallEnumsAndFuncs(source, index, oop)
if source.type == 'function' and source.bindDocs then
if not source.args then
return
@@ -1328,6 +1328,20 @@ local function getCallEnumsAndFuncs(source, index)
end
end
if source.type == 'doc.type.function' then
+ --[[
+ always use literal index, that is:
+ ```
+ ---@class Class
+ ---@field f(x: number, y: boolean)
+ local c
+
+ c.f(1, true) -- correct
+ c:f(1, true) -- also correct
+ ```
+ --]]
+ if oop then
+ index = index - 1
+ end
local arg = source.args[index]
if arg then
return pushCallEnumsAndFuncs(vm.getDefs(arg.extends))
@@ -1349,14 +1363,15 @@ end
local function getCallArgInfo(call, text, offset)
if not call.args then
- return 1, nil
+ return 1, nil, nil
end
+ local oop = call.node.type == 'getmethod'
for index, arg in ipairs(call.args) do
if arg.start <= offset and arg.finish >= offset then
- return index, arg
+ return index, arg, oop
end
end
- return #call.args + 1, nil
+ return #call.args + 1, nil, oop
end
local function getFuncParamByCallIndex(func, index)
@@ -1458,14 +1473,14 @@ local function tryCallArg(ast, text, offset, results)
return
end
local myResults = {}
- local argIndex, arg = getCallArgInfo(call, text, offset)
+ local argIndex, arg, oop = getCallArgInfo(call, text, offset)
if arg and arg.type == 'function' then
return
end
local defs = vm.getDefs(call.node)
for _, def in ipairs(defs) do
def = searcher.getObjectValue(def) or def
- local enums = getCallEnumsAndFuncs(def, argIndex)
+ local enums = getCallEnumsAndFuncs(def, argIndex, oop)
if enums then
mergeEnums(myResults, enums, arg)
end