Skip to content

Commit 426c393

Browse files
committed
add new format variable to protocol;
1 parent f29fa8a commit 426c393

8 files changed

Lines changed: 45 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ hs_err_pid*
3030
target/
3131
.settings
3232
**/.checkstyle
33-
target/
3433
bin/
3534
**/lib/
3635

3736
jdt-language-server-latest.tar.gz
3837
jdtls/
3938

40-
!.mvn/wrapper/maven-wrapper.jar
39+
!.mvn/wrapper/maven-wrapper.jar

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/DebugSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.gson.JsonSyntaxException;
2020
import com.google.gson.annotations.SerializedName;
21+
import com.microsoft.java.debug.core.adapter.formatter.NumericFormatEnum;
2122
import com.microsoft.java.debug.core.protocol.JsonUtils;
2223
import com.microsoft.java.debug.core.protocol.Requests.ClassFilters;
2324
import com.microsoft.java.debug.core.protocol.Requests.StepFilters;
@@ -32,7 +33,7 @@ public final class DebugSettings {
3233
public int numericPrecision = 0;
3334
public boolean showStaticVariables = false;
3435
public boolean showQualifiedNames = false;
35-
public boolean showHex = false;
36+
public NumericFormatEnum formatType = NumericFormatEnum.DEC;
3637
public boolean showLogicalStructure = true;
3738
public boolean showToString = true;
3839
public String logLevel;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
6161
EvaluateArguments evalArguments = (EvaluateArguments) arguments;
6262
final boolean showStaticVariables = DebugSettings.getCurrent().showStaticVariables;
6363
Map<String, Object> options = context.getVariableFormatter().getDefaultOptions();
64-
VariableUtils.applyFormatterOptions(options, evalArguments.format != null && evalArguments.format.hex);
64+
VariableUtils.applyFormatterOptions(options, evalArguments.format);
6565
String expression = evalArguments.expression;
6666

6767
if (StringUtils.isBlank(expression)) {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
import com.microsoft.java.debug.core.DebugSettings;
1919
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
2020
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
21+
import com.microsoft.java.debug.core.adapter.formatter.NumericFormatEnum;
2122
import com.microsoft.java.debug.core.protocol.Events.InvalidatedAreas;
2223
import com.microsoft.java.debug.core.protocol.Events.InvalidatedEvent;
2324
import com.microsoft.java.debug.core.protocol.Messages.Response;
25+
import com.microsoft.java.debug.core.protocol.Requests;
2426
import com.microsoft.java.debug.core.protocol.Requests.Arguments;
2527
import com.microsoft.java.debug.core.protocol.Requests.Command;
2628
import com.microsoft.java.debug.core.protocol.Requests.RefreshVariablesArguments;
2729

30+
import static com.microsoft.java.debug.core.adapter.formatter.NumericFormatEnum.HEX;
31+
import static com.microsoft.java.debug.core.adapter.formatter.NumericFormatEnum.DEC;
32+
2833
public class RefreshVariablesHandler implements IDebugRequestHandler {
2934

3035
@Override
@@ -37,7 +42,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
3742
IDebugAdapterContext context) {
3843
RefreshVariablesArguments refreshArgs = (RefreshVariablesArguments) arguments;
3944
if (refreshArgs != null) {
40-
DebugSettings.getCurrent().showHex = refreshArgs.showHex;
45+
DebugSettings.getCurrent().formatType = getFormatType(refreshArgs.showHex, refreshArgs.formatType);
4146
DebugSettings.getCurrent().showQualifiedNames = refreshArgs.showQualifiedNames;
4247
DebugSettings.getCurrent().showStaticVariables = refreshArgs.showStaticVariables;
4348
DebugSettings.getCurrent().showLogicalStructure = refreshArgs.showLogicalStructure;
@@ -47,4 +52,15 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
4752
context.getProtocolServer().sendEvent(new InvalidatedEvent(InvalidatedAreas.VARIABLES));
4853
return CompletableFuture.completedFuture(response);
4954
}
55+
56+
private NumericFormatEnum getFormatType(boolean showHex, String formatType) {
57+
if (formatType != null) {
58+
try {
59+
return NumericFormatEnum.valueOf(formatType);
60+
} catch (IllegalArgumentException exp) {
61+
// can't parse format so just return default value;
62+
}
63+
}
64+
return showHex ? NumericFormatEnum.HEX : NumericFormatEnum.DEC;
65+
}
5066
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
7777
boolean showStaticVariables = DebugSettings.getCurrent().showStaticVariables;
7878
IVariableFormatter variableFormatter = context.getVariableFormatter();
7979
Map<String, Object> options = variableFormatter.getDefaultOptions();
80-
VariableUtils.applyFormatterOptions(options, setVarArguments.format != null && setVarArguments.format.hex);
80+
VariableUtils.applyFormatterOptions(options, setVarArguments.format);
8181

8282
Object container = context.getRecyclableIdPool().getObjectById(setVarArguments.variablesReference);
8383
// container is null means the stack frame is continued by user manually.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
7676
boolean showStaticVariables = DebugSettings.getCurrent().showStaticVariables;
7777

7878
Map<String, Object> options = variableFormatter.getDefaultOptions();
79-
VariableUtils.applyFormatterOptions(options, varArgs.format != null && varArgs.format.hex);
79+
VariableUtils.applyFormatterOptions(options, varArgs.format);
8080
IEvaluationProvider evaluationEngine = context.getProvider(IEvaluationProvider.class);
8181

8282
List<Types.Variable> list = new ArrayList<>();

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/variables/VariableUtils.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.microsoft.java.debug.core.adapter.formatter.NumericFormatter;
2727
import com.microsoft.java.debug.core.adapter.formatter.SimpleTypeFormatter;
2828
import com.microsoft.java.debug.core.adapter.formatter.StringObjectFormatter;
29+
import com.microsoft.java.debug.core.protocol.Requests;
2930
import com.sun.jdi.AbsentInformationException;
3031
import com.sun.jdi.ArrayReference;
3132
import com.sun.jdi.ArrayType;
@@ -256,13 +257,15 @@ public static List<Variable> listStaticVariables(StackFrame stackFrame) {
256257
* variable view/debug console.
257258
*
258259
* @param defaultOptions the initial options for adding options from user settings
259-
* @param hexInArgument when request sent by vscode declare hex format explicitly, settings this parameter true to override value in DebugSettings class.
260+
* @param format when request sent by vscode declare format explicitly, settings this parameter true to override value in DebugSettings class.
260261
*/
261-
public static void applyFormatterOptions(Map<String, Object> defaultOptions, boolean hexInArgument) {
262+
public static void applyFormatterOptions(Map<String, Object> defaultOptions, Requests.ValueFormat format) {
262263
Map<String, Object> options = defaultOptions;
263264
boolean showFullyQualifiedNames = DebugSettings.getCurrent().showQualifiedNames;
264-
if (hexInArgument || DebugSettings.getCurrent().showHex) {
265-
options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX);
265+
if (format == null) {
266+
options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, DebugSettings.getCurrent().formatType);
267+
} else {
268+
options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, parseValueFormat(format));
266269
}
267270
if (showFullyQualifiedNames) {
268271
options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, true);
@@ -277,6 +280,17 @@ public static void applyFormatterOptions(Map<String, Object> defaultOptions, boo
277280
}
278281
}
279282

283+
private static NumericFormatEnum parseValueFormat(Requests.ValueFormat format) {
284+
if (format.type != null) {
285+
try {
286+
return NumericFormatEnum.valueOf(format.type);
287+
} catch (IllegalArgumentException exp) {
288+
// can't parse format so just return default value;
289+
}
290+
}
291+
return format.hex ? NumericFormatEnum.HEX : NumericFormatEnum.DEC;
292+
}
293+
280294
/**
281295
* Get the name for evaluation of variable.
282296
*

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
public class Requests {
2525

2626
public static class ValueFormat {
27+
@Deprecated
2728
public boolean hex;
29+
public String type;
2830
}
2931

3032
public static class Arguments {
@@ -300,7 +302,9 @@ public static class SetVariableArguments extends Arguments {
300302
public static class RefreshVariablesArguments extends Arguments {
301303
public boolean showStaticVariables = false;
302304
public boolean showQualifiedNames = false;
305+
@Deprecated
303306
public boolean showHex = false;
307+
public String formatType = null;
304308
public boolean showLogicalStructure = true;
305309
public boolean showToString = true;
306310
}

0 commit comments

Comments
 (0)