Skip to content

Commit d08b752

Browse files
committed
🐛 Fix issue when Exception doesn't raised to caller
1 parent f686c79 commit d08b752

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/com/uriyyo/evaluate_async_code/AsyncPyDebugRunner.kt

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.jetbrains.python.debugger.PyDebugProcess
66
import com.jetbrains.python.debugger.PyDebugRunner
77
import com.jetbrains.python.debugger.PyDebugValue
88
import com.jetbrains.python.run.PythonCommandLineState
9+
import com.jetbrains.rd.util.string.printToString
910
import java.net.ServerSocket
1011

1112
class AsyncPyDebugRunner : PyDebugRunner() {
@@ -22,7 +23,20 @@ class AsyncPyDebugRunner : PyDebugRunner() {
2223
session, serverSocket, result.executionConsole, result.processHandler, pyState.isMultiprocessDebug
2324
) {
2425
override fun evaluate(expression: String?, execute: Boolean, doTrunc: Boolean): PyDebugValue {
25-
super.evaluate(PLUGIN, true, true)
26+
if (expression?.isAsyncCode == true) {
27+
// FIXME: why so terrible? this code must be refactored
28+
super.evaluate(PLUGIN, true, true)
29+
30+
val fixedExpression = expression
31+
.printToString()
32+
.replace("\n", "\\n")
33+
34+
val code = "__async_result__ = __async_eval__($fixedExpression, globals(), locals())"
35+
super.evaluate(code, true, doTrunc)
36+
37+
return super.evaluate("__async_result__", false, doTrunc)
38+
}
39+
2640
return super.evaluate(expression, execute, doTrunc)
2741
}
2842
}

src/main/java/com/uriyyo/evaluate_async_code/AsyncPyDebugUtils.kt

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package com.uriyyo.evaluate_async_code
22

33
import com.jetbrains.python.psi.LanguageLevel
44

5+
val String.isAsyncCode
6+
get() = "async" in this || "await" in this
7+
58
fun isSupportedVersion(version: String?): Boolean =
69
version !== null && LanguageLevel
710
.fromPythonVersion(version.split(" ").last())

0 commit comments

Comments
 (0)