-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Generate Documentation Auto-Insert #76665
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
Merged
akhera99
merged 49 commits into
dotnet:main
from
akhera99:dev/ankitakhera/aai_doc_comments
Feb 21, 2025
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
b6b952a
wip
akhera99 5ed5ee7
wip
akhera99 f416e98
wip
akhera99 38fa91a
wip
akhera99 1f6a30f
wip
akhera99 6de1307
wip
akhera99 ed36e8f
wip
akhera99 9fd8f89
remove some commented out code
akhera99 36a8305
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 9c33d32
still cleaning up
akhera99 f2ec7f1
revert file
akhera99 0f8e4f3
clean up + option
akhera99 c096031
wip
akhera99 f46e751
dispose of disable of intellicode line completions
akhera99 0676f73
comments
akhera99 c028cc9
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 5ffb800
comments
akhera99 30c4aaf
add quota exceeded checks
akhera99 1f93a1f
fix tests
akhera99 8f64473
revert file
akhera99 2e2f6f0
remove unused optional params
akhera99 77a3f0c
last few fixes
akhera99 ae0ffe6
feedback
akhera99 ce330fe
fix tests
akhera99 ed65b3b
small fix
akhera99 73e3e8e
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 c756a4a
fix
akhera99 5fef68f
feedback
akhera99 dde66ab
feedback
akhera99 4e8f752
removed per comments
akhera99 b6688d6
remove unused usings
akhera99 5decd9b
feedback
akhera99 daff7a1
feedback
akhera99 4dc63b8
move stuff around with new EA structure in roslyn
akhera99 96bd8e2
wip
akhera99 906aed9
feedback
akhera99 61acead
feedbacl
akhera99 ae609fa
fix
akhera99 423a6df
feedback
akhera99 7683098
feedback
akhera99 ec34831
feedback
akhera99 b6b8e8c
revert
akhera99 dbff122
remove null check
akhera99 41be07f
clean up
akhera99 a63b731
fix
akhera99 faea3a8
fix tests
akhera99 4d8d15f
last fixes
akhera99 66bd0ef
telemetry + fixes
akhera99 d5d5437
last comments
akhera99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/EditorFeatures/Core/DocumentationComments/CopilotGenerateDocumentationCommentManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Copilot; | ||
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Microsoft.CodeAnalysis.Shared.TestHooks; | ||
using Microsoft.VisualStudio.Language.Suggestions; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
|
||
namespace Microsoft.CodeAnalysis.DocumentationComments | ||
{ | ||
[Export(typeof(CopilotGenerateDocumentationCommentManager))] | ||
internal class CopilotGenerateDocumentationCommentManager | ||
{ | ||
private readonly SuggestionServiceBase? _suggestionServiceBase; | ||
private readonly IThreadingContext _threadingContext; | ||
private readonly IAsynchronousOperationListener _asyncListener; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public CopilotGenerateDocumentationCommentManager([Import(AllowDefault = true)] SuggestionServiceBase? suggestionServiceBase, IThreadingContext threadingContext, | ||
IAsynchronousOperationListenerProvider listenerProvider) | ||
{ | ||
_suggestionServiceBase = suggestionServiceBase; | ||
_threadingContext = threadingContext; | ||
_asyncListener = listenerProvider.GetListener(FeatureAttribute.GenerateDocumentation); | ||
} | ||
|
||
public void TriggerDocumentationCommentProposalGeneration(Document document, | ||
DocumentationCommentSnippet snippet, ITextSnapshot snapshot, VirtualSnapshotPoint caret, ITextView textView, CancellationToken cancellationToken) | ||
{ | ||
if (_suggestionServiceBase is null) | ||
{ | ||
return; | ||
} | ||
|
||
var token = _asyncListener.BeginAsyncOperation(nameof(GenerateDocumentationCommentProposalsAsync)); | ||
_ = GenerateDocumentationCommentProposalsAsync(document, snippet, snapshot, caret, textView, cancellationToken).CompletesAsyncOperation(token); | ||
} | ||
|
||
private async Task GenerateDocumentationCommentProposalsAsync(Document document, DocumentationCommentSnippet snippet, ITextSnapshot snapshot, VirtualSnapshotPoint caret, ITextView textView, CancellationToken cancellationToken) | ||
{ | ||
var generateDocumentationCommentProvider = await CreateProviderAsync(document, textView, cancellationToken).ConfigureAwait(false); | ||
if (generateDocumentationCommentProvider is not null) | ||
{ | ||
await generateDocumentationCommentProvider.GenerateDocumentationProposalAsync(snippet, snapshot, caret, cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
private async Task<CopilotGenerateDocumentationCommentProvider?> CreateProviderAsync(Document document, ITextView textView, CancellationToken cancellationToken) | ||
{ | ||
var copilotService = await IsGenerateDocumentationAvailableAsync(document, cancellationToken).ConfigureAwait(false); | ||
|
||
if (copilotService is null) | ||
{ | ||
return null; | ||
} | ||
|
||
var provider = textView.Properties.GetOrCreateSingletonProperty(typeof(CopilotGenerateDocumentationCommentProvider), | ||
() => new CopilotGenerateDocumentationCommentProvider(_threadingContext, copilotService)); | ||
|
||
await provider!.InitializeAsync(textView, _suggestionServiceBase!, cancellationToken).ConfigureAwait(false); | ||
|
||
return provider; | ||
} | ||
|
||
private static async Task<ICopilotCodeAnalysisService?> IsGenerateDocumentationAvailableAsync(Document document, CancellationToken cancellationToken) | ||
{ | ||
// Bailing out if copilot is not available or the option is not enabled. | ||
if (document.GetLanguageService<ICopilotOptionsService>() is not { } copilotOptionService || | ||
!await copilotOptionService.IsGenerateDocumentationCommentOptionEnabledAsync().ConfigureAwait(false)) | ||
{ | ||
return null; | ||
} | ||
|
||
if (document.GetLanguageService<ICopilotCodeAnalysisService>() is not { } copilotService || | ||
await copilotService.IsAvailableAsync(cancellationToken).ConfigureAwait(false) is false) | ||
{ | ||
return null; | ||
} | ||
|
||
return copilotService; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.