Search in sources :

Example 1 with XDebuggerEvaluator

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

Example 2 with XDebuggerEvaluator

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);
            }
        });
    });
}
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 3 with XDebuggerEvaluator

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();
        }
    };
}
Also used : AllIcons(com.intellij.icons.AllIcons) com.goide.psi(com.goide.psi) GoIcons(com.goide.GoIcons) DlvApi(com.goide.dlv.protocol.DlvApi) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) DlvRequest(com.goide.dlv.protocol.DlvRequest) XValueChildrenList(com.intellij.xdebugger.frame.XValueChildrenList) ModuleBasedConfiguration(com.intellij.execution.configurations.ModuleBasedConfiguration) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Promise(org.jetbrains.concurrency.Promise) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) XValue(com.intellij.xdebugger.frame.XValue) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) XCompositeNode(com.intellij.xdebugger.frame.XCompositeNode) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) StringUtil(com.intellij.openapi.util.text.StringUtil) RunProfile(com.intellij.execution.configurations.RunProfile) TextRange(com.intellij.openapi.util.TextRange) SystemInfo(com.intellij.openapi.util.SystemInfo) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ColoredTextContainer(com.intellij.ui.ColoredTextContainer) GoSdkService(com.goide.sdk.GoSdkService) Nullable(org.jetbrains.annotations.Nullable) XSourcePosition(com.intellij.xdebugger.XSourcePosition) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) XDebuggerUtil(com.intellij.xdebugger.XDebuggerUtil) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) javax.swing(javax.swing) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DlvRequest(com.goide.dlv.protocol.DlvRequest) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Nullable(org.jetbrains.annotations.Nullable) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with XDebuggerEvaluator

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);
    }
}
Also used : XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) XDebuggerEditorBase(com.intellij.xdebugger.impl.ui.XDebuggerEditorBase)

Example 5 with XDebuggerEvaluator

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));
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) EvaluationMode(com.intellij.xdebugger.evaluation.EvaluationMode) XExpression(com.intellij.xdebugger.XExpression) Editor(com.intellij.openapi.editor.Editor) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) XValue(com.intellij.xdebugger.frame.XValue)

Aggregations

XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)7 NotNull (org.jetbrains.annotations.NotNull)4 Editor (com.intellij.openapi.editor.Editor)3 TextRange (com.intellij.openapi.util.TextRange)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 XDebugSession (com.intellij.xdebugger.XDebugSession)2 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)2 XValue (com.intellij.xdebugger.frame.XValue)2 Nullable (org.jetbrains.annotations.Nullable)2 Promise (org.jetbrains.concurrency.Promise)2 GoIcons (com.goide.GoIcons)1 DlvApi (com.goide.dlv.protocol.DlvApi)1 DlvRequest (com.goide.dlv.protocol.DlvRequest)1 com.goide.psi (com.goide.psi)1 GoSdkService (com.goide.sdk.GoSdkService)1 ModuleBasedConfiguration (com.intellij.execution.configurations.ModuleBasedConfiguration)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 ConsoleExecuteAction (com.intellij.execution.console.ConsoleExecuteAction)1 LanguageConsoleView (com.intellij.execution.console.LanguageConsoleView)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1