Skip to content

Commit ec8ba9b

Browse files
committed
🐛 Fix issue with evaluation of expr at python3.6
1 parent ee5b1f1 commit ec8ba9b

File tree

4 files changed

+347
-283
lines changed

4 files changed

+347
-283
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88

99

1010
group = "com.uriyyo.evaluate_async_code"
11-
version = "1.6"
11+
version = "1.7"
1212

1313
repositories {
1414
mavenCentral()
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,18 @@
11
package com.uriyyo.evaluate_async_code
22

3-
import com.intellij.execution.ExecutionResult
4-
import com.intellij.xdebugger.XDebugSession
5-
import com.jetbrains.python.debugger.PyDebugProcess
3+
import com.intellij.execution.configurations.GeneralCommandLine
4+
import com.intellij.execution.configurations.ParamsGroup
5+
import com.intellij.openapi.project.Project
66
import com.jetbrains.python.debugger.PyDebugRunner
7-
import com.jetbrains.python.debugger.PyDebugValue
87
import com.jetbrains.python.run.PythonCommandLineState
9-
import java.net.ServerSocket
108

119
class AsyncPyDebugRunner : PyDebugRunner() {
12-
override fun createDebugProcess(
13-
session: XDebugSession,
14-
serverSocket: ServerSocket,
15-
result: ExecutionResult,
16-
pyState: PythonCommandLineState
17-
): PyDebugProcess {
18-
if (!isSupportedVersion(pyState.sdk?.versionString))
19-
return super.createDebugProcess(session, serverSocket, result, pyState)
20-
21-
return object : PyDebugProcess(
22-
session, serverSocket, result.executionConsole, result.processHandler, pyState.isMultiprocessDebug
23-
) {
24-
override fun evaluate(expression: String?, execute: Boolean, doTrunc: Boolean): PyDebugValue {
25-
if (expression?.isAsyncCode == true) {
26-
// FIXME: why so terrible? this code must be refactored
27-
super.evaluate(PLUGIN, true, true)
28-
29-
// TODO: Does Kotlin has smth like python repr?
30-
val fixedExpression = expression
31-
.replace("'''", "\\'\\'\\'")
32-
.let { "'''$it'''" }
33-
34-
val code = "__async_result__ = __import__('sys').__async_eval__($fixedExpression, globals(), locals())"
35-
super.evaluate(code, true, doTrunc)
36-
37-
return super.evaluate("__async_result__", false, doTrunc)
38-
}
39-
40-
return super.evaluate(expression, execute, doTrunc)
41-
}
10+
override fun configureDebugParameters(project: Project, debugParams: ParamsGroup, pyState: PythonCommandLineState, cmd: GeneralCommandLine) {
11+
if (isSupportedVersion(pyState.sdk?.versionString)) {
12+
asyncPyDevScript().writeText(PYDEVD_ASYNC_MAIN_PLUGIN)
13+
debugParams.addPyDevAsyncWork()
4214
}
43-
}
4415

16+
super.configureDebugParameters(project, debugParams, pyState, cmd)
17+
}
4518
}

0 commit comments

Comments
 (0)