Skip to content

Commit

Permalink
Merge pull request #727 from dsyme/fixes3
Browse files Browse the repository at this point in the history
fix 708: ReturnType from ApiDocMember
  • Loading branch information
dsyme authored Nov 10, 2021
2 parents 5848842 + b46cf8c commit bbb430a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 38 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.0.0

* Fix [Getting ReturnType from ApiDocMember without Html already embedded](https://github.com/fsprojects/FSharp.Formatting/issues/708)

## 13.0.1

* Skip the output folder when processing
Expand Down
28 changes: 16 additions & 12 deletions src/FSharp.Formatting.ApiDocs/GenerateHtml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down Expand Up @@ -206,7 +206,11 @@ 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
Expand All @@ -229,7 +233,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" ] [
Expand All @@ -238,7 +242,7 @@ type HtmlRender(model: ApiDocModel) =
else
"Field type: ")
]
embed t
embed returnTypeHtml
]
dd [ Class "fsdocs-return-docs" ] [
match m.ReturnInfo.ReturnDocs with
Expand Down Expand Up @@ -390,19 +394,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 -> ()

Expand All @@ -411,19 +415,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 -> ()

Expand Down
20 changes: 10 additions & 10 deletions src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> ()
Expand Down Expand Up @@ -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
Expand Down
50 changes: 34 additions & 16 deletions src/FSharp.Formatting.ApiDocs/GenerateModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ type ApiDocMemberDetails =
| ApiDocMemberDetails of
usageHtml: ApiDocHtml *
paramTypes: (Choice<FSharpParameter, FSharpField> * 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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1644,18 +1644,24 @@ 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
// | [] -> retTypeText
// | [[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
Expand All @@ -1666,7 +1672,16 @@ 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) =

Expand Down Expand Up @@ -1762,7 +1777,7 @@ module internal SymbolReader =
if isUnitType retType then
None
else
Some retTypeHtml
Some(retType, retTypeHtml)

let loc = tryGetLocation field

Expand Down Expand Up @@ -2695,19 +2710,22 @@ 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(
typ.FSharpDelegateSignature,
formatDelegateSignatureAsHtml ctx.UrlMap typ.DisplayName typ.FSharpDelegateSignature
|> codeHtml
)
Expand Down

0 comments on commit bbb430a

Please sign in to comment.