馃 my neovim config:)
1local components = {
2 {
3 name = "inlay_hint",
4 callback = function(client, buf)
5 if client.server_capabilities.inlayHintProvider then
6 vim.lsp.inlay_hint.enable(true, { bufnr = buf })
7 end
8 end,
9 },
10 {
11 name = "document_highlight",
12 callback = function(client, buf)
13 if client.server_capabilities.documentHighlightProvider then
14 local augroup = vim.augroup(string.format("@ivy.lsp.document_highlight.%d", buf), true)
15 augroup({ "CursorHold", "CursorHoldI" }, nil, {
16 buffer = buf,
17 desc = "highlight lsp reference",
18 }, function()
19 vim.lsp.buf.clear_references()
20 vim.lsp.buf.document_highlight()
21 end)
22 augroup("CursorMoved", nil, {
23 buffer = buf,
24 desc = "clear lsp references",
25 }, function()
26 vim.lsp.buf.clear_references()
27 end)
28 end
29 end,
30 },
31 {
32 name = "linked_editing_range",
33 callback = function(client, _)
34 if client.server_capabilities.linkedEditingRangeProvider then
35 vim.lsp.linked_editing_range.enable(true, { client_id = client.id })
36 end
37 end,
38 },
39 {
40 name = "document_color",
41 callback = function(client, bufnr)
42 if client.server_capabilities.documentColorProvider then
43 vim.lsp.document_color.enable(true, bufnr)
44 end
45 end,
46 },
47 { name = "user", callback = vim.g.lsp_on_attach },
48}
49
50vim.iter(ipairs(components)):each(function(_, fn)
51 vim.augroup("@ivy.lsp." .. fn.name, true)("LspAttach", nil, {}, function(ev)
52 local client = vim.lsp.get_client_by_id(ev.data.client_id)
53 if client == nil then
54 return
55 end
56 local ok, result = pcall(fn.callback, client, ev.buf)
57 if not ok then
58 vim.notify(
59 ("unable to run attach events for lsp server '%s':\n\t%s"):format(client.name, vim.inspect(result)),
60 vim.log.levels.ERROR
61 )
62 return
63 end
64 end)
65end)