all repos

init.lua @ main

my nvim config

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

vim.lsp.enable {
  "elmls",
  "gleam",
  "golangci_lint_ls",
  "gopls",
  "jsonls",
  "lua_ls",
  "markdown_oxide",
  "ts_ls",
  "yamlls",
}

vim.api.nvim_create_user_command("LspRestart", function(opts)
  vim.lsp.enable(opts.args, false)
  vim.lsp.enable(opts.args, true)
end, { nargs = 1, complete = u.lsp.get_clients })

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(vim.lsp.protocol.Methods.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", "gd", Snacks.picker.lsp_definitions, bufnr)
    u.map("n", "gr", Snacks.picker.lsp_references, bufnr)
    u.map("n", "gi", Snacks.picker.lsp_implementations, 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>ll", vim.lsp.codelens.run, bufnr)
    u.map("n", "<leader>ls", Snacks.picker.lsp_symbols)
    u.map("n", "<leader>lS", Snacks.picker.lsp_workspace_symbols)
    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,
})