From ef22c35aac6236cbaff0f60e176c078030499d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82uszak?= Date: Fri, 4 Oct 2024 16:42:26 +0200 Subject: [PATCH 1/4] [fix] Fix python debugging --- .../blaze/python/run/BlazePyDebugRunner.java | 31 +++++++++---------- .../run/BlazePyRunConfigurationRunner.java | 5 ++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java index 85fcae479a7..65bfe44202f 100644 --- a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java +++ b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java @@ -31,6 +31,12 @@ import com.jetbrains.python.debugger.PyDebugProcess; import com.jetbrains.python.debugger.PyDebugRunner; import com.jetbrains.python.run.PythonCommandLineState; +import com.jetbrains.python.run.PythonScriptCommandLineState; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.concurrency.Promise; +import org.jetbrains.concurrency.Promises; + import java.net.ServerSocket; /** Blaze plugin specific {@link PyDebugRunner}. */ @@ -57,11 +63,11 @@ public boolean canRun(String executorId, RunProfile profile) { } @Override - protected PyDebugProcess createDebugProcess( - XDebugSession xDebugSession, - ServerSocket serverSocket, - ExecutionResult executionResult, - PythonCommandLineState pythonCommandLineState) { + protected @NotNull PyDebugProcess createDebugProcess( + @NotNull XDebugSession xDebugSession, + ServerSocket serverSocket, + ExecutionResult executionResult, + PythonCommandLineState pythonCommandLineState) { PyDebugProcess process = super.createDebugProcess( xDebugSession, serverSocket, executionResult, pythonCommandLineState); @@ -70,19 +76,10 @@ protected PyDebugProcess createDebugProcess( } @Override - protected RunContentDescriptor doExecute(RunProfileState state, ExecutionEnvironment environment) - throws ExecutionException { + protected @NotNull Promise<@Nullable RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException { if (!(state instanceof BlazePyDummyRunProfileState)) { - return null; - } - EventLoggingService.getInstance().logEvent(getClass(), "debugging-python"); - try { - state = ((BlazePyDummyRunProfileState) state).toNativeState(environment); - return super.doExecute(state, environment); - } catch (ExecutionException e) { - throw e; - } catch (Exception e) { - throw new ExecutionException(e); + return Promises.resolvedPromise(); } + return super.execute(environment, ((BlazePyDummyRunProfileState) state).toNativeState(environment)); } } diff --git a/python/src/com/google/idea/blaze/python/run/BlazePyRunConfigurationRunner.java b/python/src/com/google/idea/blaze/python/run/BlazePyRunConfigurationRunner.java index 81de18d57bc..28de8108e66 100644 --- a/python/src/com/google/idea/blaze/python/run/BlazePyRunConfigurationRunner.java +++ b/python/src/com/google/idea/blaze/python/run/BlazePyRunConfigurationRunner.java @@ -70,6 +70,7 @@ import com.intellij.util.execution.ParametersListUtil; import com.jetbrains.python.console.PyDebugConsoleBuilder; import com.jetbrains.python.console.PythonDebugLanguageConsoleView; +import com.jetbrains.python.run.AbstractPythonRunConfiguration; import com.jetbrains.python.run.CommandLinePatcher; import com.jetbrains.python.run.PythonConfigurationType; import com.jetbrains.python.run.PythonRunConfiguration; @@ -125,7 +126,9 @@ PythonScriptCommandLineState toNativeState(ExecutionEnvironment env) throws Exec if (sdk == null) { throw new ExecutionException("Can't find a Python SDK when debugging a python target."); } - nativeConfig.setModule(null); + + var modules = AbstractPythonRunConfiguration.getValidModules(env.getProject()); + nativeConfig.setModule(modules.get(0)); nativeConfig.setSdkHome(sdk.getHomePath()); BlazePyRunConfigState handlerState = From 4e509fd5a65e919c105d0de03493c27ef4ec20ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82uszak?= Date: Fri, 4 Oct 2024 16:46:24 +0200 Subject: [PATCH 2/4] Format --- .../google/idea/blaze/python/run/BlazePyDebugRunner.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java index 65bfe44202f..15aaf7e7593 100644 --- a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java +++ b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java @@ -31,7 +31,6 @@ import com.jetbrains.python.debugger.PyDebugProcess; import com.jetbrains.python.debugger.PyDebugRunner; import com.jetbrains.python.run.PythonCommandLineState; -import com.jetbrains.python.run.PythonScriptCommandLineState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.concurrency.Promise; @@ -76,7 +75,10 @@ public boolean canRun(String executorId, RunProfile profile) { } @Override - protected @NotNull Promise<@Nullable RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException { + protected @NotNull Promise<@Nullable RunContentDescriptor> execute( + @NotNull ExecutionEnvironment environment, + @NotNull RunProfileState state) throws ExecutionException { + EventLoggingService.getInstance().logEvent(getClass(), "debugging-python"); if (!(state instanceof BlazePyDummyRunProfileState)) { return Promises.resolvedPromise(); } From 6ede461ad29962116e96c935139523010bd856ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82uszak?= Date: Fri, 4 Oct 2024 16:50:09 +0200 Subject: [PATCH 3/4] Logging --- .../com/google/idea/blaze/python/run/BlazePyDebugRunner.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java index 15aaf7e7593..64272b7a027 100644 --- a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java +++ b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java @@ -78,10 +78,11 @@ public boolean canRun(String executorId, RunProfile profile) { protected @NotNull Promise<@Nullable RunContentDescriptor> execute( @NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException { - EventLoggingService.getInstance().logEvent(getClass(), "debugging-python"); if (!(state instanceof BlazePyDummyRunProfileState)) { return Promises.resolvedPromise(); } + EventLoggingService.getInstance().logEvent(getClass(), "debugging-python"); + return super.execute(environment, ((BlazePyDummyRunProfileState) state).toNativeState(environment)); } } From ac13c7ad817f4c511bc4a7cabd5efd830fd1cc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82uszak?= Date: Fri, 4 Oct 2024 16:52:55 +0200 Subject: [PATCH 4/4] Annotation --- .../com/google/idea/blaze/python/run/BlazePyDebugRunner.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java index 64272b7a027..456974a0521 100644 --- a/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java +++ b/python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java @@ -32,7 +32,6 @@ import com.jetbrains.python.debugger.PyDebugRunner; import com.jetbrains.python.run.PythonCommandLineState; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.concurrency.Promise; import org.jetbrains.concurrency.Promises; @@ -75,7 +74,7 @@ public boolean canRun(String executorId, RunProfile profile) { } @Override - protected @NotNull Promise<@Nullable RunContentDescriptor> execute( + protected @NotNull Promise execute( @NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException { if (!(state instanceof BlazePyDummyRunProfileState)) {