From 9277ff9c2aaf2fbdc9867b76b3f067e0d01822e0 Mon Sep 17 00:00:00 2001 From: dawe Date: Fri, 24 Jan 2025 16:41:03 +0100 Subject: [PATCH] fix func signature for empty param names (#1351) * fix func signature for empty param names * add testcase --- src/FsAutoComplete.Core/SignatureFormatter.fs | 8 +++++++- test/FsAutoComplete.Tests.Lsp/CoreTests.fs | 11 +++++++++-- .../TestCases/Tooltips/Script.fsx | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/FsAutoComplete.Core/SignatureFormatter.fs b/src/FsAutoComplete.Core/SignatureFormatter.fs index 2662e0c5c..c79e34433 100644 --- a/src/FsAutoComplete.Core/SignatureFormatter.fs +++ b/src/FsAutoComplete.Core/SignatureFormatter.fs @@ -505,7 +505,13 @@ module SignatureFormatter = many |> List.map (fun (paramTypes) -> paramTypes - |> List.map (fun p -> formatName p + ":" ++ (formatParameter p)) + |> List.map (fun p -> + let paramName = formatName p + + if String.IsNullOrWhiteSpace(paramName) then + formatParameter p + else + paramName + ":" ++ (formatParameter p)) |> String.concat (" * ")) |> String.concat (" -> ") diff --git a/test/FsAutoComplete.Tests.Lsp/CoreTests.fs b/test/FsAutoComplete.Tests.Lsp/CoreTests.fs index 0ef83eb6f..2595a8d22 100644 --- a/test/FsAutoComplete.Tests.Lsp/CoreTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CoreTests.fs @@ -461,12 +461,19 @@ let tooltipTests state = #if NET8_0 [ "active pattern ValueWithName: " " input: Expr" - " -> option" ]) ] ] + " -> option" ]) #else [ "active pattern ValueWithName: " " input: Expr" - " -> option" ]) ] ] + " -> option" ]) #endif + verifySignature + 96u + 7u + (concatLines + [ "interface IWithAndWithoutParamNames" + " abstract member WithParamNames: arg1: int * arg2: float -> string" + " abstract member WithoutParamNames: int * string -> int" ]) ] ] let closeTests state = // Note: clear diagnostics also implies clear caches (-> remove file & project options from State). diff --git a/test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx b/test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx index e20699b62..a36c69ed5 100644 --- a/test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx +++ b/test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx @@ -93,3 +93,7 @@ type Awaitable = (awaitable: 'Awaitable) = awaitable.GetAwaiter() + +type IWithAndWithoutParamNames = + abstract member WithParamNames : arg1: int * arg2: float -> string + abstract member WithoutParamNames : int * string -> int