You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Send extra newline for 'Run Selection/Line in Python Terminal' to immediately execute #169
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.
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
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.
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.
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:
publicasyncsendText(text: string): Promise<void>{awaitthis.ensureTerminal();this.terminal!.show(true);this.terminal!.sendText(`${text}`);// send carriage return to make code executeawaitnewPromise(resolve=>setTimeout(resolve,100));this.terminal.sendText('\u000D',false);awaitnewPromise(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:
Activity
DonJayamanne commentedon Nov 14, 2017
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.
DonJayamanne commentedon Nov 14, 2017
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 commentedon Nov 14, 2017
Possibly related to https://github.com/DonJayamanne/pythonVSCode/issues/1180
DonJayamanne commentedon Feb 5, 2018
ruben-aghayan are you able to test this on the latest version of VS Code and let us know whether it works.
62 remaining items
vasselai commentedon Jan 2, 2019
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.
brettcannon commentedon Jan 3, 2019
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.
greazer commentedon 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 commentedon Feb 1, 2019
I've been looking at a few ways to address this issue. Here are some approaches:
{ "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" } }{ "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 --existingluabud commentedon Feb 7, 2019
We're not fixing the issue as stated because of limitations with the terminal. Closing in favor of #727
gui-leeahni commentedon Feb 26, 2019
Scott Saponas (@saponas) this works. can combine opt1 with multi-command ext, too.