From 20d8bad14cc9f2efe44a855da11c713452dba6e3 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 10 Nov 2021 19:23:16 +0000 Subject: [PATCH] fix Getting ReturnType from ApiDocMember without Html already embedded #708 --- RELEASE_NOTES.md | 4 ++ src/FSharp.Formatting.ApiDocs/GenerateHtml.fs | 24 ++++++------ .../GenerateMarkdown.fs | 20 +++++----- .../GenerateModel.fs | 37 ++++++++++--------- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index dea0efa85..a255e9904 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +## 13.0.2 + +* Fix [Getting ReturnType from ApiDocMember without Html already embedded](https://github.com/fsprojects/FSharp.Formatting/issues/708) + ## 13.0.0 * Remove unused TransformAndOutputDocument from API diff --git a/src/FSharp.Formatting.ApiDocs/GenerateHtml.fs b/src/FSharp.Formatting.ApiDocs/GenerateHtml.fs index 102b00be0..31890aa07 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateHtml.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateHtml.fs @@ -159,7 +159,7 @@ type HtmlRender(model: ApiDocModel) = br [] match m.ReturnInfo.ReturnType with | None -> () - | Some rty -> + | Some (_, rty) -> span [] [ !!(if m.Kind <> ApiDocMemberKind.RecordField then "Returns: " @@ -206,7 +206,7 @@ type HtmlRender(model: ApiDocModel) = | None -> () match m.ExtendedType with - | Some s -> p [] [ !! "Extended Type: "; embed s ] + | Some (_, extendedTypeHtml) -> p [] [ !! "Extended Type: "; embed extendedTypeHtml ] | _ -> () if not m.Parameters.IsEmpty then @@ -229,7 +229,7 @@ type HtmlRender(model: ApiDocModel) = match m.ReturnInfo.ReturnType with | None -> () - | Some t -> + | Some (_, returnTypeHtml) -> dl [ Class "fsdocs-returns" ] [ dt [] [ span [ Class "fsdocs-return-name" ] [ @@ -238,7 +238,7 @@ type HtmlRender(model: ApiDocModel) = else "Field type: ") ] - embed t + embed returnTypeHtml ] dd [ Class "fsdocs-return-docs" ] [ match m.ReturnInfo.ReturnDocs with @@ -390,19 +390,19 @@ type HtmlRender(model: ApiDocModel) = match entity.AbbreviatedType with - | Some abbreviatedTyp -> + | Some (_, abbreviatedTypHtml) -> dt [] [ !! "Abbreviation For: " - embed abbreviatedTyp + embed abbreviatedTypHtml ] | None -> () match entity.BaseType with - | Some baseType -> + | Some (_, baseTypeHtml) -> dt [] [ !! "Base Type: " - embed baseType + embed baseTypeHtml ] | None -> () @@ -411,19 +411,19 @@ type HtmlRender(model: ApiDocModel) = | l -> dt [] [ !!("All Interfaces: ") - for (i, ity) in Seq.indexed l do + for (i, (_, ityHtml)) in Seq.indexed l do if i <> 0 then !! ", " - embed ity + embed ityHtml ] if entity.Symbol.IsValueType then dt [] [ !!("Kind: Struct") ] match entity.DelegateSignature with - | Some d -> + | Some (_, delegateSigHtml) -> dt [] [ !!("Delegate Signature: ") - embed d + embed delegateSigHtml ] | None -> () diff --git a/src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs b/src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs index 1d38580bd..f6e014f0a 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs @@ -72,19 +72,19 @@ type MarkdownRender(model: ApiDocModel) = match m.ExtendedType with | None -> () - | Some s -> + | Some (_, extendedTypeHtml) -> p [ !! "Extended Type: " - embedSafe s + embedSafe extendedTypeHtml br ] match m.ReturnInfo.ReturnType with | None -> () - | Some t -> + | Some (_, returnTypeHtml) -> p [ !!(if m.Kind <> ApiDocMemberKind.RecordField then "Returns: " else "Field type: ") - embedSafe t + embedSafe returnTypeHtml br match m.ReturnInfo.ReturnDocs with | None -> () @@ -178,30 +178,30 @@ type MarkdownRender(model: ApiDocModel) = (parentModule.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ] match entity.AbbreviatedType with - | Some 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 | [] -> () | l -> p [ !! "All Interfaces: " - for (i, ity) in Seq.indexed l do + for (i, (_, interfaceTyHtml)) in Seq.indexed l do if i <> 0 then !! ", " - embed ity ] + embed interfaceTyHtml ] if entity.Symbol.IsValueType then p [ !!("Kind: Struct") ] match entity.DelegateSignature with - | Some d -> + | Some (_, delegateSigHtml) -> p [ !!("Delegate Signature: ") - embed d ] + embed delegateSigHtml ] | None -> () if entity.Symbol.IsProvided then diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 069d9d1ae..44371383c 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -280,10 +280,10 @@ type ApiDocMemberDetails = | ApiDocMemberDetails of usageHtml: ApiDocHtml * paramTypes: (Choice * string * ApiDocHtml) list * - returnType: ApiDocHtml option * + returnType: (FSharpType * ApiDocHtml) option * modifiers: string list * typars: string list * - baseType: ApiDocHtml option * + extendedType: (FSharpEntity * ApiDocHtml) option * location: string option * compiledName: string option @@ -304,7 +304,7 @@ type ApiDocMember warn ) = - let (ApiDocMemberDetails (usageHtml, paramTypes, returnType, modifiers, typars, baseType, location, compiledName)) = + let (ApiDocMemberDetails (usageHtml, paramTypes, returnType, modifiers, typars, extendedType, location, compiledName)) = details let m = defaultArg symbol.DeclarationLocation range0 @@ -409,7 +409,7 @@ type ApiDocMember member x.SourceLocation: string option = location /// The type extended by an extension member, if any - member x.ExtendedType: ApiDocHtml option = baseType + member x.ExtendedType: (FSharpEntity * ApiDocHtml) option = extendedType /// The members details member x.Details = details @@ -602,16 +602,16 @@ type ApiDocEntity pats ] /// All interfaces of the type, formatted - member x.AllInterfaces: ApiDocHtml list = allInterfaces + member x.AllInterfaces: (FSharpType * ApiDocHtml) list = allInterfaces /// The base type of the type, formatted - member x.BaseType: ApiDocHtml option = baseType + member x.BaseType: (FSharpType * ApiDocHtml) option = baseType /// If this is a type abbreviation, then the abbreviated type - member x.AbbreviatedType: ApiDocHtml option = abbreviatedType + member x.AbbreviatedType: (FSharpType * ApiDocHtml) option = abbreviatedType /// If this is a delegate, then e formatted signature - member x.DelegateSignature: ApiDocHtml option = delegateSignature + member x.DelegateSignature: (FSharpDelegateSignature * ApiDocHtml) option = delegateSignature /// The constuctorsof the type member x.Constructors: ApiDocMember list = ctors @@ -1644,7 +1644,10 @@ module internal SymbolReader = if isUnitType retType then None else - retTypeHtml + match retTypeHtml with + | None -> None + | Some html -> Some (retType, html) + //let signatureTooltip = // match argInfos with @@ -1652,10 +1655,10 @@ module internal SymbolReader = // | [[x]] when (v.IsPropertyGetterMethod || v.HasGetterMethod) && x.Name.IsNone && isUnitType x.Type -> retTypeText // | _ -> (formatArgsUsageAsText true v argInfos) + " -> " + retTypeText - let baseType = + let extendedType = if v.IsExtensionMember then try - Some(formatTyconRefAsHtml ctx.UrlMap v.ApparentEnclosingEntity |> codeHtml) + Some(v.ApparentEnclosingEntity, formatTyconRefAsHtml ctx.UrlMap v.ApparentEnclosingEntity |> codeHtml) with | _ -> None else @@ -1666,7 +1669,7 @@ module internal SymbolReader = let location = formatSourceLocation ctx.UrlRangeHighlight ctx.SourceFolderRepository loc - ApiDocMemberDetails(usageHtml, paramTypes, returnType, modifiers, typars, baseType, location, getCompiledName v) + ApiDocMemberDetails(usageHtml, paramTypes, returnType, modifiers, typars, extendedType, location, getCompiledName v) let readUnionCase (ctx: ReadingContext) (_typ: FSharpEntity) (case: FSharpUnionCase) = @@ -1762,7 +1765,7 @@ module internal SymbolReader = if isUnitType retType then None else - Some retTypeHtml + Some (retType, retTypeHtml) let loc = tryGetLocation field @@ -2695,19 +2698,19 @@ module internal SymbolReader = let cvals, svals = svals |> List.partition (fun v -> v.CompiledName = ".ctor") - let baseType = typ.BaseType |> Option.map (formatTypeAsHtml ctx.UrlMap >> codeHtml) + let baseType = typ.BaseType |> Option.map (fun bty -> bty, bty |> formatTypeAsHtml ctx.UrlMap |> codeHtml) - let allInterfaces = [ for i in typ.AllInterfaces -> formatTypeAsHtml ctx.UrlMap i |> codeHtml ] + let allInterfaces = [ for i in typ.AllInterfaces -> (i, formatTypeAsHtml ctx.UrlMap i |> codeHtml) ] let abbreviatedType = if typ.IsFSharpAbbreviation then - Some(formatTypeAsHtml ctx.UrlMap typ.AbbreviatedType |> codeHtml) + Some(typ.AbbreviatedType, formatTypeAsHtml ctx.UrlMap typ.AbbreviatedType |> codeHtml) else None let delegateSignature = if typ.IsDelegate then - Some( + Some(typ.FSharpDelegateSignature, formatDelegateSignatureAsHtml ctx.UrlMap typ.DisplayName typ.FSharpDelegateSignature |> codeHtml )