Skip to content

Run Selection/Line in xxx be more smart? #18105

Closed

Description

@gonghenghai

When we execute the command of Run Selection/Line in xxx, it only executes either the current line if nothing is selected or the selection. For example:

dtypes = {
    'date' : 'str',
    'item_code' : 'category',
    'branch_code' : 'category',
    'sale_qty' : 'float',
    'sale_val' : 'float',
    'return_qty' : 'float',
    'return_val' : 'float'
}

When I put my cursor at the first line, it would attempt to run dtypes = { only. But in the other IDEs such as RStudio, it's a little smart, it intelligently knows that the current line is part of a multiline statement and runs the whole statement.

Thanks.

Activity

  1. karthiknadig commented on Dec 2, 2021

    @karthiknadig
    Member

    Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.

  2. palindali commented on Dec 9, 2021

    @palindali

    This feature request is based on this question on Stack Overflow, for reference.

  3. brettcannon commented on Feb 3, 2022

    @brettcannon
    Member

    Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.

    We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most.

  4. cbrnr commented on Apr 5, 2022

    @cbrnr

    This would be a great feature. FWIW, maybe looking at how other extensions do it might help. For example, the Julia extension uses Shift+Enter, and the R extension uses cmd+Enter to run multiline statements without any selection.

  5. andycraig commented on Sep 1, 2022

    @andycraig

    Equivalent feature request for Jupyter extension: microsoft/vscode-jupyter#1471

  6. GitHunter0 commented on Sep 3, 2022

    @GitHunter0

    RStudio related issue rstudio/rstudio#9014

  7. andycraig commented on Nov 19, 2022

    @andycraig

    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!

  8. brettcannon commented on Nov 21, 2022

    @brettcannon
    Member

    There's currently no movement on this from our side, so if you do create an extension please let us know!

  9. kylebarron commented on Dec 1, 2022

    @kylebarron

    (This is mostly a copy of my comment in the vscode-jupyter thread here)

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

    Implementation

    • The github repo for this is here: https://github.com/kylebarron/vscode-jupyter-python

    • This is based off of https://github.com/nteract/hydrogen and https://github.com/nikitakit/hydrogen-python, specifically the code here. The idea is pretty simple:

      1. Include the current line plus any additional lines that have a greater initial indent

      2. Define a (user-editable) list of keywords that should be marked as "include this line even if it's at the same indent as the start line". So for example the default list includes elif and else, so that if your cursor is at the initial if line, the if plus elif plus else blocks all get evaluated at the same time.

        The default setting for this is: else, elif, except, finally, }, ], ).

      This heuristic generally works on most "clean" code; I assume it's possible to construct a case that would break the current implementation.

    • Using the block of text inferred by the above heuristic, call the jupyter.execSelectionInteractive command in the jupyter package

    Caveats

    • I personally really love IPython and find the rich outputs (like dataframe rendering) useful, so the extension I wrote only supports the jupyter extension at this time and not the bare python extension.

    • I wrote this extension super fast, so it probably has bugs and I don't want to make any promises about my maintenance of it going forward.

  10. KatlehoJordan commented on Jun 22, 2023

    @KatlehoJordan

    Any plans by the VSCode-python team to pick this up? It's been >18 months, and if I am to believe the screencast by Kyle Barron (@kylebarron), then there's already a starting point to build upon...

    This would be an excellent feature, 🤞

  11. brettcannon commented on Jun 22, 2023

    @brettcannon
    Member

    We will post when we have anything to specifically share. Unfortunately this issue doesn't even make it to the first page of upvoted issues. But when we take on redesigning any REPL experience we will make sure this is taken into consideration.

  12. anthonykim1 commented on Dec 14, 2023

    @anthonykim1

    Hi everyone! This is implemented in #21779 Feel free to check out the feature and also note there is setting to toggle Smart Send on/off with a warning that lets you know when feature usage is not possible due to invalid or deprecated Python code. Simply search for repl in extension setting.

  13. locked as resolved and limited conversation to collaborators on Jan 14, 2024
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