@@ -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 ()
234235end
@@ -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
491493fw .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
530532end )
531533
0 commit comments