Skip to content

Commit c5511d5

Browse files
committed
pipe appended data info to webview
1 parent 0edc352 commit c5511d5

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,20 @@ function scrollingEnabled(output: OutputItem, options: RenderOptions) {
265265
metadata.scrollable : options.outputScrolling;
266266
}
267267

268+
interface OutputWithAppend extends OutputItem {
269+
appendedText?(): string | undefined;
270+
}
271+
268272
// div.cell_container
269273
// div.output_container
270274
// div.output.output-stream <-- outputElement parameter
271275
// div.scrollable? tabindex="0" <-- contentParent
272276
// div output-item-id="{guid}" <-- content from outputItem parameter
273-
function renderStream(outputInfo: OutputItem, outputElement: HTMLElement, error: boolean, ctx: IRichRenderContext): IDisposable {
277+
function renderStream(outputInfo: OutputWithAppend, outputElement: HTMLElement, error: boolean, ctx: IRichRenderContext): IDisposable {
278+
const appendedText = outputInfo.appendedText?.();
279+
if (appendedText) {
280+
console.log(`appending output version ${appendedText}`);
281+
}
274282
const disposableStore = createDisposableStore();
275283
const outputScrolling = scrollingEnabled(outputInfo, ctx.settings);
276284

@@ -301,6 +309,9 @@ function renderStream(outputInfo: OutputItem, outputElement: HTMLElement, error:
301309
const existingContent = outputElement.querySelector(`[output-item-id="${outputInfo.id}"]`) as HTMLElement | null;
302310
let contentParent = existingContent?.parentElement;
303311
if (existingContent && contentParent) {
312+
if (appendedText){
313+
existingContent
314+
}
304315
existingContent.replaceWith(newContent);
305316
while (newContent.nextSibling) {
306317
// clear out any stale content if we had previously combined streaming outputs into this one

src/vs/workbench/api/common/extHostNotebookDocument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class ExtHostCell {
132132
const compressed = notebookCommon.compressOutputItemStreams(mimeOutputs.get(mime)!);
133133
output.items.push({
134134
mime,
135-
data: compressed.buffer
135+
data: compressed.data.buffer
136136
});
137137
});
138138
}

src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
15061506
if (content.type === RenderOutputType.Extension) {
15071507
const output = content.source.model;
15081508
const firstBuffer = output.outputs.find(op => op.mime === content.mimeType)!;
1509+
const appenededData = output.appendedSinceVersion(outputCache.versionId, content.mimeType);
1510+
const appended = appenededData ? { valueBytes: appenededData.buffer, previousVersion: outputCache.versionId } : undefined;
15091511

15101512
const valueBytes = copyBufferIfNeeded(firstBuffer.data.buffer, transfer);
15111513
updatedContent = {
@@ -1515,6 +1517,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
15151517
output: {
15161518
mime: content.mimeType,
15171519
valueBytes,
1520+
appended: appended
15181521
},
15191522
allOutputs: output.outputs.map(output => ({ mime: output.mime }))
15201523
};

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewMessages.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,18 @@ export interface IOutputRequestDto {
188188
export interface OutputItemEntry {
189189
readonly mime: string;
190190
readonly valueBytes: Uint8Array;
191+
readonly appended?: { valueBytes: Uint8Array; previousVersion: number };
191192
}
192193

193194
export type ICreationContent =
194195
| { readonly type: RenderOutputType.Html; readonly htmlContent: string }
195-
| { readonly type: RenderOutputType.Extension; readonly outputId: string; readonly metadata: unknown; readonly output: OutputItemEntry; readonly allOutputs: ReadonlyArray<{ readonly mime: string }> };
196+
| {
197+
readonly type: RenderOutputType.Extension;
198+
readonly outputId: string;
199+
readonly metadata: unknown;
200+
readonly output: OutputItemEntry;
201+
readonly allOutputs: ReadonlyArray<{ readonly mime: string }>;
202+
};
196203

197204
export interface ICreationRequestMessage {
198205
readonly type: 'html';

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ async function webviewPreloads(ctx: PreloadContext) {
804804

805805
interface ExtendedOutputItem extends rendererApi.OutputItem {
806806
readonly _allOutputItems: ReadonlyArray<AdditionalOutputItemInfo>;
807+
appendedText?(): string | undefined;
807808
}
808809

809810
let hasWarnedAboutAllOutputItemsProposal = false;
@@ -813,20 +814,29 @@ async function webviewPreloads(ctx: PreloadContext) {
813814
mime: string,
814815
metadata: unknown,
815816
valueBytes: Uint8Array,
816-
allOutputItemData: ReadonlyArray<{ readonly mime: string }>
817+
allOutputItemData: ReadonlyArray<{ readonly mime: string }>,
818+
appended?: { valueBytes: Uint8Array; previousVersion: number }
817819
): ExtendedOutputItem {
818820

819821
function create(
820822
id: string,
821823
mime: string,
822824
metadata: unknown,
823825
valueBytes: Uint8Array,
826+
appended?: { valueBytes: Uint8Array; previousVersion: number }
824827
): ExtendedOutputItem {
825828
return Object.freeze<ExtendedOutputItem>({
826829
id,
827830
mime,
828831
metadata,
829832

833+
appendedText(): string | undefined {
834+
if (appended) {
835+
return textDecoder.decode(appended.valueBytes);
836+
}
837+
return undefined;
838+
},
839+
830840
data(): Uint8Array {
831841
return valueBytes;
832842
},
@@ -874,7 +884,7 @@ async function webviewPreloads(ctx: PreloadContext) {
874884
});
875885
}));
876886

877-
const item = create(id, mime, metadata, valueBytes);
887+
const item = create(id, mime, metadata, valueBytes, appended);
878888
allOutputItemCache.set(mime, Promise.resolve(item));
879889
return item;
880890
}
@@ -2542,7 +2552,7 @@ async function webviewPreloads(ctx: PreloadContext) {
25422552
const errors = preloadErrors.filter((e): e is Error => e instanceof Error);
25432553
showRenderError(`Error loading preloads`, this.element, errors);
25442554
} else {
2545-
const item = createOutputItem(this.outputId, content.output.mime, content.metadata, content.output.valueBytes, content.allOutputs);
2555+
const item = createOutputItem(this.outputId, content.output.mime, content.metadata, content.output.valueBytes, content.allOutputs, content.output.appended);
25462556

25472557
const controller = new AbortController();
25482558
this.renderTaskAbort = controller;

0 commit comments

Comments
 (0)