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

Also add additional spaces for update record. #3018

Merged
merged 1 commit into from
Dec 18, 2023
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
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
Loading