Support import column vs import-as column
parent
4b12115712
commit
8de56ba11d
|
@ -169,6 +169,7 @@ defaultTestConfig = Config
|
|||
, _lconfig_indentWhereSpecial = coerce True
|
||||
, _lconfig_indentListSpecial = coerce True
|
||||
, _lconfig_importColumn = coerce (60 :: Int)
|
||||
, _lconfig_importAsColumn = coerce (60 :: Int)
|
||||
, _lconfig_altChooser = coerce $ AltChooserBoundedSearch 3
|
||||
, _lconfig_columnAlignMode = coerce (ColumnAlignModeMajority 0.7)
|
||||
, _lconfig_alignmentLimit = coerce (30 :: Int)
|
||||
|
|
|
@ -51,6 +51,7 @@ defaultTestConfig = Config
|
|||
, _lconfig_indentWhereSpecial = coerce True
|
||||
, _lconfig_indentListSpecial = coerce True
|
||||
, _lconfig_importColumn = coerce (60 :: Int)
|
||||
, _lconfig_importAsColumn = coerce (60 :: Int)
|
||||
, _lconfig_altChooser = coerce $ AltChooserBoundedSearch 3
|
||||
, _lconfig_columnAlignMode = coerce (ColumnAlignModeMajority 0.7)
|
||||
, _lconfig_alignmentLimit = coerce (30 :: Int)
|
||||
|
|
|
@ -59,6 +59,7 @@ staticDefaultConfig = Config
|
|||
, _lconfig_indentWhereSpecial = coerce True
|
||||
, _lconfig_indentListSpecial = coerce True
|
||||
, _lconfig_importColumn = coerce (50 :: Int)
|
||||
, _lconfig_importAsColumn = coerce (50 :: Int)
|
||||
, _lconfig_altChooser = coerce (AltChooserBoundedSearch 3)
|
||||
, _lconfig_columnAlignMode = coerce (ColumnAlignModeMajority 0.7)
|
||||
, _lconfig_alignmentLimit = coerce (30 :: Int)
|
||||
|
@ -106,6 +107,7 @@ configParser = do
|
|||
ind <- addFlagReadParams "" ["indent"] "AMOUNT" (flagHelpStr "spaces per indentation level")
|
||||
cols <- addFlagReadParams "" ["columns"] "AMOUNT" (flagHelpStr "target max columns (80 is an old default for this)")
|
||||
importCol <- addFlagReadParams "" ["import-col"] "N" (flagHelpStr "column to align import lists at")
|
||||
importAsCol <- addFlagReadParams "" ["import-as-col"] "N" (flagHelpStr "column to qualified-as module names at")
|
||||
|
||||
dumpConfig <- addSimpleBoolFlag "" ["dump-config"] (flagHelp $ parDoc "dump the programs full config (merged commandline + file + defaults)")
|
||||
dumpAnnotations <- addSimpleBoolFlag "" ["dump-annotations"] (flagHelp $ parDoc "dump the full annotations returned by ghc-exactprint")
|
||||
|
@ -155,6 +157,7 @@ configParser = do
|
|||
, _lconfig_indentWhereSpecial = mempty -- falseToNothing _
|
||||
, _lconfig_indentListSpecial = mempty -- falseToNothing _
|
||||
, _lconfig_importColumn = optionConcat importCol
|
||||
, _lconfig_importAsColumn = optionConcat importAsCol
|
||||
, _lconfig_altChooser = mempty
|
||||
, _lconfig_columnAlignMode = mempty
|
||||
, _lconfig_alignmentLimit = mempty
|
||||
|
|
|
@ -54,6 +54,11 @@ data CLayoutConfig f = LayoutConfig
|
|||
-- when creating zero-indentation
|
||||
-- multi-line list literals.
|
||||
, _lconfig_importColumn :: f (Last Int)
|
||||
-- ^ for import statement layouting, column at which to align the
|
||||
-- elements to be imported from a module.
|
||||
, _lconfig_importAsColumn :: f (Last Int)
|
||||
-- ^ for import statement layouting, column at which put the module's
|
||||
-- "as" name (which also affects the positioning of the "as" keyword).
|
||||
, _lconfig_altChooser :: f (Last AltChooser)
|
||||
, _lconfig_columnAlignMode :: f (Last ColumnAlignMode)
|
||||
, _lconfig_alignmentLimit :: f (Last Int)
|
||||
|
|
|
@ -46,6 +46,7 @@ layoutImport :: ToBriDoc ImportDecl
|
|||
layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
|
||||
ImportDecl _ (L _ modName) pkg src safe q False mas mllies -> do
|
||||
importCol <- mAsk <&> _conf_layout .> _lconfig_importColumn .> confUnpack
|
||||
importAsCol <- mAsk <&> _conf_layout .> _lconfig_importAsColumn .> confUnpack
|
||||
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
|
||||
let
|
||||
compact = indentPolicy == IndentPolicyLeft
|
||||
|
@ -136,9 +137,9 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
|
|||
Just n | enoughRoom -> docLines [docSeq [importHead, asDoc], bindingLine]
|
||||
| otherwise -> docLines [importHead, asDoc, bindingLine]
|
||||
where
|
||||
enoughRoom = nameCost < importCol - asCost
|
||||
enoughRoom = nameCost < importAsCol - asCost
|
||||
asDoc =
|
||||
docEnsureIndent (BrIndentSpecial (importCol - asCost))
|
||||
docEnsureIndent (BrIndentSpecial (importAsCol - asCost))
|
||||
$ makeAsDoc n
|
||||
Nothing | enoughRoom -> docSeq [importHead, bindingLine]
|
||||
| otherwise -> docLines [importHead, bindingLine]
|
||||
|
|
Loading…
Reference in New Issue