tb-dotfiles/chezmoi/private_dot_config/nvim/lua/plugins/lsp.lua

148 lines
4.2 KiB
Lua
Raw Normal View History

-- LSP Configuration & Plugins
return {
{
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
{
"j-hui/fidget.nvim",
tag = "legacy",
},
"folke/neodev.nvim",
"RRethy/vim-illuminate",
"nanotee/nvim-lsp-basics",
"jose-elias-alvarez/null-ls.nvim",
},
config = function()
-- Set up Mason before anything else
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls",
},
automatic_installation = true,
})
-- Quick access via keymap
require("helpers.keys").map("n", "<leader>M", "<cmd>Mason<cr>", "Show Mason")
-- Neodev setup before LSP config
require("neodev").setup()
-- Turn on LSP status information
require("fidget").setup()
-- linter and formatter configurations
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.gofumpt,
null_ls.builtins.formatting.goimports,
null_ls.builtins.formatting.isort,
null_ls.builtins.formatting.black.with({
extra_args = { "-l 120" }
}),
null_ls.builtins.diagnostics.flake8.with({
extra_args = { "--max-line-length=120" }
}),
2023-07-17 16:33:58 -04:00
null_ls.builtins.diagnostics.markdownlint,
null_ls.builtins.formatting.rubocop,
null_ls.builtins.formatting.rustfmt,
null_ls.builtins.diagnostics.shellcheck,
null_ls.builtins.formatting.stylua,
}
})
-- Set up cool signs for diagnostics
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
-- Diagnostic config
local config = {
virtual_text = false,
signs = {
active = signs,
},
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
focusable = true,
style = "minimal",
border = "rounded",
source = "always",
header = "",
prefix = "",
},
}
vim.diagnostic.config(config)
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(client, bufnr)
local basics = require("lsp_basics")
basics.make_lsp_commands(client, bufnr)
basics.make_lsp_mappings(client, bufnr)
local lsp_map = require("helpers.keys").lsp_map
lsp_map("<leader>lr", vim.lsp.buf.rename, bufnr, "Rename symbol")
lsp_map("<leader>la", vim.lsp.buf.code_action, bufnr, "Code action")
lsp_map("<leader>ld", vim.lsp.buf.type_definition, bufnr, "Type definition")
lsp_map("<leader>ls", require("telescope.builtin").lsp_document_symbols, bufnr, "Document symbols")
lsp_map("gd", vim.lsp.buf.definition, bufnr, "Goto Definition")
lsp_map("gr", require("telescope.builtin").lsp_references, bufnr, "Goto References")
lsp_map("gI", vim.lsp.buf.implementation, bufnr, "Goto Implementation")
lsp_map("K", vim.lsp.buf.hover, bufnr, "Hover Documentation")
lsp_map("gD", vim.lsp.buf.declaration, bufnr, "Goto Declaration")
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
vim.lsp.buf.format()
end, { desc = "Format current buffer with LSP" })
lsp_map("<leader>ff", "<cmd>Format<cr>", bufnr, "Format")
-- Attach and configure vim-illuminate
require("illuminate").on_attach(client)
end
local lspconfig = require("lspconfig")
require("mason-lspconfig").setup_handlers({
function(server_name)
lspconfig[server_name].setup({
on_attach = on_attach,
})
end,
["lua_ls"] = function()
lspconfig.lua_ls.setup({
on_attach = on_attach,
-- capabilities = capabilities,
settings = {
Lua = {
completion = {
callSnippet = "Replace",
},
diagnostics = {
globals = { "vim" },
},
workspace = {
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.stdpath("config") .. "/lua"] = true,
},
},
},
},
})
end
})
end,
},
}