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

Fix arguments naming and escape operator name in usageHtml #765

Merged
merged 9 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
24 changes: 8 additions & 16 deletions src/FSharp.Formatting.ApiDocs/GenerateModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ module internal TypeFormatter =
argName, argType

// Format each argument, including its name and type
let formatArgUsageAsHtml _ctx i (arg: FSharpParameter) =
let formatArgUsageAsHtml i (arg: FSharpParameter) =
let argName, _argType = formatArgNameAndType i arg
!!argName

Expand Down Expand Up @@ -1462,32 +1462,24 @@ module internal SymbolReader =
| _, false, _, name, _ when PrettyNaming.IsMangledOpName v.CompiledName ->
match argInfos with
// binary operators (taking a tuple)
| [ [ x; y ] ] ->
let left = formatCurriedArgsUsageAsHtml true false [ [ x ] ]

let nm = PrettyNaming.DecompileOpName v.CompiledName

let right = formatCurriedArgsUsageAsHtml true false [ [ y ] ]

span [] [ left; !! " "; !!nm; !! " "; right ]

| [ [ x; y ] ]
// binary operators (curried, like in FSharp.Core.Operators)
| [ args1; args2 ] ->
let left = formatCurriedArgsUsageAsHtml true false [ args1 ]
| [ [ x ]; [ y ] ] ->
let left = formatArgUsageAsHtml 0 x

let nm = PrettyNaming.DecompileOpName v.CompiledName

let right = formatCurriedArgsUsageAsHtml true false [ args2 ]
let right = formatArgUsageAsHtml 1 y

span [] [ left; !! " "; !!nm; !! " "; right ]
span [] [ left; !! " "; encode nm; !! " "; right ]

// unary operators
| [ [ x ] ] ->
let nm = PrettyNaming.DecompileOpName v.CompiledName

let right = formatCurriedArgsUsageAsHtml true false [ [ x ] ]
let right = formatArgUsageAsHtml 0 x

span [] [ !!nm; right ]
span [] [ encode nm; right ]
| _ ->
span
[]
Expand Down
18 changes: 18 additions & 0 deletions tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ let ``ApiDocs works on two sample F# assemblies`` (format: OutputFormat) =
files.[(sprintf "fslib-union.%s" format.Extension)]
|> shouldContainText "<span>Naming(<span>rate,&#32;string</span>)</span>"

// Check that operators are encoded

// arg0 <&> arg1
files[$"fslib-operatorswithfsi.%s{format.Extension}"]
|> shouldContainText "arg0&#32;&lt;&amp;&gt;&#32;arg1"

// x ?<? y
files[$"fslib-operatorswithfsi.%s{format.Extension}"]
|> shouldContainText "x&#32;?&lt;?&#32;y"

// <?arg0
files[$"fslib-operatorswithfsi.%s{format.Extension}"]
|> shouldContainText "&lt;?arg0"

// <?>x
files[$"fslib-operatorswithfsi.%s{format.Extension}"]
|> shouldContainText "&lt;?&gt;x"

(* This may be addressed in a separate issue or removed if not an issue.
// Check that implict cast operator is generated correctly
files.[(sprintf "fslib-space-missing-implicit-cast.%s" format.Extension)] |> shouldContainText "<code><span>op_Implicit&#32;<span>source</span></span></code>"
Expand Down
2 changes: 2 additions & 0 deletions tests/FSharp.ApiDocs.Tests/files/FsLib1/FsLib1.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Library1.fs" />
<Compile Include="OperatorsWithFsi.fsi" />
<Compile Include="OperatorsWithFsi.fs" />
<None Include="paket.references" />
</ItemGroup>
<Import Project="..\..\..\..\.paket\Paket.Restore.targets" />
Expand Down
6 changes: 6 additions & 0 deletions tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module FsLib.OperatorsWithFsi

let ( <&> ) x y = x > y
let ( ?<? ) x y = x > y
let (<?) x = x
let (<?>) x = x
14 changes: 14 additions & 0 deletions tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module FsLib.OperatorsWithFsi

/// <summary>The binary operator 1</summary>
val ( <&> ): 'T -> 'T -> bool when 'T : comparison

/// <summary>The binary operator 2</summary>
val ( ?<? ): x: 'T -> y: 'T -> bool when 'T : comparison

/// <summary>The unary operator 1</summary>
val (<?): 'T -> 'T

/// <summary>The unary operator 2</summary>
val (<?>): x: 'T -> 'T