hoangKnLai / vscode-ipython

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

Send multi-line selection as a block #17

Closed cameronbracken closed 1 year ago

cameronbracken commented 2 years ago

When multiple lines are selected and It would be great to have all the lines sent as a block instead of one by one. When lines are copy-pasted this is how they are input.

hoangKnLai commented 2 years ago

Is this not the case? Here is an example of multi-cursors each with single or multi-lines or words selected and run. Note that all lines across all cursor are indent corrected before being sent to IPython. image

Also, a single multi-line selection with corrected indentation:
image

cameronbracken commented 2 years ago

Your screenshots look like how I would expect it to work, but when I run "IPython: Run Code Selection(s) or Line at each Cursor", it looks like this for me: Screen Shot 2022-09-12 at 9 39 33 AM Screen Shot 2022-09-12 at 9 39 57 AM

Screen Shot 2022-09-12 at 9 40 40 AM Screen Shot 2022-09-12 at 9 40 58 AM

hoangKnLai commented 2 years ago

That is interesting. The older version does execute line-by-line but should be fixed in v2022.9.x. Can you confirm the version of the extension you're using?

ma-sadeghi commented 2 years ago

I'm using the latest version, and it's line-by-line

cameronbracken commented 2 years ago

I'm on v2022.9.2

hoangKnLai commented 2 years ago

K. Let's look at something else since I'm unable to replicate the problem. Can you guys provide a bit on the computing system/environment you're using? Like, Window vs. Linux.

Also, I've found that the Jupyter extension tends to conflict with this extension. It might help with diagnoses by disabling the Jupyter extension to check.

hoangKnLai commented 2 years ago

I was able to replicate the problem when testing on a Linux Debian environment. Hopefully it is not the case that IPython behaves differently between the two systems. Build and test the extension on Linux requires npm, yo, vsce packages and they are so far a serious pain to build (still can't build them all yet).

"There should be one-- and preferably only one --obvious way to do it." Zen of Python.

hoangKnLai commented 2 years ago

It appears to be a case of IPython behaving differently between Linux and Window. Anyhow, I might the hotfix for this. Will have to test it out more releasing this weekend.

cameronbracken commented 2 years ago

Thanks for looking into this! I am on MacOS so it is probably behaving similarly to Linux in this case.

hoangKnLai commented 1 year ago

Ok. Tested the v2022.09.3 fix and it works on both Linux and Window. If it works for you, please confirm and close this issue.

Also, in case you're interested, the fix includes:

There might be an unintended effect with the copy/paste:

A better solution likely includes:

cameronbracken commented 1 year ago

It works great on MacOS too! Thanks so much for the fix.

And thanks for the heads up about the potential slowness when the clipboard buffer is large.

cameronbracken commented 1 year ago

Looks like we are back to the old behavior of sending one line at a time, on MacOS at least. I'm using ipython v2023.2.3 and vscode 1.76.0.

hoangKnLai commented 1 year ago

Sorry about that. Forgot to test on Linux/Unix system. Will release a fix soon.

Anyhow, have you try out the file option to send command? It should be quite a bit faster than the clipboard when it comes to large block of code.