diff options
-rw-r--r-- | script/filewatch.lua | 22 | ||||
-rw-r--r-- | script/parser/guide.lua | 3 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 17 |
3 files changed, 35 insertions, 7 deletions
diff --git a/script/filewatch.lua b/script/filewatch.lua index 72f5eec5..1c69ee50 100644 --- a/script/filewatch.lua +++ b/script/filewatch.lua @@ -34,8 +34,9 @@ m._watchings = {} ---@param path string ---@param recursive boolean -function m.watch(path, recursive) - if path == '' then +---@param filter? fun(path: string):boolean +function m.watch(path, recursive, filter) + if path == '' or not fs.is_directory(fs.path(path)) then return function () end end if m._watchings[path] then @@ -43,7 +44,22 @@ function m.watch(path, recursive) else local watch = fw.create() watch:add(path) - watch:recursive(recursive) + log.debug('Watch add:', path) + if recursive then + local function scanDirctory(dir) + for fullpath in fs.pairs(dir) do + if fs.is_directory(fullpath) then + if not filter or filter(fullpath:string()) then + watch:add(fullpath:string()) + log.debug('Watch add:', fullpath:string()) + scanDirctory(fullpath) + end + end + end + end + + scanDirctory(fs.path(path)) + end m._watchings[path] = { count = 1, watch = watch, diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 7f569d71..f3b5d502 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -82,7 +82,8 @@ local m = {} m.ANY = {"<ANY>"} -m.namePattern = '[%a_\x80-\xff][%w_\x80-\xff]*' +m.notNamePattern = '[^%w_\x80-\xff]' +m.namePattern = '[%a_\x80-\xff][%w_\x80-\xff]*' m.namePatternFull = '^' .. m.namePattern .. '$' local blockTypes = { diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 7031064b..fd2e8f31 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -231,7 +231,6 @@ function m.getLibraryMatchers(scp) end --- 文件是否被忽略 ----@async ---@param uri uri function m.isIgnored(uri) local scp = scope.getScope(uri) @@ -308,7 +307,13 @@ function m.awaitPreload(scp) if scp.uri and not scp:get('bad root') then log.info('Scan files at:', scp:getName()) - scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true)) + scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true, function (path) + local uri = furi.encode(path) + if m.isIgnored(uri) and not files.isLibrary(uri) then + return false + end + return true + end)) local count = 0 ---@async native:scan(furi.decode(scp.uri), function (path) @@ -326,7 +331,13 @@ function m.awaitPreload(scp) for _, libMatcher in ipairs(librarys) do log.info('Scan library at:', libMatcher.uri) local count = 0 - scp:gc(fw.watch(furi.decode(libMatcher.uri), true)) + scp:gc(fw.watch(furi.decode(libMatcher.uri), true, function (path) + local uri = furi.encode(path) + if m.isIgnored(uri) and not files.isLibrary(uri) then + return false + end + return true + end)) scp:addLink(libMatcher.uri) ---@async libMatcher.matcher:scan(furi.decode(libMatcher.uri), function (path) |