use of com.intellij.xdebugger.evaluation.XDebuggerEvaluator in project intellij-community by JetBrains.
the class XQuickEvaluateHandler method createValueHintAsync.
@NotNull
@Override
public Promise<AbstractValueHint> createValueHintAsync(@NotNull final Project project, @NotNull final Editor editor, @NotNull final Point point, final ValueHintType type) {
final XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
if (session == null) {
return Promise.resolve(null);
}
final XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator();
if (evaluator == null) {
return Promise.resolve(null);
}
int offset = AbstractValueHint.calculateOffset(editor, point);
return getExpressionInfo(evaluator, project, type, editor, offset).thenAsync(expressionInfo -> {
AsyncPromise<AbstractValueHint> resultPromise = new AsyncPromise<>();
UIUtil.invokeLaterIfNeeded(() -> {
int textLength = editor.getDocument().getTextLength();
if (expressionInfo == null) {
resultPromise.setResult(null);
return;
}
TextRange range = expressionInfo.getTextRange();
if (range.getStartOffset() > range.getEndOffset() || range.getStartOffset() < 0 || range.getEndOffset() > textLength) {
LOG.error("invalid range: " + range + ", text length = " + textLength + ", evaluator: " + evaluator);
resultPromise.setResult(null);
return;
}
resultPromise.setResult(new XValueHint(project, editor, point, type, expressionInfo, evaluator, session));
});
return resultPromise;
});
}
use of com.intellij.xdebugger.evaluation.XDebuggerEvaluator in project intellij-community by JetBrains.
the class XEvaluateInConsoleFromEditorActionHandler method perform.
@Override
protected void perform(@NotNull XDebugSession session, DataContext dataContext) {
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
if (editor == null || !(editor instanceof EditorEx)) {
return;
}
int selectionStart = editor.getSelectionModel().getSelectionStart();
int selectionEnd = editor.getSelectionModel().getSelectionEnd();
Promise<Pair<TextRange, String>> rangeAndText = null;
if (selectionStart != selectionEnd) {
TextRange textRange = new TextRange(selectionStart, selectionEnd);
rangeAndText = Promise.resolve(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;
}
return Pair.create(expressionInfo.getTextRange(), XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument()));
});
} else {
return;
}
}
rangeAndText.done(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);
}
});
});
}
use of com.intellij.xdebugger.evaluation.XDebuggerEvaluator in project go-lang-idea-plugin by go-lang-plugin-org.
the class DlvStackFrame method getEvaluator.
@Nullable
@Override
public XDebuggerEvaluator getEvaluator() {
return new XDebuggerEvaluator() {
@Override
public void evaluate(@NotNull String expression, @NotNull XEvaluationCallback callback, @Nullable XSourcePosition expressionPosition) {
myProcessor.send(new DlvRequest.EvalSymbol(expression, myId)).done(variable -> callback.evaluated(createXValue(variable, AllIcons.Debugger.Watch))).rejected(throwable -> callback.errorOccurred(throwable.getMessage()));
}
@Nullable
private PsiElement findElementAt(@Nullable PsiFile file, int offset) {
return file != null ? file.findElementAt(offset) : null;
}
@Nullable
@Override
public TextRange getExpressionRangeAtOffset(@NotNull Project project, @NotNull Document document, int offset, boolean sideEffectsAllowed) {
Ref<TextRange> currentRange = Ref.create(null);
PsiDocumentManager.getInstance(project).commitAndRunReadAction(() -> {
try {
PsiElement elementAtCursor = findElementAt(PsiDocumentManager.getInstance(project).getPsiFile(document), offset);
GoTypeOwner e = PsiTreeUtil.getParentOfType(elementAtCursor, GoExpression.class, GoVarDefinition.class, GoConstDefinition.class, GoParamDefinition.class);
if (e != null) {
currentRange.set(e.getTextRange());
}
} catch (IndexNotReadyException ignored) {
}
});
return currentRange.get();
}
};
}
use of com.intellij.xdebugger.evaluation.XDebuggerEvaluator in project intellij-community by JetBrains.
the class XDebuggerEvaluationDialog method startEvaluation.
public void startEvaluation(@NotNull XDebuggerEvaluator.XEvaluationCallback evaluationCallback) {
final XDebuggerEditorBase inputEditor = getInputEditor();
inputEditor.saveTextInHistory();
XExpression expression = inputEditor.getExpression();
XDebuggerEvaluator evaluator = mySession.getDebugProcess().getEvaluator();
if (evaluator == null) {
evaluationCallback.errorOccurred(XDebuggerBundle.message("xdebugger.evaluate.stack.frame.has.not.evaluator"));
} else {
evaluator.evaluate(expression, evaluationCallback, null);
}
}
use of com.intellij.xdebugger.evaluation.XDebuggerEvaluator in project intellij-community by JetBrains.
the class XDebuggerEvaluateActionHandler method perform.
@Override
protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) {
final XDebuggerEditorsProvider editorsProvider = session.getDebugProcess().getEditorsProvider();
final XStackFrame stackFrame = session.getCurrentStackFrame();
final XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator();
if (evaluator == null) {
return;
}
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
EvaluationMode mode = EvaluationMode.EXPRESSION;
String selectedText = editor != null ? editor.getSelectionModel().getSelectedText() : null;
if (selectedText != null) {
selectedText = evaluator.formatTextForEvaluation(selectedText);
mode = evaluator.getEvaluationMode(selectedText, editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd(), CommonDataKeys.PSI_FILE.getData(dataContext));
}
Promise<String> expressionTextPromise = Promise.resolve(selectedText);
if (selectedText == null && editor != null) {
expressionTextPromise = getExpressionText(evaluator, CommonDataKeys.PROJECT.getData(dataContext), editor);
}
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
EvaluationMode finalMode = mode;
XValue value = XDebuggerTreeActionBase.getSelectedValue(dataContext);
expressionTextPromise.done(expressionText -> {
if (expressionText == null && value != null) {
value.calculateEvaluationExpression().done(expression -> {
if (expression != null) {
AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, expression));
}
});
} else {
XExpression expression = XExpressionImpl.fromText(StringUtil.notNullize(expressionText), finalMode);
AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, expression));
}
});
}
Aggregations