1
1
package com.uriyyo.evaluate_async_code
2
2
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
6
6
import com.jetbrains.python.debugger.PyDebugRunner
7
- import com.jetbrains.python.debugger.PyDebugValue
8
7
import com.jetbrains.python.run.PythonCommandLineState
9
- import java.net.ServerSocket
10
8
11
9
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()
42
14
}
43
- }
44
15
16
+ super .configureDebugParameters(project, debugParams, pyState, cmd)
17
+ }
45
18
}
0 commit comments