mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
notebooks: renderer messaging feedback
This commit is contained in:
parent
889fc9ed82
commit
90aa979bb7
8
src/vs/vscode.d.ts
vendored
8
src/vs/vscode.d.ts
vendored
|
@ -11571,11 +11571,13 @@ declare module 'vscode' {
|
|||
|
||||
/**
|
||||
* Sends a message to the renderer.
|
||||
* @param editor Editor to target with the message
|
||||
* @param message Message to send
|
||||
* @returns a boolean indicating whether the message was successfully delivered
|
||||
* @param editor Editor to target with the message. If not provided, the
|
||||
* message is sent to all renderers.
|
||||
* @returns a boolean indicating whether the message was successfully
|
||||
* delivered to any renderer.
|
||||
*/
|
||||
postMessage(editor: NotebookEditor, message: any): Thenable<boolean>;
|
||||
postMessage(message: any, editor?: NotebookEditor): Thenable<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ export class MainThreadNotebookRenderers extends Disposable implements MainThrea
|
|||
}));
|
||||
}
|
||||
|
||||
$postMessage(editorId: string, rendererId: string, message: unknown): Promise<boolean> {
|
||||
$postMessage(editorId: string | undefined, rendererId: string, message: unknown): Promise<boolean> {
|
||||
return this.messaging.receiveMessage(editorId, rendererId, message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -936,7 +936,7 @@ export interface MainThreadNotebookKernelsShape extends IDisposable {
|
|||
}
|
||||
|
||||
export interface MainThreadNotebookRenderersShape extends IDisposable {
|
||||
$postMessage(editorId: string, rendererId: string, message: unknown): Promise<boolean>;
|
||||
$postMessage(editorId: string | undefined, rendererId: string, message: unknown): Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface MainThreadInteractiveShape extends IDisposable {
|
||||
|
|
|
@ -44,14 +44,15 @@ export class ExtHostNotebookRenderers implements ExtHostNotebookRenderersShape {
|
|||
|
||||
return this.getOrCreateEmitterFor(rendererId).event(wrappedListener, thisArg, disposables);
|
||||
},
|
||||
postMessage: (editorOrAlias, message) => {
|
||||
const editor = notebookEditorVisible ? editorOrAlias : notebookEditorAliases.get(editorOrAlias);
|
||||
const extHostEditor = editor && ExtHostNotebookEditor.apiEditorsToExtHost.get(editor);
|
||||
if (!extHostEditor) {
|
||||
throw new Error(`The first argument to postMessage() must be a NotebookEditor`);
|
||||
postMessage: (message, editorOrAlias) => {
|
||||
if (ExtHostNotebookEditor.apiEditorsToExtHost.has(message)) { // back compat for swapped args
|
||||
[message, editorOrAlias] = [editorOrAlias, message];
|
||||
}
|
||||
|
||||
return this.proxy.$postMessage(extHostEditor.id, rendererId, message);
|
||||
|
||||
const editor = notebookEditorVisible ? editorOrAlias : notebookEditorAliases.get(editorOrAlias!);
|
||||
const extHostEditor = editor && ExtHostNotebookEditor.apiEditorsToExtHost.get(editor);
|
||||
return this.proxy.$postMessage(extHostEditor?.id, rendererId, message);
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,12 @@ export class NotebookRendererMessagingService implements INotebookRendererMessag
|
|||
constructor(@IExtensionService private readonly extensionService: IExtensionService) { }
|
||||
|
||||
/** @inheritdoc */
|
||||
public receiveMessage(editorId: string, rendererId: string, message: unknown): Promise<boolean> {
|
||||
public receiveMessage(editorId: string | undefined, rendererId: string, message: unknown): Promise<boolean> {
|
||||
if (editorId === undefined) {
|
||||
const sends = [...this.scopedMessaging.values()].map(e => e.receiveMessageHandler?.(rendererId, message));
|
||||
return Promise.all(sends).then(s => s.some(s => !!s));
|
||||
}
|
||||
|
||||
return this.scopedMessaging.get(editorId)?.receiveMessageHandler?.(rendererId, message) ?? Promise.resolve(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ export interface INotebookRendererMessagingService {
|
|||
/**
|
||||
* Called when the main thread gets a message for a renderer.
|
||||
*/
|
||||
receiveMessage(editorId: string, rendererId: string, message: unknown): Promise<boolean>;
|
||||
receiveMessage(editorId: string | undefined, rendererId: string, message: unknown): Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface IScopedRendererMessaging extends IDisposable {
|
||||
|
|
Loading…
Reference in a new issue