Skip to content

Commit 6a5b559

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

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-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: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,31 @@ 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 = m.getAbsolutePath(scp.uri, libPath)
228+
if nLibPath then
229+
local relativeToLibPath = fs.relative(fs.path(nPath), fs.path(nLibPath)):string()
230+
if relativeToLibPath ~= '' -- will be empty string on windows if drive letter is different
231+
and relativeToLibPath:sub(1, 2) ~= '..' -- a valid subpath of libPath should not starts with `..`
232+
then
233+
isLibPattern = true
234+
-- add leading `/` to convert subpath to absolute gitignore pattern path
235+
local subPattern = '/' .. relativeToLibPath
236+
libPatterns[nLibPath] = libPatterns[nLibPath] or {}
237+
table.insert(libPatterns[nLibPath], subPattern)
238+
end
239+
end
240+
end
241+
if not isLibPattern then
242+
pattern[#pattern+1] = path
243+
end
222244
end
223245

224246
local librarys = {}
@@ -239,8 +261,16 @@ function m.getLibraryMatchers(scp)
239261
local matchers = {}
240262
for path in pairs(librarys) do
241263
if fs.exists(fs.path(path)) then
264+
local patterns = libPatterns[path]
265+
if patterns then
266+
-- append default pattern
267+
util.arrayMerge(patterns, pattern)
268+
else
269+
-- use default pattern
270+
patterns = pattern
271+
end
242272
local nPath = fs.absolute(fs.path(path)):string()
243-
local matcher = glob.gitignore(pattern, {
273+
local matcher = glob.gitignore(patterns, {
244274
root = path,
245275
ignoreCase = platform.os == 'windows',
246276
}, globInteferFace)

0 commit comments

Comments
 (0)