Skip to content

Commit

Permalink
[fix] Fix python debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
agluszak committed Oct 4, 2024
1 parent 0cf662e commit ef22c35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
31 changes: 14 additions & 17 deletions python/src/com/google/idea/blaze/python/run/BlazePyDebugRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}. */
Expand All @@ -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);
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit ef22c35

Please sign in to comment.