diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-25 17:39:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-25 17:39:30 +0800 |
commit | 0606ce1ae00fe10623e75952723efbbbd311efdd (patch) | |
tree | 0ab3e0a3628f2c82f5cdbd4ac1d551b2ebdad8d5 /server/src | |
parent | 60fd4db0e553208b5a7b68e167517424f4dea3c4 (diff) | |
download | lua-language-server-0606ce1ae00fe10623e75952723efbbbd311efdd.zip |
忽略.gitignore中列举的文件
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/async/scanfiles.lua | 82 | ||||
-rw-r--r-- | server/src/workspace.lua | 10 |
2 files changed, 84 insertions, 8 deletions
diff --git a/server/src/async/scanfiles.lua b/server/src/async/scanfiles.lua index f53564f8..c242dcfe 100644 --- a/server/src/async/scanfiles.lua +++ b/server/src/async/scanfiles.lua @@ -2,17 +2,85 @@ local args = ... require 'utility' local fs = require 'bee.filesystem' -local ignore = { '.git', 'node_modules' } - local root = fs.absolute(fs.path(args.root)) -for name in pairs(args.ignore) do - ignore[#ignore+1] = name + +local function glob_compile(pattern) + return ("^%s$"):format(pattern:gsub("[%^%$%(%)%%%.%[%]%+%-%?]", "%%%0"):gsub("%*", ".*")) +end +local function glob_match(pattern, target) + return target:match(pattern) ~= nil +end + +local function accept_path(t, path) + if t[path:string()] then + return + end + t[#t+1] = path:string() + t[path:string()] = #t +end +local function expand_dir(t, pattern, dir) + if not fs.exists(dir) then + return + end + for file in dir:list_directory() do + if fs.is_directory(file) then + expand_dir(t, pattern, file) + else + if glob_match(pattern, file:filename():string():lower()) then + accept_path(t, file) + end + end + end +end +local function expand_path(t, root, source) + if source:sub(1, 1) == '/' then + source = source:sub(2) + end + local path = root / source + if source:find("*", 1, true) == nil then + accept_path(t, path) + return + end + local filename = path:filename():string():lower() + local pattern = glob_compile(filename) + expand_dir(t, pattern, path:parent_path()) +end +local function get_sources(root, sources) + local result = {} + local ignore = {} + for _, source in ipairs(sources) do + if source:sub(1,1) ~= "!" then + expand_path(result, root, source) + else + expand_path(ignore, root, source:sub(2)) + end + end + for _, path in ipairs(ignore) do + local pos = result[path] + if pos then + result[pos] = result[#result] + result[result[pos]] = pos + result[path] = nil + result[#result] = nil + end + end + return result end -for i, name in ipairs(ignore) do - ignore[i] = root / name + +local function computePath() + local ignore = { '.git' } + + + for name in pairs(args.ignore) do + ignore[#ignore+1] = name:lower() + end + + return get_sources(root, ignore) end -for path in io.scan(root, ignore) do +local ignored = computePath() + +for path in io.scan(root, ignored) do if path:extension():string() == '.lua' then local buf = io.load(path) if buf then diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 6e7faaaf..d393c3b7 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -83,7 +83,7 @@ function mt:init(rootUri) ignored[path] = true end if config.config.workspace.ignoreSubmodules then - local buf = io.load(ROOT:parent_path() / '.gitmodules') + local buf = io.load(self.root / '.gitmodules') if buf then for path in buf:gmatch('path = ([^\r\n]+)') do log.debug('忽略子模块:', path) @@ -91,6 +91,14 @@ function mt:init(rootUri) end end end + if true then + local buf = io.load(self.root / '.gitignore') + if buf then + for line in buf:gmatch '[^\r\n]+' do + ignored[line] = true + end + end + end async.run('scanfiles', { root = self.root:string(), |