Skip to content

Commit

Permalink
Add an action to highlight the current stack frame for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
gzsombor committed Jul 26, 2023
1 parent 17ef2e5 commit 5430e19
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
3 changes: 3 additions & 0 deletions org.eclipse.jdt.debug.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ colorizeStackFrames.tooltip=Based on the function mark the stack frames with dif
collapseStackFrames.label=Collapse Stack Frames
collapseStackFrames.tooltip=Hide less relevant stack frames

highlightStackFrame.label=Highlight Stack Frame
highlightStackFrame.tooltip=Always mark this stack frame distinctly

stepIntoSelectionHyperlinkDetector.label=Step Into Selection
stepIntoSelectionHyperlinkDetector.description=Performs the step into selection command on demand via a hyperlink

Expand Down
8 changes: 8 additions & 0 deletions org.eclipse.jdt.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,14 @@
enablesFor="+"
id="org.eclipse.jdt.debug.ui.actions.EditStepFiltersAction">
</action>
<action
label="%highlightStackFrame.label"
tooltip="%highlightStackFrame.tooltip"
menubarPath="emptyThreadGroup"
enablesFor="+"
class="org.eclipse.jdt.internal.debug.ui.actions.HighlightStackFrameAction"
id="org.eclipse.jdt.debug.ui.actions.HighlightStackFrameAction">
</action>
</objectContribution>
<viewerContribution
targetID="org.eclipse.debug.ui.VariableView.detail"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void widgetSelected(SelectionEvent e) {

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

//widgets
private PreferenceButton fColorizeStackFrames;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2023 Zsombor Gegesy and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Zsombor Gegesy - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.debug.ui.actions;

import java.util.Objects;

import org.eclipse.debug.core.DebugException;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
import org.eclipse.jdt.internal.debug.ui.JavaStackFramePreferencePage;
import org.eclipse.jdt.internal.ui.filtertable.Filter;
import org.eclipse.jdt.internal.ui.filtertable.FilterManager;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IStructuredSelection;

/**
* Add the current stack frame to the highlighted frames.
*
*/
public class HighlightStackFrameAction extends ObjectActionDelegate {

@Override
public void run(IAction action) {
// Make sure there is a current selection
IStructuredSelection selection = getCurrentSelection();
if (selection == null) {
return;
}

final var preferenceStore = JDIDebugUIPlugin.getDefault().getPreferenceStore();
final var filterManager = JavaStackFramePreferencePage.CUSTOM_STACK_FRAMES;
for (Object selected : selection) {
if (selected instanceof IJavaStackFrame) {
IJavaStackFrame frame = (IJavaStackFrame) selected;
try {
addFilter(filterManager, preferenceStore, frame.getDeclaringTypeName());
// Reset all the stack frames, to be evaluated on the next step again.
var thread = frame.getThread();
var frames = thread.getStackFrames();
for (var oneFrame : frames) {
if (oneFrame instanceof IJavaStackFrame) {
((IJavaStackFrame) oneFrame).setCategory(null);
}
}
} catch (DebugException e) {
JDIDebugUIPlugin.log(e);
}
}
}

}

private void addFilter(FilterManager filterManager, IPreferenceStore preferenceStore, String filterName) {
var allStoredFilters = filterManager.getAllStoredFilters(preferenceStore, false);
if (enableFilter(allStoredFilters, filterName)) {
filterManager.save(preferenceStore, allStoredFilters);
} else {
var plusOne = new Filter[allStoredFilters.length + 1];
plusOne[0] = new Filter(filterName, true);
System.arraycopy(allStoredFilters, 0, plusOne, 1, allStoredFilters.length);
filterManager.save(preferenceStore, plusOne);
}
}

private boolean enableFilter(Filter[] allFilter, String filterName) {
for (Filter filter : allFilter) {
if (Objects.equals(filterName, filter.getName())) {
filter.setChecked(true);
return true;
}
}
return false;
}
}

0 comments on commit 5430e19

Please sign in to comment.