summaryrefslogtreecommitdiff
path: root/script-beta/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-23 19:17:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-23 19:17:20 +0800
commit88c9bd52b5a148f33ce88a265962a32af4832afd (patch)
tree4b2d12f2c08fb261b15f3fe8087d5bed890f0efb /script-beta/core
parent73fb79c13e846774b99d3c0dab886c639611ed48 (diff)
downloadlua-language-server-88c9bd52b5a148f33ce88a265962a32af4832afd.zip
整理代码
Diffstat (limited to 'script-beta/core')
-rw-r--r--script-beta/core/definition.lua21
-rw-r--r--script-beta/core/reference.lua21
2 files changed, 42 insertions, 0 deletions
diff --git a/script-beta/core/definition.lua b/script-beta/core/definition.lua
index 6a895256..22bb48ab 100644
--- a/script-beta/core/definition.lua
+++ b/script-beta/core/definition.lua
@@ -4,6 +4,24 @@ local files = require 'files'
local vm = require 'vm'
local findSource = require 'core.find-source'
+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,
@@ -97,5 +115,8 @@ return function (uri, offset)
if #results == 0 then
return nil
end
+
+ sortResults(results)
+
return results
end
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