summaryrefslogtreecommitdiff
path: root/server-beta/src/workspace
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-23 21:46:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-23 21:46:20 +0800
commit83a5cdc86fed194c453518e8ae3d1f58c6c84fdd (patch)
tree2b5fa13414f5115aa5f45b0a4c0e1587af997dc3 /server-beta/src/workspace
parent4dec306912bd95049e038c110ec4356b67630d60 (diff)
downloadlua-language-server-83a5cdc86fed194c453518e8ae3d1f58c6c84fdd.zip
预读文件
Diffstat (limited to 'server-beta/src/workspace')
-rw-r--r--server-beta/src/workspace/workspace.lua29
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