summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-06-24 16:20:39 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-06-24 16:20:39 +0800
commitc597a4c796f46421775a04f7577fb22ef8fed69e (patch)
tree99b129357f56a773f6a6f76aff670bb987060ebe
parent1025cce98d50c31c0f5ce4bcc90ec106530695f0 (diff)
downloadlua-language-server-c597a4c796f46421775a04f7577fb22ef8fed69e.zip
整理代码
-rw-r--r--server/src/async/loadfile.lua4
-rw-r--r--server/src/async/scanfiles.lua74
-rw-r--r--server/src/workspace.lua30
3 files changed, 62 insertions, 46 deletions
diff --git a/server/src/async/loadfile.lua b/server/src/async/loadfile.lua
index a7838f7f..33851f58 100644
--- a/server/src/async/loadfile.lua
+++ b/server/src/async/loadfile.lua
@@ -2,10 +2,10 @@ require 'utility'
local fs = require 'bee.filesystem'
while true do
- local filename = IN:bpop()
+ local filename, mode = IN:bpop()
local buf = io.load(fs.path(filename))
if buf then
- OUT:push(filename, buf)
+ OUT:push(filename, mode, buf)
end
GC:push(ID, collectgarbage 'count')
end
diff --git a/server/src/async/scanfiles.lua b/server/src/async/scanfiles.lua
index 7932ac31..090e866f 100644
--- a/server/src/async/scanfiles.lua
+++ b/server/src/async/scanfiles.lua
@@ -1,41 +1,51 @@
local args = ...
+require 'utility'
local fs = require 'bee.filesystem'
local glob = require 'glob'
-local root = fs.path(args.root)
-local session = glob.gitignore(args.pattern, args.options)
-session:setInterface('type', function (path)
- local fullpath = root / path
- if not fs.exists(fullpath) then
+local function scan(mode, root, pattern, options)
+ OUT:push('log', 'Scanning:', root:string())
+ OUT:push('log', 'Scan pattern:', table.dump(pattern))
+ OUT:push('log', 'Scan options:', table.dump(options))
+ local session = glob.gitignore(pattern, options)
+ session:setInterface('type', function (path)
+ local fullpath = root / path
+ if not fs.exists(fullpath) then
+ return nil
+ end
+ if fs.is_directory(fullpath) then
+ return 'directory'
+ else
+ return 'file'
+ end
return nil
- end
- if fs.is_directory(fullpath) then
- return 'directory'
- else
- return 'file'
- end
- return nil
-end)
-session:setInterface('list', function (path)
- local fullpath = root / path
- if not fs.exists(fullpath) then
- return nil
- end
- local list = {}
- for child in fullpath:list_directory() do
- list[#list+1] = child:string()
- end
- return list
-end)
+ end)
+ session:setInterface('list', function (path)
+ local fullpath = root / path
+ if not fs.exists(fullpath) then
+ return nil
+ end
+ local list = {}
+ for child in fullpath:list_directory() do
+ list[#list+1] = child:string()
+ end
+ return list
+ end)
+
+ session:scan(function (path)
+ local ok, msg = IN:pop()
+ if ok and msg == 'stop' then
+ OUT:push 'stop'
+ return
+ end
+ OUT:push(mode, fs.absolute(root / path):string())
+ end)
+end
-session:scan(function (path)
- local ok, msg = IN:pop()
- if ok and msg == 'stop' then
- OUT:push 'stop'
- return
- end
- OUT:push('path', fs.absolute(root / path):string())
-end)
+for _, data in ipairs(args) do
+ local root = fs.path(data.root)
+ scan(data.mode, root, data.pattern, data.options)
+end
OUT:push 'ok'
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index 9d341cdd..0933509c 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -54,7 +54,7 @@ function mt:fileNameEq(a, b)
end
function mt:listenLoadFile()
- self._loadFileRequest = async.run('loadfile', nil, function (filename, buf)
+ self._loadFileRequest = async.run('loadfile', nil, function (filename, mode, buf)
local path = fs.path(filename)
local name = getFileName(path)
local uri = uric.encode(path)
@@ -95,13 +95,17 @@ function mt:buildScanPattern()
end
end
end
+ -- config.workspace.library
+ for path in pairs(config.config.workspace.library) do
+ pattern[#pattern+1] = path
+ end
return pattern
end
function mt:scanFiles()
if self._scanRequest then
- log.info('中断上次扫描文件任务')
+ log.info('Break scan.')
self._scanRequest:push('stop')
self._scanRequest = nil
self._complete = false
@@ -112,33 +116,35 @@ function mt:scanFiles()
local options = {
ignoreCase = platform.OS == 'Windows',
}
- log.info('ignore pattern:\r\n' .. table.concat(pattern, '\r\n'))
- log.info('ignore options:' .. table.dump(options))
- log.info('开始扫描文件任务')
+
self.gitignore = glob.gitignore(pattern, options)
self._currentScanCompiled = {}
local count = 0
self._scanRequest = async.run('scanfiles', {
- root = self.root:string(),
- pattern = pattern,
+ {
+ mode = 'workspace',
+ root = self.root:string(),
+ pattern = pattern,
+ options = options,
+ }
}, function (mode, ...)
if mode == 'ok' then
- log.info('扫描文件任务完成,共', count, '个文件。')
+ log.info('Scan finish, got', count, 'files.')
self._complete = true
self._scanRequest = nil
self:reset()
return true
elseif mode == 'log' then
log.debug(...)
- elseif mode == 'path' then
+ elseif mode == 'workspace' then
local path = fs.path(...)
if not self:isLuaFile(path) then
return
end
- self._loadFileRequest:push(path:string())
+ self._loadFileRequest:push(path:string(), 'workspace')
count = count + 1
elseif mode == 'stop' then
- log.info('扫描文件任务中断')
+ log.info('Scan stoped.')
return false
end
end)
@@ -160,7 +166,7 @@ function mt:init(rootUri)
end
function mt:isComplete()
- return not not self._complete
+ return self._complete == true
end
function mt:isLuaFile(path)