Skip to content

Commit

Permalink
fix #128765.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Jul 26, 2021
1 parent c5720ec commit 955a1ac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/notebook/browser/media/notebook.css
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@
word-wrap: break-word;
}

.monaco-workbench .notebookOverlay .output > div.foreground .output-stream pre,
.monaco-workbench .notebookOverlay .output > div.foreground .output-plaintext pre {
font-family: var(--monaco-monospace-font);
}

.monaco-workbench .notebookOverlay .output > div.foreground.error .output-stream {
color: red; /*TODO@rebornix theme color*/
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEd
import { isCompositeNotebookEditorInput, NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl';
import { CellKind, CellToolbarLocation, CellToolbarVisibility, CellUri, DisplayOrderKey, UndoRedoPerCell, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookTextDiffEditorPreview, NotebookWorkingCopyTypeIdentifier, ShowCellStatusBar, CompactView, FocusIndicator, InsertToolbarLocation, GlobalToolbar, ConsolidatedOutputButton, ShowFoldingControls, DragAndDropEnabled, NotebookCellEditorOptionsCustomizations, ConsolidatedRunButton } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellToolbarLocation, CellToolbarVisibility, CellUri, DisplayOrderKey, UndoRedoPerCell, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookTextDiffEditorPreview, NotebookWorkingCopyTypeIdentifier, ShowCellStatusBar, CompactView, FocusIndicator, InsertToolbarLocation, GlobalToolbar, ConsolidatedOutputButton, ShowFoldingControls, DragAndDropEnabled, NotebookCellEditorOptionsCustomizations, ConsolidatedRunButton, TextOutputLineLimit } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
Expand Down Expand Up @@ -724,6 +724,11 @@ configurationRegistry.registerConfiguration({
default: false,
tags: ['notebookLayout']
},
[TextOutputLineLimit]: {
description: nls.localize('notebook.textOutputLineLimit', "Control how many lines of text in a text output is rendered."),
type: 'number',
default: 30
},
[NotebookCellEditorOptionsCustomizations]: editorOptionsCustomizationSchema
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Mimes } from 'vs/base/common/mime';
import { dirname } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { MarkdownRenderer } from 'vs/editor/browser/core/markdownRenderer';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { IOpenerService } from 'vs/platform/opener/common/opener';
Expand All @@ -18,7 +19,7 @@ import { LinkDetector } from 'vs/workbench/contrib/debug/browser/linkDetector';
import { ICellOutputViewModel, ICommonNotebookEditor, IOutputTransformContribution as IOutputRendererContribution, IRenderOutput, RenderOutputType } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { OutputRendererRegistry } from 'vs/workbench/contrib/notebook/browser/view/output/rendererRegistry';
import { truncatedArrayOfString } from 'vs/workbench/contrib/notebook/browser/view/output/transforms/textHelper';
import { IOutputItemDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IOutputItemDto, TextOutputLineLimit } from 'vs/workbench/contrib/notebook/common/notebookCommon';


class JavaScriptRendererContrib extends Disposable implements IOutputRendererContribution {
Expand Down Expand Up @@ -63,6 +64,7 @@ class StreamRendererContrib extends Disposable implements IOutputRendererContrib
@IOpenerService private readonly openerService: IOpenerService,
@IThemeService private readonly themeService: IThemeService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super();
}
Expand All @@ -72,7 +74,8 @@ class StreamRendererContrib extends Disposable implements IOutputRendererContrib

const text = getStringValue(item);
const contentNode = DOM.$('span.output-stream');
truncatedArrayOfString(notebookUri, output.cellViewModel, contentNode, [text], linkDetector, this.openerService, this.themeService);
const lineLimit = this.configurationService.getValue<number>(TextOutputLineLimit) ?? 30;
truncatedArrayOfString(notebookUri, output.cellViewModel, Math.max(lineLimit, 6), contentNode, [text], linkDetector, this.openerService, this.themeService);
container.appendChild(contentNode);

return { type: RenderOutputType.Mainframe };
Expand Down Expand Up @@ -161,6 +164,7 @@ class PlainTextRendererContrib extends Disposable implements IOutputRendererCont
public notebookEditor: ICommonNotebookEditor,
@IOpenerService private readonly openerService: IOpenerService,
@IThemeService private readonly themeService: IThemeService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super();
Expand All @@ -171,7 +175,8 @@ class PlainTextRendererContrib extends Disposable implements IOutputRendererCont

const str = getStringValue(item);
const contentNode = DOM.$('.output-plaintext');
truncatedArrayOfString(notebookUri, output.cellViewModel, contentNode, [str], linkDetector, this.openerService, this.themeService);
const lineLimit = this.configurationService.getValue<number>(TextOutputLineLimit) ?? 30;
truncatedArrayOfString(notebookUri, output.cellViewModel, Math.max(lineLimit, 6), contentNode, [str], linkDetector, this.openerService, this.themeService);
container.appendChild(contentNode);

return { type: RenderOutputType.Mainframe, supportAppend: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { URI } from 'vs/base/common/uri';
import { IGenericCellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';

const SIZE_LIMIT = 65535;
const LINES_LIMIT = 500;

function generateViewMoreElement(notebookUri: URI, cellViewModel: IGenericCellViewModel, outputs: string[], openerService: IOpenerService) {
const md: IMarkdownString = {
Expand All @@ -46,7 +45,7 @@ function generateViewMoreElement(notebookUri: URI, cellViewModel: IGenericCellVi
return element;
}

export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGenericCellViewModel, container: HTMLElement, outputs: string[], linkDetector: LinkDetector, openerService: IOpenerService, themeService: IThemeService) {
export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGenericCellViewModel, linesLimit: number, container: HTMLElement, outputs: string[], linkDetector: LinkDetector, openerService: IOpenerService, themeService: IThemeService) {
const fullLen = outputs.reduce((p, c) => {
return p + c.length;
}, 0);
Expand All @@ -60,7 +59,7 @@ export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGeneric
const factory = bufferBuilder.finish();
buffer = factory.create(DefaultEndOfLine.LF).textBuffer;
const sizeBufferLimitPosition = buffer.getPositionAt(SIZE_LIMIT);
if (sizeBufferLimitPosition.lineNumber < LINES_LIMIT) {
if (sizeBufferLimitPosition.lineNumber < linesLimit) {
const truncatedText = buffer.getValueInRange(new Range(1, 1, sizeBufferLimitPosition.lineNumber, sizeBufferLimitPosition.column), EndOfLinePreference.TextDefined);
container.appendChild(handleANSIOutput(truncatedText, linkDetector, themeService, undefined));
// view more ...
Expand All @@ -76,7 +75,7 @@ export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGeneric
buffer = factory.create(DefaultEndOfLine.LF).textBuffer;
}

if (buffer.getLineCount() < LINES_LIMIT) {
if (buffer.getLineCount() < linesLimit) {
const lineCount = buffer.getLineCount();
const fullRange = new Range(1, 1, lineCount, Math.max(1, buffer.getLineLastNonWhitespaceColumn(lineCount)));
container.appendChild(handleANSIOutput(buffer.getValueInRange(fullRange, EndOfLinePreference.TextDefined), linkDetector, themeService, undefined));
Expand All @@ -85,7 +84,7 @@ export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGeneric

const pre = DOM.$('pre');
container.appendChild(pre);
pre.appendChild(handleANSIOutput(buffer.getValueInRange(new Range(1, 1, LINES_LIMIT - 5, buffer.getLineLastNonWhitespaceColumn(LINES_LIMIT - 5)), EndOfLinePreference.TextDefined), linkDetector, themeService, undefined));
pre.appendChild(handleANSIOutput(buffer.getValueInRange(new Range(1, 1, linesLimit - 5, buffer.getLineLastNonWhitespaceColumn(linesLimit - 5)), EndOfLinePreference.TextDefined), linkDetector, themeService, undefined));

// view more ...
container.appendChild(generateViewMoreElement(notebookUri, cellViewModel, outputs, openerService));
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ export const DragAndDropEnabled = 'notebook.dragAndDropEnabled';
export const NotebookCellEditorOptionsCustomizations = 'notebook.editorOptionsCustomizations';
export const ConsolidatedRunButton = 'notebook.consolidatedRunButton';
export const OpenGettingStarted = 'notebook.experimental.openGettingStarted';
export const TextOutputLineLimit = 'notebook.output.textLineLimit';

export const enum CellStatusbarAlignment {
Left = 1,
Expand Down

0 comments on commit 955a1ac

Please sign in to comment.