From 9365a8e96827cbf7bc5adad6d29bcd05b4d761b2 Mon Sep 17 00:00:00 2001 From: bee Date: Tue, 5 May 2026 22:37:10 +0530 Subject: Migrate from nixcats to nix-wrapper-modules --- lua/bee/LSPs/on_attach.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lua/bee/LSPs/on_attach.lua (limited to 'lua/bee/LSPs/on_attach.lua') diff --git a/lua/bee/LSPs/on_attach.lua b/lua/bee/LSPs/on_attach.lua new file mode 100644 index 0000000..d4d69e4 --- /dev/null +++ b/lua/bee/LSPs/on_attach.lua @@ -0,0 +1,54 @@ +-- vim.api.nvim_create_autocmd('LspAttach', { +-- group = vim.api.nvim_create_augroup('my-lsp-attach', { clear = true }), +-- callback = function(event) +-- require('birdee.LSPs.on_attach')(vim.lsp.get_client_by_id(event.data.client_id), event.buf) +-- end, +-- }) +return function(_, bufnr) + -- we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + + local map = function(keys, func, desc, mode) + if desc then + desc = "LSP: " .. desc + end + vim.keymap.set(mode or "n", keys, func, { buffer = bufnr, desc = desc }) + end + + map("rn", vim.lsp.buf.rename, "[R]e[n]ame") + map("la", vim.lsp.buf.code_action, "[L]sp [A]ction") + + -- See `:help K` for why this keymap + map("K", vim.lsp.buf.hover, "Hover Documentation") + map("", vim.lsp.buf.signature_help, "Signature Documentation") + + -- Lesser used LSP functionality + map("wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") + map("wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") + map("wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, "[W]orkspace [L]ist Folders") + + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) + vim.lsp.buf.format() + end, { desc = "Format current buffer with LSP" }) + map("Fl", ":Format", "[F]ormat with [l]sp") + map("FL", ":Format", "[F]ormat with [L]SP") + -- The following two autocommands are used to highlight references of the + -- word under your cursor when your cursor rests there for a little while. + -- See `:help CursorHold` for information about when this is executed + -- When you move your cursor, the highlights will be cleared (the second autocommand). + -- local client = vim.lsp.get_client_by_id(event.data.client_id) + -- if client and client.server_capabilities.documentHighlightProvider then + -- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + -- buffer = event.buf, + -- callback = vim.lsp.buf.document_highlight, + -- }) + + -- vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + -- buffer = event.buf, + -- callback = vim.lsp.buf.clear_references, + -- }) + -- end +end -- cgit v1.3.1