Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private async Task GenerateDocumentationCommentProposalsAsync(Document document,
var generateDocumentationCommentProvider = await CreateProviderAsync(document, textView, snippet.MemberNode, cancellationToken).ConfigureAwait(false);
if (generateDocumentationCommentProvider is not null)
{
await generateDocumentationCommentProvider.GenerateDocumentationProposalAsync(snippet, snapshot, caret, cancellationToken).ConfigureAwait(false);
await generateDocumentationCommentProvider.GenerateDocumentationProposalAsync(document, snippet, snapshot, caret, cancellationToken).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -46,7 +47,7 @@ public async Task InitializeAsync(ITextView textView, SuggestionServiceBase sugg
_suggestionManager ??= await suggestionServiceBase.TryRegisterProviderAsync(this, textView, "AmbientAIDocumentationComments", cancellationToken).ConfigureAwait(false);
}

public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet snippet,
public async Task GenerateDocumentationProposalAsync(Document document, DocumentationCommentSnippet snippet,
ITextSnapshot oldSnapshot, VirtualSnapshotPoint oldCaret, CancellationToken cancellationToken)
{
// Checks to see if the feature is enabled and if the suggestionManager is available
Expand All @@ -58,7 +59,7 @@ public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet
await TaskScheduler.Default;

// MemberNode is not null at this point, checked when determining if the file is excluded.
var snippetProposal = GetSnippetProposal(snippet.SnippetText, snippet.MemberNode!, snippet.Position, snippet.CaretOffset);
var snippetProposal = GetSnippetProposal(document, snippet.SnippetText, snippet.MemberNode!, snippet.Position, snippet.CaretOffset);

if (snippetProposal is null)
{
Expand All @@ -85,7 +86,7 @@ public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet
/// <summary>
/// Traverses the documentation comment shell and retrieves the pieces that are needed to generate the documentation comment.
/// </summary>
private static DocumentationCommentProposal? GetSnippetProposal(string comments, SyntaxNode memberNode, int? position, int caret)
private static DocumentationCommentProposal? GetSnippetProposal(Document document, string comments, SyntaxNode memberNode, int? position, int caret)
{
if (position is null)
{
Expand Down Expand Up @@ -175,7 +176,7 @@ public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet
index = exceptionEndTag + "</exception>".Length;
}

return new DocumentationCommentProposal(memberNode.ToFullString(), proposedEdits.ToImmutableArray());
return new DocumentationCommentProposal(document, memberNode, proposedEdits.ToImmutableArray());
}

/// <summary>
Expand All @@ -186,7 +187,9 @@ private static async Task<IReadOnlyList<ProposedEdit>> GetProposedEditsAsync(
ITextSnapshot oldSnapshot, string? indentText, CancellationToken cancellationToken)
{
var list = new List<ProposedEdit>();
var (documentationCommentDictionary, isQuotaExceeded) = await copilotService.GetDocumentationCommentAsync(proposal, cancellationToken).ConfigureAwait(false);
var documentationCommentResults = await copilotService.GetDocumentationCommentAsync([proposal], cancellationToken).ConfigureAwait(false);

var (documentationCommentDictionary, isQuotaExceeded) = documentationCommentResults.FirstOrDefault();

// Quietly fail if the quota has been exceeded.
if (isQuotaExceeded)
Expand Down
4 changes: 2 additions & 2 deletions src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
Return Task.FromResult(False)
End Function

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

Public Function GetOnTheFlyDocsPromptAsync(onTheFlyDocsInfo As OnTheFlyDocsInfo, cancellationToken As CancellationToken) As Task(Of String) Implements ICopilotCodeAnalysisService.GetOnTheFlyDocsPromptAsync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ public Task<bool> IsFileExcludedAsync(string filePath, CancellationToken cancell
public Task StartRefinementSessionAsync(Document oldDocument, Document newDocument, Diagnostic? primaryDiagnostic, CancellationToken cancellationToken)
=> throw new NotImplementedException();

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

public Task<ImmutableDictionary<SyntaxNode, ImplementationDetails>> ImplementNotImplementedExceptionsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ internal interface ICopilotCodeAnalysisService : ILanguageService
Task<bool> IsFileExcludedAsync(string filePath, CancellationToken cancellationToken);

/// <summary>
/// Method to retrieve the documentation comment for a given <paramref name="proposal"/>
/// Method to retrieve the documentation comment for given <paramref name="proposals"/>
/// </summary>
/// <param name="proposal">The documentation comment that has been broken down into its individual pieces.</param>
Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken);
/// <param name="proposals">The documentation comments that have been broken down into its individual pieces.</param>
Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentAsync(ImmutableArray<DocumentationCommentProposal> proposals, CancellationToken cancellationToken);

/// <summary>
/// Checks if the feature for implementing <see cref="System.NotImplementedException"/> is available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ namespace Microsoft.CodeAnalysis.DocumentationComments;
/// </summary>
internal sealed record DocumentationCommentProposal
{
public string SymbolToAnalyze { get; }
public Document Document { get; }

/// <summary>
/// Represents the node that is getting an auto-inserted documentation comment.
/// </summary>
public SyntaxNode MemberNode { get; }

public ImmutableArray<DocumentationCommentProposedEdit> ProposedEdits { get; }

public DocumentationCommentProposal(string symbolToAnalyze, ImmutableArray<DocumentationCommentProposedEdit> proposedEdits)
public DocumentationCommentProposal(Document document, SyntaxNode memberNode, ImmutableArray<DocumentationCommentProposedEdit> proposedEdits)
{
SymbolToAnalyze = symbolToAnalyze;
Document = document;
MemberNode = memberNode;
ProposedEdits = proposedEdits;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public CopilotDocumentationCommentProposalWrapper(DocumentationCommentProposal d

}

public string SymbolToAnalyze => _documentationCommentProposal.SymbolToAnalyze;
public Document Document => _documentationCommentProposal.Document;
public SyntaxNode MemberNode => _documentationCommentProposal.MemberNode;
public ImmutableArray<CopilotDocumentationCommentProposedEditWrapper> ProposedEdits => _wrappedProposedEdits;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot
{
internal interface IExternalCSharpCopilotGenerateDocumentationService
{
Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentAsync(CopilotDocumentationCommentProposalWrapper proposal, CancellationToken cancellationToken);
Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentAsync(ImmutableArray<CopilotDocumentationCommentProposalWrapper> proposals, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal abstract class AbstractCopilotCodeAnalysisService(IDiagnosticsRefresher
protected abstract Task<string> GetOnTheFlyDocsPromptCoreAsync(OnTheFlyDocsInfo onTheFlyDocsInfo, CancellationToken cancellationToken);
protected abstract Task<(string responseString, bool isQuotaExceeded)> GetOnTheFlyDocsResponseCoreAsync(string prompt, CancellationToken cancellationToken);
protected abstract Task<bool> IsFileExcludedCoreAsync(string filePath, CancellationToken cancellationToken);
protected abstract Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentCoreAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken);
protected abstract Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentCoreAsync(ImmutableArray<DocumentationCommentProposal> proposals, CancellationToken cancellationToken);
protected abstract Task<ImmutableDictionary<SyntaxNode, ImplementationDetails>> ImplementNotImplementedExceptionsCoreAsync(Document document, ImmutableDictionary<SyntaxNode, ImmutableArray<ReferencedSymbol>> methodOrProperties, CancellationToken cancellationToken);
protected abstract bool IsImplementNotImplementedExceptionsAvailableCore();

Expand Down Expand Up @@ -183,6 +183,7 @@ public async Task<string> GetOnTheFlyDocsPromptAsync(OnTheFlyDocsInfo onTheFlyDo
{
return await GetOnTheFlyDocsPromptCoreAsync(onTheFlyDocsInfo, cancellationToken).ConfigureAwait(false);
}

public async Task<(string responseString, bool isQuotaExceeded)> GetOnTheFlyDocsResponseAsync(string prompt, CancellationToken cancellationToken)
{
if (!await IsAvailableAsync(cancellationToken).ConfigureAwait(false))
Expand All @@ -199,12 +200,12 @@ public async Task<bool> IsFileExcludedAsync(string filePath, CancellationToken c
return await IsFileExcludedCoreAsync(filePath, cancellationToken).ConfigureAwait(false);
}

public async Task<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)> GetDocumentationCommentAsync(DocumentationCommentProposal proposal, CancellationToken cancellationToken)
public async Task<ImmutableArray<(Dictionary<string, string>? responseDictionary, bool isQuotaExceeded)>> GetDocumentationCommentAsync(ImmutableArray<DocumentationCommentProposal> proposals, CancellationToken cancellationToken)
{
if (!await IsAvailableAsync(cancellationToken).ConfigureAwait(false))
return (null, false);
return [(null, false)];

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

public async Task<bool> IsImplementNotImplementedExceptionsAvailableAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ protected override Task<bool> IsFileExcludedCoreAsync(string filePath, Cancellat
return Task.FromResult(false);
}

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

return Task.FromResult<(Dictionary<string, string>?, bool)>((null, false));
{
var wrappedProposals = proposals.SelectAsArray(p => new CopilotDocumentationCommentProposalWrapper(p));
return GenerateDocumentationService.GetDocumentationCommentAsync(wrappedProposals, cancellationToken);
}
return Task.FromResult(ImmutableArray.Create<(Dictionary<string, string>?, bool)>((null, false)));
}

protected override bool IsImplementNotImplementedExceptionsAvailableCore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotChecksumWrapper
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotChecksumWrapper.Equals(Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotChecksumWrapper? other) -> bool
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper.CopilotDocumentationCommentProposalWrapper(Microsoft.CodeAnalysis.DocumentationComments.DocumentationCommentProposal! documentationCommentProposal) -> void
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper.Document.get -> Microsoft.CodeAnalysis.Document!
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper.MemberNode.get -> Microsoft.CodeAnalysis.SyntaxNode!
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper.ProposedEdits.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposedEditWrapper!>
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper.SymbolToAnalyze.get -> string!
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposedEditWrapper
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposedEditWrapper.CopilotDocumentationCommentProposedEditWrapper(Microsoft.CodeAnalysis.DocumentationComments.DocumentationCommentProposedEdit! proposedEdit) -> void
Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposedEditWrapper.SpanToReplace.get -> Microsoft.CodeAnalysis.Text.TextSpan
Expand Down Expand Up @@ -48,7 +49,7 @@ Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotCodeAnalysis
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotCodeAnalysisService.IsFileExcludedAsync(string! filePath, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
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!
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotGenerateDocumentationService
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)>!
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotGenerateDocumentationService.GetDocumentationCommentAsync(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotDocumentationCommentProposalWrapper!> proposals, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Immutable.ImmutableArray<(System.Collections.Generic.Dictionary<string!, string!>? responseDictionary, bool isQuotaExceeded)>>!
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!>!>!
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpOnTheFlyDocsService
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpOnTheFlyDocsService.GetOnTheFlyDocsPromptAsync(Microsoft.CodeAnalysis.ExternalAccess.Copilot.CopilotOnTheFlyDocsInfoWrapper! onTheFlyDocsInfo, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<string!>!
Expand Down
Loading