Implement experimental semicolon-into-newlines feature
parent
77d6d5b553
commit
f87c0c64b8
|
@ -179,6 +179,7 @@ defaultTestConfig = Config
|
||||||
, _lconfig_reformatModulePreamble = coerce True
|
, _lconfig_reformatModulePreamble = coerce True
|
||||||
, _lconfig_allowSingleLineExportList = coerce True
|
, _lconfig_allowSingleLineExportList = coerce True
|
||||||
, _lconfig_allowHangingQuasiQuotes = coerce True
|
, _lconfig_allowHangingQuasiQuotes = coerce True
|
||||||
|
, _lconfig_experimentalSemicolonNewlines = coerce False
|
||||||
}
|
}
|
||||||
, _conf_errorHandling = (_conf_errorHandling staticDefaultConfig)
|
, _conf_errorHandling = (_conf_errorHandling staticDefaultConfig)
|
||||||
{ _econf_omit_output_valid_check = coerce True
|
{ _econf_omit_output_valid_check = coerce True
|
||||||
|
|
|
@ -60,6 +60,7 @@ defaultTestConfig = Config
|
||||||
, _lconfig_reformatModulePreamble = coerce True
|
, _lconfig_reformatModulePreamble = coerce True
|
||||||
, _lconfig_allowSingleLineExportList = coerce True
|
, _lconfig_allowSingleLineExportList = coerce True
|
||||||
, _lconfig_allowHangingQuasiQuotes = coerce True
|
, _lconfig_allowHangingQuasiQuotes = coerce True
|
||||||
|
, _lconfig_experimentalSemicolonNewlines = coerce False
|
||||||
}
|
}
|
||||||
, _conf_errorHandling = (_conf_errorHandling staticDefaultConfig)
|
, _conf_errorHandling = (_conf_errorHandling staticDefaultConfig)
|
||||||
{ _econf_ExactPrintFallback = coerce ExactPrintFallbackModeNever
|
{ _econf_ExactPrintFallback = coerce ExactPrintFallbackModeNever
|
||||||
|
|
|
@ -225,11 +225,18 @@ layoutBriDocM = \case
|
||||||
-- mModify $ \s -> s { _lstate_curYOrAddNewline = Right 0 }
|
-- mModify $ \s -> s { _lstate_curYOrAddNewline = Right 0 }
|
||||||
BDAnnotationRest annKey bd -> do
|
BDAnnotationRest annKey bd -> do
|
||||||
layoutBriDocM bd
|
layoutBriDocM bd
|
||||||
mComments <- do
|
annMay <- do
|
||||||
state <- mGet
|
state <- mGet
|
||||||
let m = _lstate_comments state
|
let m = _lstate_comments state
|
||||||
let mComments = nonEmpty =<< extractAllComments <$> Map.lookup annKey m
|
pure $ Map.lookup annKey m
|
||||||
mSet $ state
|
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
|
{ _lstate_comments = Map.adjust
|
||||||
( \ann -> ann { ExactPrint.annFollowingComments = []
|
( \ann -> ann { ExactPrint.annFollowingComments = []
|
||||||
, ExactPrint.annPriorComments = []
|
, ExactPrint.annPriorComments = []
|
||||||
|
@ -240,11 +247,12 @@ layoutBriDocM = \case
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
annKey
|
annKey
|
||||||
m
|
(_lstate_comments state)
|
||||||
}
|
}
|
||||||
return mComments
|
|
||||||
case mComments of
|
case mComments of
|
||||||
Nothing -> pure ()
|
Nothing -> do
|
||||||
|
when shouldAddSemicolonNewlines $ do
|
||||||
|
[1..semiCount] `forM_` \_ -> layoutWriteNewline
|
||||||
Just comments -> do
|
Just comments -> do
|
||||||
comments `forM_` \(ExactPrint.Types.Comment comment _ _, ExactPrint.Types.DP (y, x)) ->
|
comments `forM_` \(ExactPrint.Types.Comment comment _ _, ExactPrint.Types.DP (y, x)) ->
|
||||||
when (not $ comment == "(" || comment == ")") $ do
|
when (not $ comment == "(" || comment == ")") $ do
|
||||||
|
|
|
@ -76,6 +76,7 @@ staticDefaultConfig = Config
|
||||||
, _lconfig_reformatModulePreamble = coerce True
|
, _lconfig_reformatModulePreamble = coerce True
|
||||||
, _lconfig_allowSingleLineExportList = coerce False
|
, _lconfig_allowSingleLineExportList = coerce False
|
||||||
, _lconfig_allowHangingQuasiQuotes = coerce True
|
, _lconfig_allowHangingQuasiQuotes = coerce True
|
||||||
|
, _lconfig_experimentalSemicolonNewlines = coerce False
|
||||||
}
|
}
|
||||||
, _conf_errorHandling = ErrorHandlingConfig
|
, _conf_errorHandling = ErrorHandlingConfig
|
||||||
{ _econf_produceOutputOnErrors = coerce False
|
{ _econf_produceOutputOnErrors = coerce False
|
||||||
|
@ -179,6 +180,7 @@ cmdlineConfigParser = do
|
||||||
, _lconfig_reformatModulePreamble = mempty
|
, _lconfig_reformatModulePreamble = mempty
|
||||||
, _lconfig_allowSingleLineExportList = mempty
|
, _lconfig_allowSingleLineExportList = mempty
|
||||||
, _lconfig_allowHangingQuasiQuotes = mempty
|
, _lconfig_allowHangingQuasiQuotes = mempty
|
||||||
|
, _lconfig_experimentalSemicolonNewlines = mempty
|
||||||
}
|
}
|
||||||
, _conf_errorHandling = ErrorHandlingConfig
|
, _conf_errorHandling = ErrorHandlingConfig
|
||||||
{ _econf_produceOutputOnErrors = wrapLast $ falseToNothing outputOnErrors
|
{ _econf_produceOutputOnErrors = wrapLast $ falseToNothing outputOnErrors
|
||||||
|
|
|
@ -127,6 +127,21 @@ data CLayoutConfig f = LayoutConfig
|
||||||
-- > let body = [json|
|
-- > let body = [json|
|
||||||
-- > hello
|
-- > 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)
|
deriving (Generic)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue