Skip to content

Commit

Permalink
Stub vscode 'Notebook' API
Browse files Browse the repository at this point in the history
* Remove stub notebook.api.ts file
* introduce Disposable.NULL and use it wherever possible in plugin folder
* Avoid unnecessary code for stubbing (all event management in document)
* Remove file-system-ext-impl entry
  • Loading branch information
rschnekenbu committed Dec 6, 2022
1 parent 948f444 commit 905e040
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 89 deletions.
5 changes: 1 addition & 4 deletions packages/plugin-ext/src/main/browser/workspace-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,7 @@ export class WorkspaceMainImpl implements WorkspaceMain, Disposable {
}

$registerNotebookSerializer(notebookType: string, serializer: theia.NotebookSerializer, options?: theia.NotebookDocumentContentOptions | undefined): theia.Disposable {
return {
dispose(): void {
},
};
return Disposable.NULL;
}

$unregisterTextDocumentContentProvider(scheme: string): void {
Expand Down
8 changes: 0 additions & 8 deletions packages/plugin-ext/src/plugin/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,12 @@ export class DocumentsExtImpl implements DocumentsExt {
private _onDidChangeDocument = new Emitter<theia.TextDocumentChangeEvent>();
private _onDidSaveTextDocument = new Emitter<theia.TextDocument>();
private _onWillSaveTextDocument = new Emitter<theia.TextDocumentWillSaveEvent>();
private _onDidAddNotebookDocument = new Emitter<theia.NotebookDocument>();
private _onDidCloseNotebookDocument = new Emitter<theia.NotebookDocument>();
private _onDidChangeNotebookDocument = new Emitter<theia.NotebookDocumentChangeEvent>();
private _onDidSaveNotebookDocument = new Emitter<theia.NotebookDocument>();

readonly onDidAddDocument: Event<theia.TextDocument> = this._onDidAddDocument.event;
readonly onDidRemoveDocument: Event<theia.TextDocument> = this._onDidRemoveDocument.event;
readonly onDidChangeDocument: Event<theia.TextDocumentChangeEvent> = this._onDidChangeDocument.event;
readonly onDidSaveTextDocument: Event<theia.TextDocument> = this._onDidSaveTextDocument.event;
readonly onWillSaveTextDocument: Event<theia.TextDocumentWillSaveEvent> = this._onWillSaveTextDocument.event;
readonly onDidAddNotebookDocument: Event<theia.NotebookDocument> = this._onDidAddNotebookDocument.event;
readonly onDidCloseNotebookDocument: Event<theia.NotebookDocument> = this._onDidCloseNotebookDocument.event;
readonly onDidChangeNotebookDocument: Event<theia.NotebookDocumentChangeEvent> = this._onDidChangeNotebookDocument.event;
readonly onDidSaveNotebookDocument: Event<theia.NotebookDocument> = this._onDidSaveNotebookDocument.event;

private proxy: DocumentsMain;
private loadingDocuments = new Map<string, Promise<DocumentDataExt | undefined>>();
Expand Down
7 changes: 0 additions & 7 deletions packages/plugin-ext/src/plugin/file-system-ext-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,6 @@ export class FileSystemExtImpl implements FileSystemExt {
};
}

registerNotebookSerializer() {
return {
dispose: () => {
}
};
}

private static _asIStat(stat: vscode.FileStat): files.Stat {
const { type, ctime, mtime, size } = stat;
return { type, ctime, mtime, size };
Expand Down
49 changes: 24 additions & 25 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ import {
InlayHint,
InlayHintKind,
InlayHintLabelPart,
NotebookCell,
NotebookCellKind,
NotebookCellStatusBarAlignment,
NotebookEditorRevealType,
Expand Down Expand Up @@ -213,7 +214,6 @@ import { CustomEditorsExtImpl } from './custom-editors';
import { WebviewViewsExtImpl } from './webview-views';
import { PluginPackage } from '../common';
import { Endpoint } from '@theia/core/lib/browser/endpoint';
import { createNotebookCellExecution } from './stubs/notebooks-api';

export function createAPIFactory(
rpc: RPCProtocol,
Expand Down Expand Up @@ -398,33 +398,21 @@ export function createAPIFactory(
return [] as theia.NotebookEditor[];
},
onDidChangeVisibleNotebookEditors(listener, thisArg?, disposables?) {
return {
dispose: () => {
}
};
return Disposable.NULL;
},
get activeNotebookEditor(): theia.NotebookEditor | undefined {
return undefined;
}, onDidChangeActiveNotebookEditor(listener, thisArg?, disposables?) {
return {
dispose: () => {
}
};
return Disposable.NULL;
},
onDidChangeNotebookEditorSelection(listener, thisArg?, disposables?) {
return {
dispose: () => {
}
};
return Disposable.NULL;
},
onDidChangeNotebookEditorVisibleRanges(listener, thisArg?, disposables?) {
return {
dispose: () => {
}
};
return Disposable.NULL;
},
showNotebookDocument(document: NotebookDocument, options?: theia.NotebookDocumentShowOptions) {
return Promise.resolve(undefined as unknown as theia.NotebookEditor);
return Promise.resolve({} as theia.NotebookEditor);
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
showQuickPick(items: any, options?: theia.QuickPickOptions, token?: theia.CancellationToken): any {
Expand Down Expand Up @@ -586,16 +574,16 @@ export function createAPIFactory(
return documents.onDidRemoveDocument(listener, thisArg, disposables);
},
onDidOpenNotebookDocument(listener, thisArg?, disposables?) {
return documents.onDidAddNotebookDocument(listener, thisArg, disposables);
return Disposable.NULL;
},
onDidCloseNotebookDocument(listener, thisArg?, disposables?) {
return documents.onDidCloseNotebookDocument(listener, thisArg, disposables);
return Disposable.NULL;
},
onDidChangeNotebookDocument(listener, thisArg?, disposables?) {
return documents.onDidChangeNotebookDocument(listener, thisArg, disposables);
return Disposable.NULL;
},
onDidSaveNotebookDocument(listener, thisArg?, disposables?) {
return documents.onDidSaveNotebookDocument(listener, thisArg, disposables);
return Disposable.NULL;
},
onDidOpenTextDocument(listener, thisArg?, disposables?) {
return documents.onDidAddDocument(listener, thisArg, disposables);
Expand Down Expand Up @@ -642,7 +630,7 @@ export function createAPIFactory(
return data && data.document;
},
async openNotebookDocument(uriOrString: theia.Uri | string, content?: NotebookData): Promise<theia.NotebookDocument | undefined> {
return undefined;
return Promise.reject(new Error('Notebook API is stubbed'));
},
createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): theia.FileSystemWatcher =>
extHostFileSystemEvent.createFileSystemWatcher(fromGlobPattern(pattern), ignoreCreate, ignoreChange, ignoreDelete),
Expand Down Expand Up @@ -684,7 +672,7 @@ export function createAPIFactory(
return timelineExt.registerTimelineProvider(plugin, scheme, provider);
},
registerNotebookSerializer(notebookType: string, serializer: theia.NotebookSerializer, options?: theia.NotebookDocumentContentOptions): theia.Disposable {
return workspaceExt.registerNotebookSerializer(notebookType, serializer, options);
return Disposable.NULL;
},
get isTrusted(): boolean {
return workspaceExt.trusted;
Expand Down Expand Up @@ -1063,7 +1051,18 @@ export function createAPIFactory(
notebookType,
label,
handler,
createNotebookCellExecution,
createNotebookCellExecution: (cell: NotebookCell) => ({
cell,
token: CancellationToken.None,
executionOrder: undefined,
start: () => undefined,
end: () => undefined,
clearOutput: () => ({} as Thenable<void>),
replaceOutput: () => ({} as Thenable<void>),
appendOutput: () => ({} as Thenable<void>),
replaceOutputItems: () => ({} as Thenable<void>),
appendOutputItems: () => ({} as Thenable<void>)
}),
executeHandler(
cells: theia.NotebookCell[],
notebook: theia.NotebookDocument,
Expand Down
35 changes: 0 additions & 35 deletions packages/plugin-ext/src/plugin/stubs/notebooks-api.ts

This file was deleted.

6 changes: 4 additions & 2 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export class Disposable {
static create(func: () => void): Disposable {
return new Disposable(func);
}

static NULL: Disposable;
}

export interface AccessibilityInformation {
Expand Down Expand Up @@ -1209,10 +1211,10 @@ export class NotebookDocument implements theia.NotebookDocument {
readonly cellCount: number;

cellAt(index: number): theia.NotebookCell {
return undefined as unknown as theia.NotebookCell;
return {} as theia.NotebookCell;
}
save(): theia.Thenable<boolean> {
return undefined as unknown as Thenable<boolean>;
return Promise.resolve(false);
}

getCells(range?: theia.NotebookRange | undefined): theia.NotebookCell[] {
Expand Down
8 changes: 0 additions & 8 deletions packages/plugin-ext/src/plugin/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,6 @@ export class WorkspaceExtImpl implements WorkspaceExt {
};
}

registerNotebookSerializer(notebookType: string, serializer: theia.NotebookSerializer, options?: theia.NotebookDocumentContentOptions): theia.Disposable {
return {
dispose(): void {

},
};
}

async $provideTextDocumentContent(documentURI: string): Promise<string | undefined | null> {
const uri = URI.parse(documentURI);
const provider = this.documentContentProviders.get(uri.scheme);
Expand Down

0 comments on commit 905e040

Please sign in to comment.