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

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

Closed
DonJayamanne opened this issue Nov 14, 2017 · 46 comments
Labels
area-terminal feature-request Request for new features or functionality

Comments

@DonJayamanne
Copy link

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

@DonJayamanne
Copy link
Author

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

@DonJayamanne
Copy link
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.

@DonJayamanne
Copy link
Author

@brettcannon brettcannon added awaiting 2-PR area-terminal bug Issue identified by VS Code Team member as probable bug labels Nov 14, 2017
@DonJayamanne
Copy link
Author

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

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed awaiting 2-PR labels Feb 5, 2018
@DonJayamanne DonJayamanne added this to the February 2018 milestone Feb 5, 2018
@ruben-aghayan
Copy link

As far as I can tell, the issue is still there. Has it stopped on your machine? / Is it just me?

@amccaugh
Copy link

amccaugh commented Feb 9, 2018

This bug also occurs for me, exactly as initially described.

@DonJayamanne
Copy link
Author

@ruben-aghayan @amccaugh
In ipython, you do need a blank line and then you need to hit the enter key for IPython to evaluate the request. This is the standard behavior in ipython.

  • Ignore VS Code for a moment,
  • just launch the terminal and start ipython
  • type in the text print("test") and hit the enter key
  • A blank line will be displayed (standard ipython behavior)
  • You need to hit the enter key once again for the print("test") statement to get evaluated.

Please test and confirm this is the behavior outside VS Code.

@ruben-aghayan
Copy link

The issue persists if a blank line is included then the 'run selection' command is given.

If, in order to run the line, the user must change the focus to IPython and hit enter ( and this can't or shouldnt be done in the Run Line/Selection command) then I think we can close it.

@amccaugh
Copy link

amccaugh commented Feb 9, 2018

@DonJayamanne In my terminal (windows), using IPython 6.1.0 (Python 3.6), I do not need to hit the enter key twice. The behavior I see is:

  • launch the terminal and start ipython
  • type in the text print("test") and hit the enter key (only once)
  • the line is evaluated, and the word "test" is printed along with a blank line underneath it

@amccaugh
Copy link

amccaugh commented Feb 9, 2018

I've also tested this on a Debian box with IPython 0.13.1 + Python 2.7, and it's the same behavior (a single keypress of enter evaluates the line). From what I can tell, getting a newline in the IPython prompt is actually somewhat difficult

@DonJayamanne
Copy link
Author

@ruben-aghayan @amccaugh
This works at my end, please could you install the latest development version of the extension and test this out.

@DonJayamanne DonJayamanne removed this from the March 2018 milestone Mar 21, 2018
@draran
Copy link

draran commented Mar 21, 2018

I have installed the latest development version of the extension. As before, running the first line of the selection executes nicely in ipython - this has never been an issue for me. The rest of the selection however, does not. This behaviour has been described in #460 already and it is still marked as needs-verification.

@brettcannon
Copy link
Member

Ignore the other issue; it's closed.

Can someone upload a GIF showing what's happening for them including what OS, Python version, and IPython version they are using? We simply can't reproduce on our machines (I tested this issue the other day and couldn't reproduce either).

@draran
Copy link

draran commented Mar 21, 2018

System macOS 10.13.3
VS Code 1.20.1
Python 2.7.13
ipython 5.2.0
demo
This is not OS specific - tested on Ubuntu 16.04 with the development version of extension to same result

@brettcannon
Copy link
Member

@boazdori no current plans to do so.

@jflam
Copy link

jflam commented Aug 16, 2018

@boazdori If you're interested in seeing a preview of what this experience could look like, take a look at this extension: https://marketplace.visualstudio.com/items?itemName=neuron.neuron-IPE

I had some students build this proof of concept for us - would love to hear your feedback!

@draran
Copy link

draran commented Aug 17, 2018

@jflam This looks very promising. Quite similar and potentially more powerful than hydrogen package for atom IDE

@boazdori
Copy link

boazdori commented Aug 19, 2018 via email

@hoodooor
Copy link

@boazdori Agree! I think this two features are critical for vs code replacing Spyder, if this is fix I won`t hesitate to uninstall Spyder.

@jflam
Copy link

jflam commented Aug 28, 2018

Thanks! @boazdori we're definitely going to be moving forward with building out this feature set (and others) soon. Stay tuned.

@martinbel
Copy link

I've just installed vscode. Honestly, it's hard to believe this functionality isn't present. We are talking about running code in the most popular shell for data analysis. uninstalling asap vscode. A piece of advice: try to mimic Rstudio's functionality, otherwise it's useless for data science. A text editor with iPython is just better.

@jflam
Copy link

jflam commented Oct 4, 2018

@martinbel did you try the Neuron extension linked above? We are working on turning the Neuron experience into the Microsoft experience.

@martinbel
Copy link

Thanks for the suggestion but I've just finished setting up vim + tmux + vim-slime that has all I need really. I'll give it a try later on, thanks!

@vasselai
Copy link

vasselai commented Jan 2, 2019

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

@brettcannon
Copy link
Member

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

@greazer
Copy link
Member

greazer commented Jan 3, 2019

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.

@saponas
Copy link

saponas commented Feb 1, 2019

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

@luabud
Copy link
Member

luabud commented Feb 7, 2019

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

@luabud luabud closed this as completed Feb 7, 2019
@ghost ghost removed the needs decision label Feb 7, 2019
@gui-leeahni
Copy link

@saponas this works. can combine opt1 with multi-command ext, too.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 26, 2019
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

No branches or pull requests