microsoft / microsoft/vscode-markdown-notebook
Feature Request: Add Native Quick Fix / CodeAction Support for Markdown Notebook Cells and Fix Source Line Number Mapping
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 88
- Forks
- 19
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
Currently, it is difficult to run inline AI code manipulations (AI extensions like Cline, Roo Code, or Copilot), linting corrections, or standard Markdown modifications because the vscode-notebook-cell documents do not expose a native CodeActionProvider. Furthermore, when editing a cell, the line numbers shown in the editor gutter are relative to the cell context (starting at 1) rather than reflecting the actual line number of the original .md source file. This prevents the designation of a specific line as context in such an AI extension.
Summary of Solutions I Prefer
- Quick Fix Overlays: Implement a standard
vscode.languages.registerCodeActionsProviderspecifically targetting{ scheme: 'vscode-notebook-cell', language: 'markdown' }. This will allow the native VS Code "Quick Fix" box (and its tooltips) to appear automatically when diagnostics or external tools propose changes. - Correct Line Numbers: Update the editor cell execution/display layer so that the line numbers rendered in the gutter map back to their absolute line positions in the source Markdown document.
Additional context
Integrating native Code Actions makes the notebook instantly compatible with the broader VS Code ecosystem, allowing diagnostics, linters, and external agent extensions to interact seamlessly with each individual cell block.
Technical Architecture & Implementation Strategy
[ Original Markdown File ] (Global Line Numbers)
│
▼
[ VS Code Notebook Document ] ──► Splits file into discrete Cells
│
├─► Cell 1 (Edit Mode: Needs true global Line Numbers)
│ │
│ └─► [ CodeActionProvider ] ──► Triggers Native "Quick Fix" Box
│
└─► Cell 2 (Preview Mode)
Step 1: Registering the Quick Fix Box (CodeActionProvider)
Because each editing block in vscode-markdown-notebook is a native TextEditor instance under the vscode-notebook-cell scheme, we can hook directly into VS Code's standard language features.
To enable the "Quick Fix" overlay, register a CodeActionProvider bound to the notebook cell document pipeline:
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.languages.registerCodeActionsProvider(
{ scheme: 'vscode-notebook-cell', language: 'markdown' },
new MarkdownNotebookQuickFixProvider(),
{
providedCodeActionKinds: [vscode.CodeActionKind.QuickFix]
}
)
);
}
class MarkdownNotebookQuickFixProvider implements vscode.CodeActionProvider {
public provideCodeActions(
document: vscode.TextDocument,
range: vscode.Range | vscode.Selection,
context: vscode.CodeActionContext,
token: vscode.CancellationToken
): vscode.CodeAction[] {
const actions: vscode.CodeAction[] = [];
// Check if there are active diagnostics (errors/warnings/linters) on this line
if (context.diagnostics.length > 0) {
const fix = new vscode.CodeAction('✨ Apply Quick Fix for this block', vscode.CodeActionKind.QuickFix);
fix.command = {
title: 'Execute Quick Fix',
command: 'markdown-notebook.applyCellFix',
arguments: [document, range, context.diagnostics]
};
fix.isPreferred = true;
actions.push(fix);
}
return actions;
}
}
Step 2: Fixing the Line Number Bug (Source Mapping)
By default, VS Code treats each notebook cell as a standalone document, meaning line numbers within the cell editor start at line 1. To fix this and display the line numbers from the original source Markdown file:
- Calculate Global Offsets: During the document parsing stage (
notebookSerializer), track the starting line index of each Markdown block relative to the entire file. - Inject Line Interceptors: Utilize
vscode.window.onDidChangeActiveTextEditoror a customTextEditorDecorationTypeto overlay or align the gutter line numbers with the computed global line offset instead of the local cell index.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the extension activation entry point and the notebookSerializer mentioned in the issue. Trace how markdown blocks become vscode-notebook-cell documents, then investigate the active editor or decoration layer for gutter rendering. Done means markdown notebook cells expose native Quick Fix actions and their displayed lines map to the original Markdown source positions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100