Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public List<Scope> getScopes(ThreadsHandler.SuspendedThreadInfo info, int frameI
while (dscope != null) {
if (dscope.isFunctionScope() || dscope.getDeclaredValues().iterator().hasNext()) {
// provide only scopes that have some variables
scopes.add(Scope.create("Global", info.getId(dscope), true));
scopes.add(Scope.create(topScopeDapName(dscope), info.getId(dscope), true));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This changes observable DAP output, but the PR does not update the existing regression coverage. SimpleLanguageDAPTest.testScopes() still asserts Global at several scope responses, and there is no new DAP test for a language-defined top-scope display name. Please update that test and add a custom-language regression that asserts a non-default DebugScope.getName() value flows through here, plus the empty/error fallback.

}
dscope = getParent(dscope);
}
Expand All @@ -152,7 +152,24 @@ public List<Scope> getScopes(ThreadsHandler.SuspendedThreadInfo info, int frameI
return null;
}

public static Variable evaluateOnStackFrame(ThreadsHandler.SuspendedThreadInfo info, int frameId, String expression) throws DebugException {
/**
* Label for the guest language top scope in the DAP variables view. Prefer
* {@link DebugScope#getName()} (guest {@code toDisplayString}) so languages can surface a
* meaningful name; fall back to {@code "Global"} if the name is unavailable or empty.
*/
private static String topScopeDapName(DebugScope dscope) {
try {
String name = dscope.getName();
if (name != null && !name.isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This only falls back for null and the empty string. If a guest scope returns whitespace-only text from toDisplayString(), the DAP UI will get a blank label instead of the legacy Global fallback. I would trim here, or otherwise reject blank names before returning them.

return name;
}
} catch (DebugException ignored) {
// Unusable guest scope name — keep the previous fixed label behavior.
}
return "Global";
}

public static Variable evaluateOnStackFrame(ThreadsHandler.SuspendedThreadInfo info, int frameId, String expression) {
FrameWrapper frameWrapper = info.getById(FrameWrapper.class, frameId);
DebugStackFrame frame = frameWrapper != null ? frameWrapper.getFrame() : null;
if (frame != null) {
Expand Down