Vscode-jupyter: `shift + enter` broken again

Created on 14 Jul 2019  路  34Comments  路  Source: microsoft/vscode-jupyter

Issue Type: Bug

reference:
https://github.com/microsoft/vscode-python/issues/3397
https://github.com/microsoft/vscode-python/issues/5621

Below is my current keyboard shortcuts json, which was working just fine prior to the most recent vscode update.

Before, when:

  1. the editor had focus,
  2. no text was selected in the editor,
  3. in a file with #%% code 'cell' markers,

the entire 'cell' would run in the Python Interactive Pane and the focus would advance to the next 'cell' in the editor.

Now after the most recent vscode update and given the same conditions, only the line that the cursor is currently on is run in the Python Interactive Pane.

[
    {
        "key": "ctrl+shift+alt+enter",
        "command": "python.execSelectionInTerminal",
        "when": "editorFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
    },
    {
        "key": "shift+enter",
        "command": "-python.execSelectionInTerminal",
        "when": "editorFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
    },
    {
        "key": "shift+enter",
        "command": "python.datascience.execSelectionInteractive",
        "when": "editorFocus && !python.datascience.hascodecells && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
    },
    {
        "key": "shift+enter",
        "command": "python.datascience.execSelectionInteractive",
        "when": "editorFocus && python.datascience.hascodecells && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
    },
    {
        "key": "shift+enter",
        "command": "python.datascience.execSelectionInteractive",
        "when": "editorFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
    },
    {
        "key": "shift+enter",
        "command": "python.datascience.runcurrentcelladvance",
        "when": "editorFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && editorLangId == 'python'"
    }
]

Extension version: 2019.6.24221
VS Code version: Code 1.36.1 (2213894ea0415ee8c85c5eea0d0ff81ecc191529, 2019-07-08T22:59:35.033Z)
OS version: Windows_NT x64 10.0.17763


System Info

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz (4 x 2496)|
|GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_deferred_display_list: disabled_off
skia_renderer: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: disabled_off
webgl: enabled
webgl2: enabled|
|Load (avg)|undefined|
|Memory (System)|15.88GB (8.83GB free)|
|Process Argv||
|Screen Reader|no|
|VM|0%|


All 34 comments

Restarting vscode numerous times did nothing. With absolutely no other changes, restarted vs code for the umpteenth time and now it is working. No idea what the root cause was.

Started happening again. I have not figured out the exact pattern, but somehow the Python Interactive Pane loses 'prior' focus and shift + enter stops working. If I put the cursor in the code entry point at the bottom of the Python Interactive Pane, then put the cursor back into the text editor, then shift + enter works again.

Either switching windows, or using menus, or some other typical user operation causes it to fail again. So I have to keep manually putting the cursor into the bottom of the Python Interactive Pane and back into the editor repeatedly, which obviously gets tedious.

I'm experiencing the Shift+Enter problem too with a fully installed VSCode (v1.36) on my Surface Pro, which is running Windows 10.

Interestingly, Shift+Enter works fine on my work machine, which is also running Windows 10 and a portable version of VSCode v1.36.1 (I used the zip installer as we don't have admin rights).

I haven't tried clayms 'putting the cursor into the bottom of the Python Interactive Pane and back into the editor' method yet.

It seems that shift + enter breaks after simply editing the code in the editor.

Given that this is supposed to be an 'interactive' session, this happens very frequently.

So if I want to use the runcurrentcelladvance option, I have to manually put the cursor in the bottom of the Python Interactive Pane and back into the editor. Otherwise, I can just select the code I want to run and shift + enter will still run the selected, given the key bindings I have above.

Unfortunately for me, Shift+Enter doesn't work at all.

Version: 1.36.1 (user setup)
Commit: 2213894ea0415ee8c85c5eea0d0ff81ecc191529
Date: 2019-07-08T22:59:35.033Z
Electron: 4.2.5
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362

@mpatkinson7 Did you try the key bindings I have in the first post of this issue?

Do either of you have the 'enableCellCodeLens' set to false? There's a bug (#5879) where if you have the code lens disabled, shift+enter stops sending output to the interactive window.

Yes, the Python Data Science Code Lens is enabled! Thanks.

@clayms OK. I have tried the key bindings in the first post of this issue! Yes, the Interactive Windows now works. Thanks. Being a newbie with VSCode (& Python & GitHub for that matter) I am still finding my way around.

I'm coming from Atom/Hydrogen, and I'm just curious, are there any plans to get rid of the "#%%" tags to mark code cells?

When using Hydrogen a code cell is always either the current line, or whatever I have highlighted. I think it is much more intuitive. I spent 20mins googling why "Run cell and advance" hotkey in VS Code does not work just to find out that in VSCode I need to mark code cells with "#%%" :)

The short answer, no. There's no way to say what a code cell in a python file is otherwise.

We support not using them though. On a file without #%%, shift+enter will behave like Hydrogen. If no selection, the current line is sent. If selection, the selection is sent. However you have to flip the following setting (otherwise shift+enter sends to the normal terminal)
image

We believe that this issue is generally fixed. Please comment if you're finding it is not. Please provide as much detail as possible if that's the case.

The short answer, no. There's no way to say what a code cell in a python file is otherwise.

But how does Hydrogen do it? Both Atom and VS Code are built on Electron, so I was hoping that its technically possible to do it. ;-)

I tried playing with the Send Selection to Interactive Window option. Without #%% tags shift+enter behaves simply as if I pressed enter. i.e. it inserts new line if no text is selected, or removes the selected text and inserts new line if anything is selected, with nothing being sent to terminal or interactive window.

But how does Hydrogen do it? Both Atom and VS Code are built on Electron, so I was hoping that its technically possible to do it. ;-)

Sorry I worded that wrong. You can (or at least you should be able to) send anything as a cell. With no cell markers, and Send Selection to Interactive set, it should be sending code the same way Hydrogen does.

I tried playing with the Send Selection to Interactive Window option. Without #%% tags shift+enter behaves simply as if I pressed enter. i.e. it inserts new line if no text is selected, or removes the selected text and inserts new line if anything is selected, with nothing being sent to terminal or interactive window.

That sounds like a bug. Can you try the same thing with our insider's build. I fixed some bugs around shift+enter recently.

I installed the .vsix file, but it did not seem to change the behavior. Without "#%%" markers cells are not being sent to the interactive window.

I'll try again on another machine with fresh installation and let you know how it goes.

Make sure this option is set too:

image

shiftenter

Just tried on my personal machine, with a fresh VS Code install + insider's build you linked, and the option enabled. Unfortunately the behavior is the same as I described earlier.

Okay let's make sure the install worked. What does this say?

image

And then let's make sure the keyboard shortcut is registered.

What does this say?
image

image
2019-07-24 21_49_38-Keyboard Shortcuts - snippets - Visual Studio Code

I'm posting the screenshot for Run Current Cell and Advance, as that is where my problem is.

Actually your problem should be with Run selection. That's what handles shift+enter when you have no cells already defined.

The vsix for the insider's build also didn't install. The version you're showing is the last released version.

You should try uninstalling the python extension from the extensions tab, and then click on the '...' at the top of the extensions tab to install the insider's build vsix. Then reload VS Code.

The version I _should_ see is 2019.7.26477-dev?

image

I uninstalled the extension, reloaded VS code, installed from .vsix, reloaded again, and this is what I see:

image

Hmm. Try typing this in the extensions tab instead:

@installed

What does that list?

And yes you should see the 2019.7.26477-dev (or whatever version you downloaded)

I did another reinstall but now also deleted the extensions folder which is not removed during uninstallation.

Right after loading .vsix it shows the correct version:

image

Then it asked me to reload VS Code, which I did, and right after reloading its back to the previous version:

image

This is taking a lot of your time. I can just wait for the fix to be included in an official release, but if you need any more info I'm happy to help.

@karrtikr it sounds like auto update is breaking the insider's build?

@joolius it's not a problem. I'd love to get to bottom of why shift+enter doesn't work.

Okay seems like there's a new way to keep the insider's build. After you install the insider's vsix, you have to set this value (before you reload):

image

Hopefully this won't always work this way, but that's the current behavior.

The extension is now loaded, but shift+enter does not run and advance, it just runs code in current line and the cursor stays on it.

But it runs it in the interactive window? That's by design right now. It's behaving like shift+enter for the terminal.

Yes, it does. I am just a little puzzled why the command is called "run and advance", since it stays in the same line.

It's not. The command you're actually running is "Run Selection/Line in Interactive Window". There is actually 3 commands that map to shift+enter based on the context:

image

Depending upon the 'when' clause, different commands are run.

Run current cell needs a 'cell'. At least right now. We could probably redefine it if there are no cells, just use the current line or current selection. Seems like it would be nice to just shift+enter your way through a file.

Feel free to add a suggestion/bug to that effect.

current line or current selection. Seems like it would be nice to just shift+enter your way through

That would be very useful, and people migrating from atom/hydrogen would feel at home ;-) Right now I have to manually move the cursor to the next line and it feels like wasted effort. I'm a statistician and my workflow is very interactive. I almost never run the entire script in one go. I run a line, then the next, then maybe go back, etc.

Was this page helpful?
0 / 5 - 0 ratings