|
| 1 | +return { |
| 2 | + "neovim/nvim-lspconfig", |
| 3 | + event = { "BufReadPre", "BufNewFile" }, |
| 4 | + dependencies = { |
| 5 | + "williamboman/mason.nvim", |
| 6 | + "williamboman/mason-lspconfig.nvim", |
| 7 | + "hrsh7th/cmp-nvim-lsp", |
| 8 | + }, |
| 9 | + config = function() |
| 10 | + -- plugins localization -- |
| 11 | + local lspconfig = require("lspconfig") |
| 12 | + local cmp_nvim_lsp = require("cmp_nvim_lsp") |
| 13 | + local mason = require("mason") |
| 14 | + local mason_lspconfig = require("mason-lspconfig") |
| 15 | + -- language server protocol configration -- |
| 16 | + local keymap = vim.keymap -- for conciseness |
| 17 | + -- lsp keybinds |
| 18 | + vim.api.nvim_create_autocmd("LspAttach", { |
| 19 | + group = vim.api.nvim_create_augroup("UserLspConfig", {}), |
| 20 | + callback = function(ev) |
| 21 | + -- see :help vim.lsp.* |
| 22 | + local opts = { buffer = ev.buf, silent = true } |
| 23 | + -- see :help vim.lsp.buf |
| 24 | + opts.desc = "Show LSP definitions" |
| 25 | + keymap.set("n", "<CR>", vim.lsp.buf.definition, opts) |
| 26 | + opts.desc = "Show documentation for what is under cursor" |
| 27 | + keymap.set("n", "<CR>", vim.lsp.buf.hover, opts) |
| 28 | + end, |
| 29 | + }) |
| 30 | + -- used to enable autocompletion (assign to every lsp server config) |
| 31 | + local capabilities = cmp_nvim_lsp.default_capabilities() |
| 32 | + -- vim diagnostic settings |
| 33 | + local diagnostic_config = { |
| 34 | + virtual_text = true, |
| 35 | + update_in_insert = true, |
| 36 | + float = { |
| 37 | + focusable = false, |
| 38 | + border = "rounded", |
| 39 | + }, |
| 40 | + } |
| 41 | + vim.diagnostic.config(diagnostic_config) |
| 42 | + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { |
| 43 | + border = "rounded", |
| 44 | + }) |
| 45 | + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { |
| 46 | + border = "rounded", |
| 47 | + }) |
| 48 | + -- mason-lspconfig servers handler |
| 49 | + mason_lspconfig.setup_handlers({ |
| 50 | + -- default handler for installed servers |
| 51 | + function(server_name) |
| 52 | + lspconfig[server_name].setup({ |
| 53 | + capabilities = capabilities, |
| 54 | + }) |
| 55 | + end, |
| 56 | + }) |
| 57 | + -- mason package manager -- |
| 58 | + local servers = { |
| 59 | + "bashls", |
| 60 | + "tsserver", |
| 61 | + "cssls", |
| 62 | + "html", |
| 63 | + "jsonls", |
| 64 | + "pyright", |
| 65 | + } |
| 66 | + mason.setup({ |
| 67 | + ui = { |
| 68 | + icons = { |
| 69 | + package_installed = "✓", |
| 70 | + package_pending = "➜", |
| 71 | + package_uninstalled = "✗" |
| 72 | + }, |
| 73 | + }, |
| 74 | + }) |
| 75 | + mason_lspconfig.setup({ |
| 76 | + ensure_installed = servers, |
| 77 | + automatic_installation = false, |
| 78 | + }) |
| 79 | + end, |
| 80 | +} |
0 commit comments