void (@NotNull XDebugSession session, DataContext dataContext) { Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (!(editor instanceof EditorEx)) { return; } int selectionStart = editor.getSelectionModel().getSelectionStart(); int selectionEnd = editor.getSelectionModel().getSelectionEnd(); Promise<Pair<TextRange, String>> rangeAndText; if (selectionStart != selectionEnd) { TextRange textRange = new TextRange(selectionStart, selectionEnd); rangeAndText = Promises.resolvedPromise(Pair.create(textRange, editor.getDocument().getText(textRange))); } else { XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator(); if (evaluator != null) { Promise<ExpressionInfo> expressionInfoPromise = evaluator.getExpressionInfoAtOffsetAsync(session.getProject(), editor.getDocument(), selectionStart, true); rangeAndText = expressionInfoPromise.then(expressionInfo -> { if (expressionInfo == null) { return null; } // todo check - is it wrong in case of not-null expressionInfo.second - copied (to console history document) text (text range) could be not correct statement? return Pair.create(expressionInfo.getTextRange(), XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument())); }); } else { return; } } rangeAndText.onSuccess(textRangeStringPair -> ApplicationManager.getApplication().invokeLater(() -> { TextRange range = textRangeStringPair.getFirst(); String text = textRangeStringPair.getSecond(); if (text == null) return; ConsoleExecuteAction action = getConsoleExecuteAction(session); if (action != null) { action.execute(range, text, (EditorEx) editor); } })); }