Skip to content

Commit fde30d4

Browse files
nojafdawedawe
andcommitted
Remove F# option from public API. (#2759)
* Remove F# option from public API. * Apply suggestions from code review Co-authored-by: dawe <[email protected]> --------- Co-authored-by: dawe <[email protected]>
1 parent b2f3ffe commit fde30d4

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/Fantomas.Core/CodeFormatter.fs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,31 @@ type CodeFormatter =
99
static member ParseAsync(isSignature, source) : Async<(ParsedInput * string list) array> =
1010
CodeFormatterImpl.getSourceText source |> CodeFormatterImpl.parse isSignature
1111

12-
static member FormatASTAsync(ast: ParsedInput, ?source, ?config) : Async<FormatResult> =
13-
let sourceText = Option.map CodeFormatterImpl.getSourceText source
14-
let config = Option.defaultValue FormatConfig.Default config
12+
static member FormatASTAsync(ast: ParsedInput) : Async<FormatResult> =
13+
CodeFormatterImpl.formatAST ast None FormatConfig.Default None |> async.Return
14+
15+
static member FormatASTAsync(ast: ParsedInput, config) : Async<FormatResult> =
16+
CodeFormatterImpl.formatAST ast None config None |> async.Return
17+
18+
static member FormatASTAsync(ast: ParsedInput, source) : Async<FormatResult> =
19+
let sourceText = Some(CodeFormatterImpl.getSourceText source)
20+
21+
CodeFormatterImpl.formatAST ast sourceText FormatConfig.Default None
22+
|> async.Return
1523

24+
static member FormatASTAsync(ast: ParsedInput, source, config) : Async<FormatResult> =
25+
let sourceText = Some(CodeFormatterImpl.getSourceText source)
1626
CodeFormatterImpl.formatAST ast sourceText config None |> async.Return
1727

1828
static member FormatDocumentAsync(isSignature, source, ?config, ?cursor: Position) =
1929
let config = Option.defaultValue FormatConfig.Default config
2030
CodeFormatterImpl.formatDocument config isSignature (CodeFormatterImpl.getSourceText source) cursor
2131

22-
static member FormatSelectionAsync(isSignature, source, selection, config) =
23-
let config = Option.defaultValue FormatConfig.Default config
32+
static member FormatSelectionAsync(isSignature, source, selection) =
33+
CodeFormatterImpl.getSourceText source
34+
|> Selection.formatSelection FormatConfig.Default isSignature selection
2435

36+
static member FormatSelectionAsync(isSignature, source, selection, config) =
2537
CodeFormatterImpl.getSourceText source
2638
|> Selection.formatSelection config isSignature selection
2739

@@ -35,7 +47,6 @@ type CodeFormatter =
3547

3648
static member MakePosition(line, column) = Position.mkPos line column
3749

38-
[<Experimental "Only for local development">]
3950
static member ParseOakAsync(isSignature: bool, source: string) : Async<(Oak * string list) array> =
4051
async {
4152
let sourceText = CodeFormatterImpl.getSourceText source

src/Fantomas.Core/CodeFormatter.fsi

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ type CodeFormatter =
99
/// Parse a source string using given config
1010
static member ParseAsync: isSignature: bool * source: string -> Async<(ParsedInput * string list) array>
1111

12-
/// Format an abstract syntax tree using an optional source for trivia processing
13-
static member FormatASTAsync: ast: ParsedInput * ?source: string * ?config: FormatConfig -> Async<FormatResult>
12+
/// Format an abstract syntax tree
13+
static member FormatASTAsync: ast: ParsedInput -> Async<FormatResult>
14+
15+
/// Format an abstract syntax tree using a given config
16+
static member FormatASTAsync: ast: ParsedInput * config: FormatConfig -> Async<FormatResult>
17+
18+
/// Format an abstract syntax tree with the original source for trivia processing
19+
static member FormatASTAsync: ast: ParsedInput * source: string -> Async<FormatResult>
20+
21+
/// Format an abstract syntax tree with the original source for trivia processing using a given config
22+
static member FormatASTAsync: ast: ParsedInput * source: string * config: FormatConfig -> Async<FormatResult>
1423

1524
/// <summary>
1625
/// Format a source string using an optional config.
@@ -22,10 +31,14 @@ type CodeFormatter =
2231
static member FormatDocumentAsync:
2332
isSignature: bool * source: string * ?config: FormatConfig * ?cursor: pos -> Async<FormatResult>
2433

34+
/// Format a part of a source string and return the (formatted) selected part only.
35+
/// Beware that the range argument is inclusive. The closest expression inside the selection will be formatted if possible.
36+
static member FormatSelectionAsync: isSignature: bool * source: string * selection: range -> Async<string * range>
37+
2538
/// Format a part of source string using given config, and return the (formatted) selected part only.
2639
/// Beware that the range argument is inclusive. The closest expression inside the selection will be formatted if possible.
2740
static member FormatSelectionAsync:
28-
isSignature: bool * source: string * selection: range * ?config: FormatConfig -> Async<string * range>
41+
isSignature: bool * source: string * selection: range * config: FormatConfig -> Async<string * range>
2942

3043
/// Check whether an input string is invalid in F# by attempting to parse the code.
3144
static member IsValidFSharpCodeAsync: isSignature: bool * source: string -> Async<bool>

0 commit comments

Comments
 (0)