Skip to content

Commit 51721ef

Browse files
committed
Specify UnderscoreFormatType per lit format
1 parent bd58606 commit 51721ef

File tree

1 file changed

+16
-4
lines changed
  • plugins/hls-alternate-number-format-plugin/src/Ide/Plugin

1 file changed

+16
-4
lines changed

plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ module Ide.Plugin.Conversion (
1616
, toFloatDecimal
1717
, toFloatExpDecimal
1818
, toHexFloat
19+
, intFormats
20+
, fracFormats
1921
, AlternateFormat
2022
, ExtensionNeeded(..)
23+
, UnderscoreFormatType(..)
2124
) where
2225

2326
import Data.List (delete)
@@ -171,17 +174,26 @@ toBinary = toBase showBin_ "0b"
171174
showBin_ = showIntAtBase 2 intToDigit
172175

173176
toOctal = toBase showOct "0o"
177+
data UnderscoreFormatType
178+
= NoUnderscores
179+
| UseUnderscores Int
180+
deriving (Show, Eq)
174181

175182
toHex = toBase showHex "0x"
176183

177184
toDecimal :: Integral a => a -> String
178185
toDecimal = toBase showInt ""
179186

180-
toFloatDecimal :: RealFloat a => a -> String
181-
toFloatDecimal val = showFFloat Nothing val ""
187+
intFormats :: Map.Map IntFormatType [UnderscoreFormatType]
188+
intFormats = Map.fromList $ map (\t -> (t, intFormatUnderscore t)) enumerate
182189

183-
toFloatExpDecimal :: RealFloat a => a -> String
184-
toFloatExpDecimal val = showEFloat Nothing val ""
190+
intFormatUnderscore :: IntFormatType -> [UnderscoreFormatType]
191+
intFormatUnderscore formatType = NoUnderscores : map UseUnderscores (case formatType of
192+
IntDecimalFormat -> [3, 4]
193+
HexFormat -> [2, 4]
194+
OctalFormat -> [2, 4, 8]
195+
BinaryFormat -> [4]
196+
NumDecimalFormat -> [3, 4])
185197

186198
toHexFloat :: RealFloat a => a -> String
187199
toHexFloat val = showHFloat val ""

0 commit comments

Comments
 (0)