Skip to content

Commit

Permalink
Fix multiline comments with text on first line. (#4884)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchiodo authored Mar 21, 2019
1 parent 2c6b0e9 commit fcf990a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/2 Fixes/4791.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Multiline comments with text on the first line break Python Interactive window execution.
12 changes: 11 additions & 1 deletion src/client/datascience/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@ export function parseForComments(
for (const l of lines) {
const trim = l.trim();
// Multiline is triple quotes of either kind
const isMultiline = trim === '\'\'\'' || trim === '\"\"\"';
const isMultiline = trim.startsWith('\'\'\'') || trim.startsWith('\"\"\"');
if (insideMultiline) {
if (!isMultiline) {
foundCommentLine(l, pos);
} else {
insideMultiline = false;

// Might end with text too
if (trim.length > 3) {
foundNonCommentLine(trim.slice(3), pos);
}
}
} else {
if (!isMultiline) {
Expand All @@ -101,6 +106,11 @@ export function parseForComments(
}
} else {
insideMultiline = true;

// Might end with text too
if (trim.length > 3) {
foundCommentLine(trim.slice(3), pos);
}
}
}
pos += 1;
Expand Down
4 changes: 4 additions & 0 deletions src/test/datascience/datascience.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ suite('Data Science Tests', () => {
assert.equal(cells.length, 1, 'Code cell multline failed');
assert.equal(cells[0].data.cell_type, 'code', 'Code cell not generated');
assert.equal(cells[0].data.source.length, 5, 'Lines for cell not emitted');
cells = generateCells(undefined, '#%% [markdown] \n\"\"\"# a\nb\n\'\'\'', 'foo', 0, true, '1');
assert.equal(cells.length, 1, 'Markdown cell multline failed');
assert.equal(cells[0].data.cell_type, 'markdown', 'Markdown cell not generated');
assert.equal(cells[0].data.source.length, 2, 'Lines for cell not emitted');
});

});

0 comments on commit fcf990a

Please sign in to comment.