77 lines
2.8 KiB
Lua
77 lines
2.8 KiB
Lua
return {
|
|
-- lsp client plugin
|
|
"neovim/nvim-lspconfig", -- https://github.com/neovim/nvim-lspconfig
|
|
dependencies = {
|
|
"williamboman/mason.nvim", -- https://github.com/williamboman/mason.nvim
|
|
"williamboman/mason-lspconfig.nvim", -- https://github.com/williamboman/mason-lspconfig.nvim bridges the gab between lspconfig and mason
|
|
{
|
|
"folke/lazydev.nvim", -- https://github.com/folke/lazydev.nvim
|
|
ft = "lua",
|
|
opts = {
|
|
library = {
|
|
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
config = function()
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
require('mason').setup()
|
|
require('mason-lspconfig').setup({
|
|
ensure_installed = {
|
|
'lua_ls',
|
|
},
|
|
handlers = {
|
|
function(server_name)
|
|
require("lspconfig")[server_name].setup({
|
|
capabilities = capabilities
|
|
})
|
|
end,
|
|
|
|
["ansiblels"] = function()
|
|
require("lspconfig")['ansiblels'].setup({
|
|
filetypes = {
|
|
"yaml",
|
|
},
|
|
})
|
|
end,
|
|
}
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
-- group = vim.api.nvim_create_augroup('KamuLspConfig', {}),
|
|
callback = function(ev)
|
|
local opts = { buffer = ev.buf }
|
|
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
|
if not client then return end
|
|
|
|
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
|
|
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
|
|
vim.keymap.set("n", "<leader>ca", function() vim.lsp.buf.code_action() end, opts)
|
|
vim.keymap.set('n', '<space>f', function()
|
|
vim.lsp.buf.format { async = true }
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
|
|
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
|
|
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
|
|
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
|
|
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
|
|
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
|
|
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
|
|
|
|
-- Format on save
|
|
if client.supports_method('textDocument/formatting') and vim.bo.filetype == "lua" then
|
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
|
buffer = ev.buf,
|
|
callback = function()
|
|
vim.lsp.buf.format({ bufnr = ev.buf, id = client.id })
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
})
|
|
end
|
|
}
|