Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing numbers defined as hex in hexadecimal format, not just decimal #728

Open
hachigoro opened this issue Jan 5, 2024 · 4 comments
Open

Comments

@hachigoro
Copy link

Hello,

I was debugging some AS3 code, and I noticed that some variables that have a number in them, which was set in hex format, is shown as decimal in the debugger. As an example, I have this:

public static const STATE2:uint = 0xae03c339;
...
var gameState:uint = STATE2;

In VS Code this would look like this:
image

In FlashDevelop and IntelliJ IDEA it shows it in both dec and hex:

image

I think it would be very useful to show those variables in both dec and hex, to avoid having to go to an external number converter. Thanks!

@joshtynjala
Copy link
Member

Cool idea. Thanks!

@joshtynjala
Copy link
Member

I looked into this, and while it is possible to show both regular and hex representations of integers, VSCode will no longer highlight the original value as a number when I do (colored green in your screenshot, for instance). I think that it is critical to keep that color highlighting behavior for numeric values.

One possible solution would be to add the hex representation to the variable's type field so that the hex value appears in the tooltip, along with the type, but that feels hacky to me. Additionally, something may break in the future if the type field is ever used for more than simple presentation (which might not happen because it might be considered a breaking change, but I'd rather not take that chance).

At this point, I'm probably not going to change anything, since there isn't a solution that I like.

For my future reference, if I revisit this, I was able to change SWFDebugSession.mapMembersToVariables() to add a case after VariableType.STRING for numeric values.

else if (memberValue.getType() == VariableType.NUMBER) {
    String hexString = "";
    Object memberValueAsObject = memberValue.getValueAsObject();
    if (memberValueAsObject instanceof Double) {
        double memberValueAsDouble = (double) memberValueAsObject;
        if (memberValueAsDouble == Math.floor(memberValueAsDouble)) {
            hexString = " [0x" + Integer.toHexString((int) memberValueAsDouble) + "]";
        }
    }
    variable.value = memberValue.getValueAsString() + hexString;
}

@hachigoro
Copy link
Author

Thanks for looking into this. I understand the concern about losing the green coloring. However I see the color coding as a way to easily visualize things in the debugger, and showing hex numbers in hex format would probably provide more value than color coding, given that showing dec and hex next to each other make those numbers stand out from the rest. Also the time saved by not having to manually convert the numbers probably outweighs the cons.

If you are not convinced by that, I found that from version 1.50, VS Code added functionality that enables debug extensions to implement data formats for variables. It's explained here https://code.visualstudio.com/updates/v1_49#_contributable-context-menu-for-variables-view

So you could add a context menu on the debug values to show them in different formats. I still like showing both dec and hex directly as it saves time, but the context menu solution is good too. Let me know what you think.

@hachigoro
Copy link
Author

hachigoro commented Jan 30, 2024

Hello @joshtynjala, just a friendly reminder, in case you have given some thought about adding the context menu option to the debugger, to see variables in different formats, as suggested in the link I sent. So when we right click on a variable like this:
image

it shows something like this:
image

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants