use of com.intellij.xdebugger.evaluation.ExpressionInfo 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.ExpressionInfo in project intellij-plugins by JetBrains.
the class DartVmServiceEvaluator method getExpressionInfo.
@Nullable
public static ExpressionInfo getExpressionInfo(@NotNull final PsiElement contextElement) {
// todo if sideEffectsAllowed return method call like "foo()", not only "foo"
/* WEB-11715
dart psi: notes.text
REFERENCE_EXPRESSION
REFERENCE_EXPRESSION "notes"
PsiElement(.) "."
REFERENCE_EXPRESSION "text"
*/
// find topmost reference, but stop if argument list found
DartReference reference = null;
PsiElement element = contextElement;
while (true) {
if (element instanceof DartReference) {
reference = (DartReference) element;
}
element = element.getParent();
if (element == null || // int.parse(slider.value) - we must return reference expression "slider.value", but not the whole expression
element instanceof DartArgumentList || // "${seeds} seeds" - we must return only "seeds"
element instanceof DartLongTemplateEntry || element instanceof DartCallExpression || element instanceof DartFunctionBody || element instanceof IDartBlock) {
break;
}
}
if (reference != null) {
TextRange textRange = reference.getTextRange();
// note<CURSOR>s.text - the whole reference expression is notes.txt, but we must return only notes
int endOffset = contextElement.getTextRange().getEndOffset();
if (textRange.getEndOffset() != endOffset) {
textRange = new TextRange(textRange.getStartOffset(), endOffset);
}
return new ExpressionInfo(textRange);
}
PsiElement parent = contextElement.getParent();
return parent instanceof DartId ? new ExpressionInfo(parent.getTextRange()) : null;
}
use of com.intellij.xdebugger.evaluation.ExpressionInfo in project intellij-community by JetBrains.
the class XQuickEvaluateHandler method getExpressionInfo.
@NotNull
private static Promise<ExpressionInfo> getExpressionInfo(final XDebuggerEvaluator evaluator, final Project project, final ValueHintType type, @NotNull Editor editor, final int offset) {
SelectionModel selectionModel = editor.getSelectionModel();
int selectionStart = selectionModel.getSelectionStart();
int selectionEnd = selectionModel.getSelectionEnd();
if ((type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT) && selectionModel.hasSelection() && selectionStart <= offset && offset <= selectionEnd) {
return Promise.resolve(new ExpressionInfo(new TextRange(selectionStart, selectionEnd)));
}
return evaluator.getExpressionInfoAtOffsetAsync(project, editor.getDocument(), offset, type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT);
}
use of com.intellij.xdebugger.evaluation.ExpressionInfo in project intellij-community by JetBrains.
the class XDebuggerEvaluateActionHandler method getExpressionText.
/**
* The value of resulting Promise can be null
*/
@NotNull
public static Promise<String> getExpressionText(@Nullable XDebuggerEvaluator evaluator, @Nullable Project project, @NotNull Editor editor) {
if (project == null || evaluator == null) {
return Promise.resolve(null);
}
Document document = editor.getDocument();
Promise<ExpressionInfo> expressionInfoPromise = evaluator.getExpressionInfoAtOffsetAsync(project, document, editor.getCaretModel().getOffset(), true);
return expressionInfoPromise.then(expressionInfo -> getExpressionText(expressionInfo, document));
}
Aggregations