vim

Log | Files | Refs

lsp.lua (3134B)


      1 return {
      2   { "williamboman/mason.nvim", opts = {} },
      3 
      4   -- Kept as a dep: mason-lspconfig uses it for server cmd/filetype definitions.
      5   -- We do NOT call require('lspconfig').server.setup() — that API is deprecated
      6   -- in Neovim 0.11+. Configuration goes through vim.lsp.config() below.
      7   { "neovim/nvim-lspconfig" },
      8 
      9   {
     10     "williamboman/mason-lspconfig.nvim",
     11     dependencies = {
     12       "williamboman/mason.nvim",
     13       "neovim/nvim-lspconfig",
     14       "hrsh7th/cmp-nvim-lsp",
     15     },
     16     config = function()
     17       -- Keymaps set once per buffer when any LSP server attaches
     18       vim.api.nvim_create_autocmd("LspAttach", {
     19         callback = function(args)
     20           local bufnr = args.buf
     21           local m = function(keys, func, desc)
     22             vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc })
     23           end
     24           m("gd",         vim.lsp.buf.definition,     "Go to definition")
     25           m("gD",         vim.lsp.buf.declaration,    "Go to declaration")
     26           m("gr",         vim.lsp.buf.references,     "References")
     27           m("gi",         vim.lsp.buf.implementation, "Go to implementation")
     28           m("K",          vim.lsp.buf.hover,          "Hover docs")
     29           m("<leader>rn", vim.lsp.buf.rename,         "Rename")
     30           m("<leader>ca", vim.lsp.buf.code_action,    "Code action")
     31           m("<leader>cf", function()
     32             require("conform").format({ async = true, lsp_fallback = true })
     33           end, "Format file")
     34         end,
     35       })
     36 
     37       -- Apply nvim-cmp capabilities to every server
     38       vim.lsp.config("*", {
     39         capabilities = require("cmp_nvim_lsp").default_capabilities(),
     40       })
     41 
     42       -- Per-server settings via native vim.lsp.config (Neovim 0.11+)
     43       vim.lsp.config("pylsp", {
     44         settings = {
     45           pylsp = {
     46             plugins = {
     47               ruff        = { enabled = true },
     48               pyflakes    = { enabled = false },
     49               pycodestyle = { enabled = false },
     50               mccabe      = { enabled = false },
     51             },
     52           },
     53         },
     54       })
     55 
     56       vim.lsp.config("yamlls", {
     57         filetypes = { "yaml" },   -- ansiblels handles yaml.ansible
     58         settings = {
     59           yaml = {
     60             validate    = true,
     61             schemaStore = { enable = true },
     62           },
     63         },
     64       })
     65 
     66       vim.lsp.config("ansiblels", {
     67         filetypes = { "yaml.ansible" },
     68       })
     69 
     70       vim.lsp.config("lua_ls", {
     71         settings = {
     72           Lua = {
     73             diagnostics = { globals = { "vim" } },
     74             workspace   = { checkThirdParty = false },
     75             telemetry   = { enable = false },
     76           },
     77         },
     78       })
     79 
     80       -- Install servers; mason-lspconfig calls vim.lsp.enable() for each one
     81       require("mason-lspconfig").setup({
     82         ensure_installed = {
     83           "pylsp",       -- Python
     84           "bashls",      -- Bash/Shell  (requires node)
     85           "yamlls",      -- YAML        (requires node)
     86           "ansiblels",   -- Ansible     (requires node)
     87           "terraformls", -- OpenTofu / Terraform
     88           "lua_ls",      -- Lua
     89         },
     90       })
     91     end,
     92   },
     93 }