Skip to content

Commit 9e6dca8

Browse files
authored
Generate-Documentation Check if file is excluded (#77353)
* check for excluded files * remove unused usings * fix indentation
1 parent 410c349 commit 9e6dca8

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/EditorFeatures/Core/DocumentationComments/CopilotGenerateDocumentationCommentManager.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections.Generic;
76
using System.ComponentModel.Composition;
8-
using System.Linq;
9-
using System.Text;
107
using System.Threading;
118
using System.Threading.Tasks;
129
using Microsoft.CodeAnalysis.Copilot;
@@ -51,16 +48,16 @@ public void TriggerDocumentationCommentProposalGeneration(Document document,
5148

5249
private async Task GenerateDocumentationCommentProposalsAsync(Document document, DocumentationCommentSnippet snippet, ITextSnapshot snapshot, VirtualSnapshotPoint caret, ITextView textView, CancellationToken cancellationToken)
5350
{
54-
var generateDocumentationCommentProvider = await CreateProviderAsync(document, textView, cancellationToken).ConfigureAwait(false);
51+
var generateDocumentationCommentProvider = await CreateProviderAsync(document, textView, snippet.MemberNode, cancellationToken).ConfigureAwait(false);
5552
if (generateDocumentationCommentProvider is not null)
5653
{
5754
await generateDocumentationCommentProvider.GenerateDocumentationProposalAsync(snippet, snapshot, caret, cancellationToken).ConfigureAwait(false);
5855
}
5956
}
6057

61-
private async Task<CopilotGenerateDocumentationCommentProvider?> CreateProviderAsync(Document document, ITextView textView, CancellationToken cancellationToken)
58+
private async Task<CopilotGenerateDocumentationCommentProvider?> CreateProviderAsync(Document document, ITextView textView, SyntaxNode? memberNode, CancellationToken cancellationToken)
6259
{
63-
var copilotService = await IsGenerateDocumentationAvailableAsync(document, cancellationToken).ConfigureAwait(false);
60+
var copilotService = await IsGenerateDocumentationAvailableAsync(document, memberNode, cancellationToken).ConfigureAwait(false);
6461

6562
if (copilotService is null)
6663
{
@@ -75,7 +72,7 @@ private async Task GenerateDocumentationCommentProposalsAsync(Document document,
7572
return provider;
7673
}
7774

78-
private static async Task<ICopilotCodeAnalysisService?> IsGenerateDocumentationAvailableAsync(Document document, CancellationToken cancellationToken)
75+
private static async Task<ICopilotCodeAnalysisService?> IsGenerateDocumentationAvailableAsync(Document document, SyntaxNode? memberNode, CancellationToken cancellationToken)
7976
{
8077
// Bailing out if copilot is not available or the option is not enabled.
8178
if (document.GetLanguageService<ICopilotOptionsService>() is not { } copilotOptionService ||
@@ -90,6 +87,17 @@ await copilotService.IsAvailableAsync(cancellationToken).ConfigureAwait(false) i
9087
return null;
9188
}
9289

90+
if (memberNode is null)
91+
{
92+
return null;
93+
}
94+
95+
// Check to see if the file containing the member being documented has been excluded.
96+
if (await copilotService.IsFileExcludedAsync(memberNode.SyntaxTree.FilePath, cancellationToken).ConfigureAwait(false))
97+
{
98+
return null;
99+
}
100+
93101
return copilotService;
94102
}
95103
}

src/EditorFeatures/Core/DocumentationComments/CopilotGenerateDocumentationCommentProvider.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task InitializeAsync(ITextView textView, SuggestionServiceBase sugg
4343
}
4444

4545
public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet snippet,
46-
ITextSnapshot oldSnapshot, VirtualSnapshotPoint oldCaret, CancellationToken cancellationToken)
46+
ITextSnapshot oldSnapshot, VirtualSnapshotPoint oldCaret, CancellationToken cancellationToken)
4747
{
4848
await Task.Yield().ConfigureAwait(false);
4949

@@ -52,7 +52,8 @@ public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet
5252
return;
5353
}
5454

55-
var snippetProposal = GetSnippetProposal(snippet.SnippetText, snippet.MemberNode, snippet.Position, snippet.CaretOffset);
55+
// MemberNode is not null at this point, checked when determining if the file is exluded.
56+
var snippetProposal = GetSnippetProposal(snippet.SnippetText, snippet.MemberNode!, snippet.Position, snippet.CaretOffset);
5657

5758
if (snippetProposal is null)
5859
{
@@ -80,13 +81,8 @@ public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet
8081
/// <summary>
8182
/// Traverses the documentation comment shell and retrieves the pieces that are needed to generate the documentation comment.
8283
/// </summary>
83-
private static DocumentationCommentProposal? GetSnippetProposal(string comments, SyntaxNode? memberNode, int? position, int caret)
84+
private static DocumentationCommentProposal? GetSnippetProposal(string comments, SyntaxNode memberNode, int? position, int caret)
8485
{
85-
if (memberNode is null)
86-
{
87-
return null;
88-
}
89-
9086
if (position is null)
9187
{
9288
return null;

0 commit comments

Comments
 (0)