diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-20 19:52:59 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-20 19:52:59 +0800 |
commit | f73fbc54e6924580cbde1b0b10600e688f1bc1f6 (patch) | |
tree | b35a75425459d16c135fc3818795a4045e8cbb10 /server | |
parent | 27100cea721488e379ad83812b293858a14187a9 (diff) | |
download | lua-language-server-f73fbc54e6924580cbde1b0b10600e688f1bc1f6.zip |
因为source范围可能互相重叠,find_result的时候找范围最小的那个
Diffstat (limited to 'server')
-rw-r--r-- | server/src/matcher/find_result.lua | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/server/src/matcher/find_result.lua b/server/src/matcher/find_result.lua index 2b7c1b98..17cc25a1 100644 --- a/server/src/matcher/find_result.lua +++ b/server/src/matcher/find_result.lua @@ -6,21 +6,36 @@ local function isContainPos(obj, pos) end local function findAtPos(results, pos) + local res = {} for sources, object in pairs(results.sources) do if sources.type == 'multi-source' then for _, source in ipairs(source) do if source.type ~= 'simple' and isContainPos(source, pos) then - return object, source + res[#res+1] = { + object = object, + source = source, + range = source.finish - source.start, + } end end else local source = sources if source.type ~= 'simple' and isContainPos(source, pos) then - return object, source + res[#res+1] = { + object = object, + source = source, + range = source.finish - source.start, + } end end end - return nil + if #res == 0 then + return nil + end + table.sort(res, function (a, b) + return a.range < b.range + end) + return res[1].object, res[1].source end local function findClosePos(results, pos) |