summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-20 15:25:49 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-20 15:25:49 +0800
commitb7f6abe31b42c1b55143de8273d43e56463f1be5 (patch)
treef04f6e5677a19f7bb1e67532306fdc0e6a5565e7 /server/src
parentfdebcb663c6dafe862005f4ea6c734185fe5e887 (diff)
downloadlua-language-server-b7f6abe31b42c1b55143de8273d43e56463f1be5.zip
在另一个线程中读取本地lua文件名
Diffstat (limited to 'server/src')
-rw-r--r--server/src/async.lua7
-rw-r--r--server/src/workspace.lua25
2 files changed, 24 insertions, 8 deletions
diff --git a/server/src/async.lua b/server/src/async.lua
index 01c6c3ac..24e8b538 100644
--- a/server/src/async.lua
+++ b/server/src/async.lua
@@ -21,7 +21,12 @@ local errlog = thread.channel 'errlog'
local function task()
local dump, env = request:bpop()
- local f, err = load(dump, '=task', 't', env or _ENV)
+ if env then
+ setmetatable(env, { __index = _ENV })
+ else
+ env = _ENV
+ end
+ local f, err = load(dump, '=task', 't', env)
if not f then
errlog:push(err)
return
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index c4dae574..4212e6fe 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -1,4 +1,5 @@
local fs = require 'bee.filesystem'
+local async = require 'async'
local function uriDecode(uri)
if uri:sub(1, 8) ~= 'file:///' then
@@ -48,15 +49,25 @@ function mt:init(rootUri)
return
end
log.info('Workspace inited, root: ', self.root)
- local count = 0
- for path in io.scan(self.root) do
- if path:extension():string() == '.lua' then
- local uri = uriEncode(path)
+ async.call([[
+ require 'utility'
+ local fs = require 'bee.filesystem'
+ local list = {}
+ for path in io.scan(fs.path(ROOT)) do
+ if path:extension():string() == '.lua' then
+ list[#list+1] = path:string()
+ end
+ end
+ return list
+ ]], {
+ ROOT = self.root:string()
+ }, function (list)
+ log.info(('Found [%d] files'):format(#list))
+ for _, filename in ipairs(list) do
+ local uri = uriEncode(fs.path(filename))
self.files[uri] = true
- count = count + 1
end
- end
- log.info(('Found [%d] files'):format(count))
+ end)
end
function mt:addFile(uri)