fix(lspconfig): remove all references to lspconfig. Closes #6426

This commit is contained in:
Folke Lemaitre
2025-09-15 20:42:10 +02:00
parent 167d39b2be
commit 23b9cdeb34
7 changed files with 44 additions and 85 deletions

View File

@@ -60,28 +60,22 @@ return {
keys = {
{ "<leader>ch", "<cmd>ClangdSwitchSourceHeader<cr>", desc = "Switch Source/Header (C/C++)" },
},
root_dir = function(bufnr, ondir)
local root_directory = function(fname)
return require("lspconfig.util").root_pattern(
"Makefile",
"configure.ac",
"configure.in",
"config.h.in",
"meson.build",
"meson_options.txt",
"build.ninja"
)(fname) or require("lspconfig.util").root_pattern(
"compile_commands.json",
"compile_flags.txt"
)(fname) or require("lspconfig.util").find_git_ancestor(fname)
end
if type(bufnr) == "string" then
return root_directory(bufnr)
else
local fname = vim.api.nvim_buf_get_name(bufnr)
ondir(root_directory(fname))
end
end,
root_markers = {
".clangd",
".clang-tidy",
".clang-format",
"compile_commands.json",
"compile_flags.txt",
"configure.ac", -- AutoTools
"Makefile",
"configure.ac",
"configure.in",
"config.h.in",
"meson.build",
"meson_options.txt",
"build.ninja",
".git",
},
capabilities = {
offsetEncoding = { "utf-16" },
},

View File

@@ -91,9 +91,7 @@ return {
table.insert(cmd, string.format("--jvm-arg=-javaagent:%s", lombok_jar))
end
return {
-- How to find the root dir for a given filename. The default comes from
-- lspconfig which provides a function specifically for java projects.
root_dir = LazyVim.lsp.get_raw_config("jdtls").default_config.root_dir,
root_dir = vim.fs.root(0, vim.lsp.config.jdtls.root_markers),
-- How to find the project name for a given root dir.
project_name = function(root_dir)

View File

@@ -26,17 +26,15 @@ return {
"reason",
"dune",
},
root_dir = function(fname)
return require("lspconfig.util").root_pattern(
"*.opam",
"esy.json",
"package.json",
".git",
"dune-project",
"dune-workspace",
"*.ml"
)(fname)
end,
root_markers = {
"*.opam",
"esy.json",
"package.json",
".git",
"dune-project",
"dune-workspace",
"*.ml",
},
},
},
},

View File

@@ -65,11 +65,7 @@ return {
opts = {
servers = {
r_language_server = {
root_dir = function(fname)
return require("lspconfig.util").root_pattern("DESCRIPTION", "NAMESPACE", ".Rbuildignore")(fname)
or require("lspconfig.util").find_git_ancestor(fname)
or vim.loop.os_homedir()
end,
root_markers = { "DESCRIPTION", "NAMESPACE", ".Rbuildignore" },
},
},
},

View File

@@ -28,11 +28,10 @@ return {
},
setup = {
tailwindcss = function(_, opts)
local tw = LazyVim.lsp.get_raw_config("tailwindcss")
opts.filetypes = opts.filetypes or {}
-- Add default filetypes
vim.list_extend(opts.filetypes, tw.default_config.filetypes)
vim.list_extend(opts.filetypes, vim.lsp.config.tailwindcss.filetypes)
-- Remove excluded filetypes
--- @param ft string

View File

@@ -228,15 +228,22 @@ return {
})
end
if LazyVim.lsp.is_enabled("denols") and LazyVim.lsp.is_enabled("vtsls") then
local is_deno = require("lspconfig.util").root_pattern("deno.json", "deno.jsonc")
LazyVim.lsp.disable("vtsls", is_deno)
LazyVim.lsp.disable("denols", function(root_dir, config)
if not is_deno(root_dir) then
config.settings.deno.enable = false
end
return false
end)
if vim.lsp.is_enabled("denols") and vim.lsp.is_enabled("vtsls") then
---@param server string
---@param markers string[]
local resolve = function(server, markers)
vim.lsp.config(server, {
root_dir = function(bufnr, on_dir)
local is_deno = vim.fs.root(bufnr, { "deno.json", "deno.jsonc" }) ~= nil
if is_deno == (server == "denols") then
local root = vim.fs.root(bufnr, markers)
return root and on_dir(root)
end
end,
})
end
resolve("denols", vim.lsp.config.denols.root_markers)
resolve("vtsls", vim.lsp.config.vtsls.root_markers)
end
end,
},

View File

@@ -107,39 +107,6 @@ function M.on_supports_method(method, fn)
})
end
---@return vim.lsp.Config
function M.get_config(server)
local configs = require("lspconfig.configs")
return rawget(configs, server)
end
---@return {default_config:lspconfig.Config}
function M.get_raw_config(server)
local ok, ret = pcall(require, "lspconfig.configs." .. server)
if ok then
return ret
end
return require("lspconfig.server_configurations." .. server)
end
function M.is_enabled(server)
local c = M.get_config(server)
return c and c.enabled ~= false
end
---@param server string
---@param cond fun( root_dir, config): boolean
function M.disable(server, cond)
local util = require("lspconfig.util")
local def = M.get_config(server)
---@diagnostic disable-next-line: undefined-field
def.document_config.on_new_config = util.add_hook_before(def.document_config.on_new_config, function(config, root_dir)
if cond(root_dir, config) then
config.enabled = false
end
end)
end
---@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter)}
function M.formatter(opts)
opts = opts or {}