Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

No description provided.

@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 8, 2025
@CyrusNajmabadi CyrusNajmabadi changed the title WIP: Demonstrate how to simplify code. Simplify channel-processing code in SemanticSearch. Apr 8, 2025

public async IAsyncEnumerable<SyntaxNode> FindAsync(ISymbol symbol)
{
var channel = Channel.CreateUnbounded<ReferenceLocation>(new()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to helper in ProducerConsumer that already does the concurrent production/consumption work over an unbounded channel.

public async IAsyncEnumerable<SyntaxNode> FindAsync(ISymbol symbol)
{
var channel = Channel.CreateUnbounded<ReferenceLocation>(new()
using var _ = PooledHashSet<SyntaxNode>.GetInstance(out var cachedRoots);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also added this so that we don't continually reparse documents with multiple results in them.

@CyrusNajmabadi CyrusNajmabadi requested review from ToddGrun and tmat April 8, 2025 19:13
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review April 8, 2025 19:13
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 8, 2025 19:13
@CyrusNajmabadi
Copy link
Member Author

@tmat this is ready for review.


using var _ = cancellationToken.Register(
static (obj, cancellationToken) => ((Channel<SourceReferenceItem>)obj!).Writer.TryComplete(new OperationCanceledException(cancellationToken)),
state: channel);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProducerConsumer.RunChannelAsync basically has all this code, and is the centralized place where so much of our Producer/Consumer logic goes through. I added a new entrypoint to it to represent this case (where caller just wants to grab the produced results and do transformations on it itself).

// then convert this to a simple IAsyncEnumerable<ReferenceLocation> that we can iterate over, converting those
// locations to SyntaxNodes in the corresponding C# or VB document.
await foreach (var item in ProducerConsumer<ReferenceLocation>.RunAsync(
FuncReferencesAsync, args: (solution, symbol), cancellationToken))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "FindReferencesAsync"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use lambda?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we generally designed all of these overloads, from the start, to be non-allocating (they get used heavily in some scenarios with lots of callbacks and whatnot). To just simplify the surface area, that means they're all "Delegate + Args". I could def pass a lambda. But there's a certain niceness in just knowing that no delegates (except the first) will actually be allocated :).

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge April 8, 2025 19:25
@CyrusNajmabadi CyrusNajmabadi merged commit ad71cae into dotnet:main Apr 8, 2025
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the simplifyChannel branch April 8, 2025 20:37
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 8, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants