Skip to content

Fixes bugs #11777 and #11726, 'outputPrepend' needed to be cleared on each cell execute. #11871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 18, 2020
5 changes: 5 additions & 0 deletions src/client/datascience/interactive-ipynb/nativeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
// Clear the result if we've run before
await this.clearResult(cell.id);

// Clear 'per run' data passed to WebView before execution
if (cell.data.metadata.tags !== undefined) {
cell.data.metadata.tags = cell.data.metadata.tags.filter((t) => t !== 'outputPrepend');
}

const code = concatMultilineStringInput(cell.data.source);
// Send to ourselves.
await this.submitCode(code, Identifiers.EmptyFileName, 0, cell.id, cell.data, undefined, cancelToken);
Expand Down
28 changes: 16 additions & 12 deletions src/client/datascience/jupyter/jupyterNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,8 @@ export class JupyterNotebookBase implements INotebook {
trimFunc: (str: string) => string
) {
const data: nbformat.ICodeCell = cell.data as nbformat.ICodeCell;
let originalTextLenght = 0;
let trimmedTextLenght = 0;
let originalTextLength = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not sure how this addresses https://github.com/microsoft/vscode-python/issues/11777
I think we need some tests to confirm the fix.
Again will wait for feedback from the rest of the team.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spelling error fix is a side effect of fixing the actual bug, as in, leave the area nicer than you found it. Clearing the tag, fixes the bug. The truncating always worked, it was when the warning showed up that didn't.

let trimmedTextLength = 0;

// Clear output if waiting for a clear
if (clearState.value) {
Expand All @@ -1301,32 +1301,36 @@ export class JupyterNotebookBase implements INotebook {
// tslint:disable-next-line:restrict-plus-operands
existing.text = existing.text + msg.content.text;
const originalText = formatStreamText(concatMultilineStringOutput(existing.text));
originalTextLenght = originalText.length;
originalTextLength = originalText.length;
existing.text = trimFunc(originalText);
trimmedTextLenght = existing.text.length;
trimmedTextLength = existing.text.length;
} else {
const originalText = formatStreamText(concatMultilineStringOutput(msg.content.text));
originalTextLenght = originalText.length;
originalTextLength = originalText.length;
// Create a new stream entry
const output: nbformat.IStream = {
output_type: 'stream',
name: msg.content.name,
text: trimFunc(originalText)
};
data.outputs = [...data.outputs, output];
trimmedTextLenght = output.text.length;
trimmedTextLength = output.text.length;
cell.data = data;
}

// If the output was trimmed, we add the 'outputPrepend' metadata tag.
// Later, the react side will display a message letting the user know
// the output is trimmed and what setting changes that.
if (trimmedTextLenght < originalTextLenght) {
if (!data.metadata.tags) {
data.metadata.tags = ['outputPrepend'];
} else {
data.metadata.tags.push('outputPrepend');
}
// * If data.metadata.tags is undefined, define it so the following
// code is can rely on it being defined.
if (data.metadata.tags === undefined) {
data.metadata.tags = [];
}

data.metadata.tags = data.metadata.tags.filter((t) => t !== 'outputPrepend');

if (trimmedTextLength < originalTextLength) {
data.metadata.tags.push('outputPrepend');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/datascience-ui/interactive-common/kernelSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export class KernelSelection extends React.Component<IKernelSelectionProps> {
: ImageName.JupyterServerConnected;
}

private getMaxWidth(charLenght: number): string {
private getMaxWidth(charLength: number): string {
// This comes from a linear regression
const width = 0.57674 * charLenght + 1.70473;
const width = 0.57674 * charLength + 1.70473;
const unit = 'em';
return Math.round(width).toString() + unit;
}
Expand Down