Skip to content

Commit

Permalink
Fix AP signatures for APs with names which are substrings of other APs (
Browse files Browse the repository at this point in the history
  • Loading branch information
dawedawe authored Nov 28, 2023
1 parent 3d96eda commit 79ee428
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/FsAutoComplete.Core/SignatureFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/CoreTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,28 @@ let tooltipTests state =
" body : (MailboxProcessor<string> -> Async<unit>) *"
" cancellationToken: option<System.Threading.CancellationToken>"
" -> MailboxProcessor<string>" ])
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<obj * System.Type>" ])
verifySignature
65
7
(concatLines
[ "active pattern DefaultValue: "
" input: Expr"
" -> option<System.Type>" ])
verifySignature
70
7
(concatLines
[ "active pattern ValueWithName: "
" input: Expr"
" -> option<obj * System.Type * string>" ]) ] ]

let closeTests state =
// Note: clear diagnostics also implies clear caches (-> remove file & project options from State).
Expand Down
17 changes: 17 additions & 0 deletions test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 79ee428

Please sign in to comment.