From e4ab28f3ed06d08084ddc782a7a7e1814675d2d3 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Mon, 17 Feb 2025 18:20:50 +0530 Subject: [PATCH 1/2] Add FAQ entry for `source.*` code actions in Notebook --- docs/faq.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index 431ada6329be2..37c0aed2be31b 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -643,3 +643,24 @@ force colors on by setting `FORCE_COLOR` to any non-empty value (e.g. `FORCE_COL [`colored`](https://crates.io/crates/colored) also supports the `CLICOLOR` and `CLICOLOR_FORCE` environment variables (see the [spec](https://bixense.com/clicolors/)). + +## Ruff behaves unexpectedly when using `source.*` code actions in Notebooks. What's going on? {: #source-code-actions-in-notebooks } + +Starting with `0.9.7`, Ruff does not support `source.organizeImports` and `source.fixAll` code +actions in Jupyter Notebooks (`notebook.codeActionsOnSave` in VS Code). It's recommended to use the +`notebook` prefixed code actions for the same such as `notebook.source.organizeImports` and +`notebook.source.fixAll` respectively. + +Ruff requires to have a full view of the notebook to provide accurate diagnostics and fixes. For +example, if you have a cell that imports a module and another cell that uses that module, Ruff +needs to see both cells to mark the import as used. If Ruff were to only see one cell at a time, +it would incorrectly mark the import as unused. + +When using the `source.*` code actions for a Notebook, Ruff will be asked to fix any issues for each +cell in parallel, which can lead to unexpected behavior. For example, if a user has configured to +run `source.organizeImports` code action on save for a Notebook, Ruff will attempt to fix the +imports for the entire notebook corresponding to each cell. This leads to the client making the same +changes to the notebook multiple times, which can lead to unexpected behavior +([astral-sh/ruff-vscode#680](https://github.com/astral-sh/ruff-vscode/issues/680), +[astral-sh/ruff-vscode#640](https://github.com/astral-sh/ruff-vscode/issues/640), +[astral-sh/ruff-vscode#391](https://github.com/astral-sh/ruff-vscode/issues/391)). From f38160fa08b231a1b02caabbcfcb8c67a1f9884e Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Mon, 17 Feb 2025 19:59:58 +0530 Subject: [PATCH 2/2] Avoid mentioning ruff version --- docs/faq.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 37c0aed2be31b..4224d1ebb048b 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -646,10 +646,10 @@ environment variables (see the [spec](https://bixense.com/clicolors/)). ## Ruff behaves unexpectedly when using `source.*` code actions in Notebooks. What's going on? {: #source-code-actions-in-notebooks } -Starting with `0.9.7`, Ruff does not support `source.organizeImports` and `source.fixAll` code -actions in Jupyter Notebooks (`notebook.codeActionsOnSave` in VS Code). It's recommended to use the -`notebook` prefixed code actions for the same such as `notebook.source.organizeImports` and -`notebook.source.fixAll` respectively. +Ruff does not support `source.organizeImports` and `source.fixAll` code actions in Jupyter Notebooks +(`notebook.codeActionsOnSave` in VS Code). It's recommended to use the `notebook` prefixed code +actions for the same such as `notebook.source.organizeImports` and `notebook.source.fixAll` +respectively. Ruff requires to have a full view of the notebook to provide accurate diagnostics and fixes. For example, if you have a cell that imports a module and another cell that uses that module, Ruff