Skip to content

Commit

Permalink
Revert "Updates content exclusion for on-the-fly-docs (#75172)" (#75279
Browse files Browse the repository at this point in the history
…) (#75284)

This reverts commit 2f6b493.

Co-authored-by: Fred Silberberg <frsilb@microsoft.com>
  • Loading branch information
akhera99 and 333fred authored Sep 27, 2024
1 parent 23f900a commit ba2f19a
Show file tree
Hide file tree
Showing 26 changed files with 35 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,15 @@ public OnTheFlyDocsView(ITextView textView, IViewElementFactoryService viewEleme
_document = editorFeaturesOnTheFlyDocsElement.Document;

var sparkle = new ImageElement(new VisualStudio.Core.Imaging.ImageId(CopilotConstants.CopilotIconMonikerGuid, CopilotConstants.CopilotIconSparkleId));
object onDemandLinkText = _onTheFlyDocsElement.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,
onDemandLinkText,
ClassifiedTextElement.CreateHyperlink(EditorFeaturesResources.Describe_with_Copilot, EditorFeaturesResources.Generate_summary_with_Copilot, () =>
RequestResults()),
}));

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

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

var editorFeaturesOnTheFlyDocsElement = (EditorFeaturesOnTheFlyDocsElement)model;

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

var quickInfoSession = _asyncQuickInfoBroker.GetSession(textView);

Expand Down
3 changes: 0 additions & 3 deletions src/EditorFeatures/Core/EditorFeaturesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,4 @@ 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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.

5 changes: 0 additions & 5 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.pt-BR.xlf

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

5 changes: 0 additions & 5 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: 0 additions & 5 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,7 +2,6 @@
// 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 @@ -19,5 +18,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> IsFileExcludedAsync(string filePath, CancellationToken cancellationToken);
Task<bool> IsAnyExclusionAsync(CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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 @@ -40,7 +39,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> IsFileExcludedCoreAsync(string filePath, CancellationToken cancellationToken);
protected abstract Task<bool> IsAnyExclusionCoreAsync(CancellationToken cancellationToken);

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

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

return await IsFileExcludedCoreAsync(filePath, cancellationToken).ConfigureAwait(false);
return await IsAnyExclusionCoreAsync(cancellationToken).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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 @@ -37,7 +36,7 @@ private sealed class ReflectionWrapper : IExternalCSharpCopilotCodeAnalysisServi
private const string GetCachedDiagnosticsAsyncMethodName = "GetCachedDiagnosticsAsync";
private const string StartRefinementSessionAsyncMethodName = "StartRefinementSessionAsync";
private const string GetOnTheFlyDocsAsyncMethodName = "GetOnTheFlyDocsAsync";
private const string IsFileExcludedAsyncMethodName = "IsFileExcludedAsync";
private const string IsAnyExclusionAsyncMethodName = "IsAnyExclusionAsync";

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

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

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

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

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

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

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

0 comments on commit ba2f19a

Please sign in to comment.