Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from genlu April 25, 2025 19:01
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 25, 2025 19:01
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 25, 2025
internal sealed class CSharpContextProviderService([ImportMany] IEnumerable<IContextProvider> providers)
: ICSharpCopilotContextProviderService
{
// Exposed for testing
Copy link
Member Author

Choose a reason for hiding this comment

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

note: i couldn't find this actually read anywhere. if it is used for testing, it should be exposed through a GetTestAccessor() method.

Copy link
Member

Choose a reason for hiding this comment

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

oops, I forgot to move the tests over.


<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading" />
</ItemGroup>
Copy link
Member Author

Choose a reason for hiding this comment

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

definitely do not want this.

builder.Add(item);
}

return builder.ToArray();
Copy link
Member Author

Choose a reason for hiding this comment

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

this really should be using an IProgress value in LSP. That way this can stream the context items back to the caller, and so we can be canceled if we take too long, while also providing some items back that can be used within the time budgets of hte caller.

Copy link
Member

Choose a reason for hiding this comment

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

yea, I was planning to do this, just didn'r have time to figure out how to return an AyncIterable yet
see: https://github.com/github/copilot-client/blob/fa8dce2647472b64bbad2128acb607d11811ead8/types/src/contextProviderApiV1.ts#L55

private readonly ImmutableArray<IContextProvider> _providers = [.. providers];

public IAsyncEnumerable<IContextItem> GetContextItemsAsync(Document document, int position, IReadOnlyDictionary<string, object> activeExperiments, CancellationToken cancellationToken)
=> ProducerConsumer<IContextItem>.RunParallelStreamAsync(
Copy link
Member Author

Choose a reason for hiding this comment

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

this automatically parallelizes, prefering to utilize all cores to finish a fixed set of work that is then added to as work items complete. this is better than kicking off N items (which may be far mroe than the number of cores), causing them to contend with each other, and trying to .WhenAll them.

Copy link
Member

Choose a reason for hiding this comment

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

thanks! I initially tried to use roslyn's ProducerConsumer but it quickly ended up with the problem of requiring too much code to be exposed via EA, so I wrote my own parallelization instead. Now that we moved this code over, it makes perfect sense to fix it

callback(item);

return default;
}, cancellationToken).ConfigureAwait(false),
Copy link
Member Author

Choose a reason for hiding this comment

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

note: if ProvideContextItemsAsync just took an Action this could would be simplified to:

Suggested change
}, cancellationToken).ConfigureAwait(false),
(provider, cancellationToken) => provider.ProvideContextItemsAsync(
document, position, activeExperiments, callback, cancellationToken);

Which is much nicer and cleaner. It's unclear why we're passing a callback that has to package up everything in an array and be async.

@CyrusNajmabadi
Copy link
Member Author

@genlu ptal.

Note: i would like to take this, and include inthe backport if possible.

@CyrusNajmabadi
Copy link
Member Author

@genlu ptal.

Copy link
Member

@genlu genlu left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit 0211c26 into dotnet:main Apr 29, 2025
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the cleanupCopilot branch April 29, 2025 18:07
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 29, 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