Skip to content

Commit b368760

Browse files
added attributes to VariablePresentationHint as specified in protocol definition
1 parent a4c27fb commit b368760

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/VariablesRequestHandler.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class VariablesRequestHandler implements IDebugRequestHandler {
8282
* single-threaded JDWP request processing strategy,
8383
* a single JDWP latency is about 10ms.
8484
*/
85-
static final long USABLE_JDWP_LATENCY = 10/**ms*/;
85+
static final long USABLE_JDWP_LATENCY = 10/*ms*/;
8686

8787
@Override
8888
public List<Command> getTargetCommands() {
@@ -370,10 +370,12 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
370370
referenceId = context.getRecyclableIdPool().addObject(containerNode.getThreadId(), varProxy);
371371
}
372372

373+
String[] rawAttributes = extractAttributes(javaVariable);
374+
373375
Types.Variable typedVariables = new Types.Variable(name, valueString, typeString, referenceId, evaluateName);
374376
typedVariables.indexedVariables = Math.max(indexedVariables, 0);
375-
if (varProxy != null && varProxy.isLazyVariable()) {
376-
typedVariables.presentationHint = new VariablePresentationHint(true);
377+
if ((varProxy != null && varProxy.isLazyVariable()) || (rawAttributes.length > 0)) {
378+
typedVariables.presentationHint = new VariablePresentationHint(varProxy == null || varProxy.isLazyVariable(), rawAttributes);
377379
}
378380

379381
if (detailsValue != null) {
@@ -391,6 +393,28 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
391393
return CompletableFuture.completedFuture(response);
392394
}
393395

396+
private String[] extractAttributes(Variable variable) {
397+
final List<String> attributes = new ArrayList<>();
398+
if (variable.field != null) {
399+
if (variable.field.isStatic()) {
400+
attributes.add("static");
401+
}
402+
if (variable.field.isFinal()) {
403+
// static final fields are compile-time constants in Java
404+
if (variable.field.isStatic()) {
405+
attributes.add("constant");
406+
}
407+
attributes.add("readOnly");
408+
}
409+
}
410+
// local 'final' variables get inlined by the compiler and do not appear
411+
if (variable.value instanceof StringReference) {
412+
attributes.add("rawString");
413+
}
414+
415+
return attributes.toArray(new String[0]);
416+
}
417+
394418
private boolean supportsLogicStructureView(IDebugAdapterContext context) {
395419
return (!useAsyncJDWP(context) || context.getJDWPLatency() <= USABLE_JDWP_LATENCY)
396420
&& DebugSettings.getCurrent().showLogicalStructure;

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/protocol/Types.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,13 @@ public static class StackFrame {
4949
/**
5050
* Constructs a StackFrame with the given information.
5151
*
52-
* @param id
53-
* the stack frame id
54-
* @param name
55-
* the stack frame name
56-
* @param src
57-
* source info of the stack frame
58-
* @param ln
59-
* line number of the stack frame
60-
* @param col
61-
* column number of the stack frame
62-
* @param presentationHint
63-
* An optional hint for how to present this frame in the UI.
64-
* Values: 'normal', 'label', 'subtle'
52+
* @param id the stack frame id
53+
* @param name the stack frame name
54+
* @param src source info of the stack frame
55+
* @param ln line number of the stack frame
56+
* @param col column number of the stack frame
57+
* @param presentationHint An optional hint for how to present this frame in the UI.
58+
* Values: 'normal', 'label', 'subtle'
6559
*/
6660
public StackFrame(int id, String name, Source src, int ln, int col, String presentationHint) {
6761
this.id = id;
@@ -408,9 +402,11 @@ public static class ExceptionDetails {
408402

409403
public static class VariablePresentationHint {
410404
public boolean lazy;
405+
public String[] attributes;
411406

412-
public VariablePresentationHint(boolean lazy) {
407+
public VariablePresentationHint(boolean lazy, String[] attributes) {
413408
this.lazy = lazy;
409+
this.attributes = attributes;
414410
}
415411
}
416412

0 commit comments

Comments
 (0)