🪴 my neovim config:)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(lsp): move to `plugin/lsp.lua`

robin c2fb2ea8 3cb3d989

+99 -73
-35
config/lua/ivy/config/lsp.lua
··· 1 - local props = vim.g.lsp_config or {} 2 - 3 - vim.validate("vim.g.lsp_config.common", props.common, { "table", "function" }) 4 - vim.validate("vim.g.lsp_config.servers", props.servers, { "table", "function" }) 5 - vim.validate("vim.g.lsp_config.on_attach", props.on_attach, "function") 6 - 7 - local function setup_ls(name, cfg) 8 - ---@diagnostic disable-next-line: param-type-mismatch 9 - local ok, result = pcall(vim.lsp.config, name, cfg) 10 - if not ok then 11 - vim.notify(("unable to configure lsp server %s:\n\t%s"):format(name, result)) 12 - return 13 - end 14 - vim.lsp.enable(name) 15 - end 16 - 17 - vim.api.nvim_create_autocmd("LspAttach", { 18 - group = vim.api.nvim_create_augroup("LspAttach", { clear = true }), 19 - callback = props.on_attach, 20 - }) 21 - 22 - local common = props.common 23 - if type(common) == "function" then 24 - common = common() 25 - end 26 - 27 - vim.lsp.config("*", common) 28 - 29 - local servers = props.servers 30 - if type(servers) == "function" then 31 - servers = servers() 32 - end 33 - 34 - ---@diagnostic disable-next-line: param-type-mismatch 35 - vim.iter(pairs(servers)):each(setup_ls)
+2 -38
config/lua/ivy/init.lua
··· 87 87 zls = {}, 88 88 } 89 89 end, 90 - on_attach = function(ev) 91 - local client = vim.lsp.get_client_by_id(ev.data.client_id) 92 - 93 - if client == nil then 94 - return 95 - end 96 - 97 - if client.server_capabilities.inlayHintProvider then 98 - vim.lsp.inlay_hint.enable(true, { bufnr = ev.buf }) 99 - end 100 - 101 - if client.server_capabilities.documentHighlightProvider then 102 - local group = vim.api.nvim_create_augroup(string.format("lsp:document_highlight:%d", ev.buf), { clear = true }) 103 - vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { 104 - group = group, 105 - buffer = ev.buf, 106 - callback = function() 107 - vim.lsp.buf.clear_references() 108 - vim.lsp.buf.document_highlight() 109 - end, 110 - desc = "highlight lsp reference", 111 - }) 112 - vim.api.nvim_create_autocmd("CursorMoved", { 113 - group = group, 114 - buffer = ev.buf, 115 - callback = function() 116 - vim.lsp.buf.clear_references() 117 - end, 118 - desc = "clear lsp references", 119 - }) 120 - end 121 - 122 - if client.server_capabilities.linkedEditingRangeProvider then 123 - vim.lsp.linked_editing_range.enable(true, { client_id = client.id }) 124 - end 125 - 126 - local opts = { buffer = ev.buf } 90 + on_attach = function(_, buf) 91 + local opts = { buffer = buf } 127 92 vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) 128 93 end, 129 94 } ··· 146 111 { "cmds", event = "VimEnter" }, 147 112 { "ft" }, 148 113 { "keybinds", event = "UIEnter" }, 149 - { "lsp", event = { "BufReadPre", "BufNewFile" } }, 150 114 { "neovide", event = "UIEnter" }, 151 115 { "options" }, 152 116 }))
+97
config/plugin/lsp.lua
··· 1 + local props = vim.g.lsp_config or {} 2 + 3 + vim.validate("vim.g.lsp_config.common", props.common, { "table", "function" }) 4 + vim.validate("vim.g.lsp_config.servers", props.servers, { "table", "function" }) 5 + vim.validate("vim.g.lsp_config.on_attach", props.on_attach, "function") 6 + 7 + local components = { 8 + { 9 + name = "inlay_hint", 10 + callback = function(client, buf) 11 + if client.server_capabilities.inlayHintProvider then 12 + vim.lsp.inlay_hint.enable(true, { bufnr = buf }) 13 + end 14 + end, 15 + }, 16 + { 17 + name = "document_highlight", 18 + callback = function(client, buf) 19 + if client.server_capabilities.documentHighlightProvider then 20 + local group = vim.api.nvim_create_augroup(string.format("lsp:document_highlight:%d", buf), { clear = true }) 21 + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { 22 + group = group, 23 + buffer = buf, 24 + callback = function() 25 + vim.lsp.buf.clear_references() 26 + vim.lsp.buf.document_highlight() 27 + end, 28 + desc = "highlight lsp reference", 29 + }) 30 + vim.api.nvim_create_autocmd("CursorMoved", { 31 + group = group, 32 + buffer = buf, 33 + callback = function() 34 + vim.lsp.buf.clear_references() 35 + end, 36 + desc = "clear lsp references", 37 + }) 38 + end 39 + end, 40 + }, 41 + { 42 + name = "linked_editing_range", 43 + callback = function(client, _) 44 + if client.server_capabilities.linkedEditingRangeProvider then 45 + vim.lsp.linked_editing_range.enable(true, { client_id = client.id }) 46 + end 47 + end, 48 + }, 49 + { name = "user", callback = props.on_attach }, 50 + } 51 + 52 + vim.iter(ipairs(components)):each(function(_, fn) 53 + vim.api.nvim_create_autocmd("LspAttach", { 54 + group = vim.api.nvim_create_augroup("lsp:" .. fn.name, { clear = true }), 55 + callback = function(ev) 56 + local client = vim.lsp.get_client_by_id(ev.data.client_id) 57 + if client == nil then 58 + return 59 + end 60 + local ok, result = pcall(fn.callback, client, ev.buf) 61 + if not ok then 62 + vim.api.nvim_echo( 63 + { { "unable to run on attach events for lsp server " }, { client.name }, { ":\n\t" }, { result } }, 64 + true, 65 + { err = true } 66 + ) 67 + return 68 + end 69 + end, 70 + }) 71 + end) 72 + 73 + local common = props.common 74 + if type(common) == "function" then 75 + common = common() 76 + end 77 + 78 + vim.lsp.config("*", common) 79 + 80 + local function setup_ls(name, cfg) 81 + ---@diagnostic disable-next-line: param-type-mismatch 82 + local ok, result = pcall(vim.lsp.config, name, cfg) 83 + if not ok then 84 + vim.notify(("unable to configure lsp server %s:\n\t%s"):format(name, result)) 85 + return 86 + end 87 + vim.lsp.enable(name) 88 + end 89 + 90 + local servers = props.servers 91 + if type(servers) == "function" then 92 + ---@diagnostic disable-next-line: cast-local-type 93 + servers = servers() 94 + end 95 + 96 + ---@diagnostic disable-next-line: param-type-mismatch 97 + vim.iter(pairs(servers)):each(setup_ls)