public void init(IPageBookViewPage page, final IConsole console) {
if (!(console instanceof ProcessConsole)) {
return;
}
ProcessConsole processConsole = (ProcessConsole) console;
IProcess process = processConsole.getProcess();
if (process == null) {
return;
}
if (!PyCodeCompletionPreferencesPage.useCodeCompletion()
|| !PyCodeCompletionPreferencesPage.useCodeCompletionOnDebug()) {
return;
}
String attribute = process.getAttribute(Constants.PYDEV_DEBUG_IPROCESS_ATTR);
if (!Constants.PYDEV_DEBUG_IPROCESS_ATTR_TRUE.equals(attribute)) {
//Only provide code-completion for pydev debug processes.
return;
}
Control control = page.getControl();
if (page instanceof IOConsolePage) {
//Note that completions on "all letters and '_'" are already activated just by installing
//the content assist, but the completions on the default keybinding is not, so, we have to
//call it ourselves here.
control.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (KeyBindingHelper.matchesContentAssistKeybinding(e)) {
contentAssist.showPossibleCompletions();
}
}
public void keyReleased(KeyEvent e) {
}
});
IOConsolePage consolePage = (IOConsolePage) page;
TextConsoleViewer viewer = consolePage.getViewer();
contentAssist = new PyContentAssistant() {
public String showPossibleCompletions() {
//Only show completions if we're in a suspended console.
if (getCurrentSuspendedPyStackFrame(console) == null) {
return null;
}
return super.showPossibleCompletions();
};
};
contentAssist.setInformationControlCreator(PyContentAssistant.createInformationControlCreator(viewer));
ILaunch launch = process.getLaunch();
IDebugTarget debugTarget = launch.getDebugTarget();
IInterpreterInfo projectInterpreter = null;
if (debugTarget instanceof PyDebugTarget) {
PyDebugTarget pyDebugTarget = (PyDebugTarget) debugTarget;
PythonNature nature = PythonNature.getPythonNature(pyDebugTarget.project);