Skip to content

"Run Selection/Line in Python Terminal" should automatically select the surrounding block of code #17209

Closed

Description

Discussed in #16541

Originally posted by nchammas June 22, 2021
Consider this little example:

spark = (
    SparkSession.builder
    .conf('spark.jars.packages', 'org.apache.iceberg:iceberg-spark3-runtime:0.11.1')
    .getOrCreate()
)

Say my cursor is on the line that contains .conf(), with no text highlighted. If I hit Shift + Enter (python.execSelectionInTerminal), then only the .conf() line will be sent to the terminal, and it will fail with a syntax error.

What I want is to run the complete block of code, starting with spark = and going all the way to the closing parenthesis. To do that today, I need to highlight all the lines myself.

It would be great if this extension automatically detected and ran the block of code surrounding the current cursor position, specifically in the case where no text is highlighted. That way I could place my cursor anywhere inside the above example block of code, hit Shift + Enter, and the entire block of code will be sent to the terminal. I don't need to explicitly highlight the lines myself.

Having this ability lends to a more Jupyter-like experience, without needing to define explicit cells or move to notebooks. And it makes it much easier and quicker to send multi-line units of code -- like the above example, or function definitions, or if blocks, etc. -- to the terminal.

It seems like the extension should have enough information to correctly detect the block of code surrounding the current cursor position. In fact, if you move your cursor somewhere inside the above block of code and repeatedly run "Expand Selection" (editor.action.smartSelect.expand) it will incrementally grow the selection until the whole block is selected. Perhaps the underlying machinery can be reused to implement this idea.

Activity

  1. brettcannon commented on Sep 1, 2021

    @brettcannon
    MemberAuthor

    Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 5 👍 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. brettcannon commented on Nov 1, 2021

    @brettcannon
    MemberAuthor

    Thank you for submitting your feature request and everyone who considered it! Unfortunately this issue did not receive enough votes over the allotted time, and so we are closing the issue.

  3. locked as resolved and limited conversation to collaborators on Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions