diff options
| author | ache <ache@ache.one> | 2024-07-21 05:30:30 +0200 |
|---|---|---|
| committer | ache <ache@ache.one> | 2024-07-21 05:30:30 +0200 |
| commit | d69c281f43ba4168df32ef4ae6b77f88bfc60d86 (patch) | |
| tree | 844fe20b45d099cbd35c1ccb3ae89dafb3da51a7 /lua/ache/plugins/lsp | |
Init commit
Diffstat (limited to 'lua/ache/plugins/lsp')
| -rw-r--r-- | lua/ache/plugins/lsp/lspconfig.lua | 158 | ||||
| -rw-r--r-- | lua/ache/plugins/lsp/mason-config.lua | 53 | ||||
| -rw-r--r-- | lua/ache/plugins/lsp/mason-lspconf.lua | 8 | ||||
| -rw-r--r-- | lua/ache/plugins/lsp/rust-tools.lua | 17 |
4 files changed, 236 insertions, 0 deletions
diff --git a/lua/ache/plugins/lsp/lspconfig.lua b/lua/ache/plugins/lsp/lspconfig.lua new file mode 100644 index 0000000..d7ef824 --- /dev/null +++ b/lua/ache/plugins/lsp/lspconfig.lua @@ -0,0 +1,158 @@ +return { + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "williamboman/mason-lspconfig.nvim", + { "antosha417/nvim-lsp-file-operations", config = true }, + { "folke/neodev.nvim", opts = {} }, + }, + config = function() + local lspconfig = require("lspconfig") + local mason_lspconfig = require("mason-lspconfig") + local cmp_nvim_lsp = require("cmp_nvim_lsp") + + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(ev) + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the functions below. + + -- Keybinds + vim.keymap.set( + "n", + "gR", + "<cmd>Telescope lsp_references<CR>", + { buffer = ev.buf, silent = true, desc = "Show LSP references" } + ) + vim.keymap.set( + "n", + "gD", + vim.lsp.buf.declaration, + { buffer = ev.buf, silent = true, desc = "Go to declaration" } + ) + vim.keymap.set( + "n", + "gd", + "<cmd>Telescope lsp_definitions<CR>", + { buffer = ev.buf, silent = true, desc = "Show LSP definitions" } + ) + vim.keymap.set( + "n", + "gi", + "<cmd>Telescope lsp_implementations<CR>", + { buffer = ev.buf, silent = true, desc = "Show LSP implementations" } + ) + vim.keymap.set( + "n", + "gt", + "<cmd>Telescope lsp_type_definitions<CR>", + { buffer = ev.buf, silent = true, desc = "Show LSP type definitions" } + ) + vim.keymap.set( + { "n", "v" }, + "<leader>ca", + vim.lsp.buf.code_action, + { buffer = ev.buf, silent = true, desc = "See available code actions" } + ) + vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { buffer = ev.buf, silent = true, desc = "Smart rename" }) + vim.keymap.set( + "n", + "<leader>D", + "<cmd>Telescope diagnostics bufnr=0<CR>", + { buffer = ev.buf, silent = true, desc = "Show buffer diagnostics" } + ) + vim.keymap.set( + "n", + "<leader>d", + vim.diagnostic.open_float, + { buffer = ev.buf, silent = true, desc = "Show line diagnostics" } + ) + vim.keymap.set( + "n", + "<d", + vim.diagnostic.goto_prev, + { buffer = ev.buf, silent = true, desc = "Go to previous diagnostic" } + ) + vim.keymap.set( + "n", + ">d", + vim.diagnostic.goto_next, + { buffer = ev.buf, silent = true, desc = "Go to next diagnostic" } + ) + vim.keymap.set( + "n", + "K", + vim.lsp.buf.hover, + { buffer = ev.buf, silent = true, desc = "Show documentation for what is under the cursor" } + ) + vim.keymap.set( + "n", + "<leader>rs", + "<cmd>LspRestart<CR>", + { buffer = ev.buf, silent = true, desc = "Restart LSP" } + ) + end, + }) + + -- used to enable autocompletion (assign to every lsp server config) + local capabilities = cmp_nvim_lsp.default_capabilities() + + -- Change the diagnostics symbols in the sign column (gutter) + 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 + + mason_lspconfig.setup_handlers({ + -- default handler for installed servers + function(server_name) + lspconfig[server_name].setup({ + capabilities = capabilities, + }) + end, + ["svelte"] = function() + -- Configuration specific to svelte LSP server + lspconfig["svelte"].setup({ + capabilities = capabilities, + on_attach = function(client, bufnr) + vim.api.nvim_create_autocmd("BufWritePost", { + pattern = { "*.js", "*.ts" }, + callback = function(ctx) + -- Here use ctx.match instead of ctx.file + client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match }) + end, + }) + end, + }) + end, + ["lua_ls"] = function() + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + settings = { + Lua = { + -- make the language server recognize the "vim" global variable + diagnostics = { + globals = { "vim" }, + }, + completion = { + callSnippet = "Replace", + }, + }, + }, + }) + end, + ["pyright"] = function() + lspconfig["pyright"].setup({ + capabilities = capabilities, + settings = { + python = { + pythonPath = "/usr/bin/python", + }, + }, + }) + end, + }) + end, +} diff --git a/lua/ache/plugins/lsp/mason-config.lua b/lua/ache/plugins/lsp/mason-config.lua new file mode 100644 index 0000000..bd2dcbe --- /dev/null +++ b/lua/ache/plugins/lsp/mason-config.lua @@ -0,0 +1,53 @@ +return { + "williamboman/mason.nvim", + dependencies = { + "WhoIsSethDaniel/mason-tool-installer.nvim", + "mfussenegger/nvim-dap", + "jay-babu/mason-nvim-dap.nvim", + "neovim/nvim-lspconfig", + }, + config = function() + local mason = require("mason") + + local mason_lspconfig = require("mason-lspconfig") + local mason_tool_installer = require("mason-tool-installer") + local mason_dap = require("mason-nvim-dap") + local lspconfig = require("lspconfig") + + mason.setup() + mason_dap.setup({ + ensure_installed = { + "codelldb", + }, + }) + + mason_lspconfig.setup({ + lazy = true, + ensure_installed = { + "tsserver", + "html", + "cssls", + "tailwindcss", + "svelte", + "lua_ls", + "pyright", + "ruff_lsp", + "rust_analyzer", + }, + }) + + mason_tool_installer.setup({ + ensure_installed = { + "prettier", -- Web related formatter + "stylua", -- Lua formatter + "isort", -- Python formatter + "black", -- Python formatter too + -- "ruff", -- Python linter + "eslint_d", -- JS linter + "llm-ls", + }, + }) + + -- lspconfig.pyright.setup({}) + end, +} diff --git a/lua/ache/plugins/lsp/mason-lspconf.lua b/lua/ache/plugins/lsp/mason-lspconf.lua new file mode 100644 index 0000000..267bbb2 --- /dev/null +++ b/lua/ache/plugins/lsp/mason-lspconf.lua @@ -0,0 +1,8 @@ +return { + -- NOTE: mason is a dependencie of mason-lspconfig. Not the other way around. + "williamboman/mason-lspconfig.nvim", + dependencies = { + "williamboman/mason.nvim", + "neovim/nvim-lspconfig", + }, +} diff --git a/lua/ache/plugins/lsp/rust-tools.lua b/lua/ache/plugins/lsp/rust-tools.lua new file mode 100644 index 0000000..ee94be5 --- /dev/null +++ b/lua/ache/plugins/lsp/rust-tools.lua @@ -0,0 +1,17 @@ +return { + "simrat39/rust-tools.nvim", + config = function() + local rt = require("rust-tools") + + rt.setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "<C-!>", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "<leader>a", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, + }) + end, +} |