diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/core/hint.lua | 2 | ||||
-rw-r--r-- | script/files.lua | 1 | ||||
-rw-r--r-- | script/filewatch.lua | 2 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 70 |
4 files changed, 38 insertions, 37 deletions
diff --git a/script/core/hint.lua b/script/core/hint.lua index 79ba5548..e6eb483c 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -242,8 +242,8 @@ end return function (uri, start, finish) local results = {} typeHint(uri, results, start, finish) - awaitHint(uri, results, start, finish) paramName(uri, results, start, finish) + awaitHint(uri, results, start, finish) arrayIndex(uri, results, start, finish) return results end diff --git a/script/files.lua b/script/files.lua index b2b74c26..03ce47c2 100644 --- a/script/files.lua +++ b/script/files.lua @@ -105,7 +105,6 @@ end ---@param libraryUri uri function m.setLibraryUri(scp, uri, libraryUri) scp:get 'libraryMap' [uri] = libraryUri - scp:addLink(libraryUri) end --- 是否是库文件 diff --git a/script/filewatch.lua b/script/filewatch.lua index dd46d1a3..586903c6 100644 --- a/script/filewatch.lua +++ b/script/filewatch.lua @@ -45,7 +45,7 @@ end function m.update() local collect - for _ = 1, 100 do + for _ = 1, 10000 do local ev, path = fw.select() if not ev then break diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 5277f38e..8a5e2b52 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -228,7 +228,8 @@ function m.awaitLoadFile(uri) log.info('Scan files at:', uri) ---@async native:scan(furi.decode(uri), function (path) - ld:loadFile(furi.encode(path)) + files.remove(furi.encode(path)) + ld:loadFile(furi.encode(path), nil) end) ld:loadAll() end @@ -238,7 +239,7 @@ function m.removeFile(uri) if scp:isChildUri(uri) or scp:isLinkedUri(uri) then local cachedUris = scp:get 'cachedUris' - if cachedUris[uri] then + if cachedUris and cachedUris[uri] then cachedUris[uri] = nil files.delRef(uri) end @@ -281,9 +282,10 @@ function m.awaitPreload(scp) for _, libMatcher in ipairs(librarys) do log.info('Scan library at:', libMatcher.uri) + scp:addLink(libMatcher.uri) ---@async libMatcher.matcher:scan(furi.decode(libMatcher.uri), function (path) - ld:loadFile(furi.encode(path), libMatcher.uri) + ld:loadFile(furi.encode(path)) end) watchers[#watchers+1] = fw.watch(furi.decode(libMatcher.uri)) end @@ -490,42 +492,42 @@ end) fw.event(function (changes) ---@async for _, change in ipairs(changes) do - local path = change.path - local uri = furi.encode(path) - m.awaitReady(uri) - if change.type == 'create' then - log.debug('FileChangeType.Created', uri) - m.awaitLoadFile(uri) - elseif change.type == 'delete' then - log.debug('FileChangeType.Deleted', uri) - files.remove(uri) - m.removeFile(uri) - local childs = files.getChildFiles(uri) - for _, curi in ipairs(childs) do - log.debug('FileChangeType.Deleted.Child', curi) - files.remove(curi) + ---@async + await.call(function () + local path = change.path + local uri = furi.encode(path) + if change.type == 'create' then + log.debug('FileChangeType.Created', uri) + m.awaitLoadFile(uri) + elseif change.type == 'delete' then + log.debug('FileChangeType.Deleted', uri) + files.remove(uri) m.removeFile(uri) - end - elseif change.type == 'change' then - if m.isValidLuaUri(uri) then - -- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新 - if not files.isOpen(uri) then - files.setText(uri, util.loadFile(furi.decode(uri)), false) + local childs = files.getChildFiles(uri) + for _, curi in ipairs(childs) do + log.debug('FileChangeType.Deleted.Child', curi) + files.remove(curi) + m.removeFile(uri) end - else - local filename = fs.path(path):filename():string() - -- 排除类文件发生更改需要重新扫描 - if filename == '.gitignore' - or filename == '.gitmodules' then - local scp = scope.getScope(uri) - if scp.type ~= 'fallback' then - m.reload(scp) + elseif change.type == 'change' then + if m.isValidLuaUri(uri) then + -- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新 + if not files.isOpen(uri) then + files.setText(uri, pub.awaitTask('loadFile', furi.decode(uri)), false) + end + else + local filename = fs.path(path):filename():string() + -- 排除类文件发生更改需要重新扫描 + if filename == '.gitignore' + or filename == '.gitmodules' then + local scp = scope.getScope(uri) + if scp.type ~= 'fallback' then + m.reload(scp) + end end - break end end - end - ::CONTINUE:: + end) end end) |