summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-05 15:17:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-05 15:17:32 +0800
commit88ad1dcbab24491726fbdc51a93afd599ecc12a1 (patch)
tree59f4cc848aa07f8534d0b5231b4fb014da8a7b02 /script/core
parent339ffb42ac8bc457e631f373629ce8875e6ad8f0 (diff)
downloadlua-language-server-88ad1dcbab24491726fbdc51a93afd599ecc12a1.zip
update
Diffstat (limited to 'script/core')
-rw-r--r--script/core/collector.lua101
-rw-r--r--script/core/searcher.lua2
2 files changed, 87 insertions, 16 deletions
diff --git a/script/core/collector.lua b/script/core/collector.lua
index 45dae65f..43e584d5 100644
--- a/script/core/collector.lua
+++ b/script/core/collector.lua
@@ -60,35 +60,106 @@ end
local DUMMY_FUNCTION = function () end
---- 迭代某个名字的订阅
----@param uri uri
----@param name string
-function m.each(uri, name)
- local nameCollect = collect[name]
- if not nameCollect then
- return DUMMY_FUNCTION
+---@param scp scope
+local function eachOfFolder(nameCollect, scp)
+ local curi, value
+
+ local function getNext()
+ curi, value = next(nameCollect, curi)
+ if not curi then
+ return nil, nil
+ end
+ if scp:isChildUri(curi)
+ or scp:isLinkedUri(curi) then
+ return value, curi
+ end
+ return getNext()
end
- ---@type scope
- local scp = scope.getFolder(uri)
- or scope.getLinkedScope(uri)
- or scope.fallback
+ return getNext
+end
+
+---@param scp scope
+local function eachOfLinked(nameCollect, scp)
local curi, value
+
local function getNext()
curi, value = next(nameCollect, curi)
if not curi then
return nil, nil
end
- if not scp:isChildUri(curi)
- and not scp:isLinkedUri(curi) then
- return getNext()
+ if scp:isChildUri(curi)
+ and scp:isLinkedUri(curi) then
+ return value, curi
end
- return value, curi
+ local cscp = scope.getFolder(curi)
+ or scope.getLinkedScope(curi)
+ or scope.fallback
+
+ if cscp == scp
+ or cscp:isChildUri(scp.uri)
+ or cscp:isLinkedUri(scp.uri) then
+ return value, curi
+ end
+
+ return getNext()
end
+
return getNext
end
+---@param scp scope
+local function eachOfFallback(nameCollect, scp)
+ local curi, value
+
+ local function getNext()
+ curi, value = next(nameCollect, curi)
+ if not curi then
+ return nil, nil
+ end
+ if scp:isLinkedUri(curi) then
+ return value, curi
+ end
+
+ local cscp = scope.getFolder(curi)
+ or scope.getLinkedScope(curi)
+ or scope.fallback
+
+ if cscp == scp then
+ return value, curi
+ end
+
+ return getNext()
+ end
+
+ return getNext
+end
+
+--- 迭代某个名字的订阅
+---@param uri uri
+---@param name string
+function m.each(uri, name)
+ local nameCollect = collect[name]
+ if not nameCollect then
+ return DUMMY_FUNCTION
+ end
+
+ local scp = scope.getFolder(uri)
+
+ if scp then
+ return eachOfFolder(nameCollect, scp)
+ end
+
+ scp = scope.getLinkedScope(uri)
+
+ if scp then
+ return eachOfLinked(nameCollect, scp)
+ end
+
+ return eachOfFallback(nameCollect, scope.fallback)
+end
+
--- 迭代某个名字的引用订阅
---@param uri uri
---@param name string
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 558dc96b..10f1d3db 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -27,7 +27,7 @@ local getUri = guide.getUri
local getRoot = guide.getRoot
local ceach = collector.each
-local ceachref = collector.eachRef
+local ceachref = collector.each
local getState = files.getState