Skip to content
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

Run Selection/Line in Python Terminal does not work with empty spaces #1207

Closed
mnarodovitch opened this issue Mar 27, 2018 · 5 comments · Fixed by #1432
Closed

Run Selection/Line in Python Terminal does not work with empty spaces #1207

mnarodovitch opened this issue Mar 27, 2018 · 5 comments · Fixed by #1432
Labels
area-terminal feature-request Request for new features or functionality
Milestone

Comments

@mnarodovitch
Copy link

mnarodovitch commented Mar 27, 2018

Environment data

  • VS Code version: 1.21.1
  • Extension version (available under the Extensions sidebar): 2018.2.1
  • OS and version: Ubuntu 16.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: -

Actual behavior

Selecting

if True:
    #do some stuff

    #do more stuff
    print("should print")

and running "Run Selection/Line in Python Terminal" [ / python.execSelectionInTerminal ] produces an error.

Expected behavior

Console should print

Logs

>>> if True:
...     #do some stuff
...
  File "<stdin>", line 3

    ^
IndentationError: expected an indented block
>>>     #do more stuff
...     print("should print")
  File "<stdin>", line 2
    print("should print")
    ^
IndentationError: unexpected indent
@mnarodovitch
Copy link
Author

mnarodovitch commented Mar 27, 2018

Is it possible, that this function should execute the normalizedCode?

https://github.com/Microsoft/vscode-python/blob/master/src/client/terminals/codeExecution/codeExecutionManager.ts

private async executeSelection(executionService: ICodeExecutionService): Promise<void> {
    const activeEditor = this.documentManager.activeTextEditor;
    if (!activeEditor) {
        return;
    }
    const codeExecutionHelper = this.serviceContainer.get<ICodeExecutionHelper>(ICodeExecutionHelper);
    const codeToExecute = await codeExecutionHelper.getSelectedTextToExecute(activeEditor!);
    const normalizedCode = codeExecutionHelper.normalizeLines(codeToExecute!);
    if (!normalizedCode || normalizedCode.trim().length === 0) {
        return;
    }

    await executionService.execute(codeToExecute!, activeEditor!.document.uri);

}

@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug needs verification area-terminal labels Mar 27, 2018
@fishhead108
Copy link

fishhead108 commented Mar 29, 2018

Confirm, the same issue here

VS Code version: 1.21.1
Extension version (available under the Extensions sidebar): 2018.2.1
OS and version: Arch Linux 4.15.12-1
Python version (& distribution if applicable, e.g. Anaconda): 3.6
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
Relevant/affected Python packages and their versions: -

@brettcannon brettcannon added feature-request Request for new features or functionality needs decision and removed needs verification bug Issue identified by VS Code Team member as probable bug labels Mar 29, 2018
@brettcannon
Copy link
Member

I think what people are after is a feature enhancement to strip blank lines from the code sent to the REPL to prevent the REPL from interpreting the code's newline as the end of a block.

@mnarodovitch
Copy link
Author

mnarodovitch commented Mar 31, 2018

Actually, when I select some correct code and I press on the "execute selection" button, then I would expect that the selection will be executed. This is not the case.
The feature, which strips blank lines is already implimented and the executeSelection function uses this feature to strip the lines. But then, the executeSelection executes the raw code.
I would propose to change this issue it to type-bug again, unless you didn't intend to implement this feature. This could be possibly easily fixed by replacing
await executionService.execute(codeToExecute!, activeEditor!.document.uri);
with await executionService.execute(normalizedCode!, activeEditor!.document.uri);

@brettcannon
Copy link
Member

@michaelnarodovitch if you want to submit a PR for your proposed change we would happily review it.

@brettcannon brettcannon added this to the April 2018 milestone Apr 2, 2018
DonJayamanne added a commit that referenced this issue Apr 23, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants