Replies: 2 comments 9 replies
-
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to specify absolute paths in
"workspace.ignoreDir"
? I tried a lot and cant quite figure it out.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:
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.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 =)
Beta Was this translation helpful? Give feedback.
All reactions