Skip to content

Add code action to introduce _ in number literals #4650

@fendor

Description

@fendor

When converting from one number format to another, we lose the information of _.

Image

The binary format is rather hard to read, so maybe it might be nice to offer a code action that translates a number format to a predefined format using _?

For example, let's assume this:

foo = 0b111001100110

We could offer a code action that translates this number to

foo = 0b1110_0110_0110

Similarly, we could offer to fix typos ala:

foo = 0b1110_011_00110

Not sure whether this is worth the extra complexity, it is just an idea.

I think it would make sense to offer for each number format the following grouping styles:

  • decimal: 3, 4 (e.g., 123_456 and 1234_5678)
  • hexadecimal: 2,4 (0xAB_CD,0xC0_FFEE)
  • octal: 2,4,8
  • binary: 4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions