Skip to content

chore: add Neovim Lua plugin#290

Merged
mbhall88 merged 14 commits into
snakemake:masterfrom
mbhall88:neovim
Apr 30, 2026
Merged

chore: add Neovim Lua plugin#290
mbhall88 merged 14 commits into
snakemake:masterfrom
mbhall88:neovim

Conversation

@mbhall88
Copy link
Copy Markdown
Member

@mbhall88 mbhall88 commented Apr 30, 2026

Summary

  • Adds a standalone Lua-based Neovim plugin for snakefmt.
  • Supports Neovim 0.10+ using vim.system for async formatting.
  • Implements tiered path resolution (Local venv -> Project venv -> Global -> uvx).
  • Adds documentation in docs/editor_integration.md.

Test Plan

  • Verified manually in Neovim with auto_format enabled.
  • Verified path resolution correctly identifies local .venv binaries.
  • Verified uvx fallback works when binary is not in path.

Summary by CodeRabbit

  • New Features

    • Added Neovim plugin for snakefmt integration with :Snakefmt and :SnakefmtInfo commands
    • Auto-format on save capability for Python Snake files
    • Fallback to uv tool when snakefmt isn't available locally
  • Documentation

    • Added Neovim (Recommended) setup guide with lazy.nvim configuration example
    • Reorganized editor integration docs with separate Vim (Legacy) section

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@mbhall88 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 20 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3faadee9-e4da-49cc-9dcd-0fc2fde2b682

📥 Commits

Reviewing files that changed from the base of the PR and between 49bd5d4 and 2f7a796.

📒 Files selected for processing (3)
  • docs/editor_integration.md
  • lua/snakefmt/init.lua
  • lua/snakefmt/paths.lua
📝 Walkthrough

Walkthrough

This pull request introduces a Neovim plugin for snakefmt integration with configuration management and executable path resolution, updates editor integration documentation to include Neovim-specific guidance, and modifies .gitignore to specifically exclude the poetry.lock.worktrees/ directory instead of poetry.lock.

Changes

Cohort / File(s) Summary
Build Configuration
.gitignore
Updated to exclude poetry.lock.worktrees/ directory instead of poetry.lock for more granular artifact management.
Documentation
docs/editor_integration.md
Reorganized Vim/Neovim editor guidance into combined section with "Neovim (Recommended)" subsection detailing async Lua plugin features, lazy.nvim configuration, and commands (:Snakefmt, :SnakefmtInfo); retained legacy Vim instructions in separate "Vim (Legacy)" subsection with version/Python notes; removed Black dependency troubleshooting.
Neovim Plugin
lua/snakefmt/config.lua, lua/snakefmt/init.lua, lua/snakefmt/paths.lua
Implements complete Neovim plugin with configuration module (defaults, setup with deep-merge), main plugin module (setup, format command, auto-format on save via :Snakefmt and :SnakefmtInfo), and path resolution module with fallback chain: configured bin, virtual environment, local .venv, global executable, and uvx fallback.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Neovim as Neovim Editor
    participant Init as snakefmt.init
    participant Config as snakefmt.config
    participant Paths as snakefmt.paths
    participant System as vim.system

    User->>Neovim: Call setup(opts)
    Neovim->>Init: M.setup(opts)
    Init->>Config: config.setup(opts)
    Config->>Config: Deep merge opts into defaults
    Init->>Init: Clear & recreate augroup<br/>Register BufWritePre & commands

    User->>Neovim: Trigger :Snakefmt or BufWritePre
    Neovim->>Init: M.format()
    Init->>Paths: paths.get_snakefmt_bin(config.options)
    Paths->>Paths: Resolve bin: configured,<br/>$VIRTUAL_ENV, .venv,<br/>global, or uvx fallback
    Paths-->>Init: Return bin command array or nil
    Init->>System: vim.system(bin + args,<br/>stdin=buffer_content)
    System-->>Init: On completion: stdout/stderr
    Init->>Neovim: Replace buffer with formatted output<br/>or display error notification
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: add Neovim Lua plugin' accurately describes the main change—a new Neovim plugin written in Lua—which is well-reflected in the substantial new files (lua/snakefmt modules and updated editor documentation).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 39 minutes and 20 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.52%. Comparing base (4144047) to head (2f7a796).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #290   +/-   ##
=======================================
  Coverage   96.52%   96.52%           
=======================================
  Files          12       12           
  Lines        1497     1497           
  Branches      309      309           
=======================================
  Hits         1445     1445           
  Misses         24       24           
  Partials       28       28           
Flag Coverage Δ
unittests 96.45% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/editor_integration.md`:
- Line 84: Update the docs to reflect the actual fallback command: change the
wording that currently says "Automatic fallback to `uvx snakefmt`" to describe
that the plugin runs `uv run --with snakefmt snakefmt` as implemented in
lua/snakefmt/paths.lua; ensure the text explicitly matches that command so
readers/debuggers see the real runtime behavior.

In `@lua/snakefmt/init.lua`:
- Around line 42-44: Before starting the async format capture the buffer id and
its change tick (use bufnr and nvim_buf_get_changedtick) and include that tick
with the request; in the async callback (where you currently check
nvim_buf_is_valid and call nvim_buf_set_lines) re-check that the buffer is still
valid and that nvim_buf_get_changedtick(bufnr) equals the original tick before
replacing lines (do not overwrite if ticks differ), i.e., add a pre-write guard
around the nvim_buf_set_lines call to prevent applying stale output to an edited
buffer.
- Around line 11-18: The autocmd using BufWritePre calls M.format()
asynchronously which allows the buffer to be written before formatting finishes;
modify M.format to accept a sync boolean (e.g., M.format(sync)) and implement a
synchronous path when sync==true that uses vim.system(...):wait() (or equivalent
blocking API) to run snakefmt and apply edits before the write completes, then
change the BufWritePre autocmd callback to call M.format(true) while keeping the
existing async behavior for manual :Snakefmt calls (M.format(false) or default).

In `@lua/snakefmt/paths.lua`:
- Around line 12-13: The resolver currently builds a Unix-only path (venv ..
"/bin/snakefmt") and checks it with vim.fn.executable, which misses Windows venv
layouts; update the lookup to try multiple candidate paths (e.g., venv ..
"/bin/snakefmt", venv .. "/Scripts/snakefmt.exe", and venv ..
"/Scripts/snakefmt") and use vim.fn.executable over each candidate until one is
executable, replacing the single `path` check; refer to the `venv` and `path`
variables and the `vim.fn.executable` checks in the resolver so both Unix and
Windows virtualenv layouts are supported.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e82b4e6-9ff9-4dc9-81a5-f1cf05032ada

📥 Commits

Reviewing files that changed from the base of the PR and between 4144047 and 49bd5d4.

📒 Files selected for processing (5)
  • .gitignore
  • docs/editor_integration.md
  • lua/snakefmt/config.lua
  • lua/snakefmt/init.lua
  • lua/snakefmt/paths.lua

Comment thread docs/editor_integration.md Outdated
Comment thread lua/snakefmt/init.lua
Comment thread lua/snakefmt/init.lua
Comment thread lua/snakefmt/paths.lua Outdated
@mbhall88 mbhall88 merged commit 0096e1b into snakemake:master Apr 30, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant