summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/lsp.lua
blob: 296e73af4e659fe45bba86e5250e1d8699a91bd5 (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
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
-- Language server for specified languages
-- Hover with 'K'
-- Goto definition with :Goto
-- Open code action with :Codeact

local servers = {
  "lua_ls", "bashls", "clangd", "marksman", "pyright", "lemminx",
}

return {
  {
    "williamboman/mason.nvim",
    config = function()
      require("mason").setup()
    end
  },

  {
    "williamboman/mason-lspconfig.nvim",
    config = function()
      require("mason-lspconfig").setup {
        ensure_installed = servers,
        automatic_installation = true,
      }
    end
  },

  {
    "neovim/nvim-lspconfig",
    config = function()
      -- Advertise autocompletion to lsp
      local capabilities = require('cmp_nvim_lsp').default_capabilities()
      local lspconfig = require("lspconfig")
      for _, server in ipairs(servers) do
        lspconfig[server].setup {
          capabilities = capabilities,
        }
      end

      -- Key mapping
      -- Hover for definition
      vim.keymap.set('n', 'K', vim.lsp.buf.hover, {})

      -- Move to definition
      vim.api.nvim_create_user_command(
        "Goto",
        function()
          vim.lsp.buf.definition()
        end,
        {}
      )

      -- Code action
      vim.api.nvim_create_user_command(
        "Codeact",
        function()
          vim.lsp.buf.code_action()
        end,
        {}
      )
    end
  }
}