diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-03-18 14:48:49 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-03-18 14:48:49 +0800 |
commit | 9f6cf53d0452b33316225450af5022f70bffca4c (patch) | |
tree | be69953b576bdec5c70b324659bcf2149e0caa45 /script | |
parent | 5c39b8fc967b1dec072d9dcd01bee4752f184044 (diff) | |
download | lua-language-server-9f6cf53d0452b33316225450af5022f70bffca4c.zip |
fix #452 fix matching gitignore of root
Diffstat (limited to 'script')
-rw-r--r-- | script/glob/gitignore.lua | 72 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 2 |
2 files changed, 47 insertions, 27 deletions
diff --git a/script/glob/gitignore.lua b/script/glob/gitignore.lua index 46d9d573..f1c654ef 100644 --- a/script/glob/gitignore.lua +++ b/script/glob/gitignore.lua @@ -116,7 +116,7 @@ function mt:checkDirectory(catch, path, matcher) end function mt:simpleMatch(path) - path = path:gsub('^[/\\]+', '') + path = self:getRelativePath(path) for i = #self.matcher, 1, -1 do local matcher = self.matcher[i] local catch = matcher(path) @@ -148,48 +148,66 @@ function mt:finishMatch(path) return false end -function mt:scan(root, callback) +function mt:getRelativePath(path) + local root = self.options.root or '' + if self.options.ignoreCase then + path = path:lower() + root = root:lower() + end + path = path:gsub('^[/\\]+', ''):gsub('[/\\]+', '/') + root = root:gsub('^[/\\]+', ''):gsub('[/\\]+', '/') + if path:sub(1, #root) == root then + path = path:sub(#root + 1) + path = path:gsub('^[/\\]+', '') + end + return path +end + +function mt:scan(path, callback) local files = {} if type(callback) ~= 'function' then callback = nil end - local list = { root } + local list = {} + + local function check(current) + local fileType = self:callInterface('type', current) + if fileType == 'file' then + if callback then + callback(current) + end + files[#files+1] = current + elseif fileType == 'directory' then + local result = self:callInterface('list', current) + if type(result) == 'table' then + for _, path in ipairs(result) do + local filename = path:match '([^/\\]+)[/\\]*$' + if filename + and filename ~= '.' + and filename ~= '..' then + list[#list+1] = path + end + end + end + end + end + check(path) while #list > 0 do local current = list[#list] if not current then break end list[#list] = nil - if not self:simpleMatch(current) then - local fileType = self:callInterface('type', current) - if fileType == 'file' then - if callback then - callback(current) - end - files[#files+1] = current - elseif fileType == 'directory' then - local result = self:callInterface('list', current) - if type(result) == 'table' then - for _, path in ipairs(result) do - local filename = path:match '([^/\\]+)[/\\]*$' - if filename - and filename ~= '.' - and filename ~= '..' then - list[#list+1] = path - end - end - end - end + local stem = self:getRelativePath(current) + if not self:simpleMatch(stem) then + check(current) end end return files end function mt:__call(path) - if self.options.ignoreCase then - path = path:lower() - end - path = path:gsub('^[/\\]+', '') + path = self:getRelativePath(path) return self:finishMatch(path) end diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 6d5c8034..14bde05a 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -129,6 +129,7 @@ function m.getNativeMatcher() end m.nativeMatcher = glob.gitignore(pattern, m.matchOption, globInteferFace) + m.nativeMatcher:setOption('root', m.path) m.nativeVersion = config.version return m.nativeMatcher @@ -155,6 +156,7 @@ function m.getLibraryMatchers() if fs.exists(fs.path(path)) then local nPath = fs.absolute(fs.path(path)):string() local matcher = glob.gitignore(true, m.matchOption, globInteferFace) + matcher:setOption('root', path) if platform.OS == 'Windows' then matcher:setOption 'ignoreCase' end |