Repository navigation
notebook: run notebook-scope code actions on all cells when saving - #340120
Open
Irish Joseph (Irish-Joseph) wants to merge 1 commit into
Open
Irish Joseph (Irish-Joseph) wants to merge 1 commit into
Irish Joseph (Irish-Joseph) wants to merge 1 commit into
Conversation
Copilot started reviewing on behalf of
Irish Joseph (Irish-Joseph)
October 6, 2026 18:49
View session
Notebook-scope code actions (e.g. notebook.source.organizeImports) are provided by per-cell language servers but apply to the whole notebook. The save participant only requested them from the first cell's text model, so when the first cell was markdown (a very common layout) no provider matched and the action silently did nothing. Ask the cells in order and stop once an action has been applied from one of them, so a notebook-scope action still runs at most once per save. Fixes microsoft#338963
Irish Joseph (Irish-Joseph)
force-pushed
the
fix/notebook-codeactions-on-save-markdown-first-cell
branch
from
October 6, 2026 18:51
68f2d96 to
4a989e2
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The loop can skip configured actions from later language providers and continues scanning after cancellation.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Fixes notebook-scope save actions when the first cell has no matching provider.
Changes:
- Searches cells sequentially for notebook code actions.
- Returns application status and adds regression tests.
| File | Description |
|---|---|
saveParticipants.ts |
Updates notebook action discovery and application tracking. |
saveParticipants.test.ts |
Tests markdown-first and duplicate-application scenarios. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+406
to
+408
| const applied = await this.instantiationService.invokeFunction(CodeActionParticipantUtils.applyOnSaveGenericCodeActions, textEditorModel, notebookCodeActionsOnSave, excludedActions, progress, token); | ||
| if (applied) { | ||
| break; |
Comment on lines
+407
to
+409
| if (applied) { | ||
| break; | ||
| } |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #338963 —
notebook.codeActionsOnSavedoes nothing when the notebook's first cell is a markdown cell.Notebook-scope code actions (kinds like
notebook.source.organizeImports, i.e. everything under thenotebookbase kind thatvscode.CodeActionKind.Notebookcovers) are provided per cell but apply to the whole notebook. The save participant only asked the first cell for them, so with a leading markdown cell no provider matched the markdown language and the action silently never ran — even when a later Python/code cell's language server could (and would) provide it.Change
src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.tsCodeActionOnSaveParticipant.participatenow asks the cells in order and stops as soon as one of them has applied an action.CodeActionParticipantUtils.applyOnSaveGenericCodeActionsnow returns whether at least one action was applied (Promise<void>→Promise<boolean>), used by the loop above.CodeActionOnSaveParticipantis exported for testability (no behavior change).Stopping after the first applied cell keeps notebook-scope semantics: an action such as Organize Imports touches the whole document, so applying it from every contributing cell would double-apply its multi-cell edits.
Tests
New suite:
src/vs/workbench/contrib/notebook/test/browser/contrib/saveParticipants/saveParticipants.test.ts(3 tests, realNotebookTextModel+ realLanguageFeaturesServicewith a PythonCodeActionProviderreturning anotebook.source.organizeImportsaction, and cell text models bound to the cells the same way the workbench's cell content provider does):Evidence
cells[0]): test 1 fails — the provider is never called (providerCalls === []), tests 2–3 pass. Reproduced withscripts/test.bat --run vs/workbench/contrib/notebook/test/browser/contrib/saveParticipants/saveParticipants.test.js.codeAction(8), notebookcellOperations(27),notebookBrowser(5),notebookUndoRedo(7). No other code or test references the changed paths.npm run precommit(hygiene) passes on both changed files.