hoangKnLai / vscode-ipython

VSCode Extension integrating Editor with IPython console.
MIT License
18 stars 5 forks source link

Send line or selection and advance to next line #18

Closed cameronbracken closed 1 year ago

cameronbracken commented 2 years ago

When "Run Code Selection(s) or Line at Each Cursor" is run it would nice to have the option to advance the cursor to the next line.

An extra bonus would be to have the command not just run the current line but also run subsequent lines when a code statement is broken over multiple lines.

hoangKnLai commented 2 years ago

When "Run Code Selection(s) or Line at Each Cursor" is run it would nice to have the option to advance the cursor to the next line.

This can be tricky as each selection can be single or multi line and "next line" may just be an empty line or part of a code block.

I also thought of the "extra bonus 😉". Though it started to spiral into a whole other extension for text selection and navigation. The whole idea though starting to coincide with vscode vim extension so I'm currently thinking of ways to differentiate.

Anyhow, the suggestion is taken but likely will be a long time (at my pace) to get this resolves. Unless there are more requests for this to be prioritize.

cameronbracken commented 2 years ago

Thanks for the thoughtful reply. My motivation for the bonus is coming from the way RStudio behaves, if you have a cursor anywhere in a multi line statement it will send that entire statement. It does sound tricky to implement in general though. In any case, thanks for this super useful extension!

AmerM137 commented 1 year ago

A separate command to run line and move to next line would be great too and (I assume) simple to implement. I am coming from Spyder and that's usually the default. I can hit the keybinding multiple times and run the code line by line. Maybe an option can be added to configure the current command so it moves to the next line automatically?

Running the enclosing statement that @cameronbracken is mentioning would be nice as well, but I can see how it can be tricky.

hoangKnLai commented 1 year ago

I can hit the keybinding multiple times and run the code line by line. Maybe an option can be added to configure the current command so it moves to the next line automatically?

Not sure if this would work but I can try and add a command executeLineAndMoveToNextLine for all cursors. I can use a keybinding suggestion if you have one.

Side note: due to the race condition in which command sent cannot be pushed to a stack, a rapid fire of send+run code line by line may randomly skips command(s) dependent on the command runtime.

Running the enclosing statement that @cameronbracken is mentioning would be nice as well, but I can see how it can be tricky.

This is likely doable I think if the python syntax tree can be access via intellisense. My current skill in working with the language tree / intellisense is likely at the ignoramus 😎 level. So for now, you can simply wrap the code statement in a temporary cell block instead 😉.

hoangKnLai commented 1 year ago

Just release v2023.8.0 with runLineAndAdvance without keybinding. Let me know how this works for you :). Thanks!

AmerM137 commented 1 year ago

Just release v2023.8.0 with runLineAndAdvance without keybinding. Let me know how this works for you :). Thanks!

Just tested it out and it works great! Usually I do "alt+enter" for the keybinding but I think leaving it up to the user to choose is just fine.