Closed Shi-YuZhang closed 1 year ago
Hi @guoci, do you have any plan to fix this?
Can you do a screenshot to demonstrate? I cannot run the built-in "Execute line/selection in Python console" or "smart execute selection in console" in a .ipynb file. For .py files, it works when the current line has nothing below.
I am using Dataspell, so running .py file I have no problem with it at all. Just minor point from me for the improvement of it. Currently, you need to put your cursor at the beginning line of the block code in order to make it run. But in Rstudio, you can put your cursor at anywhere in the block code, Rstudio can recognized they all connected by the "pipe". Please let me know about your thought on it
Regarding to .ipynb file, there are several things need to further work on it:
But if you just enter 1 line, it can run properly, like this
I enjoyed your plugin very much as it bring me the same experiences with Rstudio. Here are just few thing I experienced today when using it
The reason for the cursor to be at the beginning is to allow for a nested code block to be run by itself. If a cursor is in a nested code block, what should be run? The current code block or the enclosing block? To allow the whole cell to be sent, there needs to be a new action to distinguish between a current block execute and a whole cell execute. I will check if that is easy to implement. I can do a smart execute on the last line of a cell. What is your IDE version?
Yes if the whole cell can be sent to the Python console, it would be great! Really looking for it!
I still can't run the last line. I am using Data Spell 2023.1.1 RC Here is the error for the IDE: java.lang.NullPointerException: Cannot invoke "com.intellij.lang.ASTNode.getElementType()" because the return value of "com.intellij.psi.PsiElement.getNode()" is null at com.jetbrains.python.actions.PySmartExecuteSelectionAction.getEvaluableParent(PySmartExecuteSelectionAction.java:62) at com.jetbrains.python.actions.PySmartExecuteSelectionAction.smartExecuteCode(PySmartExecuteSelectionAction.java:125) at com.jetbrains.python.actions.PySmartExecuteSelectionAction.actionPerformed(PySmartExecuteSelectionAction.java:189) at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.java:333) at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:47) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:585) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$9(IdeKeyEventDispatcher.java:707) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105) at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$10(IdeKeyEventDispatcher.java:707) at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:356) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.doPerformActionInner(IdeKeyEventDispatcher.java:704) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:648) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:596) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:480) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:469) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:225) at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.kt:598) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:568) at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:68) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:349) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:348) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:348) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:343) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:994) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:113) at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:994) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$4(IdeEventQueue.kt:343) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:385) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
@ntluong95 Can you upgrade to version 2023.1.2
and retry?
I just updated, which has the same error
@ntluong95 Can you also check the version of the plugin? Is it 0.1.8
?
Yes
Yes
@ntluong95 I reproduced it, will fix.
Great. Please check also the possibility to send the whole cell to Python console
Fixed, just uploaded a new version, but will need to wait for JetBrains to approve. Try the attached if you don't want to wait.
To use it, change the extension from zip
to jar
.
pycharm-smart-execute.zip
Excellent. It fixed! Thank you for the prompt help
Great. Please check also the possibility to send the whole cell to Python console
The notebook mode is closed source, so I cannot do that.
I just curious why in Notebook, you can run part of the code or the whole cell by highlighting code, then it will send to Python Console. I just want to have a shortcut to run the whole cell without highligting everything, so the code to be sent to the console
@ntluong95 It might be possible to implement without relying on the closed-source components but may not be easy. I will work on it when I have time. Closing this since the current issue is resolved.
@ntluong95 added "Execute cell in console" feature, see https://github.com/guoci/pycharm-smart-execute/releases/tag/0.1.11
I tested and it works very well. You work my harder than Dataspell dev team 🤣🤣🤣 Unexpectedly but very good, now the feature I told you yesterday; "But in Rstudio, you can put your cursor at anywhere in the block code, Rstudio can recognized they all connected by the "pipe" now work with .py file as well. As long as the block of code are connected either inside the parathesis, or under the def, you can put your cursor any where to run it
But there is one issue, see this picture below for more detail. There are 2 block codes in the cell, but the action can only capture and run the first one only
Btw, in Jupyter lab you have the feature "Run selected line or highlighted text", I requested this feature for DataSpell for so long but they slowly working on it. Do you know any possible to have it?
It can not work when the current line is the last line of a cell in Jupyter Notebook if there exists no empty line under the line.