From 42a6fb552c7513e4d2ecef8e58b79217c1bcde40 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 25 Apr 2026 01:26:24 +0000 Subject: [PATCH] Add list_rules: populate quickfix window with all rules M.list_rules() calls ensure_index(), collects every rule and checkpoint from rule_cache into a quickfix list sorted by file then line number, and opens the quickfix window. Each entry jumps directly to the rule definition when selected with . Returns a WARN notification if no rules are found (empty project or cache not yet populated). Suggested keymap: r https://claude.ai/code/session_019k8BeVivnvcEohfcZMttjZ --- README.md | 14 +++++++++++++- lua/snakemake/init.lua | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d4dfc84..a07f628 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,11 @@ Place your cursor anywhere inside a Snakemake rule definition, press the keymap, **Subsequent uses:** if a `--forcerun` line is already present, the new rule name is appended to it (space-separated) — so you can build up a list of rules to force-rerun without editing `run.sh` by hand. -### 2. Go to producer rule (`goto_producer`) +### 2. Rule picker (`list_rules`) + +Press the keymap from anywhere and the plugin opens Neovim's built-in quickfix window listing every rule and checkpoint across all `Snakemake*`/`Snakefile*` files in the current working directory. Entries are sorted by file then line number. Navigate with standard quickfix commands (`` to jump, `:cn`/`:cp` to step through). + +### 3. Go to producer rule (`goto_producer`) Place your cursor on a quoted input filename inside any rule's `input:` block and press the keymap. The plugin will: @@ -48,6 +52,10 @@ Both exact matches (pattern equals pattern) and concrete-to-wildcard matches are vim.keymap.set("n", "o", function() require("snakemake").open_and_insert() end) + -- list all rules in the quickfix window + vim.keymap.set("n", "r", function() + require("snakemake").list_rules() + end) -- jump to the rule that produces the file under cursor vim.keymap.set("n", "g", function() require("snakemake").goto_producer() @@ -58,6 +66,10 @@ Both exact matches (pattern equals pattern) and concrete-to-wildcard matches are ## Usage +### Browsing all rules + +Press `r` from anywhere. The quickfix window opens with every rule and checkpoint found across all Snakemake files, sorted by file and line number. Press `` on any entry to jump to that rule. + ### Adding a rule to forcerun 1. Open a Snakefile in Neovim diff --git a/lua/snakemake/init.lua b/lua/snakemake/init.lua index 8df32e4..b79d835 100644 --- a/lua/snakemake/init.lua +++ b/lua/snakemake/init.lua @@ -221,4 +221,36 @@ M.goto_producer = function() vim.notify("no rule found producing: " .. target, vim.log.levels.WARN) end +-- Populate the quickfix list with every rule across all indexed Snakemake +-- files and open the quickfix window. Each entry jumps directly to the +-- rule definition line when selected. +M.list_rules = function() + ensure_index() + + local items = {} + for _, rules in pairs(rule_cache) do + for _, rule in ipairs(rules) do + table.insert(items, { + filename = rule.file, + lnum = rule.lnum, + col = 1, + text = rule.name, + }) + end + end + + if #items == 0 then + vim.notify("no rules found", vim.log.levels.WARN) + return + end + + table.sort(items, function(a, b) + if a.filename ~= b.filename then return a.filename < b.filename end + return a.lnum < b.lnum + end) + + vim.fn.setqflist({}, "r", { title = "Snakemake rules", items = items }) + vim.cmd("copen") +end + return M