@@ -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