summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-17 03:47:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-17 03:47:53 +0800
commit7075ca19746addabc66296518a1eeafca8144723 (patch)
tree17b070aab64d6f1e07ba26024a66eb959c9c9f11
parentc3b468fd4a6d745c77340eb71c0950d221a6c4ba (diff)
downloadlua-language-server-7075ca19746addabc66296518a1eeafca8144723.zip
update filewatch
-rw-r--r--script/filewatch.lua39
-rw-r--r--script/provider/provider.lua2
-rw-r--r--script/workspace/workspace.lua4
-rw-r--r--test/other/filewatch.lua2
4 files changed, 27 insertions, 20 deletions
diff --git a/script/filewatch.lua b/script/filewatch.lua
index 85a50046..72f5eec5 100644
--- a/script/filewatch.lua
+++ b/script/filewatch.lua
@@ -32,16 +32,21 @@ local m = {}
m._eventList = {}
m._watchings = {}
-function m.watch(path)
+---@param path string
+---@param recursive boolean
+function m.watch(path, recursive)
if path == '' then
return function () end
end
if m._watchings[path] then
m._watchings[path].count = m._watchings[path].count + 1
else
+ local watch = fw.create()
+ watch:add(path)
+ watch:recursive(recursive)
m._watchings[path] = {
count = 1,
- id = fw.add(path),
+ watch = watch,
}
log.debug('fw.add', path)
end
@@ -53,7 +58,6 @@ function m.watch(path)
removed = true
m._watchings[path].count = m._watchings[path].count - 1
if m._watchings[path].count == 0 then
- fw.remove(m._watchings[path].id)
m._watchings[path] = nil
log.debug('fw.remove', path)
end
@@ -75,19 +79,22 @@ end
function m.update()
local collect
- for _ = 1, 10000 do
- local ev, path = fw.select()
- if not ev then
- break
- end
- log.debug('filewatch:', ev, path)
- if not collect then
- collect = {}
- end
- if ev == 'modify' then
- collect[path] = (collect[path] or 0) | MODIFY
- elseif ev == 'rename' then
- collect[path] = (collect[path] or 0) | RENAME
+ for _, watching in pairs(m._watchings) do
+ local watch = watching.watch
+ for _ = 1, 10000 do
+ local ev, path = watch:select()
+ if not ev then
+ break
+ end
+ log.debug('filewatch:', ev, path)
+ if not collect then
+ collect = {}
+ end
+ if ev == 'modify' then
+ collect[path] = (collect[path] or 0) | MODIFY
+ elseif ev == 'rename' then
+ collect[path] = (collect[path] or 0) | RENAME
+ end
end
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index ea02579c..d19e0040 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -36,7 +36,7 @@ function m.updateConfig(uri)
log.info('Load config from specified', CONFIGPATH)
log.info(inspect(specified))
-- watch directory
- filewatch.watch(workspace.getAbsolutePath(uri, CONFIGPATH):gsub('[^/\\]+$', ''))
+ filewatch.watch(workspace.getAbsolutePath(uri, CONFIGPATH):gsub('[^/\\]+$', ''), false)
config.update(scope.override, specified)
end
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index b6be6fc5..bf4256b3 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -308,7 +308,7 @@ 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))))
+ scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true))
local count = 0
---@async
native:scan(furi.decode(scp.uri), function (path)
@@ -326,7 +326,7 @@ 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)))
+ scp:gc(fw.watch(furi.decode(libMatcher.uri), true))
scp:addLink(libMatcher.uri)
---@async
libMatcher.matcher:scan(furi.decode(libMatcher.uri), function (path)
diff --git a/test/other/filewatch.lua b/test/other/filewatch.lua
index 66a9ccbc..f5d5a03d 100644
--- a/test/other/filewatch.lua
+++ b/test/other/filewatch.lua
@@ -9,7 +9,7 @@ fs.create_directories(path)
os.remove((path / 'test.txt'):string())
-local _ <close> = fw.watch(path:string())
+local _ <close> = fw.watch(path:string(), true)
fsu.saveFile(path / 'test.txt', 'test')
local events