repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: new delete api for keymap (WIP)

710da9053c38d9fefc70491b7f518bef8681ede1

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (6)

neovim/lua/bugabinga/lsp/clients/lua.lua

Modified
52 52 workspace = { checkThirdParty = false, }
55 - before_init = function(...)
56 - local before_init_arguments = { ... }
57 - want'neodev'(function(neodev)
58 - return neodev.before_init(unpack(before_init_arguments))
59 - end, function()
60 - return nil
61 - end)
62 - end,
55 + before_init = require"neodev.lsp".before_init,
65 58 return {

neovim/lua/bugabinga/lsp/init.lua

Modified
1 1 -- TODO: setup neodev + jsonls for neovim plugins ans config
2 --- TODO: setup lua_ls for generic lua stuff
3 2 -- TODO: setup nvimjdtls + lemminx for java/maven
4 3 -- TODO: setup marksman + ltex for markdown
5 4 -- TODO: setup mason for "less important" lsps
6 --- TODO: LspInfo clone
8 6 local map = require'std.keymap'
9 7 local auto = require'std.auto'
31 29 --* closures that capture something
35 32 local lsp_start = function(file_type_event)
37 33 local match = file_type_event.match
39 35 local matches_to_ignore = ignored.filetypes
61 57 ['config.before_init'] = { config.before_init, 'function', true},
63 59 -- normalize scalar values to its vector alternative for easier processing later on
64 - -- NOTE: this mutates the lsp client configs! careful!
60 + -- this mutates the lsp client configs! careful!
65 61 config.command = type(config.command) == 'string' and { config.command } or config.command
66 62 config.filetypes = type(config.filetypes) == 'string' and { config.filetypes } or config.filetypes
67 63 return config
116 112 root_dir = config.root_dir(buffer_path),
119 - --TODO: augment other arguments from start_client
120 115 local client_id = vim.lsp.start(start_config, {
121 116 bufnr = bufnr,
122 117 -- TODO: reuse if workspaces
127 122 -- vim.print("ATTACHING LSP CLIENT", client_id)
125 +local old_formatexpr
126 +local old_omnifunc
127 +local old_tagfunc
129 +local s
130 131 --TODO: setup keybinds on attach + omnifunc + tagfunc + folding
131 -local lsp_attach = function(...)
132 - -- vim.print("ATTACH LSP", ...)
132 +local lsp_attach = function(args)
133 + local bufnr = args.buf
134 + local client = vim.lsp.get_client_by_id(args.data.client_id)
135 + if not client then return end
137 + -- vim.print(client.server_capabilities)
139 + if client.server_capabilities.definitionProvider then
140 + old_tagfunc = vim.bo[bufnr].tagfunc
141 + vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
142 + end
144 + if client.server_capabilities.documentFormattingProvider then
145 + old_formatexpr = vim.bo[bufnr].formatexpr
146 + vim.bo[bufnr].formatexpr = "v:lua.vim.lsp.formatexpr(#{timeout_ms:50})"
147 + end
149 + if client.server_capabilities.completionProvider then
150 + old_omnifunc = vim.bo[bufnr].omnifunc
151 + vim.bo[bufnr].omnifunc = "v:vim.lsp.omnifunc"
152 + end
154 + -- TODO: create register/unregister abstraction for lsp features
155 + -- TODO: show available code actions as diagnostics (must be filtered)
156 + -- TODO: use nicer guis for lsp interactive features
157 + map.normal {
158 + name = 'Show available code actions on current line.',
159 + category = 'lsp',
160 + keys = '<c-1>',
161 + command = vim.lsp.buf.code_action,
164 + map.normal {
165 + name = 'Goto to definition of symbol under cursor.',
166 + category = 'lsp',
167 + keys = '<c-2>',
168 + command = vim.lsp.buf.definition,
170 + map.normal {
171 + name = 'Goto to definition of symbol under cursor.',
172 + category = 'telescope',
173 + keys = '<c-2><c-2>',
174 + command = '<cmd>Telescope lsp_definitions<cr>',
177 + if client.server_capabilities.documentHighlightProvider then
178 + auto 'document_highlight' {
180 + description = 'Highlight symbol under cursor on hold',
181 + events = 'CursorHold',
182 + pattern = '<buffer>',
183 + command = vim.lsp.buf.document_highlight,
184 + },
185 + --TODO: debounce cursormoved events
187 + description = 'Remove highlight from symbol under cursor on move',
188 + events = { 'CursorMoved', 'InsertEnter' },
189 + pattern = '<buffer>',
190 + command = vim.lsp.buf.clear_references,
193 + end
195 + --TODO: what can we do with those?
196 + --maybe: LspCommand <command> <args>
197 + -- map to <c-3>
198 + if client.server_capabilities.executeCommandProvider then
199 + -- [1] ≔ 󰝗 lua.removeSpace 󰉾,
200 + -- [2] ≔ 󰝗 lua.solve 󰉾,
201 + -- [3] ≔ 󰝗 lua.jsonToLua 󰉾,
202 + -- [4] ≔ 󰝗 lua.setConfig 󰉾,
203 + -- [5] ≔ 󰝗 lua.getConfig 󰉾,
204 + -- [6] ≔ 󰝗 lua.autoRequire 󰉾,
206 + end
208 + map.normal {
209 + name = 'Format current buffer',
210 + category = 'lsp',
211 + keys = '<c-F>',
212 + command = vim.lsp.buf.format,
215 + map.normal {
216 + name = 'Show hover documentation above cursor.',
217 + category = 'lsp',
218 + keys = '<c-q>',
219 + command = vim.lsp.buf.hover,
222 + map.normal {
223 + name = 'Show implementations of symbol under cursor.',
224 + category = 'lsp',
225 + keys = '<c-4>',
226 + command = vim.lsp.buf.implementation,
228 + map.normal {
229 + name = 'Show implementations of symbol under cursor.',
230 + category = 'telescope',
231 + keys = '<c-4><c-4>',
232 + command = '<cmd>Telescope lsp_implementations<cr>',
235 + map.normal {
236 + name = 'Show incoming calls of symbol under cursor.',
237 + category = 'lsp',
238 + keys = '<c-5>',
239 + command = vim.lsp.buf.incoming_calls,
241 + map.normal {
242 + name = 'Show incoming calls of symbol under cursor.',
243 + category = 'telescope',
244 + keys = '<c-5><c-5>',
245 + command = '<cmd>Telescope lsp_incoming_calls<cr>',
247 + map.normal {
248 + name = 'Show outgoing calls of symbol under cursor.',
249 + category = 'lsp',
250 + keys = '<c-s-5>',
251 + command = vim.lsp.buf.outgoing_calls,
253 + map.normal {
254 + name = 'Show outgoing calls of symbol under cursor.',
255 + category = 'telescope',
256 + keys = '<c-s-5><c-s-5>',
257 + command = '<cmd>Telescope lsp_outgoing_calls<cr>',
260 + map.normal {
261 + name = 'Show references of symbol under cursor.',
262 + category = 'lsp',
263 + keys = '<c-6>',
264 + command = vim.lsp.buf.references,
266 + map.normal {
267 + name = 'Show references of symbol under cursor.',
268 + category = 'telescope',
269 + keys = '<c-6><c-6>',
270 + command = vim.lsp.buf.references,
273 + map.normal {
274 + name = 'Rename symbol under cursor.',
275 + category = 'lsp',
276 + keys = '<c-R>',
277 + command = vim.lsp.buf.rename,
280 + map.normal {
281 + name = 'Show signature help under cursor.',
282 + category = 'lsp',
283 + keys = '<c-7>',
284 + command = vim.lsp.buf.signature_help,
286 + s = map.normal {
287 + name = 'Show signature help under cursor.',
288 + category = 'telescope',
289 + keys = '<c-7><c-7>',
290 + command = '<cmd>Telescope lsp_signature_help<cr>',
134 -local lsp_detach = function(...)
295 +local lsp_detach = function(args)
135 297 -- vim.print("DETACH LSP", ...)
299 + local bufnr = args.buf
300 + local client = vim.lsp.get_client_by_id(args.data.client_id)
301 + if not client then return end
303 + if client.server_capabilities.definitionProvider then
304 + vim.bo[bufnr].tagfunc = old_tagfunc
305 + end
307 + if client.server_capabilities.documentFormattingProvider then
308 + vim.bo[bufnr].formatexpr = old_formatexpr
309 + end
311 + if client.server_capabilities.completionProvider then
312 + vim.bo[bufnr].omnifunc = old_omnifunc
313 + end
315 + if s then s() end
138 318 auto 'lsp' {
161 341 local lsp_info = function(command)
162 342 local all_or_current = command.args and command.args == 'all' and {} or { bufnr = 0 }
163 - local active_clients = vim.lsp.get_active_clients(all_or_current)
343 + local active_clients = vim.lsp.get_clients(all_or_current)
165 345 local infos = vim.iter(active_clients)
166 346 :map(function(client)
189 369 local lsp_info_extended = function(command)
190 370 local all_or_current = command.args and command.args == 'all' and {} or { bufnr = 0 }
191 - local active_clients = vim.lsp.get_active_clients(all_or_current)
371 + local active_clients = vim.lsp.get_clients(all_or_current)
192 372 ui.show_tree(active_clients)

neovim/lua/bugabinga/nugu/init.lua

Modified
173 173 DiagnosticSignHint { DiagnosticHint },
174 174 DiagnosticSignOk { DiagnosticOk },
176 - LspReferenceText { Search },
177 - LspReferenceRead { Search },
178 - LspReferenceWrite { IncSearch },
176 + LspReferenceText { bg = content_unfocus },
177 + LspReferenceRead { LspReferenceText },
178 + LspReferenceWrite { LspReferenceText },
180 180 -- hlargs.nvim
181 181 Hlargs { fg = ui_important_local, gui = 'bold underdotted' },

neovim/lua/std/icon.lua

Modified
3 3 return {
4 4 error = '󰇷',
5 5 warn = '󰱯',
6 6 info = '󰩖',
7 7 hint = '󰊪',
8 - quot_left = '',
9 - quot_right = '',
8 + quot_left = '󰝗',
9 + quot_right = '󰉾',
10 10 hash = '',
11 11 checkbox_mark = '',
12 12 checkbox_unmark = '',

neovim/lua/std/ignored.lua

Modified
5 5 'hgcommit',
6 6 'help',
7 7 'noice',
8 - 'notify'
8 + 'notify',
9 9 'TelescopePrompt',
10 10 'TelescopeResults',
11 11 'toggleterm',
12 12 'lazy',
13 - 'oil'
13 + 'oil',
16 16 local buftypes = {

neovim/lua/std/keymap.lua

Modified
53 53 if vim.tbl_isempty(self.mode) then self.mode[1] = available_modes.normal_visual_select_operator_pending end
54 54 vim.keymap.set(self.mode, keys, command, options)
55 55 self.mode = {}
57 + return function()
58 + local delete_options = options.buffer and { buffer = options.buffer } or {}
59 + vim.keymap.del(self.mode, keys, delete_options)
60 + end
58 63 local add_mode = function(self, key)