diff options
-rw-r--r-- | server/src/matcher/completion.lua | 51 | ||||
-rw-r--r-- | server/src/matcher/find_result.lua | 58 |
2 files changed, 51 insertions, 58 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index acbb367e..ce6fd277 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -217,10 +217,57 @@ local function searchAsSuffix(result, callback) end) end +local function findClosePos(vm, pos) + local curDis = math.maxinteger + local parent = nil + for sources, object in pairs(vm.results.sources) do + if sources.type == 'multi-source' then + for _, source in ipairs(sources) do + if source.type ~= 'simple' then + local dis = pos - source.finish + if dis > 0 and dis < curDis then + curDis = dis + parent = object + end + end + end + else + local source = sources + if source.type ~= 'simple' then + local dis = pos - source.finish + if dis > 0 and dis < curDis then + curDis = dis + parent = object + end + end + end + 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 + end + return nil +end + return function (vm, pos) - local result, source = findResult(vm, pos, true) + local result, source = findResult(vm, pos) if not result then - return nil + result, source = findClosePos(vm, pos) + if not result then + return nil + end end local list = {} diff --git a/server/src/matcher/find_result.lua b/server/src/matcher/find_result.lua index dcf00c66..940ef80c 100644 --- a/server/src/matcher/find_result.lua +++ b/server/src/matcher/find_result.lua @@ -38,60 +38,6 @@ local function findAtPos(results, pos) return res[1].object, res[1].source end -local function findClosePos(results, pos) - local curDis = math.maxinteger - local parent = nil - for sources, object in pairs(results.sources) do - if sources.type == 'multi-source' then - for _, source in ipairs(sources) do - if source.type ~= 'simple' then - local dis = pos - source.finish - if dis > 0 and dis < curDis then - curDis = dis - parent = object - end - end - end - else - local source = sources - if source.type ~= 'simple' then - local dis = pos - source.finish - if dis > 0 and dis < curDis then - curDis = dis - parent = object - end - end - end - 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 - end - return nil -end - -return function (vm, pos, close) - local results = vm.results - if close then - local obj, source = findAtPos(results, pos) - if obj then - return obj, source - else - return findClosePos(results, pos) - end - else - return findAtPos(results, pos) - end +return function (vm, pos) + return findAtPos(vm.results, pos) end |