Skip to content

Commit

Permalink
Remove F# option from public API. (#2759)
Browse files Browse the repository at this point in the history
* Remove F# option from public API.

* Apply suggestions from code review

Co-authored-by: dawe <dawedawe@posteo.de>

---------

Co-authored-by: dawe <dawedawe@posteo.de>
  • Loading branch information
nojaf and dawedawe committed Mar 27, 2023
1 parent e480717 commit 831df84
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
23 changes: 17 additions & 6 deletions src/Fantomas.Core/CodeFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,31 @@ type CodeFormatter =
static member ParseAsync(isSignature, source) : Async<(ParsedInput * string list) array> =
CodeFormatterImpl.getSourceText source |> CodeFormatterImpl.parse isSignature

static member FormatASTAsync(ast: ParsedInput, ?source, ?config) : Async<FormatResult> =
let sourceText = Option.map CodeFormatterImpl.getSourceText source
let config = Option.defaultValue FormatConfig.Default config
static member FormatASTAsync(ast: ParsedInput) : Async<FormatResult> =
CodeFormatterImpl.formatAST ast None FormatConfig.Default None |> async.Return

static member FormatASTAsync(ast: ParsedInput, config) : Async<FormatResult> =
CodeFormatterImpl.formatAST ast None config None |> async.Return

static member FormatASTAsync(ast: ParsedInput, source) : Async<FormatResult> =
let sourceText = Some(CodeFormatterImpl.getSourceText source)

CodeFormatterImpl.formatAST ast sourceText FormatConfig.Default None
|> async.Return

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

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

static member FormatSelectionAsync(isSignature, source, selection, config) =
let config = Option.defaultValue FormatConfig.Default config
static member FormatSelectionAsync(isSignature, source, selection) =
CodeFormatterImpl.getSourceText source
|> Selection.formatSelection FormatConfig.Default isSignature selection

static member FormatSelectionAsync(isSignature, source, selection, config) =
CodeFormatterImpl.getSourceText source
|> Selection.formatSelection config isSignature selection

Expand All @@ -35,7 +47,6 @@ type CodeFormatter =

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

[<Experimental "Only for local development">]
static member ParseOakAsync(isSignature: bool, source: string) : Async<(Oak * string list) array> =
async {
let sourceText = CodeFormatterImpl.getSourceText source
Expand Down
19 changes: 16 additions & 3 deletions src/Fantomas.Core/CodeFormatter.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ type CodeFormatter =
/// Parse a source string using given config
static member ParseAsync: isSignature: bool * source: string -> Async<(ParsedInput * string list) array>

/// Format an abstract syntax tree using an optional source for trivia processing
static member FormatASTAsync: ast: ParsedInput * ?source: string * ?config: FormatConfig -> Async<FormatResult>
/// Format an abstract syntax tree
static member FormatASTAsync: ast: ParsedInput -> Async<FormatResult>

/// Format an abstract syntax tree using a given config
static member FormatASTAsync: ast: ParsedInput * config: FormatConfig -> Async<FormatResult>

/// Format an abstract syntax tree with the original source for trivia processing
static member FormatASTAsync: ast: ParsedInput * source: string -> Async<FormatResult>

/// Format an abstract syntax tree with the original source for trivia processing using a given config
static member FormatASTAsync: ast: ParsedInput * source: string * config: FormatConfig -> Async<FormatResult>

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

/// Format a part of a source string and return the (formatted) selected part only.
/// Beware that the range argument is inclusive. The closest expression inside the selection will be formatted if possible.
static member FormatSelectionAsync: isSignature: bool * source: string * selection: range -> Async<string * range>

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

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

0 comments on commit 831df84

Please sign in to comment.