Skip to content

Commit 0164d6f

Browse files
committed
returns an immutable array for the fix-all scenario.
1 parent 42d8ebc commit 0164d6f

File tree

8 files changed

+23
-12
lines changed

8 files changed

+23
-12
lines changed

src/EditorFeatures/Core/DocumentationComments/CopilotGenerateDocumentationCommentProvider.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,16 @@ private static async Task<IReadOnlyList<ProposedEdit>> GetProposedEditsAsync(
186186
ITextSnapshot oldSnapshot, string? indentText, CancellationToken cancellationToken)
187187
{
188188
var list = new List<ProposedEdit>();
189-
var (documentationCommentDictionary, isQuotaExceeded) = await copilotService.GetDocumentationCommentAsync(proposal, cancellationToken).ConfigureAwait(false);
189+
var documentationCommentResults = await copilotService.GetDocumentationCommentAsync(proposal, cancellationToken).ConfigureAwait(false);
190+
191+
Dictionary<string, string>? documentationCommentDictionary = null;
192+
var isQuotaExceeded = false;
193+
194+
if (!documentationCommentResults.IsEmpty)
195+
{
196+
documentationCommentDictionary = documentationCommentResults[0].responseDictionary;
197+
isQuotaExceeded = documentationCommentResults[0].isQuotaExceeded;
198+
}
190199

191200
// Quietly fail if the quota has been exceeded.
192201
if (isQuotaExceeded)

src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
363363
Return Task.FromResult(False)
364364
End Function
365365

366-
Public Function GetDocumentationCommentAsync(proposal As DocumentationCommentProposal, cancellationToken As CancellationToken) As Task(Of (responseDictionary As Dictionary(Of String, String), isQuotaExceeded As Boolean)) Implements ICopilotCodeAnalysisService.GetDocumentationCommentAsync
367-
Return Task.FromResult((New Dictionary(Of String, String), False))
366+
Public Function GetDocumentationCommentAsync(proposal As DocumentationCommentProposal, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of (responseDictionary As Dictionary(Of String, String), isQuotaExceeded As Boolean))) Implements ICopilotCodeAnalysisService.GetDocumentationCommentAsync
367+
Return Task.FromResult(ImmutableArray.Create((New Dictionary(Of String, String), False)))
368368
End Function
369369

370370
Public Function GetOnTheFlyDocsPromptAsync(onTheFlyDocsInfo As OnTheFlyDocsInfo, cancellationToken As CancellationToken) As Task(Of String) Implements ICopilotCodeAnalysisService.GetOnTheFlyDocsPromptAsync

src/Features/CSharpTest/Copilot/CSharpImplementNotImplementedExceptionFixProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ public Task<bool> IsFileExcludedAsync(string filePath, CancellationToken cancell
666666
public Task StartRefinementSessionAsync(Document oldDocument, Document newDocument, Diagnostic? primaryDiagnostic, CancellationToken cancellationToken)
667667
=> throw new NotImplementedException();
668668

669-
Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> ICopilotCodeAnalysisService.GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken)
669+
Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> ICopilotCodeAnalysisService.GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken)
670670
=> throw new NotImplementedException();
671671

672672
public Task<ImmutableDictionary<SyntaxNode, ImplementationDetails>> ImplementNotImplementedExceptionsAsync(

src/Features/Core/Portable/Copilot/ICopilotCodeAnalysisService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ internal interface ICopilotCodeAnalysisService : ILanguageService
8686
/// Method to retrieve the documentation comment for a given <paramref name="proposal"/>
8787
/// </summary>
8888
/// <param name="proposal">The documentation comment that has been broken down into its individual pieces.</param>
89-
Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken);
89+
Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken);
9090

9191
/// <summary>
9292
/// Checks if the feature for implementing <see cref="System.NotImplementedException"/> is available.

src/Features/ExternalAccess/Copilot/GenerateDocumentation/IExternalCSharpCopilotGenerateDocumentationService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Generic;
6+
using System.Collections.Immutable;
67
using System.Threading;
78
using System.Threading.Tasks;
89

910
namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot
1011
{
1112
internal interface IExternalCSharpCopilotGenerateDocumentationService
1213
{
13-
Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentAsync(CopilotDocumentationCommentProposalWrapper proposal, CancellationToken cancellationToken);
14+
Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentAsync(CopilotDocumentationCommentProposalWrapper proposal, CancellationToken cancellationToken);
1415
}
1516
}

src/Features/ExternalAccess/Copilot/Internal/Analyzer/AbstractCopilotCodeAnalysisService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal abstract class AbstractCopilotCodeAnalysisService(IDiagnosticsRefresher
4444
protected abstract Task<string> GetOnTheFlyDocsPromptCoreAsync(OnTheFlyDocsInfo onTheFlyDocsInfo, CancellationToken cancellationToken);
4545
protected abstract Task<(string responseString, bool isQuotaExceeded)> GetOnTheFlyDocsResponseCoreAsync(string prompt, CancellationToken cancellationToken);
4646
protected abstract Task<bool> IsFileExcludedCoreAsync(string filePath, CancellationToken cancellationToken);
47-
protected abstract Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentCoreAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken);
47+
protected abstract Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentCoreAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken);
4848
protected abstract Task<ImmutableDictionary<SyntaxNode, ImplementationDetails>> ImplementNotImplementedExceptionsCoreAsync(Document document, ImmutableDictionary<SyntaxNode, ImmutableArray<ReferencedSymbol>> methodOrProperties, CancellationToken cancellationToken);
4949
protected abstract bool IsImplementNotImplementedExceptionsAvailableCore();
5050

@@ -183,6 +183,7 @@ public async Task<string> GetOnTheFlyDocsPromptAsync(OnTheFlyDocsInfo onTheFlyDo
183183
{
184184
return await GetOnTheFlyDocsPromptCoreAsync(onTheFlyDocsInfo, cancellationToken).ConfigureAwait(false);
185185
}
186+
186187
public async Task<(string responseString, bool isQuotaExceeded)> GetOnTheFlyDocsResponseAsync(string prompt, CancellationToken cancellationToken)
187188
{
188189
if (!await IsAvailableAsync(cancellationToken).ConfigureAwait(false))
@@ -199,10 +200,10 @@ public async Task<bool> IsFileExcludedAsync(string filePath, CancellationToken c
199200
return await IsFileExcludedCoreAsync(filePath, cancellationToken).ConfigureAwait(false);
200201
}
201202

202-
public async Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken)
203+
public async Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken)
203204
{
204205
if (!await IsAvailableAsync(cancellationToken).ConfigureAwait(false))
205-
return (null, false);
206+
return [(null, false)];
206207

207208
return await GetDocumentationCommentCoreAsync(proposal, cancellationToken).ConfigureAwait(false);
208209
}

src/Features/ExternalAccess/Copilot/Internal/Analyzer/CSharp/CSharpCopilotCodeAnalysisService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ protected override Task<bool> IsFileExcludedCoreAsync(string filePath, Cancellat
143143
return Task.FromResult(false);
144144
}
145145

146-
protected override Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentCoreAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken)
146+
protected override Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentCoreAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken)
147147
{
148148
if (GenerateDocumentationService is not null)
149149
return GenerateDocumentationService.GetDocumentationCommentAsync(new CopilotDocumentationCommentProposalWrapper(proposal), cancellationToken);
150150

151-
return Task.FromResult<(Dictionary<string, string>?, bool)>((null, false));
151+
return Task.FromResult(ImmutableArray.Create<(Dictionary<string, string>?, bool)>((null, false)));
152152
}
153153

154154
protected override bool IsImplementNotImplementedExceptionsAvailableCore()

src/Features/ExternalAccess/Copilot/InternalAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotCodeAnalysis
4949
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotCodeAnalysisService.IsFileExcludedAsync(string! filePath, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
5050
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotCodeAnalysisService.StartRefinementSessionAsync(Microsoft.CodeAnalysis.Document! oldDocument, Microsoft.CodeAnalysis.Document! newDocument, Microsoft.CodeAnalysis.Diagnostic? primaryDiagnostic, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
5151
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotGenerateDocumentationService
52-
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotGenerateDocumentationService.GetDocumentationCommentAsync(Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper! proposal, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<(System.Collections.Generic.Dictionary<string!, string!>? responseDictionary, bool isQuotaExceeded)>!
52+
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotGenerateDocumentationService.GetDocumentationCommentAsync(Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper! proposal, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Immutable.ImmutableArray<(System.Collections.Generic.Dictionary<string!, string!>? responseDictionary, bool isQuotaExceeded)>>!
5353
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotGenerateImplementationService.ImplementNotImplementedExceptionsAsync(Microsoft.CodeAnalysis.Document! document, System.Collections.Immutable.ImmutableDictionary<Microsoft.CodeAnalysis.SyntaxNode!, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.FindSymbols.ReferencedSymbol!>>! methodOrProperties, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Immutable.ImmutableDictionary<Microsoft.CodeAnalysis.SyntaxNode!, Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.ImplementationDetailsWrapper!>!>!
5454
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpOnTheFlyDocsService
5555
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpOnTheFlyDocsService.GetOnTheFlyDocsPromptAsync(Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotOnTheFlyDocsInfoWrapper! onTheFlyDocsInfo, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<string!>!

0 commit comments

Comments
 (0)