summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/collector.lua101
-rw-r--r--script/core/searcher.lua2
-rw-r--r--script/library.lua9
-rw-r--r--script/workspace/workspace.lua28
4 files changed, 104 insertions, 36 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
diff --git a/script/library.lua b/script/library.lua
index 3fa202b6..1f2e920e 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -495,12 +495,9 @@ function m.init()
return
end
m.inited = true
- if #ws.folders == 0 then
- initBuiltIn(nil)
- else
- for _, scp in ipairs(ws.folders) do
- initBuiltIn(scp.uri)
- end
+ initBuiltIn(nil)
+ for _, scp in ipairs(ws.folders) do
+ initBuiltIn(scp.uri)
end
end
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index b8ddedb5..4baacc24 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -100,8 +100,8 @@ function m.getNativeMatcher(scp)
pattern[#pattern+1] = path
end
end
- if config.get(scp.uri, 'Lua.workspace.useGitIgnore') then
- local buf = pub.awaitTask('loadFile', m.rootUri .. '/.gitignore')
+ if scp.uri and config.get(scp.uri, 'Lua.workspace.useGitIgnore') then
+ local buf = pub.awaitTask('loadFile', scp.uri .. '/.gitignore')
if buf then
for line in buf:gmatch '[^\r\n]+' do
if line:sub(1, 1) ~= '#' then
@@ -110,7 +110,7 @@ function m.getNativeMatcher(scp)
end
end
end
- buf = pub.awaitTask('loadFile', m.rootUri .. '/.git/info/exclude')
+ buf = pub.awaitTask('loadFile', scp.uri .. '/.git/info/exclude')
if buf then
for line in buf:gmatch '[^\r\n]+' do
if line:sub(1, 1) ~= '#' then
@@ -120,8 +120,8 @@ function m.getNativeMatcher(scp)
end
end
end
- if config.get(scp.uri, 'Lua.workspace.ignoreSubmodules') then
- local buf = pub.awaitTask('loadFile', m.rootUri .. '/.gitmodules')
+ if scp.uri and config.get(scp.uri, 'Lua.workspace.ignoreSubmodules') then
+ local buf = pub.awaitTask('loadFile', scp.uri .. '/.gitmodules')
if buf then
for path in buf:gmatch('path = ([^\r\n]+)') do
log.info('Ignore by .gitmodules:', path)
@@ -244,8 +244,9 @@ end
---@async
---@param scp scope
function m.awaitPreload(scp)
- await.close('preload:' .. scp.uri)
- await.setID('preload:' .. scp.uri)
+ local displayedUri = scp.uri or '<fallback>'
+ await.close('preload:' .. displayedUri)
+ await.setID('preload:' .. displayedUri)
await.sleep(0.1)
local watchers = scp:get 'watchers'
@@ -260,13 +261,13 @@ function m.awaitPreload(scp)
local ld <close> = loading.create(scp)
scp:set('loading', ld)
- log.info('Preload start:', scp.uri)
+ log.info('Preload start:', displayedUri)
local native = m.getNativeMatcher(scp)
local librarys = m.getLibraryMatchers(scp)
- do
- log.info('Scan files at:', m.rootUri)
+ if scp.uri then
+ log.info('Scan files at:', displayedUri)
---@async
native:scan(furi.decode(scp.uri), function (path)
ld:loadFile(furi.encode(path))
@@ -282,9 +283,9 @@ function m.awaitPreload(scp)
watchers[#watchers+1] = fw.watch(furi.decode(libMatcher.uri))
end
- log.info(('Found %d files at:'):format(ld.max), scp.uri)
+ log.info(('Found %d files at:'):format(ld.max), displayedUri)
ld:loadAll()
- log.info('Preload finish at:', scp.uri)
+ log.info('Preload finish at:', displayedUri)
end
--- 查找符合指定file path的所有uri
@@ -397,9 +398,8 @@ function m.init()
for _, folder in ipairs(scope.folders) do
m.reload(folder)
end
- else
- m.reload(scope.fallback)
end
+ m.reload(scope.fallback)
end
---@param scp scope