Skip to content

Commit f0164e3

Browse files
CopilotTheAngryByrd
andcommitted
Fix finding case usages from active pattern declaration
- Use case.Group.DeclaringEntity to match cases to their pattern - Compare declaring entities and pattern names - Properly handle Option types in comparisons - This enables finding ParseInt usages when querying from (|ParseInt|_|) Co-authored-by: TheAngryByrd <[email protected]>
1 parent afcf4a5 commit f0164e3

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/FsAutoComplete.Core/Commands.fs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -801,34 +801,28 @@ module Commands =
801801
| :? FSharpMemberOrFunctionOrValue as mfv when mfv.IsActivePattern ->
802802
// Querying from the active pattern function declaration
803803
// We want both the function declaration AND the case usages
804+
// Get all symbol uses in the file to find related cases
804805
let allSymbolUsesInFile = tyRes.GetCheckResults.GetAllUsesOfAllSymbolsInFile(ct)
805806

806-
// Extract pattern name from display name like "|ParseInt|_|" -> "ParseInt"
807-
let patternName =
808-
let name = mfv.DisplayName
809-
810-
if name.StartsWith("|") && name.EndsWith("|") then
811-
let inner = name.Substring(1, name.Length - 2)
812-
// For partial patterns like "|ParseInt|_|", split and take first part
813-
let parts = inner.Split('|')
814-
815-
if parts.Length > 0 && parts.[0] <> "_" then
816-
Some parts.[0]
817-
else
818-
None
819-
else
820-
None
821-
822-
// Find all case usages that match this pattern
807+
// Find case usages where the case's group declaring entity matches this function
823808
let caseUsages =
824-
match patternName with
825-
| Some pname ->
826-
allSymbolUsesInFile
827-
|> Seq.filter (fun u ->
828-
match u.Symbol with
829-
| :? FSharpActivePatternCase as case -> case.Name = pname
830-
| _ -> false)
831-
| None -> Seq.empty
809+
allSymbolUsesInFile
810+
|> Seq.filter (fun u ->
811+
match u.Symbol with
812+
| :? FSharpActivePatternCase as case ->
813+
// Check if this case's group is declared by our active pattern function
814+
// The group's declaring entity should match the entity containing our function
815+
try
816+
match case.Group.DeclaringEntity, mfv.DeclaringEntity with
817+
| Some caseEntity, Some mfvEntity ->
818+
// For patterns like (|ParseInt|_|), check if the case belongs to this pattern
819+
// We compare the full names and the pattern name
820+
caseEntity.TryFullName = mfvEntity.TryFullName
821+
&& case.Group.Name = Some mfv.DisplayName
822+
| _ -> false
823+
with _ ->
824+
false
825+
| _ -> false)
832826

833827
// Combine declaration with case usages
834828
baseFiltered |> Seq.append caseUsages

0 commit comments

Comments
 (0)