diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 6b6df752a..ddbed35cc 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -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 @@ -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 [] diff --git a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs index 474b53d02..f428c4d2a 100644 --- a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs +++ b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs @@ -253,6 +253,24 @@ let ``ApiDocs works on two sample F# assemblies`` (format: OutputFormat) = files.[(sprintf "fslib-union.%s" format.Extension)] |> shouldContainText "Naming(rate, string)" + // Check that operators are encoded + + // arg0 <&> arg1 + files[$"fslib-operatorswithfsi.%s{format.Extension}"] + |> shouldContainText "arg0 <&> arg1" + + // x ? shouldContainText "x ?<? y" + + // shouldContainText "<?arg0" + + // x + files[$"fslib-operatorswithfsi.%s{format.Extension}"] + |> shouldContainText "<?>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 "op_Implicit source" diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/FsLib1.fsproj b/tests/FSharp.ApiDocs.Tests/files/FsLib1/FsLib1.fsproj index f2882b7e6..b709c46f4 100644 --- a/tests/FSharp.ApiDocs.Tests/files/FsLib1/FsLib1.fsproj +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/FsLib1.fsproj @@ -6,6 +6,8 @@ + + diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs new file mode 100644 index 000000000..3668b3ac7 --- /dev/null +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs @@ -0,0 +1,6 @@ +module FsLib.OperatorsWithFsi + +let (<&>) x y = x > y +let (? y +let () x = x diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi new file mode 100644 index 000000000..49537d017 --- /dev/null +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi @@ -0,0 +1,13 @@ +module FsLib.OperatorsWithFsi + +/// The binary operator 1 +val (<&>): 'T -> 'T -> bool when 'T: comparison + +/// The binary operator 2 +val (? y: 'T -> bool when 'T: comparison + +/// The unary operator 1 +val ( 'T + +/// The unary operator 2 +val (): x: 'T -> 'T