Skip to content

Commit 93ea068

Browse files
committed
Enhance error logging for active pattern member lookups and improve deduplication comments
1 parent 2ee9d26 commit 93ea068

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/FsAutoComplete.Core/Commands.fs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,13 @@ module Commands =
859859
|> Seq.tryFind (fun m ->
860860
m.DisplayName.Contains(apcSearchString, System.StringComparison.OrdinalIgnoreCase)
861861
|| m.CompiledName.Contains(apCase.DisplayName, System.StringComparison.OrdinalIgnoreCase))
862-
with _ ->
862+
with e ->
863+
commandsLogger.debug (
864+
Log.setMessage "Failed to find declaring member for active pattern case {case}: {error}"
865+
>> Log.addContextDestructured "case" apCase.DisplayName
866+
>> Log.addExn e
867+
)
868+
863869
None
864870

865871
match declaringMember with
@@ -879,7 +885,13 @@ module Commands =
879885
mfv.DisplayName.Contains($"|{apc.DisplayName}|", System.StringComparison.OrdinalIgnoreCase))
880886
|> Seq.map (fun apc -> apc :> FSharpSymbol)
881887
|> Seq.toList
882-
with _ ->
888+
with e ->
889+
commandsLogger.debug (
890+
Log.setMessage "Failed to find cases for active pattern function {func}: {error}"
891+
>> Log.addContextDestructured "func" mfv.DisplayName
892+
>> Log.addExn e
893+
)
894+
883895
[]
884896

885897
symbol :: functionCases
@@ -904,11 +916,15 @@ module Commands =
904916
let references =
905917
allReferences
906918
|> Array.concat
907-
// Deduplicate - when searching for multiple symbols (e.g., active pattern function + cases),
908-
// they may return overlapping ranges at the same location.
919+
// Deduplicate overlapping ranges - when searching for multiple symbols (e.g., active pattern
920+
// function + cases), they may return overlapping ranges at the same location.
909921
// For example, at an active pattern declaration we might find both:
910922
// `|IsOneOfChoice|_|` (function symbol) and `IsOneOfChoice` (case symbol)
911923
// Keep only the outermost (longest) range when ranges overlap or are contained within each other.
924+
//
925+
// Note: This deduplication assumes active pattern references are single-line identifiers,
926+
// so we only need to compare column positions within each line. Multiline ranges would
927+
// require comparing StartLine/EndLine as well, but active pattern names cannot span lines.
912928
|> Array.groupBy (fun r -> r.StartLine)
913929
|> Array.collect (fun (_, rangesOnLine) ->
914930
// For ranges on the same line, filter out those that are contained within another
@@ -1043,8 +1059,11 @@ module Commands =
10431059
else
10441060
result.Add(k, v)
10451061

1046-
// Deduplicate across all symbol searches - when clicking on an active pattern,
1047-
// TryGetSymbolUses may return both the function and case symbol, leading to duplicates
1062+
// Final deduplication pass: remove exact duplicate ranges across all symbol searches.
1063+
// This is separate from the per-file deduplication in tryFindReferencesInFile which removes
1064+
// *contained* ranges (e.g., `IsOneOfChoice` inside `|IsOneOfChoice|_|`).
1065+
// This pass removes *identical* ranges that may arise when TryGetSymbolUses returns both
1066+
// the function and case symbol pointing to the same location.
10481067
for KeyValue(k, v) in result do
10491068
result.[k] <-
10501069
v

0 commit comments

Comments
 (0)