Skip to content

Commit

Permalink
Only trim leading empty lines, not tabs, when submitting #%% cells to…
Browse files Browse the repository at this point in the history
… the interactive window (#7483)
  • Loading branch information
joyceerhl authored Sep 11, 2021
1 parent c0f2a08 commit d96d21a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/7303.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve leading tab characters on code lines for #%% cells submitted to interactive window.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
WebViewViewChangeEventArgs
} from '../types';
import { createInteractiveIdentity, getInteractiveWindowTitle } from './identity';
import { generateMarkdownFromCodeLines } from '../../../datascience-ui/common';
import { generateMarkdownFromCodeLines, removeLinesFromFrontAndBack } from '../../../datascience-ui/common';
import { chainWithPendingUpdates } from '../notebook/helpers/notebookUpdater';
import { LineQueryRegex, linkCommandAllowList } from '../interactive-common/linkProvider';
import { INativeInteractiveWindow } from './types';
Expand Down Expand Up @@ -627,7 +627,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
const isMarkdown = cellMatcher.getCellType(code) === MARKDOWN_LANGUAGE;
const strippedCode = isMarkdown
? generateMarkdownFromCodeLines(code.splitLines()).join('')
: cellMatcher.stripFirstMarker(code).trim();
: removeLinesFromFrontAndBack(cellMatcher.stripFirstMarker(code));
const interactiveWindowCellMarker = cellMatcher.getFirstMarker(code);

// Insert cell into NotebookDocument
Expand Down
22 changes: 22 additions & 0 deletions src/test/datascience/interactiveWindow.vscode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ for i in range(10):
);
});

test('Leading and trailing empty lines in #%% cell are trimmed', async () => {
const actualCode = ` print('foo')
print('bar')`;
const codeWithWhitespace = ` # %%
${actualCode}
`;
const { activeInteractiveWindow: interactiveWindow } = await submitFromPythonFile(codeWithWhitespace);
const lastCell = await waitForLastCellToComplete(interactiveWindow);
const actualCellText = lastCell.document.getText();
assert.equal(actualCellText, actualCode);
});

// todo@joyceerhl
// test('Verify CWD', () => { });
// test('Multiple executes go to last active window', async () => { });
Expand Down

0 comments on commit d96d21a

Please sign in to comment.