Skip to content

Commit eec6f8e

Browse files
CopilotTheAngryByrd
andcommitted
Add tests for finding references from active pattern declarations
- Added test for full active pattern from declaration - Added test for partial active pattern from definition - Updated comment to clarify filtering behavior - All 18 tests now pass (9 for BackgroundCompiler + 9 for TransparentCompiler) Co-authored-by: TheAngryByrd <[email protected]>
1 parent f38bd78 commit eec6f8e

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/FsAutoComplete.Core/Commands.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ module Commands =
788788

789789
// For Active Pattern Cases, FCS returns all cases in the pattern, not just the specific one
790790
// We need to filter to only the symbol that matches our query
791+
// BUT: if querying from the Active Pattern declaration itself (FSharpMemberOrFunctionOrValue),
792+
// we want ALL cases, not filtered
791793
match symbolUse.Symbol with
792794
| :? FSharpActivePatternCase as apc ->
793795
baseFiltered

test/FsAutoComplete.Tests.Lsp/FindReferencesTests.fs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,27 @@ let private activePatternTests state =
665665
}
666666

667667
serverTestList "active patterns" state defaultConfigDto None (fun server ->
668-
[ testCaseAsync "can find references for Active Pattern Case 'Even' without including 'Odd'"
668+
[ testCaseAsync "can find references for full Active Pattern from declaration"
669+
<| checkRanges
670+
server
671+
"""
672+
module MyModule =
673+
let ($D<|Even|$0Odd|>D$) value =
674+
if value % 2 = 0 then Even else Odd
675+
676+
open MyModule
677+
let _ = ($<|Even|Odd|>$) 42
678+
let _ = MyModule.($<|Even|Odd|>$) 42
679+
let _ =
680+
match 42 with
681+
| Even -> ()
682+
| Odd -> ()
683+
let _ =
684+
match 42 with
685+
| MyModule.Even -> ()
686+
| MyModule.Odd -> ()
687+
"""
688+
testCaseAsync "can find references for Active Pattern Case 'Even' without including 'Odd'"
669689
<| checkRanges
670690
server
671691
"""
@@ -720,6 +740,25 @@ let private activePatternTests state =
720740
| MyModule.$<ParseInt>$ i -> i
721741
| _ -> 0
722742
"""
743+
testCaseAsync "can find references for Partial Active Pattern - from definition"
744+
<| checkRanges
745+
server
746+
"""
747+
module MyModule =
748+
let ($D<|ParseInt|$0_|>D$) (str: string) =
749+
let success, i = System.Int32.TryParse str
750+
if success then Some i else None
751+
752+
open MyModule
753+
let _ =
754+
match "42" with
755+
| ParseInt i -> i
756+
| _ -> 0
757+
let _ =
758+
match "test" with
759+
| MyModule.ParseInt i -> i
760+
| _ -> 0
761+
"""
723762
testCaseAsync "can find references for three-case Active Pattern - first case"
724763
<| checkRanges
725764
server

0 commit comments

Comments
 (0)