Search in sources :

Example 1 with XValueTextRendererImpl

use of com.intellij.xdebugger.impl.ui.tree.nodes.XValueTextRendererImpl 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)

Aggregations

Document (com.intellij.openapi.editor.Document)1 LineExtensionInfo (com.intellij.openapi.editor.LineExtensionInfo)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 XValuePresentation (com.intellij.xdebugger.frame.presentation.XValuePresentation)1 XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)1 XDebuggerManagerImpl (com.intellij.xdebugger.impl.XDebuggerManagerImpl)1 XVariablesView (com.intellij.xdebugger.impl.frame.XVariablesView)1 XValueNodeImpl (com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl)1 XValueTextRendererImpl (com.intellij.xdebugger.impl.ui.tree.nodes.XValueTextRendererImpl)1