use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class PythonConsoleView method addTextRangeToHistory.
@NotNull
protected String addTextRangeToHistory(@NotNull TextRange textRange, @NotNull EditorEx inputEditor, boolean preserveMarkup) {
String text;
EditorHighlighter highlighter;
if (inputEditor instanceof EditorWindow) {
PsiFile file = ((EditorWindow) inputEditor).getInjectedFile();
highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), getProject());
String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null);
highlighter.setText(fullText);
text = textRange.substring(fullText);
} else {
text = inputEditor.getDocument().getText(textRange);
highlighter = inputEditor.getHighlighter();
}
SyntaxHighlighter syntax = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter) highlighter).getSyntaxHighlighter() : null;
doAddPromptToHistory(true);
if (syntax != null) {
ConsoleViewUtil.printWithHighlighting(this, text, syntax, () -> doAddPromptToHistory(false));
} else {
print(text, ConsoleViewContentType.USER_INPUT);
}
print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
return text;
}
use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class PydevConsoleRunner method findPythonSdkAndModule.
@NotNull
static Pair<Sdk, Module> findPythonSdkAndModule(@NotNull Project project, @Nullable Module contextModule) {
Sdk sdk = null;
Module module = null;
PyConsoleOptions.PyConsoleSettings settings = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
String sdkHome = settings.getSdkHome();
if (sdkHome != null) {
sdk = PythonSdkType.findSdkByPath(sdkHome);
if (settings.getModuleName() != null) {
module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
} else {
module = contextModule;
if (module == null && ModuleManager.getInstance(project).getModules().length > 0) {
module = ModuleManager.getInstance(project).getModules()[0];
}
}
}
if (sdk == null && settings.isUseModuleSdk()) {
if (contextModule != null) {
module = contextModule;
} else if (settings.getModuleName() != null) {
module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
}
if (module != null) {
if (PythonSdkType.findPythonSdk(module) != null) {
sdk = PythonSdkType.findPythonSdk(module);
}
}
} else if (contextModule != null) {
if (module == null) {
module = contextModule;
}
if (sdk == null) {
sdk = PythonSdkType.findPythonSdk(module);
}
}
if (sdk == null) {
for (Module m : ModuleManager.getInstance(project).getModules()) {
if (PythonSdkType.findPythonSdk(m) != null) {
sdk = PythonSdkType.findPythonSdk(m);
module = m;
break;
}
}
}
if (sdk == null) {
if (PythonSdkType.getAllSdks().size() > 0) {
//noinspection UnusedAssignment
//take any python sdk
sdk = PythonSdkType.getAllSdks().get(0);
}
}
return Pair.create(sdk, module);
}
use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class PydevConsoleRunnerImpl method connectToDebugger.
private XDebugSession connectToDebugger() throws ExecutionException {
final ServerSocket serverSocket = PythonCommandLineState.createServerSocket();
final XDebugSession session = XDebuggerManager.getInstance(myProject).startSessionAndShowTab("Python Console Debugger", PythonIcons.Python.Python, null, true, new XDebugProcessStarter() {
@NotNull
public XDebugProcess start(@NotNull final XDebugSession session) {
PythonDebugLanguageConsoleView debugConsoleView = new PythonDebugLanguageConsoleView(myProject, mySdk);
PyConsoleDebugProcessHandler consoleDebugProcessHandler = new PyConsoleDebugProcessHandler(myProcessHandler);
PyConsoleDebugProcess consoleDebugProcess = new PyConsoleDebugProcess(session, serverSocket, debugConsoleView, consoleDebugProcessHandler);
PythonDebugConsoleCommunication communication = PyDebugRunner.initDebugConsoleView(myProject, consoleDebugProcess, debugConsoleView, consoleDebugProcessHandler, session);
communication.addCommunicationListener(new ConsoleCommunicationListener() {
@Override
public void commandExecuted(boolean more) {
session.rebuildViews();
}
@Override
public void inputRequested() {
}
});
myPydevConsoleCommunication.setDebugCommunication(communication);
debugConsoleView.attachToProcess(consoleDebugProcessHandler);
consoleDebugProcess.waitForNextConnection();
try {
consoleDebugProcess.connect(myPydevConsoleCommunication);
} catch (Exception e) {
//TODO
LOG.error(e);
}
myProcessHandler.notifyTextAvailable("\nDebugger connected.\n", ProcessOutputTypes.STDERR);
return consoleDebugProcess;
}
});
return session;
}
use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class PydevConsoleRunnerImpl method createExecuteActionHandler.
@NotNull
protected PydevConsoleExecuteActionHandler createExecuteActionHandler() {
myConsoleExecuteActionHandler = new PydevConsoleExecuteActionHandler(myConsoleView, myProcessHandler, myPydevConsoleCommunication);
myConsoleExecuteActionHandler.setEnabled(false);
new ConsoleHistoryController(myConsoleType.getTypeId(), "", myConsoleView).install();
return myConsoleExecuteActionHandler;
}
use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class PyAttachToProcessDebugRunner method launchRemoteDebugServer.
private XDebugSession launchRemoteDebugServer() throws ExecutionException {
final ServerSocket serverSocket;
try {
//noinspection SocketOpenedButNotSafelyClosed
serverSocket = new ServerSocket(0);
} catch (IOException e) {
throw new ExecutionException("Failed to find free socket port", e);
}
PyAttachToProcessCommandLineState state = PyAttachToProcessCommandLineState.create(myProject, mySdkPath, serverSocket.getLocalPort(), myPid);
final ExecutionResult result = state.execute(state.getEnvironment().getExecutor(), this);
//start remote debug server
return XDebuggerManager.getInstance(myProject).startSessionAndShowTab(String.valueOf(myPid), null, new XDebugProcessStarter() {
@org.jetbrains.annotations.NotNull
public XDebugProcess start(@NotNull final XDebugSession session) {
PyRemoteDebugProcess pyDebugProcess = new PyRemoteDebugProcess(session, serverSocket, result.getExecutionConsole(), result.getProcessHandler(), "") {
@Override
protected void printConsoleInfo() {
}
@Override
protected String getConnectionMessage() {
return "Attaching to a process with PID=" + myPid;
}
@Override
protected String getConnectionTitle() {
return "Attaching Debugger";
}
};
pyDebugProcess.setPositionConverter(new PyLocalPositionConverter());
createConsoleCommunicationAndSetupActions(myProject, result, pyDebugProcess, session);
return pyDebugProcess;
}
});
}
Aggregations