summaryrefslogtreecommitdiff
path: root/lua/custom/plugins/lsp.lua
blob: 256b46080d9264e9755543b6b7829872833fc6bc (plain)
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
return {
  "neovim/nvim-lspconfig",
  config = function()
    local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())

    local on_attach = function(client, bufnr)
      local opts = { buffer = bufnr, noremap = true, silent = true }

      if client.server_capabilities.inlayHintProvider then
        vim.lsp.inlay_hint.enable(true)
      end

      vim.diagnostic.config({ virtual_text = true })

      vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
      vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
      vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
    end

    local lspc = require("lspconfig")
    local servers = {
      "clangd",
      "gopls",
      "hls",
      "nixd",
      "pylsp",
      "rust_analyzer",
      "zls",
    }

    for _, s in ipairs(servers) do
      lspc[s].setup({ on_attach = on_attach, capabilities = capabilities })
    end
  end,
}