feat: support per library ignoreDir when library path prefix matched
This adds support for per library setting in ignoreDir as requested in https://github.com/LuaLS/lua-language-server/discussions/3213.
Use case
Ignore a same named folder in the library path, but not in current workspace. For more details please refer to the discussion link above.
Proposed Solution
After in-depth discussion, we come up with the following approach with NO change to existing API while maintaining backward compatibility:
- check if an
ignoreDirpath is a subpath of any library path - if it is a subpath of a library path
- extract this subpath (which is a relative path to that library path)
- convert it to absolute gitignore pattern by adding a leading
/ - keep it as library specific ignore pattern
- otherwise treat it as global ignore pattern as before
Example Config
{
"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
]
}
中文版
支持 workspace.ignoreDir 配置 只應用在指定 library 的 pattern
修改方式
- 對於每1個
ignoreDir,檢查是否屬於任意 library 的 subpath - 假設是該 library 下的 subpath
- 先提取出這個 subpath (就是該 library 下的 1個 relative path)
- 在最開首補上
/以換成1個 absolute 的 gitignore pattern - 並添加到這 library 下的 ignore pattern matcher
- 否則如常當成 global ignore pattern 來添加
我认为应该支持使用 "${lib:idx}"和${workspaceFolder:name}
Sumneko Lua translate bot
I think the use of "${lib:idx}" and ${workspaceFolder:name} should be supported
我认为应该支持使用
"${lib:idx}"
${lib:idx} 這個不好吧 🤔
因為這個受 workspace.library[] 中對應 entry 的次序影響
- 如果 user 在 array 中間插值 => 那後續的 index 就亂套了
- 並且完全不直觀,比如當看到
ignoreDir: [ "${lib:2}/xxx/yyy" ]=> 一眼看過去看不出lib:2是哪1個 library path => 還得手動數一下workspace.library[]中對應的 element 是什麼? 😂
... 和
${workspaceFolder:name}
確實是個好想法 👍
- 這個 placeholder 應該會在
files.normalize()時 由裡邊的m.resolvePathPlaceholders負責處理了的 https://github.com/LuaLS/lua-language-server/blob/32fec3cc99af8b9a1e45c2455a8c3bd0d3e38f66/script/files.lua#L984-L989 - 但問題是這 PR 中處理 per library ignoreDir 的方式
是因為
m.getLibraryMatchers本身就有為 每1個 library 創建1個 matcher => 我按 library path 對應的 matcher 來寫入不同的 ignore patterns - 而對於 workspace root 自身的 path matcher 來說
我暫不確定他的運作機制是如何 😕
我看到
m.getNativeMatcher最終只會返回 1個 matcher? 不確定可以怎樣支持到 🙈
如果有必要支持 multi root workspace 中針對不同 workspaceFolder 的 ignoreDir
感覺應該再開個新 PR 較好?
Sumneko Lua translate bot
I think the use of `"${lib:idx}" should be supported
${lib:idx} This is not good 🤔
Because this is affected by the order of the corresponding entry in workspace.library[]
- If user interpolates => in the middle of array, then the subsequent index will be messed up
- And it is completely unintuitive, for example when you see
ignoreDir: [ "${lib:2}/xxx/yyy" ]=> I can't see which library pathlib:2is => You have to manually count what is the corresponding element inworkspace.library[]? 😂
... and
${workspaceFolder:name}
It's a good idea indeed
- This placeholder should be in
files.normalize()Them.resolvePathPlaceholdersis handled by https://github.com/LuaLS/lua-language-server/blob/32fec3cc99af8b9a1e45c2455a8c3bd0d3e38f66/script/files.lua#L984-L989 - But the problem is how to deal with per library ignoreDir in this PR
Because
m.getLibraryMatchersitself has a chance Create 1 matcher for every library => I press the matcher corresponding to library path to write different ignore patterns - And for the workspace root's own path matcher
I'm not sure how it works 😕
I see that
m.getNativeMatcherwill only return 1 matcher in the end? Not sure how to support it 🙈
If necessary, support ignoreDir for different workspaceFolder in multi root workspace
I feel like it should be better to open a new PR?