Skip to content

Commit

Permalink
Also add additional spaces for update record. (fsprojects#3018)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Dec 18, 2023
1 parent 2e2e9e0 commit b6aeb81
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Changed
* Turn on strict indentation in the lexer in Fantomas.FCS. [#3014](https://github.com/fsprojects/fantomas/pull/3014)

### Fixed
* Unmatched '{' error when formatting the code. [#3017](https://github.com/fsprojects/fantomas/issues/3017)

## 6.3.0-alpha-004 - 2023-12-06

### Fixed
Expand Down
42 changes: 41 additions & 1 deletion src/Fantomas.Core.Tests/CrampedMultilineBracketStyleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,46 @@ let person =
()
"

[<Test>]
let ``multiline string before closing brace with update record, 3017`` () =
formatSourceString
"
let FableSampleExpected :Changelogs = {
Unreleased = Some {
ChangelogData.Default with
Fixed =
normalizeNewline
\"\"\"#### Python
\"\"\"
}
Releases = [
Some {
ChangelogData.Default with
Changed =
normalizeNewline \"\"
}
]
}
"
config
|> prepend newline
|> should
equal
"
let FableSampleExpected: Changelogs =
{ Unreleased =
Some
{ ChangelogData.Default with
Fixed =
normalizeNewline
\"\"\"#### Python
\"\"\" }
Releases =
[ Some
{ ChangelogData.Default with
Changed = normalizeNewline \"\" } ] }
"

[<Test>]
let ``issue 457`` () =
formatSourceString
Expand Down Expand Up @@ -828,7 +868,7 @@ module Maintoc =
[ Doc.Verbatim
\"\"\"
This is a very long line in a multi-line string, so long in fact that it is longer than that page width to which I am trying to constrain everything, and so it goes bang.
\"\"\" ] }
\"\"\" ] }
"

[<Test>]
Expand Down
19 changes: 10 additions & 9 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,26 +1739,27 @@ let genMultilineRecord (node: ExprRecordNode) (ctx: Context) =
+> genRecordFieldNameCramped false e)
ctx

// Edge case scenario to make sure that the closing brace is not before the opening one
// See unit test "multiline string before closing brace"
let genClosingBrace ctx =
let genClosingBrace =
addFixedSpaces expressionStartColumn +> genSingleTextNode node.ClosingBrace

ifElseCtx lastWriteEventIsNewline genClosingBrace (addSpaceIfSpaceAroundDelimiter +> genClosingBrace) ctx

match node.CopyInfo with
| Some _ ->
genSingleTextNode node.OpeningBrace
+> sepNlnWhenWriteBeforeNewlineNotEmptyOr addSpaceIfSpaceAroundDelimiter // comment after curly brace
+> genFields
+> addSpaceIfSpaceAroundDelimiter
+> genSingleTextNode node.ClosingBrace
+> genClosingBrace
| None ->
atCurrentColumn (
genSingleTextNodeSuffixDelimiter node.OpeningBrace
+> sepNlnWhenWriteBeforeNewlineNotEmpty // comment after curly brace
+> genFields
+> sepNlnWhenWriteBeforeNewlineNotEmpty
+> (fun ctx ->
// Edge case scenario to make sure that the closing brace is not before the opening one
// See unit test "multiline string before closing brace"
let brace =
addFixedSpaces expressionStartColumn +> genSingleTextNode node.ClosingBrace

ifElseCtx lastWriteEventIsNewline brace (addSpaceIfSpaceAroundDelimiter +> brace) ctx)
+> genClosingBrace
)

ifAlignOrStroustrupBrackets genMultilineAlignBrackets genMultilineCramped ctx
Expand Down

0 comments on commit b6aeb81

Please sign in to comment.