all repos

init.lua @ f6acf4c

my nvim config

init.lua/lua/plugins/lsp/attach.lua(view raw)

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
local attach = {}

local function map(from, to)
  vim.keymap.set("n", from, to, {
    buffer = true,
    noremap = true,
    silent = true,
  })
end

function attach.basic(_, _)
  map("<leader>lf", function()
    vim.lsp.buf.format { async = true }
  end)
  map("]d", function()
    vim.diagnostic.goto_next { float = false }
  end)
  map("[d", function()
    vim.diagnostic.goto_prev { float = false }
  end)

  map("]D", vim.diagnostic.goto_next)
  map("[D", vim.diagnostic.goto_prev)
end

function attach.common(client, bufnr)
  client.server_capabilities.documentFormattingProvider = false
  if client.name == "gopls" then
    vim.lsp.codelens.refresh()
  end

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

  attach.basic(client, bufnr)

  map("K", vim.lsp.buf.hover)
  map("gd", "<cmd>Telescope lsp_definitions<cr>")
  map("gr", "<cmd>Telescope lsp_references<cr>")
  map("gi", "<cmd>Telescope lsp_implementations<cr>")
  map("gl", vim.diagnostic.open_float)
  map("<leader>la", vim.lsp.buf.code_action)
  map("<leader>lr", vim.lsp.buf.rename)
  map("<leader>ls", "<cmd>Telescope lsp_document_symbols<cr>")
  map("<leader>ll", vim.lsp.codelens.run)

  map("<leader>li", function()
    if vim.lsp.inlay_hint.is_enabled(bufnr) then
      vim.lsp.inlay_hint.enable(bufnr, false)
      vim.print "Inlay hints disabled"
    else
      vim.lsp.inlay_hint.enable(bufnr, true)
      vim.print "Inlay hints enabled"
    end
  end)
end

return attach