Neovim: switch lsp to use mason automatic setup
This commit is contained in:
parent
b151067a21
commit
d19e5a8b6a
4 changed files with 123 additions and 128 deletions
91
home/.config/nvim/lua/plugins/mason.lua
Normal file
91
home/.config/nvim/lua/plugins/mason.lua
Normal file
|
@ -0,0 +1,91 @@
|
|||
local m = {}
|
||||
|
||||
function m.setup()
|
||||
local function on_attach()
|
||||
-- Setup lsp signature plugin
|
||||
require("lsp_signature").setup({})
|
||||
|
||||
-- Setup keybinds
|
||||
m.map_keys()
|
||||
end
|
||||
|
||||
-- Inform lsp about completion capabilities from cmp
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
require("mason").setup()
|
||||
local mason_lsp = require("mason-lspconfig")
|
||||
mason_lsp.setup()
|
||||
|
||||
mason_lsp.setup_handlers({
|
||||
-- Default handler
|
||||
function(server_name)
|
||||
require("lspconfig")[server_name].setup({
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end,
|
||||
|
||||
-- Override lua_ls settings
|
||||
["lua_ls"] = function()
|
||||
require("lspconfig").lua_ls.setup({
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||
version = "LuaJIT",
|
||||
},
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = vim.api.nvim_get_runtime_file("", true),
|
||||
},
|
||||
-- Do not send telemetry data containing a randomized but unique identifier
|
||||
telemetry = { enable = false },
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function m.map_keys()
|
||||
local wk = require("which-key")
|
||||
wk.register({
|
||||
g = {
|
||||
name = "Go to",
|
||||
d = { vim.lsp.buf.definition, "Definition" },
|
||||
D = { vim.lsp.buf.declaration, "Declaration" },
|
||||
i = { vim.lsp.buf.implementation, "Implementation" },
|
||||
r = { vim.lsp.buf.references, "References" },
|
||||
},
|
||||
["<leader>"] = {
|
||||
name = "Leader",
|
||||
w = {
|
||||
name = "Workspace",
|
||||
a = { vim.lsp.buf.add_workspace_folder, "Add folder" },
|
||||
r = { vim.lsp.buf.remove_workspace_folder, "Remove folder" },
|
||||
l = {
|
||||
function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end,
|
||||
"List folders",
|
||||
},
|
||||
},
|
||||
D = { vim.lsp.buf.type_definition, "Type definition" },
|
||||
rn = { vim.lsp.buf.rename, "Rename symbol" },
|
||||
ca = { vim.lsp.buf.code_action, "Code action" },
|
||||
e = { vim.diagnostic.open_float, "Open diagnostics" },
|
||||
f = { vim.lsp.buf.format, "Format" },
|
||||
},
|
||||
K = { vim.lsp.buf.hover, "Hover" },
|
||||
["["] = { d = { vim.diagnostic.goto_prev, "Previous diagnostic" } },
|
||||
["]"] = { d = { vim.diagnostic.goto_next, "Next diagnostic" } },
|
||||
})
|
||||
end
|
||||
|
||||
return m
|
Loading…
Add table
Add a link
Reference in a new issue