diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-20 19:55:11 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-20 19:55:11 +0800 |
commit | d0bd1eb92a2c18472d5ed0358c6fc75e06810e63 (patch) | |
tree | fa169842548c4f76704d23c0eb6af57a4ca074cc /server | |
parent | f73fbc54e6924580cbde1b0b10600e688f1bc1f6 (diff) | |
download | lua-language-server-d0bd1eb92a2c18472d5ed0358c6fc75e06810e63.zip |
先找at再找close
Diffstat (limited to 'server')
-rw-r--r-- | server/src/matcher/find_result.lua | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/server/src/matcher/find_result.lua b/server/src/matcher/find_result.lua index 17cc25a1..f876e2b3 100644 --- a/server/src/matcher/find_result.lua +++ b/server/src/matcher/find_result.lua @@ -2,7 +2,7 @@ local function isContainPos(obj, pos) if obj.start <= pos and obj.finish + 1 >= pos then return true end - return false, pos - (obj.finish + 1) + return false end local function findAtPos(results, pos) @@ -45,10 +45,8 @@ local function findClosePos(results, pos) if sources.type == 'multi-source' then for _, source in ipairs(source) do if source.type ~= 'simple' then - local inside, dis = isContainPos(source, pos) - if inside then - return object, source - elseif dis > 0 and dis < curDis then + local dis = pos - source.finish + if dis > 0 and dis < curDis then curDis = dis parent = object end @@ -57,10 +55,8 @@ local function findClosePos(results, pos) else local source = sources if source.type ~= 'simple' then - local inside, dis = isContainPos(source, pos) - if inside then - return object, source - elseif dis > 0 and dis < curDis then + local dis = pos - source.finish + if dis > 0 and dis < curDis then curDis = dis parent = object end @@ -89,7 +85,12 @@ end return function (vm, pos, close) local results = vm.results if close then - return findClosePos(results, pos) + local obj, source = findAtPos(results, pos) + if obj then + return obj, source + else + return findClosePos(results, pos) + end else return findAtPos(results, pos) end |