Skip to content

Commit

Permalink
Format using Fantomas v6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Mar 29, 2023
1 parent d812388 commit e1f6985
Show file tree
Hide file tree
Showing 41 changed files with 903 additions and 924 deletions.
4 changes: 3 additions & 1 deletion build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ let solutionFile = "FSharp.Formatting.sln"

let build _ =
solutionFile
|> DotNet.build (fun opts -> { opts with Configuration = configuration })
|> DotNet.build (fun opts ->
{ opts with
Configuration = configuration })

let tests _ =
solutionFile
Expand Down
41 changes: 32 additions & 9 deletions src/Common/StringParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,26 @@ module StringPosition =
/// Returns a string trimmed from the end
let (|TrimEnd|) (text: string, n: MarkdownRange) =
let trimmed = text.TrimEnd()
(trimmed, { n with EndColumn = n.EndColumn - text.Length + trimmed.Length })

(trimmed,
{ n with
EndColumn = n.EndColumn - text.Length + trimmed.Length })

/// Returns a string trimmed from the start
let (|TrimStart|) (text: string, n: MarkdownRange) =
let trimmed = text.TrimStart()
(trimmed, { n with StartColumn = n.StartColumn + text.Length - trimmed.Length })

(trimmed,
{ n with
StartColumn = n.StartColumn + text.Length - trimmed.Length })

/// Returns a string trimmed from the end using characters given as a parameter
let (|TrimEndUsing|) chars (text: string, n: MarkdownRange) =
let trimmed = text.TrimEnd(Array.ofSeq chars)
(trimmed, { n with EndColumn = n.EndColumn - text.Length + trimmed.Length })

(trimmed,
{ n with
EndColumn = n.EndColumn - text.Length + trimmed.Length })

/// Returns a string trimmed from the start together with
/// the number of skipped whitespace characters
Expand All @@ -160,7 +169,9 @@ module StringPosition =

len,
text.Substring(0, len).Replace("\t", " ").Length,
(trimmed, { n with StartColumn = n.StartColumn + text.Length - trimmed.Length })
(trimmed,
{ n with
StartColumn = n.StartColumn + text.Length - trimmed.Length })

/// Matches when a string starts with any of the specified sub-strings
let (|StartsWithAny|_|) (starts: seq<string>) (text: string, _n: MarkdownRange) =
Expand All @@ -172,7 +183,11 @@ module StringPosition =
/// Matches when a string starts with the specified sub-string
let (|StartsWith|_|) (start: string) (text: string, n: MarkdownRange) =
if text.StartsWith(start) then
Some(text.Substring(start.Length), { n with StartColumn = n.StartColumn + text.Length - start.Length })
Some(
text.Substring(start.Length),
{ n with
StartColumn = n.StartColumn + text.Length - start.Length }
)
else
None

Expand All @@ -182,7 +197,8 @@ module StringPosition =
if text.StartsWith(start) then
Some(
text.Substring(start.Length).Trim(),
{ n with StartColumn = n.StartColumn + text.Length - start.Length }
{ n with
StartColumn = n.StartColumn + text.Length - start.Length }
)
else
None
Expand Down Expand Up @@ -268,7 +284,12 @@ module StringPosition =

let rest = text.Substring(id + ends.Length, text.Length - id - ends.Length)

Some(wrapped, (rest, { n with StartColumn = id + ends.Length }))
Some(
wrapped,
(rest,
{ n with
StartColumn = id + ends.Length })
)
else
None
else
Expand All @@ -287,7 +308,7 @@ module List =
let inline (|DelimitedWith|_|) startl endl input =
if List.startsWith startl input then
match List.partitionUntilEquals endl (List.skip startl.Length input) with
| Some (pre, post) -> Some(pre, List.skip endl.Length post, startl.Length, endl.Length)
| Some(pre, post) -> Some(pre, List.skip endl.Length post, startl.Length, endl.Length)
| None -> None
else
None
Expand Down Expand Up @@ -388,7 +409,9 @@ module Lines =

let trimmed = s.TrimEnd([| ' ' |]) + if endsWithTwoSpaces then " " else ""

(trimmed, { n with EndColumn = n.EndColumn - s.Length + trimmed.Length }))
(trimmed,
{ n with
EndColumn = n.EndColumn - s.Length + trimmed.Length }))

/// Parameterized pattern that assigns the specified value to the
/// first component of a tuple. Usage:
Expand Down
14 changes: 7 additions & 7 deletions src/FSharp.Formatting.ApiDocs/GenerateHtml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
br []
match m.ReturnInfo.ReturnType with
| None -> ()
| Some (_, rty) ->
| Some(_, rty) ->
span
[]
[ !!(if m.Kind <> ApiDocMemberKind.RecordField then
Expand Down Expand Up @@ -195,7 +195,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
| None -> ()

match m.ExtendedType with
| Some (_, extendedTypeHtml) ->
| Some(_, extendedTypeHtml) ->
p [] [ !! "Extended Type: "; embed extendedTypeHtml ]
| _ -> ()

Expand All @@ -219,7 +219,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =

match m.ReturnInfo.ReturnType with
| None -> ()
| Some (_, returnTypeHtml) ->
| Some(_, returnTypeHtml) ->
dl
[ Class "fsdocs-returns" ]
[ dt
Expand Down Expand Up @@ -371,12 +371,12 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =


match entity.AbbreviatedType with
| Some (_, abbreviatedTypHtml) -> dt [] [ !! "Abbreviation For: "; embed abbreviatedTypHtml ]
| Some(_, abbreviatedTypHtml) -> dt [] [ !! "Abbreviation For: "; embed abbreviatedTypHtml ]

| None -> ()

match entity.BaseType with
| Some (_, baseTypeHtml) -> dt [] [ !! "Base Type: "; embed baseTypeHtml ]
| Some(_, baseTypeHtml) -> dt [] [ !! "Base Type: "; embed baseTypeHtml ]
| None -> ()

match entity.AllInterfaces with
Expand All @@ -395,7 +395,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
dt [] [ !!("Kind: Struct") ]

match entity.DelegateSignature with
| Some (_, delegateSigHtml) -> dt [] [ !!("Delegate Signature: "); embed delegateSigHtml ]
| Some(_, delegateSigHtml) -> dt [] [ !!("Delegate Signature: "); embed delegateSigHtml ]
| None -> ()

if entity.Symbol.IsProvided then
Expand Down Expand Up @@ -598,7 +598,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
match nsOpt with
| Some ns2 when ns.Name = ns2.Name ->
ul
[ Custom("list-style-type", "none") (* Class "navbar-nav " *) ]
[ Custom("list-style-type", "none") (* Class "navbar-nav " *) ]
[ for category in allByCategory do
for e in category.CategoryEntites do
li
Expand Down
10 changes: 5 additions & 5 deletions src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ type MarkdownRender(model: ApiDocModel, ?menuTemplateFolder: string) =

match m.ExtendedType with
| None -> ()
| Some (_, extendedTypeHtml) -> p [ !! "Extended Type: "; embedSafe extendedTypeHtml; br ]
| Some(_, extendedTypeHtml) -> p [ !! "Extended Type: "; embedSafe extendedTypeHtml; br ]

match m.ReturnInfo.ReturnType with
| None -> ()
| Some (_, returnTypeHtml) ->
| Some(_, returnTypeHtml) ->
p
[ !!(if m.Kind <> ApiDocMemberKind.RecordField then
"Returns: "
Expand Down Expand Up @@ -174,11 +174,11 @@ type MarkdownRender(model: ApiDocModel, ?menuTemplateFolder: string) =
(parentModule.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ]

match entity.AbbreviatedType with
| Some (_, abbreviatedTyp) -> p [ !! "Abbreviation For: "; embed abbreviatedTyp ]
| Some(_, abbreviatedTyp) -> p [ !! "Abbreviation For: "; embed abbreviatedTyp ]
| None -> ()

match entity.BaseType with
| Some (_, baseType) -> p [ !! "Base Type: "; embed baseType ]
| Some(_, baseType) -> p [ !! "Base Type: "; embed baseType ]
| None -> ()

match entity.AllInterfaces with
Expand All @@ -196,7 +196,7 @@ type MarkdownRender(model: ApiDocModel, ?menuTemplateFolder: string) =
p [ !!("Kind: Struct") ]

match entity.DelegateSignature with
| Some (_, delegateSigHtml) -> p [ !!("Delegate Signature: "); embed delegateSigHtml ]
| Some(_, delegateSigHtml) -> p [ !!("Delegate Signature: "); embed delegateSigHtml ]
| None -> ()

if entity.Symbol.IsProvided then
Expand Down
55 changes: 25 additions & 30 deletions src/FSharp.Formatting.ApiDocs/GenerateModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ type ApiDocMember
warn
) =

let (ApiDocMemberDetails (usageHtml, paramTypes, returnType, modifiers, typars, extendedType, location, compiledName)) =
let (ApiDocMemberDetails(usageHtml, paramTypes, returnType, modifiers, typars, extendedType, location, compiledName)) =
details

let m = defaultArg symbol.DeclarationLocation range0
Expand Down Expand Up @@ -674,12 +674,7 @@ type ApiDocCollection(name: string, asms: AssemblyName list, nss: ApiDocNamespac

/// High-level information about a module definition
type ApiDocEntityInfo
(
entity: ApiDocEntity,
collection: ApiDocCollection,
ns: ApiDocNamespace,
parent: ApiDocEntity option
) =
(entity: ApiDocEntity, collection: ApiDocCollection, ns: ApiDocNamespace, parent: ApiDocEntity option) =
/// The actual entity
member x.Entity = entity

Expand Down Expand Up @@ -761,7 +756,7 @@ module internal CrossReferences =

match (memb.DeclaringEntity.Value.TryFullName) with
| None -> ""
| Some (n) -> sprintf "%s:%s.%s" (getMemberXmlDocsSigPrefix memb) n memberName
| Some(n) -> sprintf "%s:%s.%s" (getMemberXmlDocsSigPrefix memb) n memberName
| n -> n

type internal CrefReference =
Expand Down Expand Up @@ -1187,13 +1182,13 @@ module internal TypeFormatter =
// of measures in a normalized form (see Andrew Kennedy technical reports). Here we detect this
// embedding and use an approximate set of rules for layout out normalized measures in a nice way.
match typ with
| MeasureProd (ty, MeasureOne)
| MeasureProd (MeasureOne, ty) -> formatTypeWithPrecAsHtml ctx prec ty
| MeasureProd (ty1, MeasureInv ty2)
| MeasureProd (ty1, MeasureProd (MeasureInv ty2, MeasureOne)) ->
| MeasureProd(ty, MeasureOne)
| MeasureProd(MeasureOne, ty) -> formatTypeWithPrecAsHtml ctx prec ty
| MeasureProd(ty1, MeasureInv ty2)
| MeasureProd(ty1, MeasureProd(MeasureInv ty2, MeasureOne)) ->
span [] [ formatTypeWithPrecAsHtml ctx 2 ty1; !! "/"; formatTypeWithPrecAsHtml ctx 2 ty2 ]
| MeasureProd (ty1, MeasureProd (ty2, MeasureOne))
| MeasureProd (ty1, ty2) ->
| MeasureProd(ty1, MeasureProd(ty2, MeasureOne))
| MeasureProd(ty1, ty2) ->
span [] [ formatTypeWithPrecAsHtml ctx 2 ty1; !! "*"; formatTypeWithPrecAsHtml ctx 2 ty2 ]
| MeasureInv ty -> span [] [ !! "/"; formatTypeWithPrecAsHtml ctx 1 ty ]
| MeasureOne -> !! "1"
Expand Down Expand Up @@ -1505,7 +1500,7 @@ module internal SymbolReader =

let argInfos, retType =
match argInfos, v.HasGetterMethod, v.HasSetterMethod with
| [ AllAndLast (args, last) ], _, true -> [ args ], Some last.Type
| [ AllAndLast(args, last) ], _, true -> [ args ], Some last.Type
| _, _, true -> argInfos, None
| [ [] ], true, _ -> [], Some retType
| _, _, _ -> argInfos, Some retType
Expand Down Expand Up @@ -1753,12 +1748,12 @@ module internal SymbolReader =

let raw =
match doc.Source with
| LiterateSource.Markdown (string) -> [ KeyValuePair(current, string) ]
| LiterateSource.Markdown(string) -> [ KeyValuePair(current, string) ]
| LiterateSource.Script _ -> []

for par in doc.Paragraphs do
match par with
| Heading (2, [ Literal (text, _) ], _) ->
| Heading(2, [ Literal(text, _) ], _) ->
current <- text.Trim()
groups.Add(current, [ par ])
| par -> groups.[groups.Count - 1] <- (current, par :: snd (groups.[groups.Count - 1]))
Expand Down Expand Up @@ -1826,7 +1821,7 @@ module internal SymbolReader =

let findCommand cmd =
match cmd with
| StringPosition.StartsWithWrapped ("[", "]") (ParseCommand (k, v), _rest) -> Some(k, v)
| StringPosition.StartsWithWrapped ("[", "]") (ParseCommand(k, v), _rest) -> Some(k, v)
| _ -> None

let rec readXmlElementAsHtml
Expand All @@ -1841,7 +1836,7 @@ module internal SymbolReader =
let text = (x :?> XText).Value

match findCommand (text, MarkdownRange.zero) with
| Some (k, v) -> cmds.Add(k, v)
| Some(k, v) -> cmds.Add(k, v)
| None -> html.Append(text) |> ignore
elif x.NodeType = XmlNodeType.Element then
let elem = x :?> XElement
Expand Down Expand Up @@ -2138,9 +2133,9 @@ module internal SymbolReader =
let rec collectSpanIndirectLinks span =
seq {
match span with
| IndirectLink (_, _, key, _) -> yield key
| IndirectLink(_, _, key, _) -> yield key
| MarkdownPatterns.SpanLeaf _ -> ()
| MarkdownPatterns.SpanNode (_, spans) ->
| MarkdownPatterns.SpanNode(_, spans) ->
for s in spans do
yield! collectSpanIndirectLinks s
}
Expand All @@ -2150,11 +2145,11 @@ module internal SymbolReader =
seq {
match par with
| MarkdownPatterns.ParagraphLeaf _ -> ()
| MarkdownPatterns.ParagraphNested (_, pars) ->
| MarkdownPatterns.ParagraphNested(_, pars) ->
for ps in pars do
for p in ps do
yield! collectParagraphIndirectLinks p
| MarkdownPatterns.ParagraphSpans (_, spans) ->
| MarkdownPatterns.ParagraphSpans(_, spans) ->
for s in spans do
yield! collectSpanIndirectLinks s
}
Expand All @@ -2175,13 +2170,13 @@ module internal SymbolReader =
/// Adds a cross-type link to the document defined links
let addLinkToType (doc: LiterateDocument) link =
match link with
| Some (k, v) -> do doc.DefinedLinks.Add(k, (v.ReferenceLink, Some v.NiceName))
| Some(k, v) -> do doc.DefinedLinks.Add(k, (v.ReferenceLink, Some v.NiceName))
| None -> ()

/// Wraps the span inside an IndirectLink if it is an inline code that can be converted to a link
let wrapInlineCodeLinksInSpans (ctx: ReadingContext) span =
match span with
| InlineCode (code, r) ->
| InlineCode(code, r) ->
match getTypeLink ctx code with
| Some _ -> IndirectLink([ span ], code, code, r)
| None -> span
Expand All @@ -2191,13 +2186,13 @@ module internal SymbolReader =
let rec wrapInlineCodeLinksInParagraphs (ctx: ReadingContext) (para: MarkdownParagraph) =
match para with
| MarkdownPatterns.ParagraphLeaf _ -> para
| MarkdownPatterns.ParagraphNested (info, pars) ->
| MarkdownPatterns.ParagraphNested(info, pars) ->
MarkdownPatterns.ParagraphNested(
info,
pars
|> List.map (fun innerPars -> List.map (wrapInlineCodeLinksInParagraphs ctx) innerPars)
)
| MarkdownPatterns.ParagraphSpans (info, spans) ->
| MarkdownPatterns.ParagraphSpans(info, spans) ->
MarkdownPatterns.ParagraphSpans(info, List.map (wrapInlineCodeLinksInSpans ctx) spans)

/// Adds the missing links to types to the document defined links
Expand All @@ -2221,7 +2216,7 @@ module internal SymbolReader =
|> List.filter (
findCommand
>> (function
| Some (k, v) ->
| Some(k, v) ->
cmds.[k] <- v
false
| _ -> true)
Expand Down Expand Up @@ -2499,7 +2494,7 @@ module internal SymbolReader =

let xmlDocText (xmlDoc: FSharpXmlDoc) =
match xmlDoc with
| FSharpXmlDoc.FromXmlText (xmlDoc) -> String.concat "" xmlDoc.UnprocessedLines
| FSharpXmlDoc.FromXmlText(xmlDoc) -> String.concat "" xmlDoc.UnprocessedLines
| _ -> ""

// Create a xml documentation snippet and add it to the XmlMemberMap
Expand Down Expand Up @@ -3023,7 +3018,7 @@ type ApiDocModel internal (substitutions, collection, entityInfos, root, qualify
| false, _ -> namespaces.Add(ns.Name, (ns.Entities, ns.NamespaceDocs, ns.Substitutions))

let namespaces =
[ for (KeyValue (name, (entities, summary, substitutions))) in namespaces do
[ for (KeyValue(name, (entities, summary, substitutions))) in namespaces do
printfn " found %d entities in namespace %s..." entities.Length name

if entities.Length > 0 then
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Formatting.CodeFormat/CodeFormat.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ type CodeFormat =
/// Formats the .fsx snippets as iPython notebook using the default settings.
static member FormatFsx(snippets) =
let snips =
[| for (Snippet (key, lines)) in snippets do
[| for (Snippet(key, lines)) in snippets do
let str =
[| for (Line (originalLine, _spans)) in lines -> originalLine |]
[| for (Line(originalLine, _spans)) in lines -> originalLine |]
|> String.concat Environment.NewLine

yield key, str |]
Expand Down
Loading

0 comments on commit e1f6985

Please sign in to comment.