Skip to content

Commit

Permalink
Stub vscode 'Notebook' API
Browse files Browse the repository at this point in the history
This enables the possibility to load and start plugins which depend on the 'Notebook' API.  The 'Notebook' functionality will not be operational but the rest of
the functionality offered by the plugin will be.

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi SCHNEKENBURGER <rschnekenburger@eclipsesource.com>
  • Loading branch information
rschnekenbu committed Dec 14, 2022
1 parent ac7a9ff commit 9d5f79c
Show file tree
Hide file tree
Showing 6 changed files with 1,727 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## v1.33.0 - unreleased

- [scripts] integrated start-up performance scripts into nightly master build [#10463](https://github.com/eclipse-theia/theia/pull/10463) - Contributed on behalf of STMicroelectronics
- [vscode] stub 'notebook' VS Code APIs - Contributed on behalf of STMicroelectronics

<a name="breaking_changes_1.33.0">[Breaking Changes:](#breaking_changes_1.33.0)</a>

Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface SerializedDocumentFilter {
language?: string;
scheme?: string;
pattern?: theia.GlobPattern;
notebookType?: string;
}

export enum CompletionTriggerKind {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ export class LanguagesExtImpl implements LanguagesExt {
$serialized: true,
language: selector.language,
scheme: selector.scheme,
pattern: selector.pattern
pattern: selector.pattern,
notebookType: selector.notebookType
};
}

Expand Down
127 changes: 127 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ import {
InlayHint,
InlayHintKind,
InlayHintLabelPart,
NotebookCell,
NotebookCellKind,
NotebookCellStatusBarAlignment,
NotebookEditorRevealType,
NotebookControllerAffinity,
NotebookCellData,
NotebookCellOutput,
NotebookCellOutputItem,
NotebookData,
NotebookDocument,
NotebookRange,
NotebookCellStatusBarItem,
NotebookEdit,
TestRunProfileKind,
TestTag,
TestRunRequest,
Expand Down Expand Up @@ -385,6 +398,26 @@ export function createAPIFactory(
throw new Error(`Failed to show text document ${documentArg.toString()}`);
}
},
get visibleNotebookEditors(): theia.NotebookEditor[] {
return [] as theia.NotebookEditor[];
},
onDidChangeVisibleNotebookEditors(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
get activeNotebookEditor(): theia.NotebookEditor | undefined {
return undefined;
}, onDidChangeActiveNotebookEditor(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
onDidChangeNotebookEditorSelection(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
onDidChangeNotebookEditorVisibleRanges(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
showNotebookDocument(document: NotebookDocument, options?: theia.NotebookDocumentShowOptions) {
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 {
return quickOpenExt.showQuickPick(items, options, token);
Expand Down Expand Up @@ -532,6 +565,9 @@ export function createAPIFactory(
onDidChangeWorkspaceFolders(listener, thisArg?, disposables?): theia.Disposable {
return workspaceExt.onDidChangeWorkspaceFolders(listener, thisArg, disposables);
},
get notebookDocuments(): theia.NotebookDocument[] {
return [] as theia.NotebookDocument[];
},
get textDocuments(): theia.TextDocument[] {
return documents.getAllDocumentData().map(data => data.document);
},
Expand All @@ -541,6 +577,18 @@ export function createAPIFactory(
onDidCloseTextDocument(listener, thisArg?, disposables?) {
return documents.onDidRemoveDocument(listener, thisArg, disposables);
},
onDidOpenNotebookDocument(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
onDidCloseNotebookDocument(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
onDidChangeNotebookDocument(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
onDidSaveNotebookDocument(listener, thisArg?, disposables?) {
return Disposable.NULL;
},
onDidOpenTextDocument(listener, thisArg?, disposables?) {
return documents.onDidAddDocument(listener, thisArg, disposables);
},
Expand Down Expand Up @@ -585,6 +633,9 @@ export function createAPIFactory(
const data = await documents.openDocument(uri);
return data && data.document;
},
openNotebookDocument(uriOrString: theia.Uri | string, content?: NotebookData): Promise<theia.NotebookDocument | undefined> {
return Promise.reject(new Error('Notebook API is stubbed'));
},
createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): theia.FileSystemWatcher =>
extHostFileSystemEvent.createFileSystemWatcher(fromGlobPattern(pattern), ignoreCreate, ignoreChange, ignoreDelete),
findFiles(include: theia.GlobPattern, exclude?: theia.GlobPattern | null, maxResults?: number, token?: CancellationToken): PromiseLike<URI[]> {
Expand Down Expand Up @@ -624,6 +675,9 @@ export function createAPIFactory(
registerTimelineProvider(scheme: string | string[], provider: theia.TimelineProvider): theia.Disposable {
return timelineExt.registerTimelineProvider(plugin, scheme, provider);
},
registerNotebookSerializer(notebookType: string, serializer: theia.NotebookSerializer, options?: theia.NotebookDocumentContentOptions): theia.Disposable {
return Disposable.NULL;
},
get isTrusted(): boolean {
return workspaceExt.trusted;
},
Expand Down Expand Up @@ -988,6 +1042,66 @@ export function createAPIFactory(
}
};

// notebooks API (@stubbed)
// The following implementation is temporarily `@stubbed` and marked as such under `theia.d.ts`
const notebooks: typeof theia.notebooks = {
createNotebookController(
id,
notebookType,
label,
handler?: (cells: theia.NotebookCell[],
notebook: theia.NotebookDocument,
controller: theia.NotebookController) => void | Thenable<void>
) {
return {
id,
notebookType,
label,
handler,
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,
controller: theia.NotebookController
): (void | Thenable<void>) { },
onDidChangeSelectedNotebooks: ({} as theia.Event<{ readonly notebook: theia.NotebookDocument; readonly selected: boolean }>),
updateNotebookAffinity: (notebook: theia.NotebookDocument, affinity: theia.NotebookControllerAffinity) => undefined,
dispose: () => undefined,
};

},
createRendererMessaging(
rendererId
) {
return {
rendererId,
onDidReceiveMessage: ({} as theia.Event<{ readonly editor: theia.NotebookEditor; readonly message: any }>),
postMessage: (message: any, editor?: theia.NotebookEditor) => ({} as Thenable<boolean>),
};
},
registerNotebookCellStatusBarItemProvider(
notebookType,
provider
) {
return {
notebookType,
provider,
dispose: () => undefined,
};
}
};

return <typeof theia>{
version: require('../../package.json').version,
authentication,
Expand All @@ -1002,6 +1116,7 @@ export function createAPIFactory(
debug,
tasks,
scm,
notebooks,
tests,
// Types
StatusBarAlignment: StatusBarAlignment,
Expand Down Expand Up @@ -1128,6 +1243,18 @@ export function createAPIFactory(
InlayHint,
InlayHintKind,
InlayHintLabelPart,
NotebookCellData,
NotebookCellKind,
NotebookCellOutput,
NotebookCellOutputItem,
NotebookCellStatusBarAlignment,
NotebookCellStatusBarItem,
NotebookControllerAffinity,
NotebookData,
NotebookEditorRevealType,
NotebookDocument,
NotebookRange,
NotebookEdit,
TestRunProfileKind,
TestTag,
TestRunRequest,
Expand Down
Loading

0 comments on commit 9d5f79c

Please sign in to comment.