Skip to content

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

Closed

Description

@mnarodovitch

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

Activity

  1. mnarodovitch commented on Mar 27, 2018

    @mnarodovitch
    Author

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

    }

  2. RootMePLS commented on Mar 29, 2018

    @RootMePLS

    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: -

  3. brettcannon commented on Mar 29, 2018

    @brettcannon
    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.

  4. mnarodovitch commented on Mar 31, 2018

    @mnarodovitch
    Author

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

  5. brettcannon commented on Apr 2, 2018

    @brettcannon
    Member

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

  6. added a commit that references this issue on Apr 23, 2018
    55f5ca5
  7. locked as resolved and limited conversation to collaborators on Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions