-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[17.14] Move Copilot context provider to EA.Copilot and handler to LanguageServer #78322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/dev17.14
Are you sure you want to change the base?
Conversation
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.Completion; | ||
|
||
internal record CodeSnippetItem : IContextItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal record CodeSnippetItem : IContextItem | |
internal selaed record CodeSnippetItem : IContextItem |
|
||
internal record CodeSnippetItem : IContextItem | ||
{ | ||
public CodeSnippetItem(string uri, string value, string[]? additionalUris = null, int importance = Completion.Importance.Default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
primary constructor?
public string[]? AdditionalUris { get; init; } | ||
|
||
[JsonPropertyName("importance")] | ||
public int Importance { get; init; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can just be [property:
attributes on primary constructor parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider doc'ing these.
|
||
internal interface ICSharpCopilotContextProviderService | ||
{ | ||
IAsyncEnumerable<IContextItem> GetContextItemsAsync(Document document, int position, IReadOnlyDictionary<string, object> activeExperiments, CancellationToken cancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's teh object
value for activeExperiments?
namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.Completion; | ||
|
||
[JsonDerivedType(typeof(CodeSnippetItem))] | ||
[JsonDerivedType(typeof(TraitItem))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ni: call these CodeSnippetContextItem and TraitContextItem to make it clearer what they are.
Document document, | ||
int position, | ||
IReadOnlyDictionary<string, object> activeExperiments, | ||
Func<ImmutableArray<IContextItem>, CancellationToken, ValueTask> callback, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why pass an array, instead of just an itemt at a time, if it's a callback?
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.Completion; | ||
|
||
internal record TraitItem : IContextItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal record TraitItem : IContextItem | |
internal sealed record TraitItem : IContextItem |
|
||
internal record TraitItem : IContextItem | ||
{ | ||
public TraitItem(string name, string value, int importance = Completion.Importance.Default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
primary constructor, with attribute on params.
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.Completion; | ||
|
||
internal record TraitItem : IContextItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does 'trait' mean here?
[Shared] | ||
[Export(typeof(ICSharpCopilotContextProviderService))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Shared] | |
[Export(typeof(ICSharpCopilotContextProviderService))] | |
[Export(typeof(ICSharpCopilotContextProviderService)), Shared] |
nit.
public CSharpContextProviderService([ImportMany] IEnumerable<IContextProvider> providers) | ||
{ | ||
Providers = providers.ToImmutableArray(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
primary constructor.
{ | ||
} | ||
}, | ||
cancellationToken)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a better api for this. ProducerConsumer. You can write this as:
return ProducerConsumer<IContextItem>.RunAsync(
static (callback, args, cancellationToken) =>
{
await RoslynParallel.ForEachAsync(
[email protected],
cancellationToken,
(provider, cancellationToken) => provider.ProviderContextItemsAsync(
args.document, args.position, args.activeExperiments, callback, cancellationToken).ConfigureAwait(False);
}
args: (@this: this, document, position, activeExperiments),
cancellationToken);
@@ -29,6 +30,10 @@ | |||
<ProjectReference Include="..\..\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" /> | |||
</ItemGroup> | |||
|
|||
<ItemGroup> | |||
<PackageReference Include="Microsoft.VisualStudio.Threading" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems undesirable. this will also make it so we can't use this code in vscode. i dont' see anything that would make this necessary.
|
||
namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Copilot; | ||
|
||
internal sealed class CodeSnippetContextItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
called 'ContextItem', but doesn't implement `IContextItem'?
|
||
namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Copilot; | ||
|
||
internal sealed class ContextResolveParam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a fairly vague name. consider calling CopilotContextResultParam
[Shared] | ||
[Method(MethodName)] | ||
[ExportCSharpVisualBasicStatelessLspService(typeof(CopilotCompletionResolveContextHandler), WellKnownLspServerKinds.Any)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Shared] | |
[Method(MethodName)] | |
[ExportCSharpVisualBasicStatelessLspService(typeof(CopilotCompletionResolveContextHandler), WellKnownLspServerKinds.Any)] | |
[Method(MethodName)] | |
[ExportCSharpVisualBasicStatelessLspService(typeof(CopilotCompletionResolveContextHandler), WellKnownLspServerKinds.Any), Shared] |
|
||
[ImportingConstructor] | ||
[Obsolete("This exported object must be obtained through the MEF export provider.", error: true)] | ||
public CopilotCompletionResolveContextHandler(ICSharpCopilotContextProviderService contextProviderService) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
primary constructor
var builder = ImmutableArray.CreateBuilder<IContextItem>(); | ||
var activeExperiments = param.GetUnpackedActiveExperiments(); | ||
|
||
await foreach (var item in ContextProviderService.GetContextItemsAsync(document, position, activeExperiments, cancellationToken).ConfigureAwait(false)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since your'e not streaming anything, you can just make GetContextItemsAsync return an immtuable array. in that case, the impl of it gets a lot simpler too.
i would recomend that htis stream though. that way the host can call into this, and we do the best we can. and it cancels us once enough time has passed.
|
||
namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Copilot; | ||
|
||
internal sealed class TraitContextItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't implement IContextItem?
Since this is a backport, i'm ok with it being mechanical. but i do think we should clean up some code here, and potentially rethink how some things are wokring. |
backport #77973