Implement experimental semicolon-into-newlines feature
parent
77d6d5b553
commit
f87c0c64b8
|
@ -179,6 +179,7 @@ defaultTestConfig = Config
|
|||
, _lconfig_reformatModulePreamble = coerce True
|
||||
, _lconfig_allowSingleLineExportList = coerce True
|
||||
, _lconfig_allowHangingQuasiQuotes = coerce True
|
||||
, _lconfig_experimentalSemicolonNewlines = coerce False
|
||||
}
|
||||
, _conf_errorHandling = (_conf_errorHandling staticDefaultConfig)
|
||||
{ _econf_omit_output_valid_check = coerce True
|
||||
|
|
|
@ -60,6 +60,7 @@ defaultTestConfig = Config
|
|||
, _lconfig_reformatModulePreamble = coerce True
|
||||
, _lconfig_allowSingleLineExportList = coerce True
|
||||
, _lconfig_allowHangingQuasiQuotes = coerce True
|
||||
, _lconfig_experimentalSemicolonNewlines = coerce False
|
||||
}
|
||||
, _conf_errorHandling = (_conf_errorHandling staticDefaultConfig)
|
||||
{ _econf_ExactPrintFallback = coerce ExactPrintFallbackModeNever
|
||||
|
|
|
@ -225,11 +225,18 @@ layoutBriDocM = \case
|
|||
-- mModify $ \s -> s { _lstate_curYOrAddNewline = Right 0 }
|
||||
BDAnnotationRest annKey bd -> do
|
||||
layoutBriDocM bd
|
||||
mComments <- do
|
||||
annMay <- do
|
||||
state <- mGet
|
||||
let m = _lstate_comments state
|
||||
let mComments = nonEmpty =<< extractAllComments <$> Map.lookup annKey m
|
||||
mSet $ state
|
||||
pure $ Map.lookup annKey m
|
||||
let mComments = nonEmpty =<< extractAllComments <$> annMay
|
||||
let semiCount = length [ ()
|
||||
| Just ann <- [ annMay ]
|
||||
, (ExactPrint.Types.AnnSemiSep, _) <- ExactPrint.Types.annsDP ann
|
||||
]
|
||||
shouldAddSemicolonNewlines <- mAsk <&>
|
||||
_conf_layout .> _lconfig_experimentalSemicolonNewlines .> confUnpack
|
||||
mModify $ \state -> state
|
||||
{ _lstate_comments = Map.adjust
|
||||
( \ann -> ann { ExactPrint.annFollowingComments = []
|
||||
, ExactPrint.annPriorComments = []
|
||||
|
@ -240,11 +247,12 @@ layoutBriDocM = \case
|
|||
}
|
||||
)
|
||||
annKey
|
||||
m
|
||||
(_lstate_comments state)
|
||||
}
|
||||
return mComments
|
||||
case mComments of
|
||||
Nothing -> pure ()
|
||||
Nothing -> do
|
||||
when shouldAddSemicolonNewlines $ do
|
||||
[1..semiCount] `forM_` \_ -> layoutWriteNewline
|
||||
Just comments -> do
|
||||
comments `forM_` \(ExactPrint.Types.Comment comment _ _, ExactPrint.Types.DP (y, x)) ->
|
||||
when (not $ comment == "(" || comment == ")") $ do
|
||||
|
|
|
@ -76,6 +76,7 @@ staticDefaultConfig = Config
|
|||
, _lconfig_reformatModulePreamble = coerce True
|
||||
, _lconfig_allowSingleLineExportList = coerce False
|
||||
, _lconfig_allowHangingQuasiQuotes = coerce True
|
||||
, _lconfig_experimentalSemicolonNewlines = coerce False
|
||||
}
|
||||
, _conf_errorHandling = ErrorHandlingConfig
|
||||
{ _econf_produceOutputOnErrors = coerce False
|
||||
|
@ -179,6 +180,7 @@ cmdlineConfigParser = do
|
|||
, _lconfig_reformatModulePreamble = mempty
|
||||
, _lconfig_allowSingleLineExportList = mempty
|
||||
, _lconfig_allowHangingQuasiQuotes = mempty
|
||||
, _lconfig_experimentalSemicolonNewlines = mempty
|
||||
}
|
||||
, _conf_errorHandling = ErrorHandlingConfig
|
||||
{ _econf_produceOutputOnErrors = wrapLast $ falseToNothing outputOnErrors
|
||||
|
|
|
@ -127,6 +127,21 @@ data CLayoutConfig f = LayoutConfig
|
|||
-- > let body = [json|
|
||||
-- > hello
|
||||
-- > |]
|
||||
, _lconfig_experimentalSemicolonNewlines :: f (Last Bool)
|
||||
-- enables an experimental feature to turn semicolons in brace notation
|
||||
-- into newlines when using layout:
|
||||
--
|
||||
-- > do { a ;; b }
|
||||
--
|
||||
-- turns into
|
||||
-- > do
|
||||
-- > a
|
||||
-- >
|
||||
-- > b
|
||||
--
|
||||
-- The implementation for this is a bit hacky and not tested; it might
|
||||
-- break output syntax or not work properly for every kind of brace. So
|
||||
-- far I have considered `do` and `case-of`.
|
||||
}
|
||||
deriving (Generic)
|
||||
|
||||
|
|
Loading…
Reference in New Issue