1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| return { { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "mason.nvim", "mason-lspconfig.nvim", "folke/neodev.nvim", }, config = function() 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 }) end
vim.api.nvim_create_autocmd("LspAttach", { callback = function(event) local map = function(keys, func, desc) vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc, }) end
map("gd", vim.lsp.buf.definition, "Go to definition") map("gr", vim.lsp.buf.references, "Go to references") map("gI", vim.lsp.buf.implementation, "Go to implementation") map("K", vim.lsp.buf.hover, "Hover documentation") map("<leader>rn", vim.lsp.buf.rename, "Rename") map("<leader>ca", vim.lsp.buf.code_action, "Code action") map("<leader>D", vim.lsp.buf.type_definition, "Type definition") map("<leader>f", function() vim.lsp.buf.format({ async = true }) end, "Format") end, }) end, },
{ "williamboman/mason.nvim", cmd = "Mason", config = function() require("mason").setup({ ui = { border = "rounded" }, }) end, },
{ "williamboman/mason-lspconfig.nvim", config = function() require("mason-lspconfig").setup({ ensure_installed = { "lua_ls", "rust_analyzer", "ts_ls", "gopls", "pyright", "jsonls", "yamlls", "tailwindcss", }, })
local lspconfig = require("lspconfig") local capabilities = require("cmp_nvim_lsp").default_capabilities()
require("mason-lspconfig").setup_handlers({ function(server_name) lspconfig[server_name].setup({ capabilities = capabilities, }) end,
["lua_ls"] = function() lspconfig.lua_ls.setup({ capabilities = capabilities, settings = { Lua = { workspace = { checkThirdParty = false }, telemetry = { enable = false }, }, }, }) end,
["rust_analyzer"] = function() lspconfig.rust_analyzer.setup({ capabilities = capabilities, settings = { ["rust-analyzer"] = { checkOnSave = { command = "clippy", }, cargo = { allFeatures = true, }, }, }, }) end, }) end, }, }
|