From 389dbe5c9de8ea72a87a55a13b47e3ee5d90d61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pankowski?= Date: Wed, 11 Mar 2026 23:20:37 +0100 Subject: [PATCH] nvim: add keys to search Go and Odin stdlib declarations --- nvim/.config/nvim/lua/plugins/fzf-lua.lua | 101 ++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/nvim/.config/nvim/lua/plugins/fzf-lua.lua b/nvim/.config/nvim/lua/plugins/fzf-lua.lua index 77dc984..a667fe5 100644 --- a/nvim/.config/nvim/lua/plugins/fzf-lua.lua +++ b/nvim/.config/nvim/lua/plugins/fzf-lua.lua @@ -20,6 +20,45 @@ if ok then } }) fzf.register_ui_select() + local odin_pkg = "~/cloned/Odin" + local function go_root() + return vim.fn.trim(vim.fn.system("go env GOROOT")) + end + local go_root_pkg = nil + local function go_mod() + return vim.fs.joinpath(vim.fn.trim(vim.fn.system("go env GOPATH")), "pkg/mod") + end + local go_mod_pkg = nil + local function go_grep(cwd) + local input = vim.fn.input("Go grep declarations> ") + if #input == 0 then + return + end + local search1 = "^(func|type) .*(?<= )(?=[A-Z])[a-zA-Z0-9_]*" .. input .. "[a-zA-Z0-9_]*( |\\()" + local search2 = "^[\\t]+(?=[A-Z])[a-zA-Z0-9_]*" .. input .. "[a-zA-Z0-9_]* +=" + local search = "(" .. search1 .. "|" .. search2 .. ")" + fzf.grep({ + cwd = cwd, + cmd = "rg -P -g '*.go'", + search = search, + no_esc = true, + profile = 'ivy', + }) + end + local function odin_grep(cwd) + local input = vim.fn.input("Odin grep declarations> ") + if #input == 0 then + return + end + local search = "^[ \\t]*[a-zA-Z0-9_]*" .. input .. "[a-zA-Z0-9_]* +::" + fzf.grep({ + cwd = cwd, + cmd = "rg -g '*.odin'", + search = search, + no_esc = true, + profile = 'ivy', + }) + end local set = vim.keymap.set set("n", "ba", fzf.buffers, { desc = "FzfLua buffers" }) set("n", "bh", fzf.history, { desc = "FzfLua history" }) @@ -109,6 +148,68 @@ if ok then set("n", "grs", fzf.lsp_type_sub, { desc = "Outgouing calls" }) set("n", "grp", fzf.lsp_type_super, { desc = "Outgouing calls" }) set("n", "grt", fzf.lsp_typedefs, { desc = "Goto Type Definition" }) + + set("n", "Gf", function() + fzf.files({ cwd = go_root(), cmd = "fd --type f -e go" }) + end, { desc = "FzfLua Go files" }) + set("n", "GF", function() + fzf.files({ cwd = go_mod(), cmd = "fd --type f -e go" }) + end, { desc = "FzfLua Go mod files" }) + set("n", "Gs", function() + go_grep(go_root()) + end, { desc = "FzfLua Go grep declarations" }) + set("n", "GS", function() + go_grep(go_mod()) + end, { desc = "FzfLua Go grep mod declarations" }) + set("n", "Gm", function() + go_grep(go_mod_pkg or go_mod()) + end, { desc = "FzfLua Go grep mod declarations" }) + set("n", "GM", function() + fzf.zoxide({ + cmd = "fd '' --type d " .. vim.fn.shellescape(go_mod()) .. [[ | awk '{print "\t"$1}']], + actions = { + ["enter"] = function(a) + go_mod_pkg = vim.fn.trim(a[1]) + go_grep(go_mod_pkg) + end + } + }) + end, { desc = "FzfLua Go select package and grep package declarations" }) + set("n", "Gp", function() + go_grep(go_root_pkg or go_root()) + end, { desc = "FzfLua Go grep package declarations" }) + set("n", "GP", function() + fzf.zoxide({ + cmd = "fd '' --type d " .. vim.fn.shellescape(go_root()) .. [[ | awk '{print "\t"$1}']], + actions = { + ["enter"] = function(a) + go_root_pkg = vim.fn.trim(a[1]) + go_grep(go_root_pkg) + end + } + }) + end, { desc = "FzfLua Go select package and grep package declarations" }) + + set("n", "of", function() + fzf.files({ cwd = "~/cloned/Odin", cmd = "fd --type f -e odin" }) + end, { desc = "FzfLua Odin files" }) + set("n", "os", function() + odin_grep("~/cloned/Odin") + end, { desc = "FzfLua Odin grep declarations" }) + set("n", "op", function() + odin_grep(odin_pkg) + end, { desc = "FzfLua Odin grep package declarations" }) + set("n", "oP", function() + fzf.zoxide({ + cmd = [[fd '' --type d ~/cloned/Odin | awk '{print "\t"$1}']], + actions = { + ["enter"] = function(a) + odin_pkg = vim.fn.trim(a[1]) + odin_grep(odin_pkg) + end + } + }) + end, { desc = "FzfLua Odin select package and grep package declarations" }) else print("plugin fzf-lua missing") end