Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support notebook-scoped VS Code actions #351

Merged
merged 1 commit into from
Jan 5, 2024
Merged

Conversation

charliermarsh
Copy link
Member

Summary

VS Code added support for notebook.*-scoped code actions (https://code.visualstudio.com/api/references/vscode-api#CodeActionKind), which are intended to run over the entire document, unlike the actions that omit the notebook. namespace, which instead only operate over individual cells. The latter are problematic for actions that need global context, e.g., our unused imports rules.

When the notebook.* actions are triggered, VS Code sends down the first cell (see: microsoft/vscode#193120) as the URI. This PR adds handlers for the actions and logic to use the notebook, rather than the cell.

Closes #320.

Test Plan

Used the following settings.json:

{
  "[python]": {
      "editor.defaultFormatter": "charliermarsh.ruff",
      "editor.codeActionsOnSave": {
        "source.organizeImports.ruff": true
      }
    },
    "notebook.codeActionsOnSave": {
      "notebook.source.fixAll": true
    }
}

Verified that imports used across cells were not removed (whereas "source.fixAll": true did cause imports to be removed).

):
# Generate the "Ruff: Organize Imports" edit
params.edit = await _fix_document_impl(document, only=["I001", "I002"])

elif settings["fixAll"] and params.kind in (
CodeActionKind.SourceFixAll,
f"{CodeActionKind.SourceFixAll.value}.ruff",
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm pretty sure we only ever pass the full action here? This is for deferred actions.

@charliermarsh charliermarsh added the bug Something isn't working label Jan 5, 2024
@charliermarsh charliermarsh force-pushed the charlie/jupyter branch 3 times, most recently from e9221a4 to 1c7c119 Compare January 5, 2024 15:51
ruff_lsp/server.py Outdated Show resolved Hide resolved
ruff_lsp/server.py Outdated Show resolved Hide resolved
Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

Sweet fix!

@charliermarsh charliermarsh mentioned this pull request Jan 5, 2024
charliermarsh added a commit that referenced this pull request Jan 5, 2024
Separating out from #351.
@charliermarsh charliermarsh merged commit 03fbbdd into main Jan 5, 2024
20 checks passed
@charliermarsh charliermarsh deleted the charlie/jupyter branch January 5, 2024 18:18
azurelotus0926 added a commit to azurelotus0926/ruff-lsp that referenced this pull request Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken "Fix All" VSCode code action for Notebooks
2 participants