Closed ubaldot closed 2 years ago
@hoangKnLai, I think this would be a very helpful feature. If you want, you could point me to the part where this would be implemented and I could try to draft a PR.
Happy to have someone else working on this project 😄.
Hmm. Where to start...
At the moment, the framework is like this:
cmd, nExec = getIpythonCommand(document, selection)
--> execute(terminal, cmd, nExec)
execute
simply sendText
to console with some time delay between each send An option is to look into extending runCursor()
which uses the framework above.
P.S. I really should start actually commenting the code properly to typescript standard.
Hi, thanks so much for this extension it's working great for me! I would also find the single line execution useful, so I'd like to second Ubaldo79's comment. In the meantime, as a work around for anyone else who'd like this, a combination of the multi-command extension and this one has been working for me with this key binding in keybindings.json
:
{
"key": "f9",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"expandLineSelection",
"ipython.runSelections",
"cursorRight"
]
}
}
Plan to deploy today's update soon which includes:
run line at cursor
that also works for multi-cursor selections.
vscode.sendText() to IPy.In[n] to IPy.Out[n]
.Better handling of code block and cells:
Left trim line while preserving python
indentation. E.g.,
# Editor:
for _ in range(4):
# %% Indented Cell with empty line(s) can now be executed correctly
i = 1
print('test 1')
if i % 2:
print('i % 2')
print('i % 2 + 1')
# IPython:
In [1]: # %% Indented Cell 1
...: print('test 1')
...: if i % 2:
...: print('i % 2')
...: print('i % 2 + 1')
...:
test 1
Out[n]: test 1
and just test 1
. Definitely not very pythonic
😉.
# Editor:
# NOTE: consequently also handle this hanging case
if True: # a code block
# ... some other code
# %% Indented Cell in a code block
print('test 2\r\n test 3')
if
code block but inside a cellprint([1, 2, 3, 4, '5'])
```ipython
# IPython:
In [2]: # %% Indented Cell 2
...: print('test 2\r\n test 3')
...: print([1, 2, 3, 4, '5'])
test 2
test 3
[1, 2, 3, 4, '5']
Works like a charm! Bravo.
Improvement suggestion: A very useful feature would be to send only the current line. Both
Matlab
andSpyder
have it and it is widely used by the users of these apps. I am sure thatVSCode
users would enjoy it as well! :)