Skip to content

Commit

Permalink
feat(lsp): automatically resolve denols/tsserver conflicts if both ar…
Browse files Browse the repository at this point in the history
…e configured
  • Loading branch information
folke committed Apr 23, 2023
1 parent c7aeda9 commit d565684
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/lazyvim/plugins/lsp/init.lua
Expand Up @@ -75,10 +75,11 @@ return {
},
---@param opts PluginLspOpts
config = function(_, opts)
local Util = require("lazyvim.util")
-- setup autoformat
require("lazyvim.plugins.lsp.format").autoformat = opts.autoformat
-- 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.keymaps").on_attach(client, buffer)
end)
Expand Down Expand Up @@ -153,6 +154,14 @@ return {
mlsp.setup({ ensure_installed = ensure_installed })
mlsp.setup_handlers({ setup })
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,
},

Expand Down
17 changes: 17 additions & 0 deletions lua/lazyvim/util/init.lua
Expand Up @@ -196,4 +196,21 @@ function M.lazy_notify()
timer:start(500, 0, replay)
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

0 comments on commit d565684

Please sign in to comment.