How can I keep the watches tree expanded?

Answered

Kinda hard to explain and I'm not sure if I use the right terminology here. I'm implementing a debugger for custom language and display certain values in the watches window. The problem is that these values represent a somewhat complex tree, and when I expand it and step over or run to the next breakpoint, the tree collapses again. Wondering if it's possible to somehow remember the last state of that tree or keep it expanded. 

0
7 comments

Hi, this is not implemented for custom debugger trees, but usually you can save expansion state with XDebuggerTreeState.saveState(tree) and restore with XDebuggerTree#rebuildAndRestore

0

Thanks, Egor, this helps but I'm still trying to figure out the right place to put this code in. So far I only have my implementations of `XExecutionStack`, `XStackFrame` and `XValue` so I'm not sure where would be the right place for the `saveState` and `rebuildAndRestore`. Any suggestions?

0

I'd try com.intellij.xdebugger.XDebugSessionListener - sessionResumed and sessionPaused

0

OK, makes sense, but how do I obtain the tree instance so that I can call XDebuggerTreeState.saveState(tree)? I saw the XdebuggerTree.getTree() method but apparently it is intended for use inside the action, because it expects ActionEvent parameter, which I don't have.  Are there any other options?

 

0

Ah, sorry, I missed that all of this is happening in the default watches tree. Then it should work out the box, try to debug com.intellij.xdebugger.impl.frame.XWatchesViewImpl#buildTreeAndRestoreState and check that the state is restored (and populated) correctly

0

Aha, so here's what's happening - the XVariablesViewBase#buildTreeAndRestoreState is called and that's where it gets interesting:

Object newEqualityObject = stackFrame.getEqualityObject();
if (newEqualityObject != null) {
  XDebuggerTreeState state = myTreeStates.get(newEqualityObject);
  if (state != null) {
    disposeTreeRestorer();
    myTreeRestorer = state.restoreState(tree);
  }
}

The stackFrame.getEqualityObject() always returns null, and I don't have this method implemented in my stack frame class. That's why the tree gets rebuilt all the time and doesn't preserve the expanded state. I guess I need to figure out how to implement it in my particular application.

0

Yes, true, usually this is something unique for a method or another program unit with the same set of (local) variables. For java it is just a string with method fqn+signature

0

Please sign in to leave a comment.