Skip to content

Commit d3bf58a

Browse files
committed
Add an action to highlight the current stack frame for debugging
1 parent aafacfa commit d3bf58a

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ colorizeStackFrames.tooltip=Based on the function mark the stack frames with dif
186186
collapseStackFrames.label=Collapse Stack Frames
187187
collapseStackFrames.tooltip=Hide less relevant stack frames
188188

189+
highlightStackFrame.label=Highlight Stack Frame
190+
highlightStackFrame.tooltip=Always mark this stack frame distinctly
191+
189192
stepIntoSelectionHyperlinkDetector.label=Step Into Selection
190193
stepIntoSelectionHyperlinkDetector.description=Performs the step into selection command on demand via a hyperlink
191194

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,14 @@
16991699
enablesFor="+"
17001700
id="org.eclipse.jdt.debug.ui.actions.EditStepFiltersAction">
17011701
</action>
1702+
<action
1703+
label="%highlightStackFrame.label"
1704+
tooltip="%highlightStackFrame.tooltip"
1705+
menubarPath="emptyThreadGroup"
1706+
enablesFor="+"
1707+
class="org.eclipse.jdt.internal.debug.ui.actions.HighlightStackFrameAction"
1708+
id="org.eclipse.jdt.debug.ui.actions.HighlightStackFrameAction">
1709+
</action>
17021710
</objectContribution>
17031711
<viewerContribution
17041712
targetID="org.eclipse.debug.ui.VariableView.detail"

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaStackFramePreferencePage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void widgetSelected(SelectionEvent e) {
152152

153153
public static final String PAGE_ID = "org.eclipse.jdt.debug.ui.JavaStackFramePreferencePage"; //$NON-NLS-1$
154154
final static FilterManager PLATFORM_STACK_FRAMES = new FilterManager(IJDIPreferencesConstants.PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST, IJDIPreferencesConstants.PREF_INACTIVE_PLATFORM_FRAME_FILTER_LIST);
155-
final static FilterManager CUSTOM_STACK_FRAMES = new FilterManager(IJDIPreferencesConstants.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST, IJDIPreferencesConstants.PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST);
155+
public static final FilterManager CUSTOM_STACK_FRAMES = new FilterManager(IJDIPreferencesConstants.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST, IJDIPreferencesConstants.PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST);
156156

157157
//widgets
158158
private PreferenceButton fColorizeStackFrames;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.Objects;
17+
18+
import org.eclipse.debug.core.DebugException;
19+
import org.eclipse.jdt.debug.core.IJavaStackFrame;
20+
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
21+
import org.eclipse.jdt.internal.debug.ui.JavaStackFramePreferencePage;
22+
import org.eclipse.jdt.internal.ui.filtertable.Filter;
23+
import org.eclipse.jdt.internal.ui.filtertable.FilterManager;
24+
import org.eclipse.jface.action.IAction;
25+
import org.eclipse.jface.preference.IPreferenceStore;
26+
import org.eclipse.jface.viewers.IStructuredSelection;
27+
28+
/**
29+
* Add the current stack frame to the highlighted frames.
30+
*
31+
*/
32+
public class HighlightStackFrameAction extends ObjectActionDelegate {
33+
34+
@Override
35+
public void run(IAction action) {
36+
// Make sure there is a current selection
37+
IStructuredSelection selection = getCurrentSelection();
38+
if (selection == null) {
39+
return;
40+
}
41+
42+
final var preferenceStore = JDIDebugUIPlugin.getDefault().getPreferenceStore();
43+
final var filterManager = JavaStackFramePreferencePage.CUSTOM_STACK_FRAMES;
44+
for (Object selected : selection) {
45+
if (selected instanceof IJavaStackFrame) {
46+
IJavaStackFrame frame = (IJavaStackFrame) selected;
47+
try {
48+
addFilter(filterManager, preferenceStore, frame.getDeclaringTypeName());
49+
// Reset all the stack frames, to be evaluated on the next step again.
50+
var thread = frame.getThread();
51+
var frames = thread.getStackFrames();
52+
for (var oneFrame : frames) {
53+
if (oneFrame instanceof IJavaStackFrame) {
54+
((IJavaStackFrame) oneFrame).setCategory(null);
55+
}
56+
}
57+
} catch (DebugException e) {
58+
JDIDebugUIPlugin.log(e);
59+
}
60+
}
61+
}
62+
63+
}
64+
65+
private void addFilter(FilterManager filterManager, IPreferenceStore preferenceStore, String filterName) {
66+
var allStoredFilters = filterManager.getAllStoredFilters(preferenceStore, false);
67+
if (enableFilter(allStoredFilters, filterName)) {
68+
filterManager.save(preferenceStore, allStoredFilters);
69+
} else {
70+
var plusOne = new Filter[allStoredFilters.length + 1];
71+
plusOne[0] = new Filter(filterName, true);
72+
System.arraycopy(allStoredFilters, 0, plusOne, 1, allStoredFilters.length);
73+
filterManager.save(preferenceStore, plusOne);
74+
}
75+
}
76+
77+
private boolean enableFilter(Filter[] allFilter, String filterName) {
78+
for (Filter filter : allFilter) {
79+
if (Objects.equals(filterName, filter.getName())) {
80+
filter.setChecked(true);
81+
return true;
82+
}
83+
}
84+
return false;
85+
}
86+
}

0 commit comments

Comments
 (0)