diff options
Diffstat (limited to 'server-beta/src/workspace/workspace.lua')
-rw-r--r-- | server-beta/src/workspace/workspace.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/server-beta/src/workspace/workspace.lua b/server-beta/src/workspace/workspace.lua index d3669031..8508e5c5 100644 --- a/server-beta/src/workspace/workspace.lua +++ b/server-beta/src/workspace/workspace.lua @@ -1,9 +1,38 @@ +local pub = require 'pub' +local fs = require 'bee.filesystem' +local furi = require 'file-uri' + local m = {} m.type = 'workspace' +--- 初始化工作区 function m.init(name, uri) m.name = name m.uri = uri end +--- 预读工作区内所有文件(异步) +function m.preload() + log.info('Preload start.') + local function scan(dir, callback) + local result = pub.task('listDirectory', dir) + if not result then + return + end + for i = 1, #result.uris do + local childUri = result.uris[i] + if result.dirs[childUri] then + scan(childUri, callback) + else + callback(childUri) + end + end + end + scan(m.uri, function (uri) + local text = pub.task('loadFile', uri) + log.debug('Preload file at: ' .. uri, #text) + end) + log.info('Preload finish.') +end + return m |