Skip to content

Commit 8178c9b

Browse files
committed
feat: support per library ignoreDir when library path prefix matched
1 parent 32fec3c commit 8178c9b

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

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

616
## 3.15.0
717
`2025-6-25`

script/workspace/workspace.lua

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,32 @@ function m.getLibraryMatchers(scp)
216216
pattern[#pattern+1] = path
217217
end
218218
end
219+
local libPatterns = {}
219220
for _, path in ipairs(config.get(scp.uri, 'Lua.workspace.ignoreDir')) do
220221
log.debug('Ignore directory:', path)
221-
pattern[#pattern+1] = path
222+
-- check for library specific ignoreDir
223+
local isLibPattern = false
224+
local nPath = files.normalize(path)
225+
for _, libPath in ipairs(config.get(scp.uri, 'Lua.workspace.library')) do
226+
-- check if ignoreDir path is relative to libPath
227+
local nLibPath = files.normalize(libPath)
228+
local libRelativePath = fs.relative(fs.path(nPath), fs.path(nLibPath)):string()
229+
if libRelativePath ~= '' -- will be empty string on windows if drive letter is different
230+
and libRelativePath:sub(1, 2) ~= '..' -- a valid subpath of libPath should not starts with `..`
231+
then
232+
isLibPattern = true
233+
local absLibPath = m.getAbsolutePath(scp.uri, libPath)
234+
if absLibPath then
235+
-- add leading `/` to convert subpath to absolute gitignore pattern path
236+
local subPattern = '/' .. libRelativePath
237+
libPatterns[absLibPath] = libPatterns[absLibPath] or {}
238+
table.insert(libPatterns[absLibPath], subPattern)
239+
end
240+
end
241+
end
242+
if not isLibPattern then
243+
pattern[#pattern+1] = path
244+
end
222245
end
223246

224247
local librarys = {}
@@ -239,8 +262,16 @@ function m.getLibraryMatchers(scp)
239262
local matchers = {}
240263
for path in pairs(librarys) do
241264
if fs.exists(fs.path(path)) then
265+
local patterns = libPatterns[path]
266+
if patterns then
267+
-- append default pattern
268+
util.arrayMerge(patterns, pattern)
269+
else
270+
-- use default pattern
271+
patterns = pattern
272+
end
242273
local nPath = fs.absolute(fs.path(path)):string()
243-
local matcher = glob.gitignore(pattern, {
274+
local matcher = glob.gitignore(patterns, {
244275
root = path,
245276
ignoreCase = platform.os == 'windows',
246277
}, globInteferFace)

0 commit comments

Comments
 (0)