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

group number by 4 digit #1262

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/FsAutoComplete/CodeFixes/AdjustConstant.fs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ module Title =

module Separate =
let decimal3 = "Separate thousands (3)"
let decimal4 = "Separate ten thousands (4)"
let hexadecimal4 = "Separate words (4)"
let hexadecimal2 = "Separate bytes (2)"
let octal3 = "Separate digit groups (3)"
Expand All @@ -548,6 +549,7 @@ module Title =
module Float =
module Separate =
let all3 = "Separate digit groups (3)"
let all4 = "Separate digit groups (4)"

module Char =
module Convert =
Expand Down Expand Up @@ -1374,7 +1376,9 @@ module private IntFix =
List.empty

match constant.Base with
| Base.Decimal -> [ yield! tryMkFix Title.Int.Separate.decimal3 3 ]
| Base.Decimal ->
[ yield! tryMkFix Title.Int.Separate.decimal3 3
yield! tryMkFix Title.Int.Separate.decimal4 4 ]
| Base.Hexadecimal ->
[ yield! tryMkFix Title.Int.Separate.hexadecimal4 4
yield! tryMkFix Title.Int.Separate.hexadecimal2 2 ]
Expand Down Expand Up @@ -1514,29 +1518,31 @@ module private FloatFix =
if text.Contains '_' then
[]
else
let edits =
[| if constant.IntRange.Length > 3 then
let makeFloatSepFix len =
[| if constant.IntRange.Length > len then
let range = constant.IntRange.ToRangeInside constant.Range
let n = range.SpanIn(lineStr).ToString()

{ Range = range
NewText = DigitGroup.addSeparator n 3 DigitGroup.RightToLeft }
if constant.DecimalRange.Length > 3 then
NewText = DigitGroup.addSeparator n len DigitGroup.RightToLeft }
if constant.DecimalRange.Length > len then
let range = constant.DecimalRange.ToRangeInside constant.Range
let n = range.SpanIn(lineStr).ToString()

{ Range = range
NewText = DigitGroup.addSeparator n 3 DigitGroup.LeftToRight }
if constant.ExponentRange.Length > 3 then
NewText = DigitGroup.addSeparator n len DigitGroup.LeftToRight }
if constant.ExponentRange.Length > len then
let range = constant.ExponentRange.ToRangeInside constant.Range
let n = range.SpanIn(lineStr).ToString()

{ Range = range
NewText = DigitGroup.addSeparator n 3 DigitGroup.RightToLeft } |]
NewText = DigitGroup.addSeparator n len DigitGroup.RightToLeft } |]

match edits with
| [||] -> []
| _ -> mkFix doc Title.Float.Separate.all3 edits |> List.singleton
[ Title.Float.Separate.all3, 3; Title.Float.Separate.all4, 4 ]
|> List.choose (fun (title, len) ->
match makeFloatSepFix len with
| [||] -> None
| edits -> Some(mkFix doc title edits))

/// Removes or adds digit group separators (`_`)
let digitGroupFixes doc (lineStr: String) (constant: FloatConstant) =
Expand Down
2 changes: 2 additions & 0 deletions src/FsAutoComplete/CodeFixes/AdjustConstant.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Title =

module Separate =
val decimal3: string
val decimal4: string
val hexadecimal4: string
val hexadecimal2: string
val octal3: string
Expand All @@ -55,6 +56,7 @@ module Title =
module Float =
module Separate =
val all3: string
val all4: string

module Char =
module Convert =
Expand Down
Loading