Search in sources :

Example 1 with ExpressionInfo

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);
            }
        });
    });
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ActionUtil(com.intellij.openapi.actionSystem.ex.ActionUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) TextRange(com.intellij.openapi.util.TextRange) ContainerUtil(com.intellij.util.containers.ContainerUtil) Editor(com.intellij.openapi.editor.Editor) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) Nullable(org.jetbrains.annotations.Nullable) Promise(org.jetbrains.concurrency.Promise) List(java.util.List) ConsoleView(com.intellij.execution.ui.ConsoleView) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction) LanguageConsoleView(com.intellij.execution.console.LanguageConsoleView) NotNull(org.jetbrains.annotations.NotNull) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) EditorEx(com.intellij.openapi.editor.ex.EditorEx) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction) Pair(com.intellij.openapi.util.Pair)

Example 2 with ExpressionInfo

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;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ExpressionInfo

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);
}
Also used : SelectionModel(com.intellij.openapi.editor.SelectionModel) TextRange(com.intellij.openapi.util.TextRange) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) AbstractValueHint(com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ExpressionInfo

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));
}
Also used : Document(com.intellij.openapi.editor.Document) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExpressionInfo (com.intellij.xdebugger.evaluation.ExpressionInfo)4 TextRange (com.intellij.openapi.util.TextRange)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)2 ConsoleExecuteAction (com.intellij.execution.console.ConsoleExecuteAction)1 LanguageConsoleView (com.intellij.execution.console.LanguageConsoleView)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ActionUtil (com.intellij.openapi.actionSystem.ex.ActionUtil)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1