lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

feat: support per library ignoreDir when library path prefix matched

Open tomlau10 opened this issue 6 months ago • 4 comments

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 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 avatar Jul 06 '25 07:07 tomlau10

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

CppCXY avatar Jul 07 '25 02:07 CppCXY

Sumneko Lua translate bot


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

Issues-translate-bot avatar Jul 07 '25 02:07 Issues-translate-bot

我认为应该支持使用 "${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 較好?

tomlau10 avatar Jul 07 '25 08:07 tomlau10

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 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.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?

Issues-translate-bot avatar Jul 07 '25 08:07 Issues-translate-bot