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

Better record and value formatting in tools #7021

Merged
merged 25 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions src/fsharp/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module internal PrintUtilities =
let bracketIfL x lyt = if x then bracketL lyt else lyt
let squareAngleL x = LeftL.leftBracketAngle ^^ x ^^ RightL.rightBracketAngle
let angleL x = sepL Literals.leftAngle ^^ x ^^ rightL Literals.rightAngle
let braceL x = leftL Literals.leftBrace ^^ x ^^ rightL Literals.rightBrace
let braceL x = wordL Literals.leftBrace ^^ x ^^ wordL Literals.rightBrace
let braceBarL x = leftL Literals.leftBraceBar ^^ x ^^ rightL Literals.rightBraceBar

let comment str = wordL (tagText (sprintf "(* %s *)" str))
Expand Down Expand Up @@ -1445,7 +1445,7 @@ module private TastDefinitionPrinting =
let lhs =
tagRecordField fld.Name
|> mkNav fld.DefinitionRange
|> wordL
|> wordL
let lhs = (if addAccess then layoutAccessibility denv fld.Accessibility lhs else lhs)
let lhs = if fld.IsMutable then wordL (tagKeyword "mutable") --- lhs else lhs
(lhs ^^ RightL.colon) --- layoutType denv fld.FormalType
Expand Down Expand Up @@ -1726,8 +1726,8 @@ module private TastDefinitionPrinting =
let denv = denv.AddAccessibility tycon.TypeReprAccessibility
match repr with
| TRecdRepr _ ->
let recdFieldRefL fld = layoutRecdField false denv fld ^^ rightL (tagPunctuation ";")
let recdL = tycon.TrueFieldsAsList |> List.map recdFieldRefL |> applyMaxMembers denv.maxMembers |> aboveListL |> braceL
let recdFieldRefL fld = layoutRecdField false denv fld
let recdL = tycon.TrueFieldsAsList |> List.map recdFieldRefL |> applyMaxMembers denv.maxMembers |> aboveListIndentOneL |> braceL
Some (addMembersAsWithEnd (addReprAccessL recdL))

| TFSharpObjectRepr r ->
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/layout.fs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ let aboveListL = function
| [x] -> x
| x :: ys -> List.fold (fun pre y -> pre @@ y) x ys

let aboveListIndentOneL = function
| [] -> emptyL
| [x] -> x
| x :: xs -> (x, xs) ||> List.fold (fun pre y -> pre @@- y)

let optionL xL = function
| None -> wordL (tagUnionCase "None")
| Some x -> wordL (tagUnionCase "Some") -- (xL x)
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/layout.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ val bracketL : Layout -> Layout
val tupleL : Layout list -> Layout
val aboveL : Layout -> Layout -> Layout
val aboveListL : Layout list -> Layout
val aboveListIndentOneL : Layout list -> Layout

val optionL : ('a -> Layout) -> 'a option -> Layout
val listL : ('a -> Layout) -> 'a list -> Layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ Full name: Microsoft.FSharp.Control.Async""".TrimStart().Replace("\r\n", "\n")

let fileContents = """namespace NS
type Re(*MarkerRecord*) = { X : int } """
let expectedQuickinfoTypeRecored = "type Re = {X: int;}"
let expectedQuickinfoTypeRecored = "type Re = { X: int }"

this.InfoInDeclarationTestQuickInfoImplWithTrim fileContents "Re(*MarkerRecord*)" expectedQuickinfoTypeRecored

Expand Down
6 changes: 3 additions & 3 deletions vsintegration/tests/UnitTests/QuickInfoTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ module Test =
let quickInfo = GetQuickInfoTextFromCode code
let expected =
expectedLines [ "type MyEmployee ="
" {mutable Name: string;"
" mutable Age: int;"
" mutable IsFTE: bool;}"
" { mutable Name: string"
" mutable Age: int"
" mutable IsFTE: bool }"
"Full name: FsTest.MyEmployee" ]
Assert.AreEqual(expected, quickInfo)
()
Expand Down