diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/core/completion/completion.lua | 55 | ||||
-rw-r--r-- | script/core/noder.lua | 25 |
2 files changed, 45 insertions, 35 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index eadf2739..e960af15 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1380,34 +1380,37 @@ local function getCallEnumsAndFuncs(source, index, oop, call) return end local results = {} - if currentIndex == 1 then - for _, doc in ipairs(class.fields) do - if doc.field ~= source - and doc.field[1] == source[1] then - local eventName = noder.getFieldEventName(doc) - if eventName then - results[#results+1] = { - label = ('%q'):format(eventName), - description = doc.comment, - kind = define.CompletionItemKind.EnumMember, - } + local valueBeforeIndex = index > 1 and call.args[index - 1][1] + + for _, doc in ipairs(class.fields) do + if doc.field ~= source + and doc.field[1] == source[1] then + local indexType = currentIndex + if not oop then + local args = noder.getFieldArgs(doc) + -- offset if doc's first arg is `self` + if args and args[1] and args[1].name[1] == 'self' then + indexType = indexType - 1 end end - end - elseif currentIndex == 2 then - local myEventName = call.args[index - 1][1] - for _, doc in ipairs(class.fields) do - if doc.field ~= source - and doc.field[1] == source[1] then - local eventName = noder.getFieldEventName(doc) - if eventName and eventName == myEventName then - local docFunc = doc.extends.types[1].args[index].extends.types[1] - results[#results+1] = { - label = infer.viewDocFunction(docFunc), - description = doc.comment, - kind = define.CompletionItemKind.Function, - insertText = buildInsertDocFunction(docFunc), - } + local eventName = noder.getFieldEventName(doc) + if eventName then + if indexType == 1 then + results[#results+1] = { + label = ('%q'):format(eventName), + description = doc.comment, + kind = define.CompletionItemKind.EnumMember, + } + elseif indexType == 2 then + if eventName == valueBeforeIndex then + local docFunc = doc.extends.types[1].args[index].extends.types[1] + results[#results+1] = { + label = infer.viewDocFunction(docFunc), + description = doc.comment, + kind = define.CompletionItemKind.Function, + insertText = buildInsertDocFunction(docFunc), + } + end end end end diff --git a/script/core/noder.lua b/script/core/noder.lua index fcc6b6f4..1e502339 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -140,11 +140,7 @@ local function getMethodNode(source) end end -local function getFieldEventName(field) - if field._eventName then - return field._eventName or nil - end - field._eventName = false +local function getFieldArgs(field) local fieldType = field.extends if not fieldType then return nil @@ -153,19 +149,29 @@ local function getFieldEventName(field) if not docFunc or docFunc.type ~= 'doc.type.function' then return nil end - local firstArg = docFunc.args and docFunc.args[1] + return docFunc.args +end + +local function getFieldEventName(field) + if field._eventName then + return field._eventName or nil + end + field._eventName = false + + local args = getFieldArgs(field) + local firstArg = args and args[1] if not firstArg then return nil end local secondArg if firstArg.name[1] == 'self' then - firstArg = docFunc.args[2] + firstArg = args[2] if not firstArg then return nil end - secondArg = docFunc.args[3] + secondArg = args[3] else - secondArg = docFunc.args[2] + secondArg = args[2] end if not secondArg then return @@ -1685,6 +1691,7 @@ function m.eachID(noders) return next, noders.source end +m.getFieldArgs = getFieldArgs m.getFieldEventName = getFieldEventName ---获取对象的noders |