summaryrefslogtreecommitdiff
path: root/server/src/core/completion.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/core/completion.lua')
-rw-r--r--server/src/core/completion.lua99
1 files changed, 66 insertions, 33 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 59a3cb3f..83d740a3 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -509,39 +509,7 @@ local function searchInRequire(vm, select, source, callback)
end
end
-local function searchCallArg(vm, source, word, callback, pos)
- local results = {}
- vm:eachSource(function (src)
- if src.type == 'call'
- and src.start <= pos
- and src.finish >= pos
- then
- results[#results+1] = src
- end
- end)
- if #results == 0 then
- return nil
- end
- -- 可能处于 'func1(func2(' 的嵌套中,将最近的call放到最前面
- table.sort(results, function (a, b)
- return a.start > b.start
- end)
- local call = results[1]
- local args = call:bindCall()
- if not args then
- return
- end
-
- local value = call:findCallFunction()
- if not value then
- return
- end
-
- local lib = value:getLib()
- if not lib then
- return
- end
-
+local function searchEnumAsLib(vm, source, word, callback, pos, args, lib)
local select = #args + 1
for i, arg in ipairs(args) do
if arg.start <= pos and arg.finish >= pos - 1 then
@@ -584,6 +552,71 @@ local function searchCallArg(vm, source, word, callback, pos)
end
end
+local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, func)
+ local select = #args + 1
+ for i, arg in ipairs(args) do
+ if arg.start <= pos and arg.finish >= pos - 1 then
+ select = i
+ break
+ end
+ end
+
+ local param = func:findEmmyParamByIndex(select)
+ if not param then
+ return
+ end
+
+ param:eachEnum(function (enum)
+ if matchKey(word, enum) then
+ callback(enum, nil, CompletionItemKind.EnumMember, {
+ label = enum,
+ })
+ end
+ end)
+end
+
+local function searchCallArg(vm, source, word, callback, pos)
+ local results = {}
+ vm:eachSource(function (src)
+ if src.type == 'call'
+ and src.start <= pos
+ and src.finish >= pos
+ then
+ results[#results+1] = src
+ end
+ end)
+ if #results == 0 then
+ return nil
+ end
+ -- 可能处于 'func1(func2(' 的嵌套中,将最近的call放到最前面
+ table.sort(results, function (a, b)
+ return a.start > b.start
+ end)
+ local call = results[1]
+ local args = call:bindCall()
+ if not args then
+ return
+ end
+
+ local value = call:findCallFunction()
+ if not value then
+ return
+ end
+
+ local lib = value:getLib()
+ if lib then
+ searchEnumAsLib(vm, source, word, callback, pos, args, lib)
+ return
+ end
+
+ ---@type function
+ local func = value:getFunction()
+ if func then
+ searchEnumAsEmmyParams(vm, source, word, callback, pos, args, func)
+ return
+ end
+end
+
local function searchAllWords(vm, source, word, callback, pos)
if word == '' then
return