From 90a92312aed79d4ee9d231f9eb3f8cd4debc46d1 Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis <12776461+dpetka2001@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:55:25 +0300 Subject: [PATCH] feat(root): provide `vim.g.root_lsp_ignore` to ignore LSP servers (#4332) ## Description This provides `vim.g.root_lsp_ignore` for users to customize which LSP servers should be taken into account when evaluating the LSP `root_dir`. ## Related Issue(s) Closes #4330 ## Screenshots ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --- lua/lazyvim/config/options.lua | 4 ++++ lua/lazyvim/util/root.lua | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index 81b5f081..3ad70c16 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -40,6 +40,10 @@ vim.g.lazyvim_statuscolumn = { -- * powershell -- LazyVim.terminal.setup("pwsh") +-- Set LSP servers to be ignored when used with `util.root.detectors.lsp` +-- for detecting the LSP root +vim.g.root_lsp_ignore = { "copilot" } + -- Hide deprecation warnings vim.g.deprecation_warnings = false diff --git a/lua/lazyvim/util/root.lua b/lua/lazyvim/util/root.lua index fc81e92f..b723b227 100644 --- a/lua/lazyvim/util/root.lua +++ b/lua/lazyvim/util/root.lua @@ -29,7 +29,11 @@ function M.detectors.lsp(buf) return {} end local roots = {} ---@type string[] - for _, client in pairs(LazyVim.lsp.get_clients({ bufnr = buf })) do + local clients = LazyVim.lsp.get_clients({ bufnr = buf }) + clients = vim.tbl_filter(function(client) + return not vim.tbl_contains(vim.g.root_lsp_ignore or {}, client.name) + end, clients) + for _, client in pairs(clients) do local workspace = client.config.workspace_folders for _, ws in pairs(workspace or {}) do roots[#roots + 1] = vim.uri_to_fname(ws.uri)