Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`<CR>` 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:

Expand Down Expand Up @@ -48,6 +52,10 @@ Both exact matches (pattern equals pattern) and concrete-to-wildcard matches are
vim.keymap.set("n", "<Leader>o", function()
require("snakemake").open_and_insert()
end)
-- list all rules in the quickfix window
vim.keymap.set("n", "<Leader>r", function()
require("snakemake").list_rules()
end)
-- jump to the rule that produces the file under cursor
vim.keymap.set("n", "<Leader>g", function()
require("snakemake").goto_producer()
Expand All @@ -58,6 +66,10 @@ Both exact matches (pattern equals pattern) and concrete-to-wildcard matches are

## Usage

### Browsing all rules

Press `<Leader>r` from anywhere. The quickfix window opens with every rule and checkpoint found across all Snakemake files, sorted by file and line number. Press `<CR>` on any entry to jump to that rule.

### Adding a rule to forcerun

1. Open a Snakefile in Neovim
Expand Down
32 changes: 32 additions & 0 deletions lua/snakemake/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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