Pass executable path directly

This commit is contained in:
Dmitry Trofimov
2016-03-01 18:54:36 +01:00
parent 805e818369
commit c20337a4dd
@@ -32,7 +32,7 @@ import com.intellij.xdebugger.attach.XLocalAttachGroup;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -55,12 +55,19 @@ public class PyLocalAttachDebuggerProvider implements XLocalAttachDebuggerProvid
List<XLocalAttachDebugger> result = contextHolder.getUserData(DEBUGGERS_KEY);
if (result != null) return result;
result = ContainerUtil.map(sdksForAttachment(processInfo), new Function<Sdk, XLocalAttachDebugger>() {
@Override
public XLocalAttachDebugger fun(Sdk sdk) {
return new PyLocalAttachDebugger(sdk);
}
});
if (processInfo.getExecutableCannonicalPath().isPresent() &&
new File(processInfo.getExecutableCannonicalPath().get()).exists()) {
result =
Lists.newArrayList(new PyLocalAttachDebugger(processInfo.getExecutableCannonicalPath().get()));
}
else {
result = ContainerUtil.map(PythonSdkType.getAllLocalCPythons(), new Function<Sdk, XLocalAttachDebugger>() {
@Override
public XLocalAttachDebugger fun(Sdk sdk) {
return new PyLocalAttachDebugger(sdk);
}
});
}
// most recent python version goes first
Collections.sort(result, new Comparator<XLocalAttachDebugger>() {
@@ -75,25 +82,19 @@ public class PyLocalAttachDebuggerProvider implements XLocalAttachDebuggerProvid
}
return Collections.emptyList();
}
private static Collection<Sdk> sdksForAttachment(ProcessInfo info) {
if (info.getExecutableCannonicalPath().isPresent()) {
Sdk sdk = PythonSdkType.findSdkByPath(info.getExecutableCannonicalPath().get());
if (sdk != null) {
return Lists.newArrayList(sdk);
}
}
return PythonSdkType.getAllLocalCPythons();
}
private static class PyLocalAttachDebugger implements XLocalAttachDebugger {
@NotNull private final Sdk mySdk;
private final String mySdkHome;
@NotNull private final String myName;
public PyLocalAttachDebugger(@NotNull Sdk sdk) {
mySdk = sdk;
myName = PythonSdkType.getInstance().getVersionString(mySdk) + " Debugger";
mySdkHome = sdk.getHomePath();
myName = PythonSdkType.getInstance().getVersionString(sdk) + " Debugger";
}
public PyLocalAttachDebugger(@NotNull String sdkHome) {
mySdkHome = sdkHome;
myName = "Python Debugger";
}
@NotNull
@@ -105,7 +106,7 @@ public class PyLocalAttachDebuggerProvider implements XLocalAttachDebuggerProvid
@NotNull
@Override
public XDebugSession attachDebugSession(@NotNull Project project, @NotNull ProcessInfo processInfo) throws ExecutionException {
PyAttachToProcessDebugRunner runner = new PyAttachToProcessDebugRunner(project, processInfo.getPid(), mySdk.getHomePath());
PyAttachToProcessDebugRunner runner = new PyAttachToProcessDebugRunner(project, processInfo.getPid(), mySdkHome);
return runner.launch();
}
}