Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b6b952a
wip
akhera99 Nov 26, 2024
5ed5ee7
wip
akhera99 Nov 27, 2024
f416e98
wip
akhera99 Nov 27, 2024
38fa91a
wip
akhera99 Nov 27, 2024
1f6a30f
wip
akhera99 Nov 29, 2024
6de1307
wip
akhera99 Nov 29, 2024
ed36e8f
wip
akhera99 Nov 29, 2024
9fd8f89
remove some commented out code
akhera99 Dec 3, 2024
36a8305
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 Jan 6, 2025
9c33d32
still cleaning up
akhera99 Jan 7, 2025
f2ec7f1
revert file
akhera99 Jan 7, 2025
0f8e4f3
clean up + option
akhera99 Jan 9, 2025
c096031
wip
akhera99 Jan 21, 2025
f46e751
dispose of disable of intellicode line completions
akhera99 Jan 27, 2025
0676f73
comments
akhera99 Jan 27, 2025
c028cc9
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 Jan 27, 2025
5ffb800
comments
akhera99 Jan 27, 2025
30c4aaf
add quota exceeded checks
akhera99 Jan 27, 2025
1f93a1f
fix tests
akhera99 Jan 28, 2025
8f64473
revert file
akhera99 Jan 28, 2025
2e2f6f0
remove unused optional params
akhera99 Jan 28, 2025
77a3f0c
last few fixes
akhera99 Jan 30, 2025
ae0ffe6
feedback
akhera99 Feb 4, 2025
ce330fe
fix tests
akhera99 Feb 4, 2025
ed65b3b
small fix
akhera99 Feb 4, 2025
73e3e8e
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 Feb 7, 2025
c756a4a
fix
akhera99 Feb 7, 2025
5fef68f
feedback
akhera99 Feb 7, 2025
dde66ab
feedback
akhera99 Feb 7, 2025
4e8f752
removed per comments
akhera99 Feb 11, 2025
b6688d6
remove unused usings
akhera99 Feb 11, 2025
5decd9b
feedback
akhera99 Feb 12, 2025
daff7a1
feedback
akhera99 Feb 12, 2025
4dc63b8
move stuff around with new EA structure in roslyn
akhera99 Feb 13, 2025
96bd8e2
wip
akhera99 Feb 13, 2025
906aed9
feedback
akhera99 Feb 13, 2025
61acead
feedbacl
akhera99 Feb 15, 2025
ae609fa
fix
akhera99 Feb 15, 2025
423a6df
feedback
akhera99 Feb 15, 2025
7683098
feedback
akhera99 Feb 18, 2025
ec34831
feedback
akhera99 Feb 18, 2025
b6b8e8c
revert
akhera99 Feb 18, 2025
dbff122
remove null check
akhera99 Feb 18, 2025
41be07f
clean up
akhera99 Feb 18, 2025
a63b731
fix
akhera99 Feb 19, 2025
faea3a8
fix tests
akhera99 Feb 19, 2025
4d8d15f
last fixes
akhera99 Feb 20, 2025
66bd0ef
telemetry + fixes
akhera99 Feb 20, 2025
d5d5437
last comments
akhera99 Feb 20, 2025
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 @@ -25,8 +25,10 @@ internal sealed class DocumentationCommentCommandHandler(
IUIThreadOperationExecutor uiThreadOperationExecutor,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
EditorOptionsService editorOptionsService)
: AbstractDocumentationCommentCommandHandler(uiThreadOperationExecutor, undoHistoryRegistry, editorOperationsFactoryService, editorOptionsService)
EditorOptionsService editorOptionsService,
CopilotGenerateDocumentationCommentManager generateDocumentationCommentManager)
: AbstractDocumentationCommentCommandHandler(uiThreadOperationExecutor, undoHistoryRegistry,
editorOperationsFactoryService, editorOptionsService, generateDocumentationCommentManager)
{
protected override string ExteriorTriviaText => "///";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.DocumentationComments;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
Expand All @@ -31,12 +32,14 @@ internal abstract class AbstractDocumentationCommentCommandHandler :
private readonly ITextUndoHistoryRegistry _undoHistoryRegistry;
private readonly IEditorOperationsFactoryService _editorOperationsFactoryService;
private readonly EditorOptionsService _editorOptionsService;
private readonly CopilotGenerateDocumentationCommentManager _generateDocumentationCommentManager;

protected AbstractDocumentationCommentCommandHandler(
IUIThreadOperationExecutor uiThreadOperationExecutor,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
EditorOptionsService editorOptionsService)
EditorOptionsService editorOptionsService,
CopilotGenerateDocumentationCommentManager generateDocumentationCommentManager)
{
Contract.ThrowIfNull(uiThreadOperationExecutor);
Contract.ThrowIfNull(undoHistoryRegistry);
Expand All @@ -46,6 +49,7 @@ protected AbstractDocumentationCommentCommandHandler(
_undoHistoryRegistry = undoHistoryRegistry;
_editorOperationsFactoryService = editorOperationsFactoryService;
_editorOptionsService = editorOptionsService;
_generateDocumentationCommentManager = generateDocumentationCommentManager;
}

protected abstract string ExteriorTriviaText { get; }
Expand Down Expand Up @@ -97,13 +101,17 @@ private bool CompleteComment(
if (snippet != null)
{
ApplySnippet(snippet, subjectBuffer, textView);
var oldSnapshot = subjectBuffer.CurrentSnapshot;
var oldCaret = textView.Caret.Position.VirtualBufferPosition;

returnValue = true;

_generateDocumentationCommentManager.TriggerDocumentationCommentProposalGeneration(document, snippet, oldSnapshot, oldCaret, textView, cancellationToken);
}
}

return returnValue;
}

public CommandState GetCommandState(TypeCharCommandArgs args, Func<CommandState> nextHandler)
=> nextHandler();

Expand Down
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;
}
}
}
Loading
Loading