From 1a3ba2089ddcf771e89e1d6b6c3b23671307501e Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:21:49 +0800 Subject: [PATCH] group number by 4 digit --- .../CodeFixes/AdjustConstant.fs | 28 +++++++++++-------- .../CodeFixes/AdjustConstant.fsi | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/FsAutoComplete/CodeFixes/AdjustConstant.fs b/src/FsAutoComplete/CodeFixes/AdjustConstant.fs index 43971b361..ec671a3ff 100644 --- a/src/FsAutoComplete/CodeFixes/AdjustConstant.fs +++ b/src/FsAutoComplete/CodeFixes/AdjustConstant.fs @@ -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)" @@ -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 = @@ -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 ] @@ -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) = diff --git a/src/FsAutoComplete/CodeFixes/AdjustConstant.fsi b/src/FsAutoComplete/CodeFixes/AdjustConstant.fsi index fc6a655f9..a3972ed2a 100644 --- a/src/FsAutoComplete/CodeFixes/AdjustConstant.fsi +++ b/src/FsAutoComplete/CodeFixes/AdjustConstant.fsi @@ -46,6 +46,7 @@ module Title = module Separate = val decimal3: string + val decimal4: string val hexadecimal4: string val hexadecimal2: string val octal3: string @@ -55,6 +56,7 @@ module Title = module Float = module Separate = val all3: string + val all4: string module Char = module Convert =