Skip to content

Send extra newline for 'Run Selection/Line in Python Terminal' to immediately execute #169

Closed

Description

From ruben-aghayan on August 25, 2017 23:2

Environment data

VS Code version: 1.15.1
Python Extension version: 0.7.0
Python Version: 3.6.2
IPython Version: 6.1.0
OS and version: Windows 10 Enterprise 1703

Actual behavior

Pastes selected line(s) into IPython but does not run them. There is a new line at the end of the pasted text.

image

Observed ouptut from highlighting line or leaving cursor on line and issuing Run Selection/Line in Python Terminal command when IPython is default interpreter

Expected behavior

To run selected line(s)

Steps to reproduce:

  • Set IPython default interpreter
  • Issue Run Selection/Line command

Copied from original issue: DonJayamanne/pythonVSCode#1180

Activity

  1. DonJayamanne commented on Nov 14, 2017

    @DonJayamanne
    Author

    From Tiemen Schuijbroek (@TiemenSch) on August 28, 2017 17:29

    What happens if you add a new line at the end of your file?

    Update:
    I tried to reproduce and it only happens when sending the selection in my case.

    Running the complete file works just fine.

  2. DonJayamanne commented on Nov 14, 2017

    @DonJayamanne
    Author

    From ruben-aghayan on August 29, 2017 17:21

    Hi Tiemen,

    When I add a new line at the end of the file, it is also pasted into IPython, but the code is not run.
    Also, I want to confirm your finding that this only occurs for sending a selection or a line, not for running the file.

    Running line by line is an important part of workflow in cases like Data Science. It also makes the most of some of the interactive features in IPython.

  3. DonJayamanne commented on Nov 14, 2017

    @DonJayamanne
    Author
  4. DonJayamanne commented on Feb 5, 2018

    @DonJayamanne
    Author

    ruben-aghayan are you able to test this on the latest version of VS Code and let us know whether it works.

  5. 62 remaining items

  6. vasselai commented on Jan 2, 2019

    @vasselai

    Don Jayamanne (@DonJayamanne) Has any progress been made on this front?

    So far, the best I could do to approximate the desired behavior, i.e. multiple selected lines properly sent and executed in the IPython terminal, was to manually send the extra line break a few milliseconds after the original code was sent. This works well for few selected lines, but of course becomes a problem when the number of selected-and-sent lines increase.

  7. brettcannon commented on Jan 3, 2019

    @brettcannon
    Member

    Fabricio Vasselai (@vasselai) our data science team has taken ownership of this issue, so it's up to Rong Lu (@ronglums) and company to make a prioritization call.

  8. greazer commented on Jan 3, 2019

    @greazer

    The original issue entered was not about data science, but only the existing python terminal window. This bug will now only track this issue.

    The other Python Interactive window issues scattered throughout this issue are likely covered by #727.

  9. saponas commented on Feb 1, 2019

    @saponas

    I've been looking at a few ways to address this issue. Here are some approaches:

    • Use keybindings.json for interacting with the terminal. You can set key bindings for shifting focus to and from the iPython terminal and also have an additional key binding to send a carriage return. Try doing a key binding for "python.execSelectionInTerminal" to send a line or lines to the terminal followed by a key binding for "workbench.action.terminal.sendSequence" with a carriage return as the argument. Here are my keybindings.json enteries:
    {
        "key":"ctrl+`",
        "command":"workbench.action.focusActiveEditorGroup",
        "when":"terminalFocus"
    },
    {
        "key":"ctrl+`",
        "command":"workbench.action.terminal.focus",
        "when":"!terminalFocus"
    },
    { 
        "key":"alt+enter",
        "command":"python.execSelectionInTerminal",
        "when":"editorFocus && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
    },
    {
        "key":"alt+shift+enter",
        "command":"workbench.action.terminal.sendSequence",
        "args":{ "text": "\u000d" }
    }
    public async sendText(text: string): Promise<void> {
            await this.ensureTerminal();
            this.terminal!.show(true);
            this.terminal!.sendText(`${text}`);
            // send carriage return to make code execute
            await new Promise(resolve => setTimeout(resolve, 100));
            this.terminal.sendText('\u000D', false);
            await new Promise(resolve => setTimeout(resolve, 100));
        }
    • Use the new REPL feature for interactive python in the Python Extension for VSCode that is available in the current build (but not yet in a release). If going that route, I use the following key binding to send a line/selection to the REPL:
    { 
        "key":"alt+shift+enter",
        "command":"python.datascience.execSelectionInteractive",
        "when":"editorFocus && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
    }

    and I also sometimes open a REPL in the terminal interface connected to the same kernel with
    jupyter console --existing

  10. luabud commented on Feb 7, 2019

    @luabud
    Member

    We're not fixing the issue as stated because of limitations with the terminal. Closing in favor of #727

  11. gui-leeahni commented on Feb 26, 2019

    @gui-leeahni

    Scott Saponas (@saponas) this works. can combine opt1 with multi-command ext, too.

  12. locked as resolved and limited conversation to collaborators on Mar 26, 2019
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions