Skip to content

Commit 5f68655

Browse files
committed
Add an action to highlight the current stack frame for debugging
1 parent 1d6b194 commit 5f68655

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

org.eclipse.jdt.debug.ui/plugin.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ collapseStackFrames.tooltip=Hide less relevant stack frames
189189
colorizeStackFrames.label=Mark Stack Frames with &Colors
190190
colorizeStackFrames.tooltip=Based on the function mark the stack frames with different colors
191191

192+
highlightStackFrame.label=Highlight Stack Frame
193+
highlightStackFrame.tooltip=Always mark this stack frame distinctly
194+
192195
stepIntoSelectionHyperlinkDetector.label=Step Into Selection
193196
stepIntoSelectionHyperlinkDetector.description=Performs the step into selection command on demand via a hyperlink
194197

org.eclipse.jdt.debug.ui/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,14 @@
17331733
enablesFor="+"
17341734
id="org.eclipse.jdt.debug.ui.actions.EditStepFiltersAction">
17351735
</action>
1736+
<action
1737+
label="%highlightStackFrame.label"
1738+
tooltip="%highlightStackFrame.tooltip"
1739+
menubarPath="emptyThreadGroup"
1740+
enablesFor="+"
1741+
class="org.eclipse.jdt.internal.debug.ui.actions.HighlightStackFrameAction"
1742+
id="org.eclipse.jdt.debug.ui.actions.HighlightStackFrameAction">
1743+
</action>
17361744
</objectContribution>
17371745
<viewerContribution
17381746
targetID="org.eclipse.debug.ui.VariableView.detail"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Zsombor Gegesy and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Zsombor Gegesy - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jdt.internal.debug.ui.actions;
15+
16+
import java.util.HashSet;
17+
18+
import org.eclipse.debug.core.DebugException;
19+
import org.eclipse.debug.core.model.IStackFrame;
20+
import org.eclipse.debug.core.model.IThread;
21+
import org.eclipse.jdt.debug.core.IJavaStackFrame;
22+
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
23+
import org.eclipse.jface.action.IAction;
24+
import org.eclipse.jface.viewers.IStructuredSelection;
25+
26+
/**
27+
* Add the current stack frame to the highlighted frames.
28+
*
29+
*/
30+
public class HighlightStackFrameAction extends ObjectActionDelegate {
31+
32+
@Override
33+
public void run(IAction action) {
34+
// Make sure there is a current selection
35+
IStructuredSelection selection = getCurrentSelection();
36+
if (selection == null) {
37+
return;
38+
}
39+
40+
final var stackFrameCategorizer = JDIDebugUIPlugin.getDefault().getStackFrameCategorizer();
41+
final var types = new HashSet<String>();
42+
final var threads = new HashSet<IThread>();
43+
for (Object selected : selection) {
44+
if (selected instanceof IJavaStackFrame frame) {
45+
try {
46+
types.add(frame.getDeclaringTypeName());
47+
} catch (DebugException e) {
48+
JDIDebugUIPlugin.log(e);
49+
}
50+
threads.add(frame.getThread());
51+
}
52+
}
53+
stackFrameCategorizer.addTypesToActiveCustomFilters(types);
54+
for (IThread thread : threads) {
55+
try {
56+
for (IStackFrame frame : thread.getStackFrames()) {
57+
if (frame instanceof IJavaStackFrame javaFrame) {
58+
javaFrame.resetCategory();
59+
}
60+
}
61+
} catch (DebugException e) {
62+
JDIDebugUIPlugin.log(e);
63+
}
64+
}
65+
66+
}
67+
68+
}

0 commit comments

Comments
 (0)