Skip to content

feat: support per library ignoreDir when library path prefix matched #3225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `NEW` Support per library settings in ignoreDir
```jsonc
{
"workspace.library": [ "/path/to/lib", "/path/to/lib2" ],
"workspace.ignoreDir": [
"/path/to/lib/**/lib-ignore", // extracted pattern will be "/**/lib-ignore" and only applies to "/path/to/lib"
"global-ignore" // this will still apply to all of "/path/to/lib", "/path/to/lib2", current workspace
]
}
```

## 3.15.0
`2025-6-25`
Expand Down
34 changes: 32 additions & 2 deletions script/workspace/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,31 @@ function m.getLibraryMatchers(scp)
pattern[#pattern+1] = path
end
end
local libPatterns = {}
for _, path in ipairs(config.get(scp.uri, 'Lua.workspace.ignoreDir')) do
log.debug('Ignore directory:', path)
pattern[#pattern+1] = path
-- check for library specific ignoreDir
local isLibPattern = false
local nPath = files.normalize(path)
for _, libPath in ipairs(config.get(scp.uri, 'Lua.workspace.library')) do
-- check if ignoreDir path is relative to libPath
local nLibPath = m.getAbsolutePath(scp.uri, libPath)
if nLibPath then
local relativeToLibPath = fs.relative(fs.path(nPath), fs.path(nLibPath)):string()
if relativeToLibPath ~= '' -- will be empty string on windows if drive letter is different
and relativeToLibPath:sub(1, 2) ~= '..' -- a valid subpath of libPath should not starts with `..`
then
isLibPattern = true
-- add leading `/` to convert subpath to absolute gitignore pattern path
local subPattern = '/' .. relativeToLibPath
libPatterns[nLibPath] = libPatterns[nLibPath] or {}
table.insert(libPatterns[nLibPath], subPattern)
end
end
end
if not isLibPattern then
pattern[#pattern+1] = path
end
end

local librarys = {}
Expand All @@ -239,8 +261,16 @@ function m.getLibraryMatchers(scp)
local matchers = {}
for path in pairs(librarys) do
if fs.exists(fs.path(path)) then
local patterns = libPatterns[path]
if patterns then
-- append default pattern
util.arrayMerge(patterns, pattern)
else
-- use default pattern
patterns = pattern
end
local nPath = fs.absolute(fs.path(path)):string()
local matcher = glob.gitignore(pattern, {
local matcher = glob.gitignore(patterns, {
root = path,
ignoreCase = platform.os == 'windows',
}, globInteferFace)
Expand Down
Loading