Search in sources :

Example 6 with XValuePresentation

use of com.intellij.xdebugger.frame.presentation.XValuePresentation 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

XValuePresentation (com.intellij.xdebugger.frame.presentation.XValuePresentation)6 NotNull (org.jetbrains.annotations.NotNull)3 XDebugSession (com.intellij.xdebugger.XDebugSession)2 HintUtil (com.intellij.codeInsight.hint.HintUtil)1 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)1 LanguageConsoleView (com.intellij.execution.console.LanguageConsoleView)1 ConsoleViewImpl (com.intellij.execution.impl.ConsoleViewImpl)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 Disposable (com.intellij.openapi.Disposable)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ShortcutSet (com.intellij.openapi.actionSystem.ShortcutSet)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 LineExtensionInfo (com.intellij.openapi.editor.LineExtensionInfo)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1