Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe this is valid syntax to have valid code lines on the same line as a docstring ends

Copy link
Author

Choose a reason for hiding this comment

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

No it's not. The linter flags it. Do you think we should show nothing then?

The problem is we remove all comments when submitting code. So what should we do with a situation like this?

Maybe we shouldn't be removing all comments, but I'd rather not change that now.

Copy link
Author

Choose a reason for hiding this comment

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

I'd be fine with showing nothing. It would just run the comment and strip out this line

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');
});

});