This works fine, however it would be nicer to not load all lua versions and instead load \"/usr/share/lua/5.4\" directly, while ignoring only the directory \"/usr/share/lua/5.4/<mymodule>\".
For my other use-case I have some scripts lying around where there are many sub directories. Maybe I have a root file called scan.lua or something like that, and I just want to get modules from the LuaRocks tree, but not from any the sub-directories. The following config does not work as intended.
{\n \"workspace.library\": [ \"/usr/share/lua\" ],\n \"runtime.path\": [ \"5.4/?.lua\", \"5.4/?/init.lua\" ],\n \"workspace.ignoreDir\": [ \"*\", \"!5.4\", \"!scan.lua\" ]\n}This doesn't work as my require path never finds the modules from the luarocks tree. If I remove the \"*\" from \"workspace.ignoreDir\" then it does find the require paths, but it will also search all the sub-directories.
So is there a way to specify an absolute path in \"workspace.ignoreDir\"? Or do you have another workaround I haven't thought of?
Thanks in advance =)
","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"/ or \\/ or \\ignoreDir sub path extraction\\ to / so as to form a valid gitignore pattern/{\n \"workspace.library\": [ \"C:\\\\Users\\\\TomLau\\\\lib\" ],\n \"workspace.ignoreDir\": [\"C:\\\\Users\\\\TomLau\\\\lib\\\\mylib\"]\n}=> extracted pattern will be /mylib
{\n \"workspace.library\": [ \"C:\\\\Users\\\\TomLau\\\\lib\" ],\n \"workspace.ignoreDir\": [\"C:\\\\Users\\\\TomLau\\\\lib\\\\**\\\\mylib\"]\n}=> extracted pattern will be /**/mylib, which is equal to matching any mylib file or folder
\n
From 7d9d29c622848c16ef7c2843f3e348b0e77bfa89 Mon Sep 17 00:00:00 2001\nFrom: Tom Lau <[email protected]>\nDate: Thu, 3 Jul 2025 09:46:00 +0800\nSubject: [PATCH] feat: support per library ignoreDir when library path prefix\n matched\n\n---\n script/workspace/workspace.lua | 40 ++++++++++++++++++++++++++++++++--\n 1 file changed, 38 insertions(+), 2 deletions(-)\n\ndiff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua\nindex d5868342..c19cf2f8 100644\n--- a/script/workspace/workspace.lua\n+++ b/script/workspace/workspace.lua\n@@ -216,9 +216,37 @@ function m.getLibraryMatchers(scp)\n pattern[#pattern+1] = path\n end\n end\n+ local libraryPatterns = {}\n for _, path in ipairs(config.get(scp.uri, 'Lua.workspace.ignoreDir')) do\n log.debug('Ignore directory:', path)\n- pattern[#pattern+1] = path\n+ -- check for library specific ignoreDir\n+ local isLibrarySpecific = false\n+ for _, libraryPath in ipairs(config.get(scp.uri, 'Lua.workspace.library')) do\n+ if path:sub(1, #libraryPath) == libraryPath -- prefix matched\n+ and (\n+ libraryPath:match('[\\\\/]$') -- either library path ends with dir separator\n+ or path:sub(#libraryPath+1):match('^[\\\\/]') -- or the subPath starts with dir separator\n+ )\n+ then\n+ -- prefix matched, remove the prefix\n+ -- convert windows path separator `\\` to `/`\n+ -- and make sure the subPath starts with a `/`\n+ local subPath = path:sub(#libraryPath+1):gsub('\\\\', '/')\n+ if subPath:sub(1, 1) ~= '/' then\n+ subPath = '/' .. subPath\n+ end\n+ local absLibraryPath = m.getAbsolutePath(scp.uri, libraryPath)\n+ if absLibraryPath then\n+ isLibrarySpecific = true\n+ local libraryPathKey = files.normalize(absLibraryPath)\n+ libraryPatterns[libraryPathKey] = libraryPatterns[libraryPathKey] or {}\n+ table.insert(libraryPatterns[libraryPathKey], subPath)\n+ end\n+ end\n+ end\n+ if not isLibrarySpecific then\n+ pattern[#pattern+1] = path\n+ end\n end\n \n local librarys = {}\n@@ -239,8 +267,16 @@ function m.getLibraryMatchers(scp)\n local matchers = {}\n for path in pairs(librarys) do\n if fs.exists(fs.path(path)) then\n+ local patterns = libraryPatterns[path]\n+ if patterns then\n+ -- append default pattern\n+ util.arrayMerge(patterns, pattern)\n+ else\n+ -- use default pattern\n+ patterns = pattern\n+ end\n local nPath = fs.absolute(fs.path(path)):string()\n- local matcher = glob.gitignore(pattern, {\n+ local matcher = glob.gitignore(patterns, {\n root = path,\n ignoreCase = platform.os == 'windows',\n }, globInteferFace)\n-- \n2.47.1.windows.2\n\n-
|
Is there a way to specify absolute paths in I have two use cases. First: When developing a LuaRocks module I get always duplicate symbols after installing my module locally and developing it at the same time. What I currently do is this: {
"workspace.library": [ "/usr/share/lua" ],
"runtime.path": [ "5.4/?.lua", "5.4/?/init.lua" ],
"workspace.ignoreDir": [ "5.4/<mymodule>", "5.1/<mymodule>" ]
}This works fine, however it would be nicer to not load all lua versions and instead load For my other use-case I have some scripts lying around where there are many sub directories. Maybe I have a root file called {
"workspace.library": [ "/usr/share/lua" ],
"runtime.path": [ "5.4/?.lua", "5.4/?/init.lua" ],
"workspace.ignoreDir": [ "*", "!5.4", "!scan.lua" ]
}This doesn't work as my require path never finds the modules from the luarocks tree. If I remove the So is there a way to specify an absolute path in Thanks in advance =) |
Beta Was this translation helpful? Give feedback.
-
|
From the codebase,
🤔 Can't you just write the config as the following? {
"workspace.library": [ "/usr/share/lua/5.4" ],
"workspace.ignoreDir": [ "<mymodule>" ]
}or is it because your current working directory also contains a |
Beta Was this translation helpful? Give feedback.
-
Here's another attempt, using your idea of "matching library path prefix" 🤔
This seems to be working well in my testing config above 👀 {
"workspace.library": [ "C:\\Users\\TomLau\\lib" ],
"workspace.ignoreDir": ["C:\\Users\\TomLau\\lib\\mylib"]
}
{
"workspace.library": [ "..\\lib" ],
"workspace.ignoreDir": ["..\\lib\\mylib"]
}
The Patch
From badeaf481e1742b727b850b59707c4b00d3365d5 Mon Sep 17 00:00:00 2001
From: Tom Lau <[email protected]>
Date: Thu, 3 Jul 2025 09:46:00 +0800
Subject: [PATCH] feat: support per library ignoreDir when library path prefix
matched
---
script/workspace/workspace.lua | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index d5868342..bcce69f8 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -216,9 +216,27 @@ function m.getLibraryMatchers(scp)
pattern[#pattern+1] = path
end
end
+ local libraryPatterns = {}
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 isLibrarySpecific = false
+ for _, libraryPath in ipairs(config.get(scp.uri, 'Lua.workspace.library')) do
+ if path:sub(1, #libraryPath) == libraryPath then
+ -- prefix matched, remove the prefix
+ local subPath = path:sub(#libraryPath+1)
+ local absLibraryPath = m.getAbsolutePath(scp.uri, libraryPath)
+ if absLibraryPath then
+ isLibrarySpecific = true
+ local libraryPathKey = files.normalize(absLibraryPath)
+ libraryPatterns[libraryPathKey] = libraryPatterns[libraryPathKey] or {}
+ table.insert(libraryPatterns[libraryPathKey], subPath)
+ end
+ end
+ end
+ if not isLibrarySpecific then
+ pattern[#pattern+1] = path
+ end
end
local librarys = {}
@@ -239,8 +257,16 @@ function m.getLibraryMatchers(scp)
local matchers = {}
for path in pairs(librarys) do
if fs.exists(fs.path(path)) then
+ local patterns = libraryPatterns[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)
--
2.47.1.windows.2
|
Beta Was this translation helpful? Give feedback.
The enhanced absolute path approach
library path matching
/or\/or\ignoreDirsub path extraction\to/so as to form a valid gitignore pattern/=> because we want this pattern to start matching from the library path root
example usage
{ "workspace.library": [ "C:\\Users\\TomLau\\lib" ], …