summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-16 17:35:24 +0800
committersumneko <sumneko@hotmail.com>2019-04-16 17:35:24 +0800
commit74f4749dc840e169ac25b7848f1f882b62388871 (patch)
tree156231eb46c9a8a821af9326aba6ef34ad4b8fa2 /server
parent9fe54198a9a435b70e41dac904d4353b67806ac8 (diff)
downloadlua-language-server-74f4749dc840e169ac25b7848f1f882b62388871.zip
加个线程读取本地文件
Diffstat (limited to 'server')
-rw-r--r--server/src/async/loadfile.lua12
-rw-r--r--server/src/async/scanfiles.lua8
-rw-r--r--server/src/workspace.lua23
3 files changed, 31 insertions, 12 deletions
diff --git a/server/src/async/loadfile.lua b/server/src/async/loadfile.lua
new file mode 100644
index 00000000..e5f270fb
--- /dev/null
+++ b/server/src/async/loadfile.lua
@@ -0,0 +1,12 @@
+require 'utility'
+local fs = require 'bee.filesystem'
+
+while true do
+ local filename = IN:bpop()
+ local buf = io.load(fs.path(filename))
+ if buf then
+ OUT:push(filename, buf)
+ end
+ collectgarbage()
+ GC:push(ID, collectgarbage 'count')
+end
diff --git a/server/src/async/scanfiles.lua b/server/src/async/scanfiles.lua
index eb3073df..f54b0866 100644
--- a/server/src/async/scanfiles.lua
+++ b/server/src/async/scanfiles.lua
@@ -47,13 +47,7 @@ for path in scan(fs.path(args.root), filter) do
OUT:push 'stop'
return
end
- local buf = io.load(path)
- if buf then
- OUT:push('file', {
- path = fs.absolute(path):string(),
- buf = buf,
- })
- end
+ OUT:push('path', fs.absolute(path):string())
end
OUT:push 'ok'
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index 37c242d6..2837f5a2 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -95,6 +95,16 @@ function mt:uriEncode(path)
return 'file:///' .. table.concat(names, '/')
end
+function mt:listenLoadFile()
+ self._loadFileRequest = async.run('loadfile', nil, function (filename, buf)
+ local path = fs.path(filename)
+ local name = getFileName(path)
+ local uri = self:uriEncode(path)
+ self.files[name] = uri
+ self.lsp:readText(uri, path, buf, self._currentScanCompiled)
+ end)
+end
+
function mt:scanFiles()
if self._scanRequest then
log.info('中断上次扫描文件任务')
@@ -128,7 +138,7 @@ function mt:scanFiles()
log.info('忽略文件:\r\n' .. table.concat(ignored, '\r\n'))
log.info('开始扫描文件任务')
- local compiled = {}
+ self._currentScanCompiled = {}
local count = 0
self._scanRequest = async.run('scanfiles', {
root = self.root:string(),
@@ -142,16 +152,18 @@ function mt:scanFiles()
return true
elseif mode == 'log' then
log.debug(...)
+ elseif mode == 'path' then
+ local path = fs.path(...)
+ if not self:isLuaFile(path) then
+ return
+ end
+ self._loadFileRequest:push(path:string())
elseif mode == 'file' then
local file = ...
local path = fs.path(file.path)
if not self:isLuaFile(path) then
return
end
- local name = getFileName(path)
- local uri = self:uriEncode(path)
- self.files[name] = uri
- self.lsp:readText(uri, path, file.buf, compiled)
count = count + 1
elseif mode == 'stop' then
log.info('扫描文件任务中断')
@@ -463,5 +475,6 @@ return function (lsp, name)
pathMatcher = {}
}, mt)
workspace:compileLuaPath()
+ workspace:listenLoadFile()
return workspace
end