summaryrefslogtreecommitdiff
path: root/lua/config/lsp.lua
blob: 61e3fc317784b3e7dbc636602c4de47aaf36e16d (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
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
vim.o.completeopt = "menuone,noselect,noinsert,popup,fuzzy"

vim.diagnostic.config({
  underline = true,
  virtual_text = {
    current_line = true,
    severity = {
      max = vim.diagnostic.severity.WARN,
    },
  },
  virtual_lines = {
    current_line = true,
    severity = {
      min = vim.diagnostic.severity.ERROR,
    },
  },
  signs = {
    text = {
      [vim.diagnostic.severity.ERROR] = "",
      [vim.diagnostic.severity.WARN] = "",
      [vim.diagnostic.severity.INFO] = "",
      [vim.diagnostic.severity.HINT] = "",
    },
  },
})

vim.lsp.config("*", {
  capabilities = {
    textDocument = {
      semanticTokens = {
        multilineTokenSupport = true,
      },
      completion = {
        completionItem = {
          snippetSupport = true,
          commitCharactersSupport = true,
          deprecatedSupport = true,
          preselectSupport = true,
          insertReplaceSupport = true,
          labelDetailsSupport = true,
          resolveSupport = {
            properties = {
              "documentation",
              "detail",
              "additionalTextEdits",
            },
          },
        },
      },
    },
  },

  on_attach = function(client, bufnr)
    if client:supports_method('textDocument/completion') then
      vim.lsp.completion.enable(true, client.id, bufnr, { autotrigger = true })
      vim.keymap.set("i", "<M-Space>", vim.lsp.completion.get, { buffer = bufnr })
    end

    if client:supports_method('textDocument/definition') then
      vim.keymap.set("n", "grd", vim.lsp.buf.definition, { desc = "Jumps to definition", buffer = bufnr })
    end
    if client:supports_method('textDocument/declaration') then
      vim.keymap.set("n", "grD", vim.lsp.buf.declaration, { desc = "Jumps to declaration", buffer = bufnr })
    end

    if client:supports_method("textDocument/inlayHint") then
      vim.lsp.inlay_hint.enable(true, { bufnr })
    end

    if client:supports_method("textDocument/formatting") then
      local description = "LSP: Formats the current buffer"
      local format_buffer = function()
        vim.lsp.buf.format({ async = true, buffer = bufnr })
      end
      vim.keymap.set("n", "<Leader>cf", format_buffer, { desc = description })
      vim.keymap.set("v", "<C-f>", format_buffer, { desc = description })
    end
  end,
})

vim.lsp.enable({
  "asm",
  "bash",
  "clangd",
  "crystal",
  "css",
  "go",
  "html",
  "javascript",
  "json",
  "lua",
  "markdown",
  "odin",
  "ruby",
  "vala",
  "yaml",
})