Skip to content

Commit 0283868

Browse files
committed
feat(rooter): allow rooter.ignore.servers to be an arbitrary filter function
1 parent 46c8c70 commit 0283868

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lua/astrocore/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
---@class AstroCoreRooterIgnore
2727
---@field dirs string[]? a list of patterns that match directories to exclude from root detection
28-
---@field servers string[]? a list of language servers to exclude from root detection
28+
---@field servers string[]|fun(client:vim.lsp.Client):boolean? a list of language servers to exclude from root detection or a filter function to return if a client should be ignored or not
2929

3030
---@class AstroCoreRooterOpts
3131
---@field detector AstroCoreRooterSpec[]? a list of specifications for the rooter detection

lua/astrocore/rooter.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ local resolve_config = function() return require("astrocore").config.rooter or {
3333
---@return AstroCoreRooterDetectorFunc
3434
function M.detectors.lsp(config)
3535
if not config then config = resolve_config() end
36+
---@type (string[]|fun(client:vim.lsp.Client):boolean)?
37+
local server_filter = vim.tbl_get(config, "ignore", "servers")
38+
if server_filter and type(server_filter) ~= "function" then
39+
local ignore_servers = server_filter
40+
server_filter = function(lsp_client) return vim.tbl_contains(ignore_servers, lsp_client.name) end
41+
end
3642
return function(bufnr)
3743
local bufpath = M.bufpath(bufnr)
3844
if not bufpath then return {} end
3945
local roots = {} ---@type string[]
4046
-- TODO: remove when dropping support for Neovim v0.9
4147
for _, client in ipairs((vim.lsp.get_clients or vim.lsp.get_active_clients) { buffer = bufnr }) do
42-
if not vim.tbl_contains(vim.tbl_get(config, "ignore", "servers") or {}, client.name) then
48+
if not server_filter or not server_filter(client) then
4349
vim.tbl_map(
4450
function(ws) table.insert(roots, vim.uri_to_fname(ws.uri)) end,
4551
client.config.workspace_folders or {}
@@ -61,10 +67,8 @@ function M.detectors.lsp(config)
6167
end
6268

6369
--- Create a detect folders matching patterns
64-
---@param config AstroCoreRooterOpts? a rooter configuration (defaults to global configuration)
6570
---@return AstroCoreRooterDetectorFunc
66-
function M.detectors.pattern(config)
67-
if not config then config = resolve_config() end
71+
function M.detectors.pattern()
6872
return function(bufnr, patterns)
6973
if type(patterns) == "string" then patterns = { patterns } end
7074
local path = M.bufpath(bufnr) or vim.loop.cwd()

0 commit comments

Comments
 (0)