Skip to content

Commit 15258f2

Browse files
committed
Enhance documentation for findPartialActivePatternCaseUsages and optimize case name extraction in AdaptiveServerState
1 parent 0837d20 commit 15258f2

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/FsAutoComplete.Core/Commands.fs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ module Commands =
107107
|> Array.filter (fun s -> not (String.IsNullOrWhiteSpace(s)))
108108
|> Array.toList
109109

110-
/// Find case usages for partial active patterns by walking the AST
111-
/// Returns ranges where the case names appear in pattern matches
110+
/// Finds usages of partial active pattern cases by walking the AST.
111+
///
112+
/// Returns syntactic ranges from the AST where the specified case names appear in pattern matches.
113+
/// For qualified identifiers (e.g., `MyModule.ParseInt`), returns the full qualified range to match FCS behavior.
114+
/// Recursively traverses all pattern forms, including nested and composite patterns (tuples, lists, or/and/as patterns, etc.).
115+
///
116+
/// Note: Only syntactic (AST) ranges are returned; semantic information is not considered.
112117
let findPartialActivePatternCaseUsages (caseNames: string list) (parseResults: FSharpParseFileResults) : range list =
113118
let rec walkPat (pat: SynPat) =
114119
seq {
@@ -270,7 +275,7 @@ module Commands =
270275
| ParsedInput.ImplFile(ParsedImplFileInput(contents = modules)) ->
271276
modules
272277
|> List.collect (fun (SynModuleOrNamespace(decls = decls)) -> decls |> List.collect (walkDecl >> Seq.toList))
273-
|> List.distinct
278+
|> List.distinctBy (fun r -> r.Start, r.End)
274279
| _ -> []
275280

276281
let addFile (fsprojPath: string) fileVirtPath =

src/FsAutoComplete/LspServers/AdaptiveServerState.fs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,10 +1173,9 @@ type AdaptiveState
11731173
binlogConfig
11741174
|> addAValLogging (fun () -> logger.info (Log.setMessage "Loading projects because binlogConfig change"))
11751175

1176-
let! projects =
1177-
// need to bind to a single value to keep the threadpool from being exhausted as LoadingProjects can be a long running operation
1178-
// and when other adaptive values await on this, the scheduler won't block those other tasks
1179-
loadProjects loader binlogConfig projects |> AMap.toAVal
1176+
// need to bind to a single value to keep the threadpool from being exhausted as LoadingProjects can be a long running operation
1177+
// and when other adaptive values await on this, the scheduler won't block those other tasks
1178+
let! projects = loadProjects loader binlogConfig projects |> AMap.toAVal
11801179

11811180
and! checker = checker
11821181
checker.ClearCaches()
@@ -2208,10 +2207,7 @@ type AdaptiveState
22082207
match! forceGetOpenFileTypeCheckResultsStale file with
22092208
| Error _ -> return baseRanges
22102209
| Ok tyRes ->
2211-
let caseNames =
2212-
patternDisplayName.TrimStart('|', '(').TrimEnd('|', '_', ')').Split('|')
2213-
|> Array.filter (fun s -> not (System.String.IsNullOrWhiteSpace(s)))
2214-
|> Array.toList
2210+
let caseNames = Commands.extractActivePatternCaseNames patternDisplayName
22152211

22162212
let caseUsageRanges =
22172213
Commands.findPartialActivePatternCaseUsages caseNames tyRes.GetParseResults

0 commit comments

Comments
 (0)