Skip to content

Commit 0470f62

Browse files
xperiandriclaude
andcommitted
Search the C# and VB consumers alongside the F# projects
The cross-language search ran after the F# one and visited the consumers one by one, so on a solution where the F# search takes minutes the C# call sites were the last thing to appear. The search now starts before the F# one and runs a few consumers at a time, each search building a compilation; the results are still reported after the F# uses, each file span once, so the order in the window is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent f8c8212 commit 0470f62

1 file changed

Lines changed: 34 additions & 20 deletions

File tree

‎vsintegration/src/FSharp.Editor/Navigation/FindUsagesService.fs‎

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,37 @@ module FSharpFindUsagesService =
116116
return referencedSymbols |> Seq.collect _.Locations
117117
}
118118

119-
/// Reports the uses in C# and VB projects that reference the assembly of a project declaring the symbol.
120-
let private findCrossLanguageReferences
121-
(docId: string)
122-
(definitionItems: (FSharpDefinitionItem * Project)[])
119+
// Every search may build a compilation, and those cost memory, not just a core.
120+
[<Literal>]
121+
let private ConcurrentCompilations = 4
122+
123+
/// The uses in the C# and VB projects that reference the assembly of a project declaring the symbol,
124+
/// each with the definition item to report them under.
125+
let private findCrossLanguageReferences (docId: string) (definitionItems: (FSharpDefinitionItem * Project)[]) =
126+
seq {
127+
for definitionItem, declaringProject in definitionItems do
128+
for project in referencingCompilationProjects declaringProject -> definitionItem, project
129+
}
130+
|> Seq.distinctBy (fun (_, project) -> project.Id)
131+
|> Seq.map (fun (definitionItem, project) ->
132+
findRoslynReferences docId project
133+
|> CancellableTask.map (Seq.map (fun location -> definitionItem, location)))
134+
|> CancellableTask.whenAllThrottled ConcurrentCompilations
135+
|> CancellableTask.map Seq.concat
136+
137+
/// Reports each file span once: the target-framework instances of a consumer share their files.
138+
let private reportCrossLanguageReferences
139+
(found: (FSharpDefinitionItem * ReferenceLocation) seq)
123140
(onReferenceFoundAsync: FSharpSourceReferenceItem -> Task)
124141
=
125142
cancellableTask {
126143
let reported = HashSet<struct (string * TextSpan)>()
127144

128-
for definitionItem, declaringProject in definitionItems do
129-
for project in referencingCompilationProjects declaringProject do
130-
let! locations = findRoslynReferences docId project
131-
132-
for location in locations do
133-
let span = location.Location.SourceSpan
145+
for definitionItem, location in found do
146+
let span = location.Location.SourceSpan
134147

135-
if reported.Add(struct (location.Document.FilePath, span)) then
136-
do!
137-
onReferenceFoundAsync (
138-
FSharpSourceReferenceItem(definitionItem, FSharpDocumentSpan(location.Document, span))
139-
)
148+
if reported.Add(struct (location.Document.FilePath, span)) then
149+
do! onReferenceFoundAsync (FSharpSourceReferenceItem(definitionItem, FSharpDocumentSpan(location.Document, span)))
140150
}
141151

142152
let findReferencedSymbolsAsync
@@ -214,12 +224,16 @@ module FSharpFindUsagesService =
214224
symbol.Ident.idText
215225
context.OnReferenceFoundAsync
216226

217-
do! SymbolHelpers.findSymbolUses symbolUse document checkFileResults onFound
218-
219-
if allReferences && not isExternal && not symbolUse.Symbol.IsInternalToProject then
227+
// Searched alongside the F# projects, reported after them.
228+
let crossLanguageSearch =
220229
match symbolUse.Symbol.DocumentationCommentId with
221-
| ValueSome docId -> do! findCrossLanguageReferences docId definitionItems context.OnReferenceFoundAsync
222-
| ValueNone -> ()
230+
| ValueSome docId when allReferences && not isExternal && not symbolUse.Symbol.IsInternalToProject ->
231+
findCrossLanguageReferences docId definitionItems cancellationToken
232+
| _ -> Task.FromResult Seq.empty
233+
234+
do! SymbolHelpers.findSymbolUses symbolUse document checkFileResults onFound
235+
let! found = crossLanguageSearch
236+
do! reportCrossLanguageReferences found context.OnReferenceFoundAsync
223237
}
224238

225239
open FSharpFindUsagesService

0 commit comments

Comments
 (0)