Skip to content

ruff.applyFormat now formats an entire notebook document - #11493

Merged
snowsignal merged 1 commit into
mainfrom
jane/server/notebook/format/all-cells-cmd
May 22, 2024
Merged

snowsignal merged 1 commit into
mainfrom
jane/server/notebook/format/all-cells-cmd

Conversation

@snowsignal

Copy link
Copy Markdown
Contributor

Summary

Previously, ruff.applyFormat, seen in VS Code as the command Ruff: Format Document, would only format the currently active notebook cell inside a notebook document. This PR makes ruff.applyFormat format the entire notebook document at once, operating on each code cell in order.

Test Plan

  1. Open a notebook document that has multiple unformatted code cells.
  2. Run Ruff: Format Document through the Command Palette (Ctrl/Cmd+Shift+P by default)
  3. Observe that all code cells in the notebook have been formatted.

@snowsignal snowsignal added notebook Related to (Jupyter) notebooks server Related to the Ruff or ty LSP server labels May 22, 2024
@snowsignal
snowsignal force-pushed the jane/server/notebook/format/all-cells-cmd branch from f31f4d2 to 4421339 Compare May 22, 2024 09:33
@github-actions

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@snowsignal
snowsignal merged commit 3cb2e67 into main May 22, 2024
@snowsignal
snowsignal deleted the jane/server/notebook/format/all-cells-cmd branch May 22, 2024 16:02
pub(super) fn format_full_document(snapshot: &DocumentSnapshot) -> Result<Fixes> {
let mut fixes = Fixes::default();

if let Some(notebook) = snapshot.query().as_notebook() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Would it make sense to store the result of snapshot.query() in a variable. It's used in multiple places and feels fairly repetitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notebook Related to (Jupyter) notebooks server Related to the Ruff or ty LSP server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants