-
Notifications
You must be signed in to change notification settings - Fork 299
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
Auto-detect code blocks around the cursor location. Shift-enter executes the entire block #1471
Comments
Just to say. This might be an improvement and we should totally consider it. But right now we had shift-enter match what the python extension does when sending code to the terminal. So if we have shift-enter move and advance we won't match the main python extension any more. Though maybe we can consider having both advance on shift-enter. |
Do microsoft/vscode-python#1 for sure. Enter a new issue for microsoft/vscode-python#2 if we don't find an easy solution. |
No. 2 is on the top of my list of things that would improve VS-py for me, cf. microsoft/vscode-python#480 |
@IanMatthewHuff You would match Jupyter Notebook/Lab behaviour though if Shift-Enter advanced after execution and Ctrl-Enter executed in place. |
@aldanor Thanks for the heads up on Ctrl-Enter. I'll look into that, at a minimum I could maybe just add a new Execution in place command and leave it unbound so that users could add it to the keybinding of their choice. |
@IanMatthewHuff That would be great, yea - at the very least to be able to remap it to user's liking without having to create macros manually. |
This PR for the PyCharm editor shows a video of the sort of features that No. 2 could provide (automatically sending whole class and function definitions): JetBrains/intellij-community#711 It would be nice if the following blocks were supported:
EDIT: The cursor would ideally go to the next code block after running the current code block. |
This relates to microsoft/vscode-python#13495. Would make a lot of sense to implement them together. |
Auto-detection of code blocks is still the feature that would make the biggest difference to my VS Code Python experience. We added something like this to one of the VS Code R extensions. I was thinking of putting my hand up to do an external contributor PR for the case of detecting blocks like
if True: # Cursor on this line
print("hello world")
# Cursor on any line
if all([
True,
'a' in {
'a',
'b',
},
len(")") > 0,
]):
print("hello world") If the extension is already parsing the file and maintaining an AST with line numbers, these two cases can be handled just as easily. If the extension isn't doing that, then handling the complicated case is a fair amount of work. This file is how we handle it for R: https://github.com/Ikuyadeu/vscode-R/blob/master/src/selection.ts Most of the code is dedicated to handling nested parentheses/brackets/braces over multiple lines. As a simpler first step that would probably handle most real-world cases, you could use this heuristic: Proposed heuristic If the cursor is on a line ending in a colon Would you be interested in an external contributor PR for this proposed heuristic method? |
I'm also interested in this feature. I think @andycraig's heuristics sound reasonable, and I think this would be a huge improvement for workflows that include use of the Interactive Window. I also filed #8658 which I think people interested in this might also want to see. |
Hi @rebornix - messaging you since you're assigned to this issue currently. This is still the feature that would improve the VS Code Python experience the most for me. Is there any interest in the heuristic approach I proposed above? If so I could work on a PR. If not I could create an extension to provide this functionality. Note that there are two feature requests in this issue:
I'm mainly talking about 2. Thanks! |
microsoft/vscode-python#18105 similar issue which I think is better described |
I'd love this block-detection functionality so I'm going to have a try at creating an extension to provide it. My plan is to use the Python Extension Template and make it compatible with both the VS Code Jupyter and VS Code Python extensions. In the meantime, if there's any move towards providing this functionality within the VS Code Jupyter or VS Code Python extensions themselves, please let me know as I'd very happily leave it to the pros! |
I used this functionality in Atom + Hydrogen every day, and now that Atom is dying in more places, I got so frustrated without this functionality in vscode that I made my own vscode extension for this. In this screencast, the only keyboard shortcut used is Shift+Enter, which runs a block and moves down to the start of the next block (Ctrl+Enter/Cmd+Enter are currently mapped to "run the current block but don't move the cursor) Screen.Recording.2022-11-28.at.10.27.28.PM.movImplementation
Caveats
(Thanks @andycraig for linking to this issue from #12176.) |
This should now be supported in VSCode since October 2023. See: https://code.visualstudio.com/updates/v1_84#_python |
That's really exciting! The screenshot in that link shows it working in the Python terminal; does it also work for Python inside Jupyter, not just in the REPL? |
That feature is just for the python REPL at this point. |
I just don't like that part, I want the option to leave the cursor where it is, because frequently I need to run the same block over and over again |
The text was updated successfully, but these errors were encountered: