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

Assists for adding and maybe removing digit separators from number literals #56467

Closed
Tracked by #56188
srawlins opened this issue Aug 14, 2024 · 0 comments
Closed
Tracked by #56188
Assignees
Labels
analyzer-assist Issues with analysis server assists area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

As part of #56188, we want to add one or more assists for adding, and maybe removing digit separators (_) from number literals. Here are the cases I've thought of:

Decimal integer literal

Given a decimal integer literal, var x = /*caret*/1000000;, offer to add a separator at 3 digits, yielding var x = 1_000_000;.

If we only offer "every 3 digits" for a decimal integer, then we cannot add any separator for a number with 1, 2, or 3 digits. But what about 4? The Internet has many opinions about whether digit separators should be used for a 4-digit integer. Wikipedia has a good section on Digit grouping. According to a guide from the International Bureau of Weights and Measures, a 4-digit number can feature a separator, but "this practice is not usually followed for numbers having only four digits on either side of the decimal marker except when uniformity in a table is desired." 🤷

I would be ok if we started offering the separators at 4 digits, or at 5 digits.

Hexadecimal integer literal

Given a hexadecimal integer literal, var x = /*caret*/0xff33cc;, offer to add a separator at every 2 digits, yielding var x = 0xff_33_cc;.

Wikipedia mentions that separating every 2 digits, equivalent to each byte, is standard: "Similarly, in hexadecimal (base-16), full spaces are usually used to group digits into twos, making each group correspond to a byte."

Decimal double literal

Given a decimal double literal, var x = /*caret*/12345.67890;, offer to add a separator at 3 digits, both to the left of the decimal, and to the right, yielding var x = 12_345.678_90;.

The same Wikipedia entry, and other areas of the Internet, indicate that commas are not standard on the fractional side of the decimal point, but that other separators like a "thin space", are standard.

Scientific notation double literal

Given a scientific notation double literal, var x = /*caret*/123123.456456e789789;, offer to add a separator at 3 digits, to the left of the decimal, the right of the decimal, and the right of the e, yielding var x = 123_123.456_456e789_789;.

I cannot find any examples or advice regarding separators in the exponent; it seems without evidence to the contrary, we should just be consistent and offer the separators.

Existing separators

When a number has existing separators, I think we should still offer to "add digit separators" to "correct" any "incorrect" ones. It could be worded something like "place digit separator every 3 digits." We could also not offer the assist when the separators are in the expected positions.

Removing separators

It seems to make sense to offer to remove separators. It makes a nice pair of opposing assists. I can also see wanting to remove separators in bulk. Although I think assists cannot currently be offered in bulk.

@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug analyzer-assist Issues with analysis server assists labels Aug 14, 2024
@srawlins srawlins mentioned this issue Aug 14, 2024
16 tasks
@srawlins srawlins self-assigned this Aug 14, 2024
copybara-service bot pushed a commit that referenced this issue Aug 14, 2024
Work towards #56467

Thw two assists do the following:

* Add a digit separators every 3 digits in a decimal int, a decimal
  double, and a scientific notation double.
* Add a digit separators every 2 digits in a hexadecimal int.

No assists are introduced which remove digit separators.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I0920fb279285963c33a78d9288317213739ae83b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380601
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-assist Issues with analysis server assists area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

1 participant