diff options
| -rw-r--r-- | dot_config/nvim/lazy-lock.json | 58 | ||||
| -rw-r--r-- | dot_config/nvim/lua/plugins/lsp.lua | 3 | ||||
| -rw-r--r-- | dot_config/nvim/plugin/keymaps.lua | 186 |
3 files changed, 136 insertions, 111 deletions
diff --git a/dot_config/nvim/lazy-lock.json b/dot_config/nvim/lazy-lock.json index 34d0797..d662013 100644 --- a/dot_config/nvim/lazy-lock.json +++ b/dot_config/nvim/lazy-lock.json @@ -1,41 +1,41 @@ { "FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" }, - "LuaSnip": { "branch": "master", "commit": "659c4479529a05cc9b05ef762639a09d366cc690" }, - "actions-preview.nvim": { "branch": "master", "commit": "9f52a01c374318e91337697ebed51c6fae57f8a4" }, - "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "LuaSnip": { "branch": "master", "commit": "c1851d5c519611dfc451b6582961b2602e0af89b" }, + "actions-preview.nvim": { "branch": "master", "commit": "36513ad213855d497b7dd3391a24d1d75d58e36f" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "conform.nvim": { "branch": "master", "commit": "023f795dbcf32d4351b6a9ed2e613d471b5bb812" }, - "gitsigns.nvim": { "branch": "main", "commit": "ac5aba6dce8c06ea22bea2c9016f51a2dbf90dc7" }, - "gruvbox.nvim": { "branch": "main", "commit": "49d9c0b150ba70efcd831ec7b3cb8ee740067045" }, - "harpoon": { "branch": "harpoon2", "commit": "a84ab829eaf3678b586609888ef52f7779102263" }, + "conform.nvim": { "branch": "master", "commit": "2b2b30260203af3b93a7470ac6c8457ddd6e32d9" }, + "gitsigns.nvim": { "branch": "main", "commit": "e399f9748d7cfd8859747c8d6c4e9c8b4d50a1bd" }, + "gruvbox.nvim": { "branch": "main", "commit": "00e38a379bab3389e187b3953566d67d494dfddd" }, + "harpoon": { "branch": "harpoon2", "commit": "ed1f853847ffd04b2b61c314865665e1dadf22c7" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "lazydev.nvim": { "branch": "main", "commit": "d5800897d9180cea800023f2429bce0a94ed6064" }, - "lsp-zero.nvim": { "branch": "v4.x", "commit": "60a66bf6ffbafd0c9442737a3ef63942008b4654" }, - "lsp_lines.nvim": { "branch": "main", "commit": "7d9e2748b61bff6ebba6e30adbc7173ccf21c055" }, - "lspkind.nvim": { "branch": "master", "commit": "a700f1436d4a938b1a1a93c9962dc796afbaef4d" }, - "luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "cab00668464d2914d0752b86168b4a431cc93eb2" }, - "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "lazydev.nvim": { "branch": "main", "commit": "2367a6c0a01eb9edb0464731cc0fb61ed9ab9d2c" }, + "lsp-zero.nvim": { "branch": "v4.x", "commit": "2afa32e732d7b36e80cd5241fbdc4a38e123c4e0" }, + "lsp_lines.nvim": { "branch": "main", "commit": "a92c755f182b89ea91bd8a6a2227208026f27b4d" }, + "lspkind.nvim": { "branch": "master", "commit": "d79a1c3299ad0ef94e255d045bed9fa26025dab6" }, + "luvit-meta": { "branch": "main", "commit": "1df30b60b1b4aecfebc785aa98943db6c6989716" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "d39a75bbce4b8aad5d627191ea915179c77c100f" }, + "mason.nvim": { "branch": "main", "commit": "888d6ee499d8089a3a4be4309d239d6be1c1e6c0" }, "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, - "neotest": { "branch": "master", "commit": "6d3d22cdad49999ef774ebe1bc250a4994038964" }, + "neotest": { "branch": "master", "commit": "862afb2a2219d9ca565f67416fb7003cc0f22c4f" }, "neotest-python": { "branch": "master", "commit": "a2861ab3c9a0bf75a56b11835c2bfc8270f5be7e" }, - "nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" }, - "nvim-lint": { "branch": "master", "commit": "36da8dd0ddc4f88e0beae234c20e75397326f143" }, - "nvim-lspconfig": { "branch": "master", "commit": "87c7c83ce62971e0bdb29bb32b8ad2b19c8f95d0" }, - "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" }, - "nvim-treesitter": { "branch": "master", "commit": "13c7caf8a602488b37cdefe8543c4cfdd5947d9d" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "3e450cd85243da99dc23ebbf14f9c70e9a0c26a4" }, - "nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-lint": { "branch": "master", "commit": "fdb04e9285edefbe25a02a31a35e8fbb10fe054d" }, + "nvim-lspconfig": { "branch": "master", "commit": "ac1dfbe3b60e5e23a2cff90e3bd6a3bc88031a57" }, + "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, + "nvim-treesitter": { "branch": "master", "commit": "066fd6505377e3fd4aa219e61ce94c2b8bdb0b79" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "b0debd5c424969b4baeabdc8f54db3036c691732" }, + "nvim-web-devicons": { "branch": "master", "commit": "d360317f8f509b99229bb31d42269987696df6ff" }, "obsidian.nvim": { "branch": "main", "commit": "ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b" }, - "oil.nvim": { "branch": "master", "commit": "8ea40b5506115b6d355e304dd9ee5089f7d78601" }, - "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, - "rose-pine": { "branch": "main", "commit": "07a887a7bef4aacea8c7caebaf8cbf808cdc7a8e" }, + "oil.nvim": { "branch": "master", "commit": "685cdb4ffa74473d75a1b97451f8654ceeab0f4a" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "rose-pine": { "branch": "main", "commit": "491a0c77abc7ecb955c27a974091a5968232995f" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, + "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, "undotree": { "branch": "main", "commit": "eab459ab87dd249617b5f7187bb69e614a083047" }, "vim-jinja": { "branch": "master", "commit": "7c54e2320c5f676636cdd8697480782eebfb2bf2" }, - "which-key.nvim": { "branch": "main", "commit": "68e37e12913a66b60073906f5d3f14dee0de19f2" } + "which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" } } diff --git a/dot_config/nvim/lua/plugins/lsp.lua b/dot_config/nvim/lua/plugins/lsp.lua index 1c7acc7..8ed54a3 100644 --- a/dot_config/nvim/lua/plugins/lsp.lua +++ b/dot_config/nvim/lua/plugins/lsp.lua @@ -164,7 +164,7 @@ return { } require("mason-lspconfig").setup({ - ensure_installed = { "ruff", "lua_ls" }, + automatic_enable = { "basedpyright", "ruff", "lua_ls" }, handlers = { -- this first function is the "default handler" -- it applies to every language server without a "custom handler" @@ -184,7 +184,6 @@ return { end, }, }) - vim.lsp.inlay_hint.enable() end, }, diff --git a/dot_config/nvim/plugin/keymaps.lua b/dot_config/nvim/plugin/keymaps.lua index 8f5ff28..38f25ce 100644 --- a/dot_config/nvim/plugin/keymaps.lua +++ b/dot_config/nvim/plugin/keymaps.lua @@ -2,15 +2,15 @@ vim.g.mapleader = " " local function map(mode, left, right, opts) - local default_opts = { - noremap = true, - silent = true, - } - opts = opts or {} - -- "keep" mode preserves the values from the leftmost table, - -- so prioritize any options provided over the defaults - local full_opts = vim.tbl_extend("keep", opts, default_opts) - vim.keymap.set(mode, left, right, full_opts) + local default_opts = { + noremap = true, + silent = true, + } + opts = opts or {} + -- "keep" mode preserves the values from the leftmost table, + -- so prioritize any options provided over the defaults + local full_opts = vim.tbl_extend("keep", opts, default_opts) + vim.keymap.set(mode, left, right, full_opts) end -- Clear any highlighted searches when pressing Esc @@ -54,86 +54,112 @@ map({ "n", "v" }, "<leader>cy", '"+y', { desc = "Clipboard yank" }) -- map("n", "g-", vim.cmd.Ex, { desc = "Open netrw" }) map("n", "<leader>gx", function() - local command = "go run " .. vim.fn.expand("%") - local f = assert(io.popen(command, "r")) - local s = assert(f:read("*a")) - f:close() - s = string.gsub(s, "^%s+", "") - s = string.gsub(s, "%s+$", "") - s = string.gsub(s, "[\n\r]+", " ") - print(s) + local command = "go run " .. vim.fn.expand("%") + local f = assert(io.popen(command, "r")) + local s = assert(f:read("*a")) + f:close() + s = string.gsub(s, "^%s+", "") + s = string.gsub(s, "%s+$", "") + s = string.gsub(s, "[\n\r]+", " ") + print(s) end, { desc = "Execute current go file" }) + +-- Create a GitHub URL for the current file and line number, and copy it +-- to the clipboard. +map("n", "<leader>yfg", function() + local remote_url = vim.fn.system("git config --get remote.origin.url") + if not remote_url:find("github.com") then + vim.notify("This is not a GitHub repository") + return + end + + local trimmed_remote_url = remote_url:gsub("%.git", ""):gsub("%s+", ""):gsub("\n", "") + local branch_name = vim.fn.system("git rev-parse --abbrev-ref HEAD"):gsub("\n", "") + + -- Now construct the link in this format: + -- <remote>/blob/<branch>/<file>#L<line> + + local filepath = vim.fn.expand("%:."):gsub("\\", "/") + + local line = vim.fn.line(".") + local result = trimmed_remote_url .. "/blob/" .. branch_name .. "/" .. filepath .. "#L" .. line + + vim.fn.setreg("+", result) + vim.notify("Copied GitHub URL to clipboard: " .. result) +end, { desc = "Yank GitHub URL to clipboard", expr = true }) + + -- LSP specific keybindings vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("IbrahimLspConfig", {}), - callback = function(evt) - local function lsp_map(mode, lhs, rhs, desc) - local opts = { buffer = evt.buf, desc = "LSP: " .. (desc or "") } - map(mode, lhs, rhs, opts) - end + group = vim.api.nvim_create_augroup("IbrahimLspConfig", {}), + callback = function(evt) + local function lsp_map(mode, lhs, rhs, desc) + local opts = { buffer = evt.buf, desc = "LSP: " .. (desc or "") } + map(mode, lhs, rhs, opts) + end - local has_telescope, _ = pcall(require, "telescope") - local function lsp_telescope_map(mode, lhs, with_telescope_rhs, no_telescope_rhs, desc) - if has_telescope then - desc = desc .. " (Telescope)" - lsp_map(mode, lhs, with_telescope_rhs, desc) - else - lsp_map(mode, lhs, no_telescope_rhs, desc) - end - end - local function tele_builtin(name, opts) - return function() - require("telescope.builtin")[name](opts) - end - end + local has_telescope, _ = pcall(require, "telescope") + local function lsp_telescope_map(mode, lhs, with_telescope_rhs, no_telescope_rhs, desc) + if has_telescope then + desc = desc .. " (Telescope)" + lsp_map(mode, lhs, with_telescope_rhs, desc) + else + lsp_map(mode, lhs, no_telescope_rhs, desc) + end + end + local function tele_builtin(name, opts) + return function() + require("telescope.builtin")[name](opts) + end + end - -- Navigation - lsp_map("n", "gd", vim.lsp.buf.definition, "[G]oto [D]efinition") - lsp_map("n", "gt", vim.lsp.buf.type_definition, "[G]oto [t]ype Definition") - lsp_map("n", "gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") - lsp_map("n", "gr", vim.lsp.buf.references, "[G]oto [R]eferences") - lsp_map("n", "gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation") + -- Navigation + lsp_map("n", "gd", vim.lsp.buf.definition, "[G]oto [D]efinition") + lsp_map("n", "gt", vim.lsp.buf.type_definition, "[G]oto [t]ype Definition") + lsp_map("n", "gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + lsp_map("n", "gr", vim.lsp.buf.references, "[G]oto [R]eferences") + lsp_map("n", "gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation") - lsp_telescope_map("n", "gr", tele_builtin("lsp_references"), vim.lsp.buf.references, "Go to references") - lsp_telescope_map( - "n", - "<leader>sn", - tele_builtin("lsp_document_symbols"), - vim.lsp.buf.document_symbol, - "Search document symbols" - ) - lsp_telescope_map( - "n", - "<leader>sN", - tele_builtin("lsp_dynamic_workspace_symbols"), - vim.lsp.buf.workspace_symbol, - "Search workspace symbols" - ) + lsp_telescope_map("n", "gr", tele_builtin("lsp_references"), vim.lsp.buf.references, "Go to references") + lsp_telescope_map( + "n", + "<leader>sn", + tele_builtin("lsp_document_symbols"), + vim.lsp.buf.document_symbol, + "Search document symbols" + ) + lsp_telescope_map( + "n", + "<leader>sN", + tele_builtin("lsp_dynamic_workspace_symbols"), + vim.lsp.buf.workspace_symbol, + "Search workspace symbols" + ) - -- Code changes - lsp_map("n", "<leader>cr", vim.lsp.buf.rename, "Rename") - -- <leader>ca is being overwritten by the 'actions-preview' plugin - -- lsp_map("n", "<leader>ca", vim.lsp.buf.code_action, "Code actions") + -- Code changes + lsp_map("n", "<leader>cr", vim.lsp.buf.rename, "Rename") + -- <leader>ca is being overwritten by the 'actions-preview' plugin + -- lsp_map("n", "<leader>ca", vim.lsp.buf.code_action, "Code actions") - -- Diagnostics - lsp_map("n", "<leader>ds", vim.diagnostic.open_float, "[s]how [d]iagnostic window") - lsp_map("n", "<leader>dn", function() - vim.diagnostic.goto_next({ float = true }) - end, "Go to [n]ext [d]iagnostic") - lsp_map("n", "<leader>dp", function() - vim.diagnostic.goto_prev({ float = true }) - end, "Go to [p]revious [d]iagnostic") + -- Diagnostics + lsp_map("n", "<leader>ds", vim.diagnostic.open_float, "[s]how [d]iagnostic window") + lsp_map("n", "<leader>dn", function() + vim.diagnostic.goto_next({ float = true }) + end, "Go to [n]ext [d]iagnostic") + lsp_map("n", "<leader>dp", function() + vim.diagnostic.goto_prev({ float = true }) + end, "Go to [p]revious [d]iagnostic") - -- See `:help K` for why this keymap - lsp_map("n", "K", vim.lsp.buf.hover, "Hover Documentation") - lsp_map("n", "<C-S-k>", vim.lsp.buf.signature_help, "Signature Documentation") + -- See `:help K` for why this keymap + lsp_map("n", "K", vim.lsp.buf.hover, "Hover Documentation") + lsp_map("n", "<C-S-k>", vim.lsp.buf.signature_help, "Signature Documentation") - -- Workspace - lsp_map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") - lsp_map("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") - lsp_map("n", "<leader>wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, "[W]orkspace [L]ist Folders") - end, + -- Workspace + lsp_map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") + lsp_map("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") + lsp_map("n", "<leader>wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, "[W]orkspace [L]ist Folders") + end, }) |
