From 359814a7e88368cafba02b83e67dfe873aff9161 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Sun, 28 Aug 2022 06:26:48 +0300 Subject: [PATCH 1/9] wip --- src/FSharp.Formatting.ApiDocs/GenerateModel.fs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 6b6df752a..e0ceb1527 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -1463,23 +1463,23 @@ module internal SymbolReader = match argInfos with // binary operators (taking a tuple) | [ [ x; y ] ] -> - let left = formatCurriedArgsUsageAsHtml true false [ [ x ] ] + let left = formatArgUsageAsHtml () 1 x let nm = PrettyNaming.DecompileOpName v.CompiledName - let right = formatCurriedArgsUsageAsHtml true false [ [ y ] ] + let right = formatArgUsageAsHtml () 2 y - span [] [ left; !! " "; !!nm; !! " "; right ] + span [] [ left; !! " "; !!HttpUtility.HtmlEncode(nm); !! " "; right ] // binary operators (curried, like in FSharp.Core.Operators) - | [ args1; args2 ] -> - let left = formatCurriedArgsUsageAsHtml true false [ args1 ] + | [ [ args1 ]; [ args2 ] ] -> + let left = formatArgUsageAsHtml () 1 args1 let nm = PrettyNaming.DecompileOpName v.CompiledName - let right = formatCurriedArgsUsageAsHtml true false [ args2 ] + let right = formatArgUsageAsHtml () 2 args2 - span [] [ left; !! " "; !!nm; !! " "; right ] + span [] [ left; !! " "; !!HttpUtility.HtmlEncode(nm); !! " "; right ] // unary operators | [ [ x ] ] -> From e3d7c16ac30bfc1a22d97449f537cb4bd49654b6 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Sun, 28 Aug 2022 06:40:10 +0300 Subject: [PATCH 2/9] wip --- src/FSharp.Formatting.ApiDocs/GenerateModel.fs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index e0ceb1527..3d57eca4e 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -1462,22 +1462,14 @@ module internal SymbolReader = | _, false, _, name, _ when PrettyNaming.IsMangledOpName v.CompiledName -> match argInfos with // binary operators (taking a tuple) - | [ [ x; y ] ] -> - let left = formatArgUsageAsHtml () 1 x - - let nm = PrettyNaming.DecompileOpName v.CompiledName - - let right = formatArgUsageAsHtml () 2 y - - span [] [ left; !! " "; !!HttpUtility.HtmlEncode(nm); !! " "; right ] - + | [ [ x; y ] ] // binary operators (curried, like in FSharp.Core.Operators) - | [ [ args1 ]; [ args2 ] ] -> - let left = formatArgUsageAsHtml () 1 args1 + | [ [ x ]; [ y ] ] -> + let left = formatArgUsageAsHtml () 0 x let nm = PrettyNaming.DecompileOpName v.CompiledName - let right = formatArgUsageAsHtml () 2 args2 + let right = formatArgUsageAsHtml () 1 y span [] [ left; !! " "; !!HttpUtility.HtmlEncode(nm); !! " "; right ] From 75cf6a2195f27a10df4fd1493c679a74ed4464c8 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Sun, 28 Aug 2022 16:27:28 +0300 Subject: [PATCH 3/9] wip --- src/FSharp.Formatting.ApiDocs/GenerateModel.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 3d57eca4e..2fb8f8d73 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -1471,7 +1471,7 @@ module internal SymbolReader = let right = formatArgUsageAsHtml () 1 y - span [] [ left; !! " "; !!HttpUtility.HtmlEncode(nm); !! " "; right ] + span [] [ left; !! " "; encode nm; !! " "; right ] // unary operators | [ [ x ] ] -> From e78ee5cb80d2e683603922293bebf4159f506288 Mon Sep 17 00:00:00 2001 From: BoundedChenn31 Date: Sun, 28 Aug 2022 17:15:01 +0300 Subject: [PATCH 4/9] Remove unused parameter --- src/FSharp.Formatting.ApiDocs/GenerateModel.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 2fb8f8d73..d523670ff 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 @@ -1465,11 +1465,11 @@ module internal SymbolReader = | [ [ x; y ] ] // binary operators (curried, like in FSharp.Core.Operators) | [ [ x ]; [ y ] ] -> - let left = formatArgUsageAsHtml () 0 x + let left = formatArgUsageAsHtml 0 x let nm = PrettyNaming.DecompileOpName v.CompiledName - let right = formatArgUsageAsHtml () 1 y + let right = formatArgUsageAsHtml 1 y span [] [ left; !! " "; encode nm; !! " "; right ] From 018739c309c8a52e45f0237df0c1af1923fa5c9e Mon Sep 17 00:00:00 2001 From: BoundedChenn31 Date: Sun, 28 Aug 2022 19:07:17 +0300 Subject: [PATCH 5/9] Encode name of unary operator --- src/FSharp.Formatting.ApiDocs/GenerateModel.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index d523670ff..7602204cc 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -1479,7 +1479,7 @@ module internal SymbolReader = let right = formatCurriedArgsUsageAsHtml true false [ [ x ] ] - span [] [ !!nm; right ] + span [] [ encode nm; right ] | _ -> span [] From 923ade5bdf7f2c819f26ac221522381e56925e10 Mon Sep 17 00:00:00 2001 From: BoundedChenn31 Date: Tue, 30 Aug 2022 20:12:45 +0300 Subject: [PATCH 6/9] Add tests for fixed cases --- tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs | 11 +++++++++++ tests/FSharp.ApiDocs.Tests/files/FsLib1/FsLib1.fsproj | 2 ++ .../files/FsLib1/OperatorsWithFsi.fs | 4 ++++ .../files/FsLib1/OperatorsWithFsi.fsi | 5 +++++ 4 files changed, 22 insertions(+) create mode 100644 tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs create mode 100644 tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi diff --git a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs index 474b53d02..c3c58cb61 100644 --- a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs +++ b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs @@ -253,6 +253,17 @@ 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 + files[$"fslib-operatorswithfsi.%s{format.Extension}"] + |> shouldContainText "<&>" + + // Check that parameters are indexed + files[$"fslib-operatorswithfsi.%s{format.Extension}"] + |> shouldContainText "arg0" + + files[$"fslib-operatorswithfsi.%s{format.Extension}"] + |> shouldContainText "arg1" + (* 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..0c63a50bc --- /dev/null +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs @@ -0,0 +1,4 @@ +module FsLib.OperatorsWithFsi + +let (<&>) (x: 'T) (y: 'T) = x < y + 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..5f2486a08 --- /dev/null +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi @@ -0,0 +1,5 @@ +module FsLib.OperatorsWithFsi + +/// The operator +val ( <&> ) : 'T -> 'T -> bool when 'T : comparison + From db9b4fd849a4f9befeb123e28a61d2cfd012ff1a Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 30 Aug 2022 23:31:16 +0300 Subject: [PATCH 7/9] yet another tests --- src/FSharp.Formatting.ApiDocs/GenerateModel.fs | 2 +- tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs | 15 +++++++++++---- .../files/FsLib1/OperatorsWithFsi.fs | 6 ++++-- .../files/FsLib1/OperatorsWithFsi.fsi | 13 +++++++++++-- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 7602204cc..ddbed35cc 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -1477,7 +1477,7 @@ module internal SymbolReader = | [ [ x ] ] -> let nm = PrettyNaming.DecompileOpName v.CompiledName - let right = formatCurriedArgsUsageAsHtml true false [ [ x ] ] + let right = formatArgUsageAsHtml 0 x span [] [ encode nm; right ] | _ -> diff --git a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs index c3c58cb61..6690ac985 100644 --- a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs +++ b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs @@ -254,15 +254,22 @@ let ``ApiDocs works on two sample F# assemblies`` (format: OutputFormat) = |> shouldContainText "Naming(rate, string)" // Check that operators are encoded + + // arg0 <&> arg1 + files[$"fslib-operatorswithfsi.%s{format.Extension}"] + |> shouldContainText "arg0 <&> arg1" + + // x ? shouldContainText "<&>" + |> shouldContainText "x ?<? y" - // Check that parameters are indexed + // -arg0 files[$"fslib-operatorswithfsi.%s{format.Extension}"] - |> shouldContainText "arg0" + |> shouldContainText "~-arg0" + // ?-x files[$"fslib-operatorswithfsi.%s{format.Extension}"] - |> shouldContainText "arg1" + |> shouldContainText "~?-x" (* This may be addressed in a separate issue or removed if not an issue. // Check that implict cast operator is generated correctly diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs index 0c63a50bc..fb4f4d4dd 100644 --- a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs @@ -1,4 +1,6 @@ module FsLib.OperatorsWithFsi -let (<&>) (x: 'T) (y: 'T) = x < y - +let ( <&> ) x y = x > y +let ( ? y +let (~-) x = x +let (~?-) x = x diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi index 5f2486a08..1b0e1acd8 100644 --- a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi @@ -1,5 +1,14 @@ module FsLib.OperatorsWithFsi -/// The operator -val ( <&> ) : 'T -> 'T -> bool when 'T : comparison +/// 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 -> 'T + +/// The unary operator 2 +val (~?-): x: 'T -> 'T From 1ff085da6f5abbc1c1077e0b7f4a057d28360ae3 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Tue, 30 Aug 2022 23:36:36 +0300 Subject: [PATCH 8/9] fix --- tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs | 8 ++++---- .../FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs | 4 ++-- .../files/FsLib1/OperatorsWithFsi.fsi | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs index 6690ac985..f428c4d2a 100644 --- a/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs +++ b/tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs @@ -263,13 +263,13 @@ let ``ApiDocs works on two sample F# assemblies`` (format: OutputFormat) = files[$"fslib-operatorswithfsi.%s{format.Extension}"] |> shouldContainText "x ?<? y" - // -arg0 + // shouldContainText "~-arg0" + |> shouldContainText "<?arg0" - // ?-x + // x files[$"fslib-operatorswithfsi.%s{format.Extension}"] - |> shouldContainText "~?-x" + |> shouldContainText "<?>x" (* This may be addressed in a separate issue or removed if not an issue. // Check that implict cast operator is generated correctly diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs index fb4f4d4dd..dbc0ce148 100644 --- a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs @@ -2,5 +2,5 @@ let ( <&> ) x y = x > y let ( ? y -let (~-) x = x -let (~?-) x = x +let () x = x diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi index 1b0e1acd8..e629258d1 100644 --- a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi @@ -7,8 +7,8 @@ val ( <&> ): 'T -> 'T -> bool when 'T : comparison val ( ? y: 'T -> bool when 'T : comparison /// The unary operator 1 -val (~-): 'T -> 'T +val ( 'T /// The unary operator 2 -val (~?-): x: 'T -> 'T +val (): x: 'T -> 'T From ff92b18997ce16018c83b8aae6dd1f0d857b06a0 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Wed, 31 Aug 2022 16:35:37 +0300 Subject: [PATCH 9/9] cleanup --- tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs | 4 ++-- tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs index dbc0ce148..3668b3ac7 100644 --- a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fs @@ -1,6 +1,6 @@ module FsLib.OperatorsWithFsi -let ( <&> ) x y = x > y -let ( ? y +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 index e629258d1..49537d017 100644 --- a/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi +++ b/tests/FSharp.ApiDocs.Tests/files/FsLib1/OperatorsWithFsi.fsi @@ -1,14 +1,13 @@ module FsLib.OperatorsWithFsi /// The binary operator 1 -val ( <&> ): 'T -> 'T -> bool when 'T : comparison +val (<&>): 'T -> 'T -> bool when 'T: comparison /// The binary operator 2 -val ( ? y: 'T -> bool when 'T : comparison +val (? y: 'T -> bool when 'T: comparison /// The unary operator 1 val ( 'T /// The unary operator 2 val (): x: 'T -> 'T -