Search in sources :

Example 6 with XDebugSessionImpl

use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.

the class XDebuggerEditorLinePainter method getLineExtensions.

@Override
public Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) {
    if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isShowValuesInline()) {
        return null;
    }
    XVariablesView.InlineVariablesInfo data = project.getUserData(XVariablesView.DEBUG_VARIABLES);
    final Document doc = FileDocumentManager.getInstance().getDocument(file);
    if (data == null || doc == null) {
        return null;
    }
    Map<Variable, VariableValue> oldValues = project.getUserData(CACHE);
    if (oldValues == null) {
        oldValues = new HashMap<>();
        project.putUserData(CACHE, oldValues);
    }
    List<XValueNodeImpl> values = data.get(file, lineNumber, doc.getModificationStamp());
    if (values != null && !values.isEmpty()) {
        XDebugSession session = XDebugView.getSession(values.iterator().next().getTree());
        final int bpLine = getCurrentBreakPointLineInFile(session, file);
        boolean isTopFrame = session instanceof XDebugSessionImpl && ((XDebugSessionImpl) session).isTopFrameSelected();
        final TextAttributes attributes = bpLine == lineNumber && isTopFrame && ((XDebuggerManagerImpl) XDebuggerManager.getInstance(project)).isFullLineHighlighter() ? getTopFrameSelectedAttributes() : getNormalAttributes();
        ArrayList<VariableText> result = new ArrayList<>();
        for (XValueNodeImpl value : values) {
            SimpleColoredText text = new SimpleColoredText();
            XValueTextRendererImpl renderer = new XValueTextRendererImpl(text);
            final XValuePresentation presentation = value.getValuePresentation();
            if (presentation == null)
                continue;
            try {
                if (presentation instanceof XValueCompactPresentation && !value.getTree().isUnderRemoteDebug()) {
                    ((XValueCompactPresentation) presentation).renderValue(renderer, value);
                } else {
                    presentation.renderValue(renderer);
                }
                if (StringUtil.isEmpty(text.toString())) {
                    final String type = value.getValuePresentation().getType();
                    if (!StringUtil.isEmpty(type)) {
                        text.append(type, SimpleTextAttributes.REGULAR_ATTRIBUTES);
                    }
                }
            } catch (Exception ignored) {
                continue;
            }
            final String name = value.getName();
            if (StringUtil.isEmpty(text.toString())) {
                continue;
            }
            final VariableText res = new VariableText();
            result.add(res);
            res.add(new LineExtensionInfo("  " + name + ": ", attributes));
            Variable var = new Variable(name, lineNumber);
            VariableValue variableValue = oldValues.computeIfAbsent(var, k -> new VariableValue(text.toString(), null, value.hashCode()));
            if (variableValue.valueNodeHashCode != value.hashCode()) {
                variableValue.old = variableValue.actual;
                variableValue.actual = text.toString();
                variableValue.valueNodeHashCode = value.hashCode();
            }
            if (!variableValue.isChanged()) {
                for (String s : text.getTexts()) {
                    res.add(new LineExtensionInfo(s, attributes));
                }
            } else {
                variableValue.produceChangedParts(res.infos);
            }
        }
        final List<LineExtensionInfo> infos = new ArrayList<>();
        for (VariableText text : result) {
            infos.addAll(text.infos);
        }
        return infos.size() > LINE_EXTENSIONS_MAX_COUNT ? infos.subList(0, LINE_EXTENSIONS_MAX_COUNT) : infos;
    }
    return null;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XValuePresentation(com.intellij.xdebugger.frame.presentation.XValuePresentation) LineExtensionInfo(com.intellij.openapi.editor.LineExtensionInfo) Document(com.intellij.openapi.editor.Document) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) XDebuggerManagerImpl(com.intellij.xdebugger.impl.XDebuggerManagerImpl) XValueTextRendererImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueTextRendererImpl) XVariablesView(com.intellij.xdebugger.impl.frame.XVariablesView) XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl)

Example 7 with XDebugSessionImpl

use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.

the class XDebuggerEvaluationDialog method addToWatches.

private void addToWatches() {
    if (myMode == EvaluationMode.EXPRESSION) {
        XExpression expression = getInputEditor().getExpression();
        if (!XDebuggerUtilImpl.isEmptyExpression(expression)) {
            XDebugSessionTab tab = ((XDebugSessionImpl) mySession).getSessionTab();
            if (tab != null) {
                tab.getWatchesView().addWatchExpression(expression, -1, true);
                getInputEditor().requestFocusInEditor();
            }
        }
    }
}
Also used : XDebugSessionTab(com.intellij.xdebugger.impl.ui.XDebugSessionTab) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl)

Example 8 with XDebugSessionImpl

use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.

the class XWatchesViewImpl method updateSessionData.

public void updateSessionData() {
    List<XExpression> watchExpressions = ContainerUtil.newArrayList();
    List<? extends WatchNode> children = myRootNode.getWatchChildren();
    for (WatchNode child : children) {
        watchExpressions.add(child.getExpression());
    }
    XDebugSession session = getSession(getTree());
    XExpression[] expressions = watchExpressions.toArray(new XExpression[watchExpressions.size()]);
    if (session != null) {
        ((XDebugSessionImpl) session).setWatchExpressions(expressions);
    } else {
        XDebugSessionData data = getData(XDebugSessionData.DATA_KEY, getTree());
        if (data != null) {
            data.setWatchExpressions(expressions);
        }
    }
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugSessionData(com.intellij.xdebugger.impl.ui.XDebugSessionData) XExpression(com.intellij.xdebugger.XExpression) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl)

Example 9 with XDebugSessionImpl

use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.

the class XWatchesViewImpl method getExpressions.

@NotNull
private XExpression[] getExpressions() {
    XDebuggerTree tree = getTree();
    XDebugSession session = getSession(tree);
    XExpression[] expressions;
    if (session != null) {
        expressions = ((XDebugSessionImpl) session).getSessionData().getWatchExpressions();
    } else {
        XDebuggerTreeNode root = tree.getRoot();
        List<? extends WatchNode> current = root instanceof WatchesRootNode ? ((WatchesRootNode) tree.getRoot()).getWatchChildren() : Collections.emptyList();
        List<XExpression> list = ContainerUtil.newArrayList();
        for (WatchNode child : current) {
            list.add(child.getExpression());
        }
        expressions = list.toArray(new XExpression[list.size()]);
    }
    return expressions;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XExpression(com.intellij.xdebugger.XExpression) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with XDebugSessionImpl

use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.

the class CodeFragmentFactoryContextWrapper method wrapContext.

private PsiElement wrapContext(Project project, final PsiElement originalContext) {
    if (project.isDefault())
        return originalContext;
    //TODO [egor] : does not work for anything other than java anyway, see IDEA-132677
    if (!(myDelegate instanceof DefaultCodeFragmentFactory)) {
        return originalContext;
    }
    PsiElement context = originalContext;
    XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
    if (session != null) {
        XValueMarkers<?, ?> markers = ((XDebugSessionImpl) session).getValueMarkers();
        Map<?, ValueMarkup> markupMap = markers != null ? markers.getAllMarkers() : null;
        //final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
        if (!ContainerUtil.isEmpty(markupMap)) {
            final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
            int offset = markupVariables.getFirst().length() - 1;
            final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
            final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
            codeFragment.accept(new JavaRecursiveElementVisitor() {

                public void visitLocalVariable(PsiLocalVariable variable) {
                    final String name = variable.getName();
                    variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
                }
            });
            final PsiElement newContext = codeFragment.findElementAt(offset);
            if (newContext != null) {
                context = newContext;
            }
        }
    }
    return context;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) PsiLocalVariable(com.intellij.psi.PsiLocalVariable) ValueMarkup(com.intellij.xdebugger.impl.ui.tree.ValueMarkup) HashMap(java.util.HashMap) Map(java.util.Map) JavaCodeFragment(com.intellij.psi.JavaCodeFragment) JavaRecursiveElementVisitor(com.intellij.psi.JavaRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl)

Aggregations

XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)11 XDebugSession (com.intellij.xdebugger.XDebugSession)9 XDebugSessionTab (com.intellij.xdebugger.impl.ui.XDebugSessionTab)4 XExpression (com.intellij.xdebugger.XExpression)2 ValueMarkup (com.intellij.xdebugger.impl.ui.tree.ValueMarkup)2 XValueNodeImpl (com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl)2 NotNull (org.jetbrains.annotations.NotNull)2 DebugEnvironment (com.intellij.debugger.DebugEnvironment)1 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 EnumerationChildrenRenderer (com.intellij.debugger.ui.tree.render.EnumerationChildrenRenderer)1 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ExecutionConsole (com.intellij.execution.ui.ExecutionConsole)1 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)1 NotificationListener (com.intellij.notification.NotificationListener)1 Document (com.intellij.openapi.editor.Document)1 LineExtensionInfo (com.intellij.openapi.editor.LineExtensionInfo)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1