Skip to content

Commit b5cd4f2

Browse files
authored
Add FAQ entry for source.* code actions in Notebook (astral-sh#16212)
## Summary This PR adds a FAQ entry to provide a brief explanation on why Ruff does not support `source.*` code actions for Notebook.
1 parent 9f111ea commit b5cd4f2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/faq.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,24 @@ force colors on by setting `FORCE_COLOR` to any non-empty value (e.g. `FORCE_COL
643643

644644
[`colored`](https://crates.io/crates/colored) also supports the `CLICOLOR` and `CLICOLOR_FORCE`
645645
environment variables (see the [spec](https://bixense.com/clicolors/)).
646+
647+
## Ruff behaves unexpectedly when using `source.*` code actions in Notebooks. What's going on? {: #source-code-actions-in-notebooks }
648+
649+
Ruff does not support `source.organizeImports` and `source.fixAll` code actions in Jupyter Notebooks
650+
(`notebook.codeActionsOnSave` in VS Code). It's recommended to use the `notebook` prefixed code
651+
actions for the same such as `notebook.source.organizeImports` and `notebook.source.fixAll`
652+
respectively.
653+
654+
Ruff requires to have a full view of the notebook to provide accurate diagnostics and fixes. For
655+
example, if you have a cell that imports a module and another cell that uses that module, Ruff
656+
needs to see both cells to mark the import as used. If Ruff were to only see one cell at a time,
657+
it would incorrectly mark the import as unused.
658+
659+
When using the `source.*` code actions for a Notebook, Ruff will be asked to fix any issues for each
660+
cell in parallel, which can lead to unexpected behavior. For example, if a user has configured to
661+
run `source.organizeImports` code action on save for a Notebook, Ruff will attempt to fix the
662+
imports for the entire notebook corresponding to each cell. This leads to the client making the same
663+
changes to the notebook multiple times, which can lead to unexpected behavior
664+
([astral-sh/ruff-vscode#680](https://github.com/astral-sh/ruff-vscode/issues/680),
665+
[astral-sh/ruff-vscode#640](https://github.com/astral-sh/ruff-vscode/issues/640),
666+
[astral-sh/ruff-vscode#391](https://github.com/astral-sh/ruff-vscode/issues/391)).

0 commit comments

Comments
 (0)