Skip to content

Commit

Permalink
lsp(mason): refine server setup handlers
Browse files Browse the repository at this point in the history
fix lspsaga keymap attach for rust
  • Loading branch information
ttytm committed Jun 19, 2024
1 parent 3e07309 commit 29e6d22
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lua/nxvim/lsp/plugins/mason/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,44 @@ local function on_attach(client, bufnr)
require("nxvim.lsp.plugins.lspsaga").on_attach(client, bufnr)
end

local default_opts = {
local opts = {
capabilities = capabilities,
on_attach = on_attach,
}

lspconfig.mojo.setup(default_opts)
lspconfig.sourcekit.setup(default_opts)
lspconfig.mojo.setup(opts)
lspconfig.sourcekit.setup(opts)

-- `:h mason-lspconfig-dynamic-server-setup`
mason_lspconfig.setup_handlers({
function(server)
local opts = default_opts
-- Insert server settings from settings file if present.
-- The name of the settings file must match the name of the language server.
local server_opts = opts
--- Insert server settings from settings file if present.
--- The name of the settings file must match the name of the language server.
local server_settings_ok, server_settings = pcall(require, "nxvim.lsp.settings." .. server)
if server_settings_ok then opts = vim.tbl_deep_extend("keep", server_settings, opts) end
if server_settings_ok then server_opts = vim.tbl_deep_extend("keep", server_settings, server_opts) end

-- Or add settings inline.
--
-- The json|ts provideFormatter setting below triggers for gopls when it shouldn't, therefore we skip it here.
--- Or add settings inline.
if server == "tsserver" then
opts.on_attach = function(client, bufnr)
server_opts.on_attach = function(client, bufnr)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
on_attach(client, bufnr)
opts.on_attach(client, bufnr)
end
end
if server == "gopls" then goto setup end
-- Use prettierd as formatter.
if server == "jsonls" then opts.init_options = { provideFormatter = false } end
if server == "jsonls" then server_opts.init_options = { provideFormatter = false } end
if server == "zls" then vim.g.zig_fmt_autosave = 0 end

::setup::
lspconfig[server].setup(opts)

-- ::continue::
end,
["rust_analyzer"] = function() require("rust-tools").setup(default_opts) end,
["rust_analyzer"] = function() require("rust-tools").setup({ server = opts }) end,
})
-- <== }

--- { == Keymaps ==> ===========================================================
-- { == Keymaps ==> ===========================================================

nx.map({
{ "<leader>l+", ":LspStart ", desc = "Select Language Server to Start", wk_label = "Start LSP" },
Expand Down

0 comments on commit 29e6d22

Please sign in to comment.