chore - group notebook specific api proposals together

This commit is contained in:
Johannes Rieken 2021-02-01 18:22:04 +01:00
parent b37252c182
commit a5a33501be

View file

@ -989,94 +989,13 @@ declare module 'vscode' {
//#endregion
//#region notebook https://github.com/microsoft/vscode/issues/106744
//#region https://github.com/microsoft/vscode/issues/106744, Notebooks (misc)
export enum CellKind {
Markdown = 1,
Code = 2
}
export enum CellOutputKind {
Text = 1,
Error = 2,
Rich = 3
}
export interface CellStreamOutput {
outputKind: CellOutputKind.Text;
text: string;
}
export interface CellErrorOutput {
outputKind: CellOutputKind.Error;
/**
* Exception Name
*/
ename: string;
/**
* Exception Value
*/
evalue: string;
/**
* Exception call stack
*/
traceback: string[];
}
export interface NotebookCellOutputMetadata {
/**
* Additional attributes of a cell metadata.
*/
custom?: { [key: string]: any; };
}
export interface CellDisplayOutput {
outputKind: CellOutputKind.Rich;
/**
* { mime_type: value }
*
* Example:
* ```json
* {
* "outputKind": vscode.CellOutputKind.Rich,
* "data": {
* "text/html": [
* "<h1>Hello</h1>"
* ],
* "text/plain": [
* "<IPython.lib.display.IFrame at 0x11dee3e80>"
* ]
* }
* }
*/
data: { [key: string]: any; };
readonly metadata?: NotebookCellOutputMetadata;
}
export type CellOutput = CellStreamOutput | CellErrorOutput | CellDisplayOutput;
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>);
}
//TODO@jrieken add id?
export class NotebookCellOutput {
readonly outputs: NotebookCellOutputItem[];
readonly metadata?: Record<string, string | number | boolean>;
constructor(outputs: NotebookCellOutputItem[], metadata?: Record<string, string | number | boolean>);
//TODO@jrieken HACK to workaround dependency issues...
toJSON(): any;
}
export enum NotebookCellRunState {
Running = 1,
Idle = 2,
@ -1247,39 +1166,6 @@ declare module 'vscode' {
metadata: NotebookDocumentMetadata;
}
export interface NotebookConcatTextDocument {
uri: Uri;
isClosed: boolean;
dispose(): void;
onDidChange: Event<void>;
version: number;
getText(): string;
getText(range: Range): string;
offsetAt(position: Position): number;
positionAt(offset: number): Position;
validateRange(range: Range): Range;
validatePosition(position: Position): Position;
locationAt(positionOrRange: Position | Range): Location;
positionAt(location: Location): Position;
contains(uri: Uri): boolean;
}
export interface WorkspaceEdit {
replaceNotebookMetadata(uri: Uri, value: NotebookDocumentMetadata): void;
replaceNotebookCells(uri: Uri, start: number, end: number, cells: NotebookCellData[], metadata?: WorkspaceEditEntryMetadata): void;
replaceNotebookCellOutput(uri: Uri, index: number, outputs: (NotebookCellOutput | CellOutput)[], metadata?: WorkspaceEditEntryMetadata): void;
replaceNotebookCellMetadata(uri: Uri, index: number, cellMetadata: NotebookCellMetadata, metadata?: WorkspaceEditEntryMetadata): void;
}
export interface NotebookEditorEdit {
replaceMetadata(value: NotebookDocumentMetadata): void;
replaceCells(start: number, end: number, cells: NotebookCellData[]): void;
replaceCellOutput(index: number, outputs: (NotebookCellOutput | CellOutput)[]): void;
replaceCellMetadata(index: number, metadata: NotebookCellMetadata): void;
}
export interface NotebookCellRange {
readonly start: number;
/**
@ -1333,6 +1219,8 @@ declare module 'vscode' {
*/
readonly visibleRanges: NotebookCellRange[];
revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
/**
* The column in which this editor shows.
*/
@ -1348,13 +1236,6 @@ declare module 'vscode' {
// todo@API fishy? notebooks are public objects, there should be a "global" events for this
readonly onDidDispose: Event<void>;
/**
* Active kernel used in the editor
*/
// todo@API unsure about that
// kernel, kernel selection, kernel provider
readonly kernel?: NotebookKernel;
/**
* Fired when the output hosting webview posts a message.
*/
@ -1379,22 +1260,7 @@ declare module 'vscode' {
// todo@API unsure about that, how do you this when executing a cell without having an editor
asWebviewUri(localResource: Uri): Uri;
/**
* Perform an edit on the notebook associated with this notebook editor.
*
* The given callback-function is invoked with an [edit-builder](#NotebookEditorEdit) which must
* be used to make edits. Note that the edit-builder is only valid while the
* callback executes.
*
* @param callback A function which can create edits using an [edit-builder](#NotebookEditorEdit).
* @return A promise that resolves with a value indicating if the edits could be applied.
*/
// @jrieken REMOVE maybe
edit(callback: (editBuilder: NotebookEditorEdit) => void): Thenable<boolean>;
setDecorations(decorationType: NotebookEditorDecorationType, range: NotebookCellRange): void;
revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
}
export interface NotebookOutputSelector {
@ -1463,6 +1329,8 @@ declare module 'vscode' {
export interface NotebookEditorSelectionChangeEvent {
readonly notebookEditor: NotebookEditor;
// @rebornix
// todo@API show NotebookCellRange[] instead
readonly selection?: NotebookCell;
}
@ -1529,31 +1397,6 @@ declare module 'vscode' {
readonly label?: string;
}
interface NotebookDocumentBackup {
/**
* Unique identifier for the backup.
*
* This id is passed back to your extension in `openNotebook` when opening a notebook editor from a backup.
*/
readonly id: string;
/**
* Delete the current backup.
*
* This is called by VS Code when it is clear the current backup is no longer needed, such as when a new backup
* is made or when the file is saved.
*/
delete(): void;
}
interface NotebookDocumentBackupContext {
readonly destination: Uri;
}
interface NotebookDocumentOpenContext {
readonly backupId?: string;
}
/**
* Communication object passed to the {@link NotebookContentProvider} and
* {@link NotebookOutputRenderer} to communicate with the webview.
@ -1589,6 +1432,193 @@ declare module 'vscode' {
// readonly onDidDispose: Event<void>;
}
// export function registerNotebookKernel(selector: string, kernel: NotebookKernel): Disposable;
export interface NotebookDocumentShowOptions {
viewColumn?: ViewColumn;
preserveFocus?: boolean;
preview?: boolean;
selection?: NotebookCellRange;
}
export namespace notebook {
export function openNotebookDocument(uri: Uri, viewType?: string): Thenable<NotebookDocument>;
export const onDidOpenNotebookDocument: Event<NotebookDocument>;
export const onDidCloseNotebookDocument: Event<NotebookDocument>;
// todo@API really needed?
export const onDidSaveNotebookDocument: Event<NotebookDocument>;
/**
* All currently known notebook documents.
*/
export const notebookDocuments: ReadonlyArray<NotebookDocument>;
export const onDidChangeNotebookDocumentMetadata: Event<NotebookDocumentMetadataChangeEvent>;
export const onDidChangeNotebookCells: Event<NotebookCellsChangeEvent>;
export const onDidChangeCellOutputs: Event<NotebookCellOutputsChangeEvent>;
export const onDidChangeCellLanguage: Event<NotebookCellLanguageChangeEvent>;
export const onDidChangeCellMetadata: Event<NotebookCellMetadataChangeEvent>;
}
export namespace window {
export const visibleNotebookEditors: NotebookEditor[];
export const onDidChangeVisibleNotebookEditors: Event<NotebookEditor[]>;
export const activeNotebookEditor: NotebookEditor | undefined;
export const onDidChangeActiveNotebookEditor: Event<NotebookEditor | undefined>;
export const onDidChangeNotebookEditorSelection: Event<NotebookEditorSelectionChangeEvent>;
export const onDidChangeNotebookEditorVisibleRanges: Event<NotebookEditorVisibleRangesChangeEvent>;
export function showNotebookDocument(document: NotebookDocument, options?: NotebookDocumentShowOptions): Thenable<NotebookEditor>;
}
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookCellOutput
export enum CellOutputKind {
Text = 1,
Error = 2,
Rich = 3
}
export interface CellStreamOutput {
outputKind: CellOutputKind.Text;
text: string;
}
export interface CellErrorOutput {
outputKind: CellOutputKind.Error;
/**
* Exception Name
*/
ename: string;
/**
* Exception Value
*/
evalue: string;
/**
* Exception call stack
*/
traceback: string[];
}
export interface NotebookCellOutputMetadata {
/**
* Additional attributes of a cell metadata.
*/
custom?: { [key: string]: any; };
}
export interface CellDisplayOutput {
outputKind: CellOutputKind.Rich;
/**
* { mime_type: value }
*
* Example:
* ```json
* {
* "outputKind": vscode.CellOutputKind.Rich,
* "data": {
* "text/html": [
* "<h1>Hello</h1>"
* ],
* "text/plain": [
* "<IPython.lib.display.IFrame at 0x11dee3e80>"
* ]
* }
* }
*/
data: { [key: string]: any; };
readonly metadata?: NotebookCellOutputMetadata;
}
export type CellOutput = CellStreamOutput | CellErrorOutput | CellDisplayOutput;
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>);
}
//TODO@jrieken add id?
export class NotebookCellOutput {
readonly outputs: NotebookCellOutputItem[];
readonly metadata?: Record<string, string | number | boolean>;
constructor(outputs: NotebookCellOutputItem[], metadata?: Record<string, string | number | boolean>);
//TODO@jrieken HACK to workaround dependency issues...
toJSON(): any;
}
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookEditorEdit
export interface WorkspaceEdit {
replaceNotebookMetadata(uri: Uri, value: NotebookDocumentMetadata): void;
replaceNotebookCells(uri: Uri, start: number, end: number, cells: NotebookCellData[], metadata?: WorkspaceEditEntryMetadata): void;
replaceNotebookCellOutput(uri: Uri, index: number, outputs: (NotebookCellOutput | CellOutput)[], metadata?: WorkspaceEditEntryMetadata): void;
replaceNotebookCellMetadata(uri: Uri, index: number, cellMetadata: NotebookCellMetadata, metadata?: WorkspaceEditEntryMetadata): void;
}
export interface NotebookEditorEdit {
replaceMetadata(value: NotebookDocumentMetadata): void;
replaceCells(start: number, end: number, cells: NotebookCellData[]): void;
replaceCellOutput(index: number, outputs: (NotebookCellOutput | CellOutput)[]): void;
replaceCellMetadata(index: number, metadata: NotebookCellMetadata): void;
}
export interface NotebookEditor {
/**
* Perform an edit on the notebook associated with this notebook editor.
*
* The given callback-function is invoked with an [edit-builder](#NotebookEditorEdit) which must
* be used to make edits. Note that the edit-builder is only valid while the
* callback executes.
*
* @param callback A function which can create edits using an [edit-builder](#NotebookEditorEdit).
* @return A promise that resolves with a value indicating if the edits could be applied.
*/
// @jrieken REMOVE maybe
edit(callback: (editBuilder: NotebookEditorEdit) => void): Thenable<boolean>;
}
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookContentProvider
interface NotebookDocumentBackup {
/**
* Unique identifier for the backup.
*
* This id is passed back to your extension in `openNotebook` when opening a notebook editor from a backup.
*/
readonly id: string;
/**
* Delete the current backup.
*
* This is called by VS Code when it is clear the current backup is no longer needed, such as when a new backup
* is made or when the file is saved.
*/
delete(): void;
}
interface NotebookDocumentBackupContext {
readonly destination: Uri;
}
interface NotebookDocumentOpenContext {
readonly backupId?: string;
}
export interface NotebookContentProvider {
readonly options?: NotebookDocumentContentOptions;
readonly onDidChangeNotebookContentOptions?: Event<NotebookDocumentContentOptions>;
@ -1613,11 +1643,32 @@ declare module 'vscode' {
// eslint-disable-next-line vscode-dts-provider-naming
backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, cancellation: CancellationToken): Thenable<NotebookDocumentBackup>;
// ???
// provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult<T[]>;
}
export namespace notebook {
// TODO@api use NotebookDocumentFilter instead of just notebookType:string?
// TODO@API options duplicates the more powerful variant on NotebookContentProvider
export function registerNotebookContentProvider(notebookType: string, provider: NotebookContentProvider,
options?: NotebookDocumentContentOptions & {
/**
* Not ready for production or development use yet.
*/
viewOptions?: {
displayName: string;
filenamePattern: NotebookFilenamePattern[];
exclusive?: boolean;
};
}
): Disposable;
}
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookKernel
export interface NotebookKernel {
readonly id?: string;
label: string;
@ -1651,7 +1702,47 @@ declare module 'vscode' {
resolveKernel?(kernel: T, document: NotebookDocument, webview: NotebookCommunication, token: CancellationToken): ProviderResult<void>;
}
// export function registerNotebookKernel(selector: string, kernel: NotebookKernel): Disposable;
export interface NotebookEditor {
/**
* Active kernel used in the editor
*/
// todo@API unsure about that
// kernel, kernel selection, kernel provider
readonly kernel?: NotebookKernel;
}
export namespace notebook {
export const onDidChangeActiveNotebookKernel: Event<{ document: NotebookDocument, kernel: NotebookKernel | undefined; }>;
export function registerNotebookKernelProvider(selector: NotebookDocumentFilter, provider: NotebookKernelProvider): Disposable;
}
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookEditorDecorationType
export interface NotebookEditor {
setDecorations(decorationType: NotebookEditorDecorationType, range: NotebookCellRange): void;
}
export interface NotebookDecorationRenderOptions {
backgroundColor?: string | ThemeColor;
borderColor?: string | ThemeColor;
top: ThemableDecorationAttachmentRenderOptions;
}
export interface NotebookEditorDecorationType {
readonly key: string;
dispose(): void;
}
export namespace notebook {
export function createNotebookEditorDecorationType(options: NotebookDecorationRenderOptions): NotebookEditorDecorationType;
}
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookCellStatusBarItem
/**
* Represents the alignment of status bar items.
@ -1682,78 +1773,7 @@ declare module 'vscode' {
dispose(): void;
}
export interface NotebookDecorationRenderOptions {
backgroundColor?: string | ThemeColor;
borderColor?: string | ThemeColor;
top: ThemableDecorationAttachmentRenderOptions;
}
export interface NotebookEditorDecorationType {
readonly key: string;
dispose(): void;
}
export interface NotebookDocumentShowOptions {
viewColumn?: ViewColumn;
preserveFocus?: boolean;
preview?: boolean;
selection?: NotebookCellRange;
}
export namespace notebook {
export function registerNotebookContentProvider(
// TODO@api use NotebookDocumentFilter?
notebookType: string,
provider: NotebookContentProvider,
// TODO@API is duplicated with a more powerful variant on NotebookContentProvider
options?: NotebookDocumentContentOptions & {
/**
* Not ready for production or development use yet.
*/
viewOptions?: {
displayName: string;
filenamePattern: NotebookFilenamePattern[];
exclusive?: boolean;
};
}
): Disposable;
export function registerNotebookKernelProvider(
selector: NotebookDocumentFilter,
provider: NotebookKernelProvider
): Disposable;
export function createNotebookEditorDecorationType(options: NotebookDecorationRenderOptions): NotebookEditorDecorationType;
export function openNotebookDocument(uri: Uri, viewType?: string): Thenable<NotebookDocument>;
export const onDidOpenNotebookDocument: Event<NotebookDocument>;
export const onDidCloseNotebookDocument: Event<NotebookDocument>;
// todo@API really needed?
export const onDidSaveNotebookDocument: Event<NotebookDocument>;
/**
* All currently known notebook documents.
*/
export const notebookDocuments: ReadonlyArray<NotebookDocument>;
export const onDidChangeNotebookDocumentMetadata: Event<NotebookDocumentMetadataChangeEvent>;
export const onDidChangeNotebookCells: Event<NotebookCellsChangeEvent>;
export const onDidChangeCellOutputs: Event<NotebookCellOutputsChangeEvent>;
export const onDidChangeCellLanguage: Event<NotebookCellLanguageChangeEvent>;
export const onDidChangeCellMetadata: Event<NotebookCellMetadataChangeEvent>;
/**
* Create a document that is the concatenation of all notebook cells. By default all code-cells are included
* but a selector can be provided to narrow to down the set of cells.
*
* @param notebook
* @param selector
*/
// @jrieken REMOVE. p_never
// todo@API really needed? we didn't find a user here
export function createConcatTextDocument(notebook: NotebookDocument, selector?: DocumentSelector): NotebookConcatTextDocument;
export const onDidChangeActiveNotebookKernel: Event<{ document: NotebookDocument, kernel: NotebookKernel | undefined; }>;
/**
* Creates a notebook cell status bar [item](#NotebookCellStatusBarItem).
* It will be disposed automatically when the notebook document is closed or the cell is deleted.
@ -1768,14 +1788,40 @@ declare module 'vscode' {
export function createCellStatusBarItem(cell: NotebookCell, alignment?: NotebookCellStatusBarAlignment, priority?: number): NotebookCellStatusBarItem;
}
export namespace window {
export const visibleNotebookEditors: NotebookEditor[];
export const onDidChangeVisibleNotebookEditors: Event<NotebookEditor[]>;
export const activeNotebookEditor: NotebookEditor | undefined;
export const onDidChangeActiveNotebookEditor: Event<NotebookEditor | undefined>;
export const onDidChangeNotebookEditorSelection: Event<NotebookEditorSelectionChangeEvent>;
export const onDidChangeNotebookEditorVisibleRanges: Event<NotebookEditorVisibleRangesChangeEvent>;
export function showNotebookDocument(document: NotebookDocument, options?: NotebookDocumentShowOptions): Thenable<NotebookEditor>;
//#endregion
//#region https://github.com/microsoft/vscode/issues/106744, NotebookConcatTextDocument
export namespace notebook {
/**
* Create a document that is the concatenation of all notebook cells. By default all code-cells are included
* but a selector can be provided to narrow to down the set of cells.
*
* @param notebook
* @param selector
*/
// @jrieken REMOVE. p_never
// todo@API really needed? we didn't find a user here
export function createConcatTextDocument(notebook: NotebookDocument, selector?: DocumentSelector): NotebookConcatTextDocument;
}
export interface NotebookConcatTextDocument {
uri: Uri;
isClosed: boolean;
dispose(): void;
onDidChange: Event<void>;
version: number;
getText(): string;
getText(range: Range): string;
offsetAt(position: Position): number;
positionAt(offset: number): Position;
validateRange(range: Range): Range;
validatePosition(position: Position): Position;
locationAt(positionOrRange: Position | Range): Location;
positionAt(location: Location): Position;
contains(uri: Uri): boolean;
}
//#endregion