diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-06-24 16:20:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-06-24 16:20:39 +0800 |
commit | c597a4c796f46421775a04f7577fb22ef8fed69e (patch) | |
tree | 99b129357f56a773f6a6f76aff670bb987060ebe /server/src/async | |
parent | 1025cce98d50c31c0f5ce4bcc90ec106530695f0 (diff) | |
download | lua-language-server-c597a4c796f46421775a04f7577fb22ef8fed69e.zip |
整理代码
Diffstat (limited to 'server/src/async')
-rw-r--r-- | server/src/async/loadfile.lua | 4 | ||||
-rw-r--r-- | server/src/async/scanfiles.lua | 74 |
2 files changed, 44 insertions, 34 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' |