Skip to content

Commit db6c9a9

Browse files
committed
limit the amount of data
1 parent c3261e5 commit db6c9a9

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -717,23 +717,29 @@ class NotebookAccessibleViewContribution extends Disposable {
717717
const outputTextModel = viewCell.model.outputs[i];
718718
const [mimeTypes, pick] = outputViewModel.resolveMimeTypes(notebookEditor.textModel, undefined);
719719
const mimeType = mimeTypes[pick].mimeType;
720-
const pickedBuffer = outputTextModel.outputs.find(output => output.mime === mimeType)?.data.buffer;
720+
let buffer = outputTextModel.outputs.find(output => output.mime === mimeType);
721721

722-
let text = `${mimeType}\n`;
723-
if (!pickedBuffer || mimeType.startsWith('image')) {
724-
const altBuffer = outputTextModel.outputs.find(output => !output.mime.startsWith('image'))?.data.buffer;
725-
if (altBuffer) {
726-
text = decoder.decode(altBuffer);
722+
if (!buffer || mimeType.startsWith('image')) {
723+
buffer = outputTextModel.outputs.find(output => !output.mime.startsWith('image'));
724+
}
725+
726+
let text = `${mimeType}`; // default in case we can't get the text value for some reason.
727+
if (buffer) {
728+
const charLimit = 100_000;
729+
text = decoder.decode(buffer.data.slice(0, charLimit).buffer);
730+
731+
if (buffer.data.byteLength > charLimit) {
732+
text = text + '...(truncated)';
733+
}
734+
735+
if (mimeType.endsWith('error')) {
736+
text = text.replace(/\\u001b\[[0-9;]*m/gi, '').replaceAll('\\n', '\n');
727737
}
728-
} else {
729-
text = decoder.decode(pickedBuffer);
730738
}
739+
731740
const index = viewCell.outputsViewModels.length > 1
732741
? `Cell output ${i + 1} of ${viewCell.outputsViewModels.length}\n`
733742
: '';
734-
if (mimeType.endsWith('error')) {
735-
text = text.replace(/\\u001b\[[0-9;]*m/gi, '').replaceAll('\\n', '\n');
736-
}
737743
outputContent = outputContent.concat(`${index}${text}\n`);
738744
}
739745

0 commit comments

Comments
 (0)