Skip to content

Commit e22fe85

Browse files
committed
feat: display line numbers in debugger stack frame elements
1 parent f391665 commit e22fe85

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/presentation/DSPDebugModelPresentation.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.eclipse.jface.viewers.LabelProvider;
3434
import org.eclipse.lsp4e.debug.DSPPlugin;
3535
import org.eclipse.lsp4e.debug.debugmodel.DSPDebugElement;
36+
import org.eclipse.lsp4e.debug.debugmodel.DSPStackFrame;
3637
import org.eclipse.lsp4e.debug.debugmodel.DSPThread;
3738
import org.eclipse.osgi.util.NLS;
3839
import org.eclipse.swt.SWT;
@@ -58,7 +59,6 @@ public String getText(Object element) {
5859
final var label = new StringBuilder();
5960
if (element instanceof DSPThread thread) {
6061
label.append(NLS.bind("Thread #{0} [{1}]", thread.getId(), thread.getName()));
61-
6262
}
6363

6464
if (label.length() != 0) {
@@ -72,6 +72,26 @@ public String getText(Object element) {
7272
} else {
7373
// Use default TODO should the entire default be copied here?
7474
label.append(DebugUIPlugin.getDefaultLabelProvider().getText(element));
75+
76+
if (element instanceof DSPStackFrame frame) {
77+
try {
78+
final int line = frame.getLineNumber();
79+
if (line > 0) {
80+
final String source = frame.getSourceName();
81+
String file = new Path(source).lastSegment();
82+
if (file == null) {
83+
file = source;
84+
}
85+
final String suffix = '(' + file + ":" + line + ')'; //$NON-NLS-1$
86+
if (!endsWith(label, suffix)) {
87+
label.append(' ');
88+
label.append(suffix);
89+
}
90+
}
91+
} catch (final Exception ex) {
92+
DSPPlugin.logWarning("Failed to determine stack frame line number", ex);
93+
}
94+
}
7595
}
7696
if (element instanceof DSPDebugElement debugElement) {
7797
if (debugElement.getErrorMessage() != null) {
@@ -197,6 +217,20 @@ public void computeDetail(IValue value, IValueDetailListener listener) {
197217
}
198218
}
199219

220+
private static boolean endsWith(final StringBuilder sb, final String suffix) {
221+
final int sbLen = sb.length();
222+
final int suffixLen = suffix.length();
223+
if (suffixLen > sbLen) {
224+
return false;
225+
}
226+
for (int i = 1; i <= suffixLen; i++) {
227+
if (sb.charAt(sbLen - i) != suffix.charAt(suffixLen - i)) {
228+
return false;
229+
}
230+
}
231+
return true;
232+
}
233+
200234
public static Display getDisplay() {
201235
Display display;
202236
display = Display.getCurrent();

0 commit comments

Comments
 (0)