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.registerCodeActionsProvider specifically 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.onDidChangeActiveTextEditor or a custom TextEditorDecorationType to overlay or align the gutter line numbers with the computed global line offset instead of the local cell index.
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-celldocuments do not expose a nativeCodeActionProvider. 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.mdsource file. This prevents the designation of a specific line as context in such an AI extension.Summary of Solutions I Prefer
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.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
Step 1: Registering the Quick Fix Box (CodeActionProvider)
Because each editing block in
vscode-markdown-notebookis a nativeTextEditorinstance under thevscode-notebook-cellscheme, we can hook directly into VS Code's standard language features.To enable the "Quick Fix" overlay, register a
CodeActionProviderbound to the notebook cell document pipeline: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:
notebookSerializer), track the starting line index of each Markdown block relative to the entire file.vscode.window.onDidChangeActiveTextEditoror a customTextEditorDecorationTypeto overlay or align the gutter line numbers with the computed global line offset instead of the local cell index.