Skip to content

Commit 996d46f

Browse files
committed
watch symbolic links
resolve #1848
1 parent 26b94a3 commit 996d46f

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

script/filewatch.lua

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,32 @@ m._watchings = {}
3434

3535
---@param path string
3636
---@param recursive boolean
37-
function m.watch(path, recursive)
38-
if path == '' then
37+
---@param filter? fun(path: string):boolean
38+
function m.watch(path, recursive, filter)
39+
if path == '' or not fs.is_directory(fs.path(path)) then
3940
return function () end
4041
end
4142
if m._watchings[path] then
4243
m._watchings[path].count = m._watchings[path].count + 1
4344
else
4445
local watch = fw.create()
4546
watch:add(path)
46-
watch:recursive(recursive)
47+
log.debug('Watch add:', path)
48+
if recursive then
49+
local function scanDirctory(dir)
50+
for fullpath in fs.pairs(dir) do
51+
if fs.is_directory(fullpath) then
52+
if not filter or filter(fullpath:string()) then
53+
watch:add(fullpath:string())
54+
log.debug('Watch add:', fullpath:string())
55+
scanDirctory(fullpath)
56+
end
57+
end
58+
end
59+
end
60+
61+
scanDirctory(fs.path(path))
62+
end
4763
m._watchings[path] = {
4864
count = 1,
4965
watch = watch,

script/parser/guide.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ local m = {}
8282

8383
m.ANY = {"<ANY>"}
8484

85-
m.namePattern = '[%a_\x80-\xff][%w_\x80-\xff]*'
85+
m.notNamePattern = '[^%w_\x80-\xff]'
86+
m.namePattern = '[%a_\x80-\xff][%w_\x80-\xff]*'
8687
m.namePatternFull = '^' .. m.namePattern .. '$'
8788

8889
local blockTypes = {

script/workspace/workspace.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ function m.getLibraryMatchers(scp)
231231
end
232232

233233
--- 文件是否被忽略
234-
---@async
235234
---@param uri uri
236235
function m.isIgnored(uri)
237236
local scp = scope.getScope(uri)
@@ -308,7 +307,13 @@ function m.awaitPreload(scp)
308307

309308
if scp.uri and not scp:get('bad root') then
310309
log.info('Scan files at:', scp:getName())
311-
scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true))
310+
scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true, function (path)
311+
local uri = furi.encode(path)
312+
if m.isIgnored(uri) and not files.isLibrary(uri) then
313+
return false
314+
end
315+
return true
316+
end))
312317
local count = 0
313318
---@async
314319
native:scan(furi.decode(scp.uri), function (path)
@@ -326,7 +331,13 @@ function m.awaitPreload(scp)
326331
for _, libMatcher in ipairs(librarys) do
327332
log.info('Scan library at:', libMatcher.uri)
328333
local count = 0
329-
scp:gc(fw.watch(furi.decode(libMatcher.uri), true))
334+
scp:gc(fw.watch(furi.decode(libMatcher.uri), true, function (path)
335+
local uri = furi.encode(path)
336+
if m.isIgnored(uri) and not files.isLibrary(uri) then
337+
return false
338+
end
339+
return true
340+
end))
330341
scp:addLink(libMatcher.uri)
331342
---@async
332343
libMatcher.matcher:scan(furi.decode(libMatcher.uri), function (path)

0 commit comments

Comments
 (0)