REPL Smart Shift+Enter and Dynamic Smart Cursor Cherry Pick #21976
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry Picked REPL Smart selection + move to next line after rebasing:
Feature Request from: #18105 #21838
#19955 (For Execute line/selection and advance to next line, referred to as dynamic smart cursor hereby)
Open Issue: #21778 #21838
Steps in implementing REPL Smart Send (smart shift+enter to the REPL) and dynamic cursor move aka. Move to Next Line (next executable line of code to be more precise):
Figure out the workflow of where things start and run when user clicks on run selection/line
Send the content of selection & document to the Python Side from Typescript side.
Respect and follow previous logic/code for EXPLICIT selection (user has highlighting particular text they want to send to REPL), but otherwise, use newly created smart send code.
Receive content of document & selection in Python Side
Use AST (standard library) to figure out if selection if selection is part of, for example, dictionary, but look for nodes and how each relates to the top level. If some selection is, for example part of a dictionary, we should run the whole dictionary. Look at how to do this for all top level, so that we run the Minimum Viable Block possible. (For example, if user selects part of a dictionary to run in REPL, it will select and send only the dictionary not the whole class or file, etc)
Receive the commands to run in typescript side and send it to the REPL
After the user has ran shift+enter(non highlight, meaning there was no explicit highlight of text), thus the incurring of smart send, and we have processed the smart selection, figure out the "next" executable line of code in the currently opened Python file.
After figuring out the "next" line number, we will move user's cursor to that line number.
Notes:
To be shipped after dropping Python3.7 support, since end_lineno, which is critical in smart shift+enter logic, is only for Python version GREATER than 3.7
Code in regards to this feature(s) should be wrapped in standard experiment (not setting based experiment)
Respective Telemetry should also be attached
EXPLICIT (highlight) selection of the text, and shift+enter/run selection should respect user's selection and send AS IT IS. (When the user selects/highlight specifically what they want to send, we should respect user's selection and send the selection as they are selected)
Smart Shift+Enter should be shipped together with dynamic smart cursor movement for smoothest experience.
This way user could shift+enter line by line (or more accurately top block after another top block) as they shift+enter their code.
Be careful with line_no usage between vscode and python as vscode counts line number starting from 0 and python ast start as normal (starts from line 1)) So vscode_lineno + 1 = python_ast_lineno