unison-cli-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Codebase.Editor.HandleInput.FormatFile

Synopsis

Documentation

formatFile :: Monad m => (Maybe (UnisonFile Symbol Ann) -> Maybe (TypecheckedUnisonFile Symbol Ann) -> m PrettyPrintEnvDecl) -> Int -> Absolute -> Maybe (UnisonFile Symbol Ann) -> Maybe (TypecheckedUnisonFile Symbol Ann) -> Maybe (Set Range) -> m (Maybe [TextReplacement]) Source #

Format a file, returning a list of Text replacements to apply to the file.

applyTextReplacements :: [TextReplacement] -> Text -> Text Source #

Apply a list of range replacements to a text, returning the updated text.

>>> applyFormatUpdates [TextReplacement "cakes" (Range (Pos.Pos 1 21) (Pos.Pos 1 28))] "my favorite food is oranges because\nthey are delicious and nutritious"
"my favorite food is cakes because\nthey are delicious and nutritious"

Multiple replacements. >>> let txt = "my favorite food is oranges becausenthey are delicious and nutritious" >>> let replacements = [TextReplacement "cakes" (Range (Pos.Pos 1 21) (Pos.Pos 1 28)), TextReplacement "decadent" (Range (Pos.Pos 2 10) (Pos.Pos 2 19)), TextReplacement "tasty" (Range (Pos.Pos 2 24) (Pos.Pos 2 34))] >>> applyFormatUpdates replacements txt "my favorite food is cakes becausenthey are decadent and tasty"

Multi-line replacements. >>> let txt = "mary had a little lambnwhose fleece was white as snownand everywhere that mary wentnthe lamb was sure to go" >>> let replacements = [TextReplacement "lambo, which" (Range (Pos.Pos 1 19) (Pos.Pos 2 13)), TextReplacement " the people stared" (Range (Pos.Pos 3 99) (Pos.Pos 4 99))] >>> applyFormatUpdates replacements txt "mary had a little lambo, which was white as snownand everywhere that mary went the people stared"