diff options
Diffstat (limited to 'server/src/matcher')
-rw-r--r-- | server/src/matcher/completion.lua | 48 | ||||
-rw-r--r-- | server/src/matcher/find_result.lua | 12 |
2 files changed, 33 insertions, 27 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index d0480cc4..1b07e5fb 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -313,26 +313,26 @@ local function findClosePos(vm, pos) found(object, sources) end end - if parent and parent.type ~= 'local' and parent.type ~= 'field' then - parent = nil - end - if parent then - -- 造个假的 DirtyName - local source = { - type = 'name', - start = pos, - finish = pos, - [1] = '', - } - local result = { - type = 'field', - parent = parent, - key = '', - source = source, - } - return result, source + if not parent then + return nil end - return nil + if parent.type ~= 'local' and parent.type ~= 'field' then + return nil + end + -- 造个假的 DirtyName + local source = { + type = 'name', + start = pos, + finish = pos, + [1] = '', + } + local result = { + type = 'field', + parent = parent, + key = '', + source = source, + } + return result, source end local function isContainPos(obj, pos) @@ -443,20 +443,22 @@ end return function (vm, pos) local result, source = findResult(vm, pos) - local closeResult, closeSource = findClosePos(vm, pos) + if not result then + result, source = findClosePos(vm, pos) + end - if not result and not closeResult then + if not result then return nil end - local list, callback = makeList(source or closeSource) + local list, callback = makeList(source) local inCall = findCall(vm, pos) local inString = findString(vm, pos) if inCall then searchInArg(vm, inCall, inString, callback) end if not inString then - searchInResult(result or closeResult, source or closeSource, vm, pos, callback) + searchInResult(result, source, vm, pos, callback) end if #list == 0 then return nil diff --git a/server/src/matcher/find_result.lua b/server/src/matcher/find_result.lua index 940ef80c..ac8dc3f4 100644 --- a/server/src/matcher/find_result.lua +++ b/server/src/matcher/find_result.lua @@ -5,7 +5,7 @@ local function isContainPos(obj, pos) return false end -local function findAtPos(results, pos) +local function findAtPos(results, pos, level) local res = {} for sources, object in pairs(results.sources) do if sources.type == 'multi-source' then @@ -35,9 +35,13 @@ local function findAtPos(results, pos) table.sort(res, function (a, b) return a.range < b.range end) - return res[1].object, res[1].source + local data = res[level or 1] + if not data then + return nil + end + return data.object, data.source end -return function (vm, pos) - return findAtPos(vm.results, pos) +return function (vm, pos, level) + return findAtPos(vm.results, pos, level) end |