From 6a5b55962031b6d37d5e11ea7d072ac1aa9d9891 Mon Sep 17 00:00:00 2001 From: Tom Lau Date: Thu, 3 Jul 2025 09:46:00 +0800 Subject: [PATCH] feat: support per library ignoreDir when library path prefix matched --- changelog.md | 10 ++++++++++ script/workspace/workspace.lua | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 03f3e7c03..1f13f7d64 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,16 @@ ## Unreleased +* `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` diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index d58683424..be6999770 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -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 = {} @@ -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)