Skip to content

Commit e7a6e6e

Browse files
authored
feat: display line numbers in debugger stack frame elements (#1384)
1 parent d142f58 commit e7a6e6e

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

org.eclipse.lsp4e.debug/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: Debug Adapter client for Eclipse IDE (Incubation)
44
Bundle-SymbolicName: org.eclipse.lsp4e.debug;singleton:=true
55
Bundle-Vendor: Eclipse LSP4E
6-
Bundle-Version: 0.15.16.qualifier
6+
Bundle-Version: 0.15.17.qualifier
77
Bundle-Activator: org.eclipse.lsp4e.debug.DSPPlugin
88
Require-Bundle: org.eclipse.ui,
99
org.eclipse.core.runtime,

org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/debugmodel/DSPStackFrame.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ public int getCharEnd() throws DebugException {
183183
return -1;
184184
}
185185

186-
public String getSourceName() {
187-
return stackFrame.getSource().getPath();
186+
public @Nullable String getSourceName() {
187+
final var source = stackFrame.getSource();
188+
return source == null ? null : source.getPath();
188189
}
189190

190191
public Integer getFrameId() {

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

Lines changed: 37 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,28 @@ 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+
if (source != null) {
82+
String file = new Path(source).lastSegment();
83+
if (file == null) {
84+
file = source;
85+
}
86+
final String suffix = '(' + file + ":" + line + ')'; //$NON-NLS-1$
87+
if (!endsWith(label, suffix)) {
88+
label.append(' ');
89+
label.append(suffix);
90+
}
91+
}
92+
}
93+
} catch (final Exception ex) {
94+
DSPPlugin.logWarning("Failed to determine stack frame line number", ex);
95+
}
96+
}
7597
}
7698
if (element instanceof DSPDebugElement debugElement) {
7799
if (debugElement.getErrorMessage() != null) {
@@ -197,6 +219,20 @@ public void computeDetail(IValue value, IValueDetailListener listener) {
197219
}
198220
}
199221

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

0 commit comments

Comments
 (0)