From 79ee428eabea059a5a14a6603d0f7867c0cb9043 Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 28 Nov 2023 19:47:33 +0100 Subject: [PATCH] Fix AP signatures for APs with names which are substrings of other APs (#1211) --- src/FsAutoComplete.Core/SignatureFormatter.fs | 4 +++- test/FsAutoComplete.Tests.Lsp/CoreTests.fs | 23 ++++++++++++++++++- .../TestCases/Tooltips/Script.fsx | 17 ++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/FsAutoComplete.Core/SignatureFormatter.fs b/src/FsAutoComplete.Core/SignatureFormatter.fs index f00406090..476321d2e 100644 --- a/src/FsAutoComplete.Core/SignatureFormatter.fs +++ b/src/FsAutoComplete.Core/SignatureFormatter.fs @@ -552,10 +552,12 @@ module SignatureFormatter = let getAPCaseSignature displayContext (apc: FSharpActivePatternCase) = let findVal = + let apcSearchString = $"|{apc.DisplayName}|" + apc.Group.DeclaringEntity |> Option.bind (fun ent -> ent.MembersFunctionsAndValues - |> Seq.tryFind (fun func -> func.DisplayName.Contains apc.DisplayName) + |> Seq.tryFind (fun func -> func.DisplayName.Contains(apcSearchString, StringComparison.OrdinalIgnoreCase)) |> Option.map (getFuncSignature displayContext)) |> Option.bind (fun n -> try diff --git a/test/FsAutoComplete.Tests.Lsp/CoreTests.fs b/test/FsAutoComplete.Tests.Lsp/CoreTests.fs index 29d1db2e9..fbc24265a 100644 --- a/test/FsAutoComplete.Tests.Lsp/CoreTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CoreTests.fs @@ -379,7 +379,28 @@ let tooltipTests state = " body : (MailboxProcessor -> Async) *" " cancellationToken: option" " -> MailboxProcessor" ]) - verifySignature 54 9 "Case2 of string * newlineBefore: bool * newlineAfter: bool" ] ] + verifySignature 54 9 "Case2 of string * newlineBefore: bool * newlineAfter: bool" + verifySignature + 60 + 7 + (concatLines + [ "active pattern Value: " + " input: Expr" + " -> option" ]) + verifySignature + 65 + 7 + (concatLines + [ "active pattern DefaultValue: " + " input: Expr" + " -> option" ]) + verifySignature + 70 + 7 + (concatLines + [ "active pattern ValueWithName: " + " input: Expr" + " -> option" ]) ] ] 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 2ff1265ca..1844e333c 100644 --- a/test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx +++ b/test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx @@ -53,3 +53,20 @@ let mailbox = type DiscUnionWithCaseOfLabeledTuple = | Case1 | Case2 of string * newlineBefore: bool * newlineAfter: bool + +open FSharp.Quotations.Patterns + +let testActivePatternSignatureWithSubStringName (expr: Quotations.Expr) = + match expr with + | Value (o, t) -> (o, t) + | _ -> failwith "no value match" + |> ignore + + match expr with + | DefaultValue t -> t + | _ -> failwith "no value match" + |> ignore + + match expr with + | ValueWithName t -> t + | _ -> failwith "no value match" \ No newline at end of file