diff --git a/CHANGELOG.md b/CHANGELOG.md index ebd31257ff..902d73c7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [6.0.0-alpha-002] - 2023-02-01 + +### Changed +* Update output for copy-and-update expression for Stroustrup. [#2748](https://github.com/fsprojects/fantomas/pull/2748) +* Drop Experimental prefix from ExperimentalStroustrup. [#2755](https://github.com/fsprojects/fantomas/pull/2755) +* Expose initial Oak API. [#2758](https://github.com/fsprojects/fantomas/pull/2758) + ## [6.0.0-alpha-001] - 2023-01-24 ### Changed diff --git a/src/Fantomas.Core/CodeFormatter.fs b/src/Fantomas.Core/CodeFormatter.fs index 99d2d28cb6..f8e7b2d352 100644 --- a/src/Fantomas.Core/CodeFormatter.fs +++ b/src/Fantomas.Core/CodeFormatter.fs @@ -2,6 +2,7 @@ namespace Fantomas.Core open FSharp.Compiler.Syntax open FSharp.Compiler.Text +open Fantomas.Core.SyntaxOak [] type CodeFormatter = @@ -33,3 +34,30 @@ type CodeFormatter = Range.mkRange fileName (Position.mkPos startLine startCol) (Position.mkPos endLine endCol) static member MakePosition(line, column) = Position.mkPos line column + + [] + static member ParseOakAsync(isSignature: bool, source: string) : Async<(Oak * string list) array> = + async { + let sourceText = CodeFormatterImpl.getSourceText source + let! ast = CodeFormatterImpl.parse isSignature sourceText + + return + ast + |> Array.map (fun (ast, defines) -> + let oak = ASTTransformer.mkOak (Some sourceText) ast + oak, defines) + } + + static member FormatOakAsync(oak: Oak) : Async = + async { + let context = Context.Context.Create FormatConfig.Default + let result = context |> CodePrinter.genFile oak |> Context.dump false + return result.Code + } + + static member FormatOakAsync(oak: Oak, config: FormatConfig) : Async = + async { + let context = Context.Context.Create config + let result = context |> CodePrinter.genFile oak |> Context.dump false + return result.Code + } diff --git a/src/Fantomas.Core/CodeFormatter.fsi b/src/Fantomas.Core/CodeFormatter.fsi index c8b8a68aa0..c1b5a8ba9f 100644 --- a/src/Fantomas.Core/CodeFormatter.fsi +++ b/src/Fantomas.Core/CodeFormatter.fsi @@ -2,6 +2,7 @@ namespace Fantomas.Core open FSharp.Compiler.Text open FSharp.Compiler.Syntax +open Fantomas.Core.SyntaxOak [] type CodeFormatter = @@ -37,3 +38,12 @@ type CodeFormatter = /// Make a pos from line and column static member MakePosition: line: int * column: int -> pos + + /// Parse a source string to SyntaxOak + static member ParseOakAsync: isSignature: bool * source: string -> Async<(Oak * string list) array> + + /// Format SyntaxOak to string + static member FormatOakAsync: oak: Oak -> Async + + /// Format SyntaxOak to string using given config + static member FormatOakAsync: oak: Oak * config: FormatConfig -> Async diff --git a/src/Fantomas.Core/SyntaxOak.fs b/src/Fantomas.Core/SyntaxOak.fs index ec27b26d7e..2d01663f39 100644 --- a/src/Fantomas.Core/SyntaxOak.fs +++ b/src/Fantomas.Core/SyntaxOak.fs @@ -1,4 +1,4 @@ -module internal rec Fantomas.Core.SyntaxOak +module rec Fantomas.Core.SyntaxOak open System.Collections.Generic open FSharp.Compiler.Text