Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put SynExpr.DotGet atCurrentColumn in if expression #1330

Merged
merged 1 commit into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Fantomas.Tests/IfThenElseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,3 +1690,51 @@ module X =

()
"""

[<Test>]
let ``if expression with SynExpr.DotGet inside, 1329`` () =
formatSourceString
false
"""
let private tryGetUrlWithExactMatch (pathPattern: string<SourcelinkPattern>) (urlPattern: string<Url>) (document: Document) =
if (UMX.untag pathPattern).Equals(UMX.untag document.Name, System.StringComparison.Ordinal)
then Some (urlPattern, normalizeRepoPath (UMX.cast<SourcelinkPattern, RepoPathSegment> pathPattern), document) else None

let private tryGetUrlWithExactMatch
(pathPattern: string<SourcelinkPattern>)
(urlPattern: string<Url>)
(document: Document)
=
if (UMX.untag pathPattern)
.Equals(UMX.untag document.Name, System.StringComparison.Ordinal) then
Some(urlPattern, normalizeRepoPath (UMX.cast<SourcelinkPattern, RepoPathSegment> pathPattern), document)
else
None
"""
{ config with IndentSize = 2 }
|> prepend newline
|> should
equal
"""
let private tryGetUrlWithExactMatch
(pathPattern: string<SourcelinkPattern>)
(urlPattern: string<Url>)
(document: Document)
=
if (UMX.untag pathPattern)
.Equals(UMX.untag document.Name, System.StringComparison.Ordinal) then
Some(urlPattern, normalizeRepoPath (UMX.cast<SourcelinkPattern, RepoPathSegment> pathPattern), document)
else
None

let private tryGetUrlWithExactMatch
(pathPattern: string<SourcelinkPattern>)
(urlPattern: string<Url>)
(document: Document)
=
if (UMX.untag pathPattern)
.Equals(UMX.untag document.Name, System.StringComparison.Ordinal) then
Some(urlPattern, normalizeRepoPath (UMX.cast<SourcelinkPattern, RepoPathSegment> pathPattern), document)
else
None
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,7 @@ and genExpr astContext synExpr ctx =
+> (match e1 with
| SynExpr.TryWith _
| SynExpr.TryFinally _ -> sepOpenT +> genExpr astContext e1 +> sepCloseT
| App (SynExpr.DotGet _, [ (Paren _) ]) -> atCurrentColumn (genExpr astContext e1)
| AppTuple _ when (isConditionMultiline) ->
sepOpenT
+> atCurrentColumn (genExpr astContext e1)
Expand Down
1 change: 1 addition & 0 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ let (|App|_|) e =
// captures application with single tuple arg
let (|AppTuple|_|) =
function
| App (SynExpr.DotGet _, [ (Paren (_, Tuple _, _)) ]) -> None
| App (e, [ (Paren (lpr, Tuple args, rpr)) ]) -> Some(e, lpr, args, rpr)
| App (e, [ (Paren (lpr, singleExpr, rpr)) ]) ->
match singleExpr with
Expand Down