summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/lsp.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/plugins/lsp.lua')
-rw-r--r--.config/nvim/lua/plugins/lsp.lua78
1 files changed, 78 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua
new file mode 100644
index 0000000..cb4511d
--- /dev/null
+++ b/.config/nvim/lua/plugins/lsp.lua
@@ -0,0 +1,78 @@
+return {
+ {
+ "neovim/nvim-lspconfig",
+ dependencies = {
+ "hrsh7th/cmp-nvim-lsp",
+ "jose-elias-alvarez/null-ls.nvim",
+ },
+ event = { "BufReadPre", "BufNewFile" },
+ config = function()
+ local lspconfig = require("lspconfig")
+ local capabilities = require("cmp_nvim_lsp").default_capabilities()
+ local common = {
+ capabilities = capabilities,
+ }
+
+ local lsps = {
+ "rust_analyzer",
+ "gopls",
+ "lua_ls",
+ "pylsp",
+ }
+
+ for _, lsp in ipairs(lsps) do
+ lspconfig[lsp].setup(common)
+ end
+
+ local wk = require("which-key")
+ wk.register({
+ ["<leader>q"] = { vim.diagnostic.open_float, "Show diagnostics in a floating window" },
+ ["[d"] = { vim.diagnostic.goto_prev, "Previous diagnostic" },
+ ["]d"] = { vim.diagnostic.goto_next, "Next diagnostic" },
+ })
+
+ vim.api.nvim_create_autocmd("LspAttach", {
+ group = vim.api.nvim_create_augroup("UserLspConfig", {}),
+ callback = function(ev)
+ wk.register({
+ gD = { vim.lsp.buf.declaration, "Go to declaration" },
+ gd = { vim.lsp.buf.definition, "Go to definition" },
+ gr = { vim.lsp.buf.references, "Go to references" },
+ gi = { vim.lsp.buf.implementation, "Go to implementation" },
+ K = { vim.lsp.buf.hover, "Show LSP hover info" },
+ ["<C-k>"] = { vim.lsp.buf.signature_help, "Show signature help" },
+ ["<leader>D"] = { vim.lsp.buf.type_definition, "Type definition" },
+ ["<leader>rn"] = { vim.lsp.buf.rename, "Rename" },
+ ["<leader>ca"] = { vim.lsp.buf.code_action, "Code action" },
+ ["<leader>F"] = {
+ function()
+ vim.lsp.buf.format({ async = true })
+ end,
+ "Format buffer",
+ },
+ ["<leader>w"] = {
+ name = "+LSP workspace",
+ a = { vim.lsp.buf.add_workspace_folder, "Add workspace folder" },
+ r = { vim.lsp.buf.remove_workspace_folder, "Remove workspace folder" },
+ l = {
+ function()
+ print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+ end,
+ "List workspace folders",
+ },
+ },
+ }, {buffer=ev.buf})
+ end,
+ })
+
+ local nls = require("null-ls")
+ nls.setup({
+ sources = {
+ nls.builtins.formatting.stylua,
+ nls.builtins.formatting.shfmt,
+ nls.builtins.code_actions.gitsigns,
+ },
+ })
+ end,
+ },
+}