Skip to content
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

Merge release/dev17.12 to main #75331

Merged
merged 3 commits into from
Oct 2, 2024
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 @@ -69,15 +69,17 @@ public OnTheFlyDocsView(ITextView textView, IViewElementFactoryService viewEleme
_document = onTheFlyDocsElement.Document;

var sparkle = new ImageElement(new VisualStudio.Core.Imaging.ImageId(CopilotConstants.CopilotIconMonikerGuid, CopilotConstants.CopilotIconSparkleId));
object onDemandLinkText = _onTheFlyDocsInfo.IsContentExcluded
? ToUIElement(new ContainerElement(ContainerElementStyle.Wrapped, new ClassifiedTextElement([new ClassifiedTextRun(ClassificationTypeNames.Text, EditorFeaturesResources.Describe_with_Copilot_is_unavailable_since_the_referenced_document_is_excluded_by_your_organization)])))
: ClassifiedTextElement.CreateHyperlink(EditorFeaturesResources.Describe_with_Copilot, EditorFeaturesResources.Generate_summary_with_Copilot, () => RequestResults());

OnDemandLinkContent = ToUIElement(
new ContainerElement(
ContainerElementStyle.Wrapped,
new object[]
{
sparkle,
ClassifiedTextElement.CreateHyperlink(EditorFeaturesResources.Describe_with_Copilot, EditorFeaturesResources.Generate_summary_with_Copilot, () =>
RequestResults()),
onDemandLinkText,
}));

LoadingContent = ToUIElement(
Expand Down Expand Up @@ -202,7 +204,6 @@ public void RequestResults()
CurrentState = OnTheFlyDocsState.Loading;
Logger.Log(FunctionId.Copilot_On_The_Fly_Docs_Loading_State_Entered, KeyValueLogMessage.Create(m =>
{
m["SymbolHeaderText"] = _onTheFlyDocsInfo.SymbolSignature;
m["HasDocumentationComments"] = _onTheFlyDocsInfo.HasComments;
}, LogLevel.Information));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public OnTheFlyDocsViewFactory(IViewElementFactoryService factoryService, IAsync

var onTheFlyDocsElement = (QuickInfoOnTheFlyDocsElement)model;

Logger.Log(FunctionId.Copilot_On_The_Fly_Docs_Showed_Link, KeyValueLogMessage.Create(m =>
{
m["SymbolHeaderText"] = onTheFlyDocsElement.Info.SymbolSignature;
}, LogLevel.Information));
Logger.Log(FunctionId.Copilot_On_The_Fly_Docs_Showed_Link, logLevel: LogLevel.Information);

var quickInfoSession = _asyncQuickInfoBroker.GetSession(textView);

Expand Down
3 changes: 3 additions & 0 deletions src/EditorFeatures/Core/EditorFeaturesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -953,4 +953,7 @@ Do you want to proceed?</value>
<data name="An_error_occurred_while_generating_documentation_for_this_code" xml:space="preserve">
<value>An error occurred while generating documentation for this code.</value>
</data>
<data name="Describe_with_Copilot_is_unavailable_since_the_referenced_document_is_excluded_by_your_organization" xml:space="preserve">
<value>'Describe with Copilot' is unavailable since the referenced document is excluded by your organization.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.Immutable;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -18,5 +19,5 @@ internal interface IExternalCSharpCopilotCodeAnalysisService
Task<ImmutableArray<Diagnostic>> GetCachedDiagnosticsAsync(Document document, string promptTitle, CancellationToken cancellationToken);
Task StartRefinementSessionAsync(Document oldDocument, Document newDocument, Diagnostic? primaryDiagnostic, CancellationToken cancellationToken);
Task<string> GetOnTheFlyDocsAsync(string symbolSignature, ImmutableArray<string> declarationCode, string language, CancellationToken cancellationToken);
Task<bool> IsAnyExclusionAsync(CancellationToken cancellationToken);
Task<bool> IsFileExcludedAsync(string filePath, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -39,7 +40,7 @@ internal abstract class AbstractCopilotCodeAnalysisService(IDiagnosticsRefresher
protected abstract Task<ImmutableArray<Diagnostic>> GetCachedDiagnosticsCoreAsync(Document document, string promptTitle, CancellationToken cancellationToken);
protected abstract Task StartRefinementSessionCoreAsync(Document oldDocument, Document newDocument, Diagnostic? primaryDiagnostic, CancellationToken cancellationToken);
protected abstract Task<string> GetOnTheFlyDocsCoreAsync(string symbolSignature, ImmutableArray<string> declarationCode, string language, CancellationToken cancellationToken);
protected abstract Task<bool> IsAnyExclusionCoreAsync(CancellationToken cancellationToken);
protected abstract Task<bool> IsFileExcludedCoreAsync(string filePath, CancellationToken cancellationToken);

public Task<bool> IsAvailableAsync(CancellationToken cancellationToken)
=> IsAvailableCoreAsync(cancellationToken);
Expand Down Expand Up @@ -180,11 +181,11 @@ public async Task<string> GetOnTheFlyDocsAsync(string symbolSignature, Immutable
return await GetOnTheFlyDocsCoreAsync(symbolSignature, declarationCode, language, cancellationToken).ConfigureAwait(false);
}

public async Task<bool> IsAnyExclusionAsync(CancellationToken cancellationToken)
public async Task<bool> IsFileExcludedAsync(string filePath, CancellationToken cancellationToken)
{
if (!await IsAvailableAsync(cancellationToken).ConfigureAwait(false))
return false;

return await IsAnyExclusionCoreAsync(cancellationToken).ConfigureAwait(false);
return await IsFileExcludedCoreAsync(filePath, cancellationToken).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.Internal.Analyzer.CSharp
using StartRefinementSessionAsyncDelegateType = Func<Document, Document, Diagnostic?, CancellationToken, Task>;
using GetOnTheFlyDocsAsyncDelegateType = Func<string, ImmutableArray<string>, string, CancellationToken, Task<string>>;
using IsAnyExclusionAsyncDelegateType = Func<CancellationToken, Task<bool>>;
using IsFileExcludedAsyncDelegateType = Func<string, CancellationToken, Task<bool>>;

internal sealed partial class CSharpCopilotCodeAnalysisService
{
Expand All @@ -36,7 +37,7 @@ private sealed class ReflectionWrapper : IExternalCSharpCopilotCodeAnalysisServi
private const string GetCachedDiagnosticsAsyncMethodName = "GetCachedDiagnosticsAsync";
private const string StartRefinementSessionAsyncMethodName = "StartRefinementSessionAsync";
private const string GetOnTheFlyDocsAsyncMethodName = "GetOnTheFlyDocsAsync";
private const string IsAnyExclusionAsyncMethodName = "IsAnyExclusionAsync";
private const string IsFileExcludedAsyncMethodName = "IsFileExcludedAsync";

// Create and cache closed delegate to ensure we use a singleton object and with better performance.
private readonly Type? _analyzerType;
Expand All @@ -47,7 +48,7 @@ private sealed class ReflectionWrapper : IExternalCSharpCopilotCodeAnalysisServi
private readonly Lazy<GetCachedDiagnosticsAsyncDelegateType?> _lazyGetCachedDiagnosticsAsyncDelegate;
private readonly Lazy<StartRefinementSessionAsyncDelegateType?> _lazyStartRefinementSessionAsyncDelegate;
private readonly Lazy<GetOnTheFlyDocsAsyncDelegateType?> _lazyGetOnTheFlyDocsAsyncDelegate;
private readonly Lazy<IsAnyExclusionAsyncDelegateType?> _lazyIsAnyExclusionAsyncDelegate;
private readonly Lazy<IsFileExcludedAsyncDelegateType?> _lazyIsFileExcludedAsyncDelegate;

public ReflectionWrapper(IServiceProvider serviceProvider, IVsService<SVsBrokeredServiceContainer, IBrokeredServiceContainer> brokeredServiceContainer)
{
Expand Down Expand Up @@ -76,7 +77,7 @@ public ReflectionWrapper(IServiceProvider serviceProvider, IVsService<SVsBrokere
_lazyGetCachedDiagnosticsAsyncDelegate = new(CreateGetCachedDiagnosticsAsyncDelegate, LazyThreadSafetyMode.PublicationOnly);
_lazyStartRefinementSessionAsyncDelegate = new(CreateStartRefinementSessionAsyncDelegate, LazyThreadSafetyMode.PublicationOnly);
_lazyGetOnTheFlyDocsAsyncDelegate = new(CreateGetOnTheFlyDocsAsyncDelegate, LazyThreadSafetyMode.PublicationOnly);
_lazyIsAnyExclusionAsyncDelegate = new(CreateIsAnyExclusionAsyncDelegate, LazyThreadSafetyMode.PublicationOnly);
_lazyIsFileExcludedAsyncDelegate = new(CreateIsFileExcludedAsyncDelegate, LazyThreadSafetyMode.PublicationOnly);
}

private T? CreateDelegate<T>(string methodName, Type[] types) where T : Delegate
Expand Down Expand Up @@ -115,8 +116,8 @@ public ReflectionWrapper(IServiceProvider serviceProvider, IVsService<SVsBrokere
private GetOnTheFlyDocsAsyncDelegateType? CreateGetOnTheFlyDocsAsyncDelegate()
=> CreateDelegate<GetOnTheFlyDocsAsyncDelegateType>(GetOnTheFlyDocsAsyncMethodName, [typeof(string), typeof(ImmutableArray<string>), typeof(string), typeof(CancellationToken)]);

private IsAnyExclusionAsyncDelegateType? CreateIsAnyExclusionAsyncDelegate()
=> CreateDelegate<IsAnyExclusionAsyncDelegateType>(IsAnyExclusionAsyncMethodName, [typeof(CancellationToken)]);
private IsFileExcludedAsyncDelegateType? CreateIsFileExcludedAsyncDelegate()
=> CreateDelegate<IsFileExcludedAsyncDelegateType>(IsFileExcludedAsyncMethodName, [typeof(string), typeof(CancellationToken)]);

public async Task<bool> IsAvailableAsync(CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -166,12 +167,12 @@ public async Task<string> GetOnTheFlyDocsAsync(string symbolSignature, Immutable
return await _lazyGetOnTheFlyDocsAsyncDelegate.Value(symbolSignature, declarationCode, language, cancellationToken).ConfigureAwait(false);
}

public async Task<bool> IsAnyExclusionAsync(CancellationToken cancellationToken)
public async Task<bool> IsFileExcludedAsync(string filePath, CancellationToken cancellationToken)
{
if (_lazyIsAnyExclusionAsyncDelegate.Value is null)
if (_lazyIsFileExcludedAsyncDelegate.Value is null)
return false;

return await _lazyIsAnyExclusionAsyncDelegate.Value(cancellationToken).ConfigureAwait(false);
return await _lazyIsFileExcludedAsyncDelegate.Value(filePath, cancellationToken).ConfigureAwait(false);
}
}
}
Loading
Loading