Skip to content

Commit b5b89b4

Browse files
committed
fix filewatch
1 parent 9ccd59b commit b5b89b4

File tree

4 files changed

+38
-37
lines changed

4 files changed

+38
-37
lines changed

script/core/hint.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ end
242242
return function (uri, start, finish)
243243
local results = {}
244244
typeHint(uri, results, start, finish)
245-
awaitHint(uri, results, start, finish)
246245
paramName(uri, results, start, finish)
246+
awaitHint(uri, results, start, finish)
247247
arrayIndex(uri, results, start, finish)
248248
return results
249249
end

script/files.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ end
105105
---@param libraryUri uri
106106
function m.setLibraryUri(scp, uri, libraryUri)
107107
scp:get 'libraryMap' [uri] = libraryUri
108-
scp:addLink(libraryUri)
109108
end
110109

111110
--- 是否是库文件

script/filewatch.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ end
4545

4646
function m.update()
4747
local collect
48-
for _ = 1, 100 do
48+
for _ = 1, 10000 do
4949
local ev, path = fw.select()
5050
if not ev then
5151
break

script/workspace/workspace.lua

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ function m.awaitLoadFile(uri)
228228
log.info('Scan files at:', uri)
229229
---@async
230230
native:scan(furi.decode(uri), function (path)
231-
ld:loadFile(furi.encode(path))
231+
files.remove(furi.encode(path))
232+
ld:loadFile(furi.encode(path), nil)
232233
end)
233234
ld:loadAll()
234235
end
@@ -238,7 +239,7 @@ function m.removeFile(uri)
238239
if scp:isChildUri(uri)
239240
or scp:isLinkedUri(uri) then
240241
local cachedUris = scp:get 'cachedUris'
241-
if cachedUris[uri] then
242+
if cachedUris and cachedUris[uri] then
242243
cachedUris[uri] = nil
243244
files.delRef(uri)
244245
end
@@ -281,9 +282,10 @@ function m.awaitPreload(scp)
281282

282283
for _, libMatcher in ipairs(librarys) do
283284
log.info('Scan library at:', libMatcher.uri)
285+
scp:addLink(libMatcher.uri)
284286
---@async
285287
libMatcher.matcher:scan(furi.decode(libMatcher.uri), function (path)
286-
ld:loadFile(furi.encode(path), libMatcher.uri)
288+
ld:loadFile(furi.encode(path))
287289
end)
288290
watchers[#watchers+1] = fw.watch(furi.decode(libMatcher.uri))
289291
end
@@ -490,42 +492,42 @@ end)
490492

491493
fw.event(function (changes) ---@async
492494
for _, change in ipairs(changes) do
493-
local path = change.path
494-
local uri = furi.encode(path)
495-
m.awaitReady(uri)
496-
if change.type == 'create' then
497-
log.debug('FileChangeType.Created', uri)
498-
m.awaitLoadFile(uri)
499-
elseif change.type == 'delete' then
500-
log.debug('FileChangeType.Deleted', uri)
501-
files.remove(uri)
502-
m.removeFile(uri)
503-
local childs = files.getChildFiles(uri)
504-
for _, curi in ipairs(childs) do
505-
log.debug('FileChangeType.Deleted.Child', curi)
506-
files.remove(curi)
495+
---@async
496+
await.call(function ()
497+
local path = change.path
498+
local uri = furi.encode(path)
499+
if change.type == 'create' then
500+
log.debug('FileChangeType.Created', uri)
501+
m.awaitLoadFile(uri)
502+
elseif change.type == 'delete' then
503+
log.debug('FileChangeType.Deleted', uri)
504+
files.remove(uri)
507505
m.removeFile(uri)
508-
end
509-
elseif change.type == 'change' then
510-
if m.isValidLuaUri(uri) then
511-
-- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新
512-
if not files.isOpen(uri) then
513-
files.setText(uri, util.loadFile(furi.decode(uri)), false)
506+
local childs = files.getChildFiles(uri)
507+
for _, curi in ipairs(childs) do
508+
log.debug('FileChangeType.Deleted.Child', curi)
509+
files.remove(curi)
510+
m.removeFile(uri)
514511
end
515-
else
516-
local filename = fs.path(path):filename():string()
517-
-- 排除类文件发生更改需要重新扫描
518-
if filename == '.gitignore'
519-
or filename == '.gitmodules' then
520-
local scp = scope.getScope(uri)
521-
if scp.type ~= 'fallback' then
522-
m.reload(scp)
512+
elseif change.type == 'change' then
513+
if m.isValidLuaUri(uri) then
514+
-- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新
515+
if not files.isOpen(uri) then
516+
files.setText(uri, pub.awaitTask('loadFile', furi.decode(uri)), false)
517+
end
518+
else
519+
local filename = fs.path(path):filename():string()
520+
-- 排除类文件发生更改需要重新扫描
521+
if filename == '.gitignore'
522+
or filename == '.gitmodules' then
523+
local scp = scope.getScope(uri)
524+
if scp.type ~= 'fallback' then
525+
m.reload(scp)
526+
end
523527
end
524-
break
525528
end
526529
end
527-
end
528-
::CONTINUE::
530+
end)
529531
end
530532
end)
531533

0 commit comments

Comments
 (0)