Skip to content

feat: support per library ignoreDir when library path prefix matched #3225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomlau10
Copy link
Contributor

@tomlau10 tomlau10 commented Jul 6, 2025

This adds support for per library setting in ignoreDir as requested in #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 ignoreDir path 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 來添加

@tomlau10 tomlau10 force-pushed the poc/per-library-ignoreDir branch from 8178c9b to 6a5b559 Compare July 6, 2025 10:20
@CppCXY
Copy link
Member

CppCXY commented Jul 7, 2025

我认为应该支持使用 "${lib:idx}"和${workspaceFolder:name}

@Issues-translate-bot
Copy link

Sumneko Lua translate bot


I think the use of "${lib:idx}" and ${workspaceFolder:name} should be supported

@tomlau10
Copy link
Contributor Author

tomlau10 commented Jul 7, 2025

我认为应该支持使用 "${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 負責處理了的
    ---@param path string
    ---@return string
    function m.normalize(path)
    path = m.resolvePathPlaceholders(path)
    path = util.expandPath(path)
    path = path:gsub('^%.[/\\]+', '')
  • 但問題是這 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 較好?

@Issues-translate-bot
Copy link

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 path lib:2 is
    => You have to manually count what is the corresponding element in workspace.library[]? 😂

... and ${workspaceFolder:name}

It's a good idea indeed

  • This placeholder should be in files.normalize()
    The m.resolvePathPlaceholders is handled by
    ---@param path string
    ---@return string
    function m.normalize(path)
    path = m.resolvePathPlaceholders(path)
    path = util.expandPath(path)
    path = path:gsub('^%.[/\\]+', '')
  • But the problem is how to deal with per library ignoreDir in this PR
    Because m.getLibraryMatchers itself 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.getNativeMatcher will 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants