summaryrefslogtreecommitdiff
path: root/script-beta/core/reference.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/core/reference.lua')
-rw-r--r--script-beta/core/reference.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/script-beta/core/reference.lua b/script-beta/core/reference.lua
index 73e1130e..5c18de1b 100644
--- a/script-beta/core/reference.lua
+++ b/script-beta/core/reference.lua
@@ -7,6 +7,24 @@ local function isValidFunction(source, offset)
return offset >= source.start and offset < source.start + #'function'
end
+local function sortResults(results)
+ -- 先按照顺序排序
+ table.sort(results, function (a, b)
+ return a.target.start < b.target.start
+ end)
+ -- 如果2个结果处于嵌套状态,则取范围小的那个
+ local lf
+ for i = #results, 1, -1 do
+ local res = results[i].target
+ local f = res.finish
+ if lf and f > lf then
+ table.remove(results, i)
+ else
+ lf = f
+ end
+ end
+end
+
local accept = {
['local'] = true,
['setlocal'] = true,
@@ -62,5 +80,8 @@ return function (uri, offset)
if #results == 0 then
return nil
end
+
+ sortResults(results)
+
return results
end