summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-22 16:53:22 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-22 16:53:22 +0800
commit382a83df0058bd6243a06f1129399060c9cb9303 (patch)
tree1c0ed4b60526af18bc137a5141e9a63eb6658fbe /server/src
parent182d49198e023f5fa13cac2a2a99045f2020ce58 (diff)
downloadlua-language-server-382a83df0058bd6243a06f1129399060c9cb9303.zip
由后端加载文件
Diffstat (limited to 'server/src')
-rw-r--r--server/src/async/scanfiles.lua10
-rw-r--r--server/src/service.lua4
-rw-r--r--server/src/workspace.lua45
3 files changed, 31 insertions, 28 deletions
diff --git a/server/src/async/scanfiles.lua b/server/src/async/scanfiles.lua
index 900cc0a8..e114eca8 100644
--- a/server/src/async/scanfiles.lua
+++ b/server/src/async/scanfiles.lua
@@ -10,8 +10,14 @@ local ignore = {
for path in io.scan(fs.path(root), ignore) do
if path:extension():string() == '.lua' then
- list[#list+1] = path:string()
+ local buf = io.load(path)
+ if buf then
+ OUT:push {
+ path = fs.absolute(path):string(),
+ buf = buf,
+ }
+ end
end
end
-OUT:push(list)
+OUT:push 'ok'
diff --git a/server/src/service.lua b/server/src/service.lua
index 9a5f5313..1d15fb0a 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -150,12 +150,12 @@ function mt:isOpen(uri)
end
end
-function mt:readText(uri, path)
+function mt:readText(uri, path, buf)
local obj = self._file[uri]
if obj then
return
end
- local text = io.load(path)
+ local text = buf or io.load(path)
if not text then
log.debug('无法找到文件:', path)
return
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index 8c1c6492..a0641b2d 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -78,33 +78,30 @@ function mt:init(rootUri)
log.info('Log path: ', logPath)
log.init(ROOT, logPath)
- async.run('scanfiles', self.root:string(), function (list)
- log.info(('Found [%d] files'):format(#list))
- local ignored = {}
- for name in pairs(config.config.workspace.ignoreDir) do
- local path = fs.absolute(self.root / name)
- local str = path:string():lower()
- ignored[#ignored+1] = str
+ local ignored = {}
+ for name in pairs(config.config.workspace.ignoreDir) do
+ local path = fs.absolute(self.root / name)
+ local str = path:string():lower()
+ ignored[#ignored+1] = str
+ end
+
+ async.run('scanfiles', self.root:string(), function (file)
+ if file == 'ok' then
+ self:reset()
+ self._complete = true
+ return true
end
- for _, filename in ipairs(list) do
- local path = fs.absolute(fs.path(filename))
- local name = path:string():lower()
- local ok = true
- for _, ignore in ipairs(ignored) do
- if name:sub(1, #ignore) == ignore then
- ok = false
- break
- end
- end
- if ok then
- local uri = self:uriEncode(path)
- self.files[name] = uri
- self.lsp:readText(uri, path)
+ local path = fs.path(file.path)
+ local name = path:string():lower()
+ for _, ignore in ipairs(ignored) do
+ if name:sub(1, #ignore) == ignore then
+ ok = false
+ return
end
end
- self:reset()
- self._complete = true
- return true
+ local uri = self:uriEncode(path)
+ self.files[name] = uri
+ self.lsp:readText(uri, path, file.buf)
end)
end