@@ -216,9 +216,32 @@ function m.getLibraryMatchers(scp)
216
216
pattern [# pattern + 1 ] = path
217
217
end
218
218
end
219
+ local libPatterns = {}
219
220
for _ , path in ipairs (config .get (scp .uri , ' Lua.workspace.ignoreDir' )) do
220
221
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
222
245
end
223
246
224
247
local librarys = {}
@@ -239,8 +262,16 @@ function m.getLibraryMatchers(scp)
239
262
local matchers = {}
240
263
for path in pairs (librarys ) do
241
264
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
242
273
local nPath = fs .absolute (fs .path (path )):string ()
243
- local matcher = glob .gitignore (pattern , {
274
+ local matcher = glob .gitignore (patterns , {
244
275
root = path ,
245
276
ignoreCase = platform .os == ' windows' ,
246
277
}, globInteferFace )
0 commit comments