mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-28 11:40:13 +02:00
feat(lsp): automatically resolve denols/tsserver conflicts if both are configured
This commit is contained in:
parent
c7aeda9db1
commit
d565684ade
2 changed files with 27 additions and 1 deletions
|
@ -75,10 +75,11 @@ return {
|
||||||
},
|
},
|
||||||
---@param opts PluginLspOpts
|
---@param opts PluginLspOpts
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
|
local Util = require("lazyvim.util")
|
||||||
-- setup autoformat
|
-- setup autoformat
|
||||||
require("lazyvim.plugins.lsp.format").autoformat = opts.autoformat
|
require("lazyvim.plugins.lsp.format").autoformat = opts.autoformat
|
||||||
-- setup formatting and keymaps
|
-- setup formatting and keymaps
|
||||||
require("lazyvim.util").on_attach(function(client, buffer)
|
Util.on_attach(function(client, buffer)
|
||||||
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
|
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
|
||||||
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
|
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
|
||||||
end)
|
end)
|
||||||
|
@ -153,6 +154,14 @@ return {
|
||||||
mlsp.setup({ ensure_installed = ensure_installed })
|
mlsp.setup({ ensure_installed = ensure_installed })
|
||||||
mlsp.setup_handlers({ setup })
|
mlsp.setup_handlers({ setup })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Util.lsp_get_config("denols") and Util.lsp_get_config("tsserver") then
|
||||||
|
local is_deno = require("lspconfig.util").root_pattern("deno.json", "deno.jsonc")
|
||||||
|
Util.lsp_disable("tsserver", is_deno)
|
||||||
|
Util.lsp_disable("denols", function(root_dir)
|
||||||
|
return not is_deno(root_dir)
|
||||||
|
end)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -196,4 +196,21 @@ function M.lazy_notify()
|
||||||
timer:start(500, 0, replay)
|
timer:start(500, 0, replay)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.lsp_get_config(server)
|
||||||
|
local configs = require("lspconfig.configs")
|
||||||
|
return rawget(configs, server)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param server string
|
||||||
|
---@param cond fun( root_dir, config): boolean
|
||||||
|
function M.lsp_disable(server, cond)
|
||||||
|
local util = require("lspconfig.util")
|
||||||
|
local def = M.lsp_get_config(server)
|
||||||
|
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
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue