-
Notifications
You must be signed in to change notification settings - Fork 102
Python: Cmd+Enter does not send portion of multi-line statement above cursor to console #1260
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
Comments
same behavior is reproduced if you use sixty = (
20
+ 20
+ 20
) when you have the cursor on the first line, it stops sending the code up until the last closing parenthesis, but does not include it. so the user needs to run cmd+enter twice. we use this kind of notation a lot in pandas for method chaining. |
@jthomasmock pointed out that there's a new experimental Python feature in 1.84, "Smart Send": https://code.visualstudio.com/updates/v1_84#_python
We should see if we can hook this behavior up to Positron's Statement Range Provider so that we can take advantage of the Smart Send logic (presuming it's more sophisticated than what we have, which it probably is -- we just use indentation). |
I did some digging into how the Smart Send feature works. The workhorse is the Some thoughts:
|
I think falling back to a less sophisticated heuristic in the case of an ast parse failure is fine. This will work often, and critically the user won't be confused by inconsistent behavior (as we will always try to execute code). Also, diagnostics should be present that indicate that something is awry. I agree that tree-sitter could be a better solution but I also agree that this isn't worth the effort at this point. |
To reproduce, create a Python file with the following contents:
Place the cursor on the middle line and press Cmd Enter.
Only the middle line is sent to the Console. However, because this is one statement spread over 3 lines, the whole statement should be sent to the Console, not just the current line.
Note
This happens because the Python statement range finder does not ever look above the cursor point (only beneath it). https://github.com/posit-dev/positron-python/blob/main/src/client/positron/statementRange.ts
The text was updated successfully, but these errors were encountered: