all repos

init.lua @ 57bd9cb

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
local u = require "core.utils"

u.aucmd("LspAttach", {
  group = u.augroup "lsp",
  callback = function(args)
    local bufnr = args.buf
    local client = vim.lsp.get_client_by_id(args.data.client_id)
    if not client then
      error "couldn't get an lsp server"
    end

    if client.supports_method "textDocument/codeLens" then
      vim.lsp.codelens.refresh { bufnr = bufnr }
    end

    u.map("n", "<leader>lf", function()
      vim.lsp.buf.format { async = true }
    end, bufnr)
    u.map("n", "]d", function()
      pcall(vim.diagnostic.jump, { count = 1, float = false })
    end, bufnr)
    u.map("n", "[d", function()
      pcall(vim.diagnostic.jump, { count = -1, float = false })
    end, bufnr)

    u.map("n", "]D", function()
      pcall(vim.diagnostic.jump, { count = 1 })
    end, bufnr)
    u.map("n", "[D", function()
      pcall(vim.diagnostic.jump, { count = -1 })
    end, bufnr)

    u.map("n", "K", vim.lsp.buf.hover, bufnr)
    u.map("n", "gd", "<cmd>Telescope lsp_definitions<cr>", bufnr)
    u.map("n", "gr", "<cmd>Telescope lsp_references<cr>", bufnr)
    u.map("n", "gi", "<cmd>Telescope lsp_implementations<cr>", bufnr)
    u.map("n", "gl", vim.diagnostic.open_float, bufnr)
    u.map("n", "<leader>la", vim.lsp.buf.code_action, bufnr)
    u.map("n", "<leader>lr", vim.lsp.buf.rename, bufnr)
    u.map("n", "<leader>ss", "<cmd>Telescope lsp_document_symbols<cr>", bufnr)
    u.map("n", "<leader>ll", vim.lsp.codelens.run, bufnr)
    u.map("n", "<leader>li", function()
      if vim.lsp.inlay_hint.is_enabled { bufnr = bufnr } then
        vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })
        vim.print "Inlay hints disabled"
      else
        vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
        vim.print "Inlay hints enabled"
      end
    end, bufnr)
  end,
})