Skip to content

Simplify notebook cell output API #107424

@jrieken

Description

@jrieken

The following changes to the current output API proposals are on the table. The focus is on simplifying and streamlining things (while still being equally powerful)

  • Instead of three types for output, have a single type
  • The effective output of a cell (NotebookCell#output) is many of these types (e.g NotebookCellOutput[])
  • Each instance of NotebookCellOutput has a mime type, a value, and its metadata (iff applicable)
  • Use a plain/text mime type for CellStreamOutput, respectively use an error mime type for CellErrorOutput
export class NotebookCellOutputItem {

	readonly mime: string;
	readonly value: unknown;
	readonly metadata?: Record<string, string | number | boolean>;

	constructor(mime: string, value: unknown, metadata?: Record<string, string | number | boolean>);
}

export class NotebookCellOutput {

	readonly outputs: NotebookCellOutputItem[];
	readonly metadata?: Record<string, string | number | boolean>;

	constructor(outputs: NotebookCellOutputItem[], metadata?: Record<string, string | number | boolean>);
}

Usage sample

// CURRENT proposed API
let output = [{
    outputKind: vscode.CellOutputKind.Rich,
    data: {
        'text/html': 'Hell<b>o</b>',
        'application/json': ['hello', 'json'],
        'image/png': '<base64>',
    },
    metadata: {
        custom: {
            'image/png': {
                'width': 640,
                'height': 480,
            }
        }
    }
}, {
    outputKind: vscode.CellOutputKind.Text,
    text: 'REPL text'
}]


// NEW proposal
let output = [
  new NotebookCellOutput([
    new vscode.NotebookCellOutputItem('text/html', 'Hell<b>o</b>'),
    new vscode.NotebookCellOutputItem('application/json', ['hello', 'json']),
    new vscode.NotebookCellOutputItem('image/png', '<base64>', { width: 640, height: 480 }),
  ], { display_id: 'xyz'} ),
  new NotebookCellOutput([
    new vscode.NotebookCellOutputItem('text/plain', 'REPL text'),
  ])
]

Metadata

Metadata

Assignees

Labels

apinotebookunder-discussionIssue is under discussion for relevance, priority, approach

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions