Skip to content

Sending block of codes behaves differently in Python script with cell and without cell #3907

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

Open
Fred-Wu opened this issue Jul 6, 2024 · 3 comments

Comments

@Fred-Wu
Copy link

Fred-Wu commented Jul 6, 2024

Positron: 2024.07.0-15
OS: MacOS

Without cell:

Only CTRL+ENTER works, and works when placing cursor anywhere in the block
image

image

However, with cell:
Both CTRL+ENTER and SHIFT+ENTER work, but behave differently

SHIFT+ENTER works when placing the cursor anywhere in the block, but NOT CTRL+ENTER (it only works when placing the cursor in the beginning of the block)

CTRL+ENTER

image image
@Fred-Wu Fred-Wu added the bug Something isn't working label Jul 6, 2024
@juliasilge
Copy link
Contributor

Yep, similar to #3908, this is currently behaving as designed/expected but we are happy to hear feedback about what you were expecting or would prefer.

Shift+Enter is a keyboard shortcut specific to code cells to run the whole code cell. There is a whole set of keyboard shortcuts specific to these kinds of cells:

Screenshot 2024-07-07 at 8 36 29 PM

Similar to what I outline in #3908, the keyboard shortcut to execute the current statement looks for the immediate current complete statement. We do have some open questions about Python statement detection in #3464 if you'd like to add your experiences and preferences there.

@juliasilge juliasilge added lang: python and removed bug Something isn't working labels Jul 8, 2024
@petetronic
Copy link
Collaborator

It looks like though that there is an issue with code block detection? Opening for RC?

@petetronic petetronic added this to the Release Candidate milestone Jul 10, 2024
@seeM
Copy link
Contributor

seeM commented Jul 11, 2024

@petetronic yes it looks like there's a bug with our fallback regex-based detector. Here's a simple repro:

  1. Write this to a file:

    x = # this line is to intentionally create a syntax error so that we fall back to the regex-based detector
    y = [
        0,
    ]
  2. Place the cursor on the 0, line and press Cmd+Enter.

  3. Only the line 0, gets sent to the console.

It should send the entire y definition to the console.

Note that it works as expected without the x = syntax error.

Possible solutions

We can try to look into fixing this case for the regex-based detector. I wonder though if we should consider moving the AST-based detector to a parser that supports syntax errors (originally raised this here).

I haven't looked into all of the options, but I know that parso (used by Jedi and maintained by the same person) does support error recovery.

@juliasilge juliasilge modified the milestones: Release Candidate, Post-RC Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants