Skip to content

Commit d79ffd5

Browse files
authored
Merge pull request #5760 from microsoft/rchiodo/release_merge
Merge commits from master
2 parents b9792df + 0e41049 commit d79ffd5

File tree

15 files changed

+85
-50
lines changed

15 files changed

+85
-50
lines changed

news/2 Fixes/5537.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix magics running from a python file.

news/2 Fixes/5560.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change scrolling to not animate to workaround async updates breaking the animation.

news/2 Fixes/5729.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adjust input box prompt to look more an IPython console prompt.

package-lock.json

Lines changed: 29 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/datascience/cellMatcher.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export class CellMatcher {
3232
return this.codeMatchRegEx.test(code);
3333
}
3434

35+
public stripMarkers(code: string) : string {
36+
const lines = code.splitLines({trim: false, removeEmptyEntries: false});
37+
return lines.filter(l => !this.isCode(l) && !this.isMarkdown(l)).join('\n');
38+
}
39+
3540
public exec(code: string) : string | undefined {
3641
let result: RegExpExecArray | null = null;
3742
if (this.codeMatchRegEx.test(code)) {

src/client/datascience/common.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ export function concatMultilineString(str: nbformat.MultilineString): string {
2424
}
2525

2626
// Strip out comment lines from code
27-
export function stripComments(str: nbformat.MultilineString): nbformat.MultilineString {
28-
if (Array.isArray(str)) {
29-
return extractNonComments(str);
30-
} else {
31-
return extractNonComments([str]);
32-
}
27+
export function stripComments(str: string): string {
28+
let result: string = '';
29+
parseForComments(
30+
str.splitLines({trim: false, removeEmptyEntries: false}),
31+
(_s) => noop,
32+
(s) => result = result.concat(`${s}\n`));
33+
return result;
3334
}
3435

3536
export function formatStreamText(str: string): string {
@@ -77,6 +78,7 @@ export function generateMarkdownFromCodeLines(lines: string[]) {
7778
return appendLineFeed(extractComments(lines.slice(1)));
7879
}
7980

81+
// tslint:disable-next-line: cyclomatic-complexity
8082
export function parseForComments(
8183
lines: string[],
8284
foundCommentLine: (s: string, i: number) => void,
@@ -109,15 +111,20 @@ export function parseForComments(
109111
}
110112
// Not inside either, see if starting a quote
111113
} else if (isMultilineQuote && !isMultilineComment) {
112-
insideMultilineQuote = isMultilineQuote;
114+
// Make sure doesn't begin and end on the same line.
115+
const beginQuote = trim.indexOf(isMultilineQuote);
116+
const endQuote = trim.lastIndexOf(isMultilineQuote);
117+
insideMultilineQuote = endQuote !== beginQuote ? undefined : isMultilineQuote;
113118
foundNonCommentLine(l, pos);
114119
// Not starting a quote, might be starting a comment
115120
} else if (isMultilineComment) {
116-
insideMultilineComment = isMultilineComment;
121+
// See if this line ends the comment too or not
122+
const endIndex = trim.indexOf(isMultilineComment, 3);
123+
insideMultilineComment = endIndex >= 0 ? undefined : isMultilineComment;
117124

118125
// Might end with text too
119126
if (trim.length > 3) {
120-
foundCommentLine(trim.slice(3), pos);
127+
foundCommentLine(trim.slice(3, endIndex >= 0 ? endIndex : undefined), pos);
121128
}
122129
} else {
123130
// Normal line
@@ -136,9 +143,3 @@ function extractComments(lines: string[]): string[] {
136143
parseForComments(lines, (s) => result.push(s), (_s) => noop());
137144
return result;
138145
}
139-
140-
function extractNonComments(lines: string[]): string[] {
141-
const result: string[] = [];
142-
parseForComments(lines, (_s) => noop, (s) => result.push(s));
143-
return result;
144-
}

src/client/datascience/jupyter/jupyterServer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { createDeferred, Deferred, sleep } from '../../common/utils/async';
2121
import * as localize from '../../common/utils/localize';
2222
import { noop } from '../../common/utils/misc';
2323
import { generateCells } from '../cellFactory';
24+
import { CellMatcher } from '../cellMatcher';
2425
import { concatMultilineString } from '../common';
2526
import { Identifiers } from '../constants';
2627
import {
@@ -514,10 +515,11 @@ export class JupyterServerBase implements INotebookServer {
514515
private generateRequest = (code: string, silent?: boolean): Kernel.IFuture | undefined => {
515516
//this.logger.logInformation(`Executing code in jupyter : ${code}`)
516517
try {
518+
const cellMatcher = new CellMatcher(this.configService.getSettings().datascience);
517519
return this.session ? this.session.requestExecute(
518520
{
519-
// Replace windows line endings with unix line endings.
520-
code: code.replace(/\r\n/g, '\n'),
521+
// Remove the cell marker if we have one.
522+
code: cellMatcher.stripMarkers(code),
521523
stop_on_error: false,
522524
allow_stdin: false,
523525
store_history: !silent // Silent actually means don't output anything. Store_history is what affects execution_count

src/datascience-ui/history-react/MainPanel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
290290
const errorBackgroundColor = getSettings().errorBackgroundColor;
291291
const actualErrorBackgroundColor = errorBackgroundColor ? errorBackgroundColor : '#FFFFFF';
292292
const maxTextSize = maxOutputSize && maxOutputSize < 10000 && maxOutputSize > 0 ? maxOutputSize : undefined;
293+
const executionCount = this.getInputExecutionCount(this.state.cellVMs);
293294

294295
return (
295296
<div className='edit-panel'>
@@ -309,6 +310,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
309310
ref={this.saveEditCellRef}
310311
gotoCode={noop}
311312
delete={noop}
313+
editExecutionCount={executionCount}
312314
onCodeCreated={this.editableCodeCreated}
313315
onCodeChange={this.codeChange}
314316
monacoTheme={this.state.monacoTheme}

src/datascience-ui/history-react/cell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import './cell.css';
2121
import { CellButton } from './cellButton';
2222
import { Code } from './code';
2323
import { CollapseButton } from './collapseButton';
24-
import { CommandPrompt } from './commandPrompt';
2524
import { ExecutionCount } from './executionCount';
2625
import { Image, ImageName } from './image';
2726
import { InputHistory } from './inputHistory';
@@ -41,6 +40,7 @@ interface ICellProps {
4140
errorBackgroundColor: string;
4241
monacoTheme: string | undefined;
4342
editorOptions: monacoEditor.editor.IEditorOptions;
43+
editExecutionCount: number;
4444
gotoCode(): void;
4545
delete(): void;
4646
submitNewCode(code: string): void;
@@ -187,7 +187,7 @@ export class Cell extends React.Component<ICellProps> {
187187
return this.props.cellVM.editable ?
188188
(
189189
<div className='controls-div'>
190-
<CommandPrompt />
190+
<ExecutionCount isBusy={busy} count={this.props.editExecutionCount.toString()} visible={this.isCodeCell()} />
191191
</div>
192192
) : (
193193
<div className='controls-div'>

src/datascience-ui/history-react/code.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
position: relative;
44
width:100%;
55
margin-bottom:16px;
6+
top: -2px; /* Account for spacing removed from the monaco editor */
67
}
78

89
.code-area-editable {

0 commit comments

Comments
 (0)