Skip to content

Commit

Permalink
Make classification, inline hints, quick info and symbol description …
Browse files Browse the repository at this point in the history
…options global
  • Loading branch information
tmat committed Feb 9, 2022
1 parent c602951 commit 1e30d36
Show file tree
Hide file tree
Showing 86 changed files with 837 additions and 874 deletions.
8 changes: 4 additions & 4 deletions src/EditorFeatures/CSharp/GoToBase/CSharpGoToBaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Composition;
using Microsoft.CodeAnalysis.Editor.GoToBase;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Editor.CSharp.GoToBase
{
[ExportLanguageService(typeof(IGoToBaseService), LanguageNames.CSharp), Shared]
internal class CSharpGoToBaseService : AbstractGoToBaseService
internal sealed class CSharpGoToBaseService : AbstractGoToBaseService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpGoToBaseService()
public CSharpGoToBaseService(IGlobalOptionService options)
: base(options)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition
{
Expand All @@ -18,8 +19,9 @@ internal class CSharpGoToDefinitionService : AbstractGoToDefinitionService
[SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
public CSharpGoToDefinitionService(
IThreadingContext threadingContext,
IStreamingFindUsagesPresenter streamingPresenter)
: base(threadingContext, streamingPresenter)
IStreamingFindUsagesPresenter streamingPresenter,
IGlobalOptionService globalOptions)
: base(threadingContext, streamingPresenter, globalOptions)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
using Microsoft.CodeAnalysis.Editor.GoToDefinition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition
{
[ExportLanguageService(typeof(IGoToSymbolService), LanguageNames.CSharp), Shared]
internal class CSharpGoToSymbolService : AbstractGoToSymbolService
internal sealed class CSharpGoToSymbolService : AbstractGoToSymbolService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpGoToSymbolService(IThreadingContext threadingContext)
: base(threadingContext)
public CSharpGoToSymbolService(IThreadingContext threadingContext, IGlobalOptionService globalOptions)
: base(threadingContext, globalOptions)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public async Task TestGetTagsOnBufferTagger()
using var workspace = TestWorkspace.CreateCSharp("class C { C c; }");
var document = workspace.Documents.First();

var listenerProvider = workspace.ExportProvider.GetExportedValue<IAsynchronousOperationListenerProvider>();
var listenerProvider = workspace.GetService<IAsynchronousOperationListenerProvider>();

var provider = new CopyPasteAndPrintingClassificationBufferTaggerProvider(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
workspace.ExportProvider.GetExportedValue<ClassificationTypeMap>(),
listenerProvider);
workspace.GetService<IThreadingContext>(),
workspace.GetService<ClassificationTypeMap>(),
listenerProvider,
workspace.GlobalOptions);

var tagger = provider.CreateTagger<IClassificationTag>(document.GetTextBuffer())!;
using var disposable = (IDisposable)tagger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ private static async Task<QuickInfoItem> GetQuickinfo(TestWorkspace workspace, D
{
var diagnosticAnalyzerService = workspace.ExportProvider.GetExportedValue<IDiagnosticAnalyzerService>();
var provider = new CSharpDiagnosticAnalyzerQuickInfoProvider(diagnosticAnalyzerService);
var options = SymbolDescriptionOptions.From(document.Project);
var info = await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, options, CancellationToken.None));
var info = await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, SymbolDescriptionOptions.Default, CancellationToken.None));
return info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.QuickInfo;
using Microsoft.CodeAnalysis.Editor.Host;
Expand Down Expand Up @@ -568,8 +569,7 @@ protected override async Task AssertNoContentAsync(
int position)
{
var provider = CreateProvider();
var options = SymbolDescriptionOptions.From(document.Project);
Assert.Null(await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, options, CancellationToken.None)));
Assert.Null(await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, SymbolDescriptionOptions.Default, CancellationToken.None)));
}

protected override async Task AssertContentIsAsync(
Expand All @@ -580,8 +580,7 @@ protected override async Task AssertContentIsAsync(
string expectedDocumentationComment = null)
{
var provider = CreateProvider();
var options = SymbolDescriptionOptions.From(document.Project);
var info = await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, options, CancellationToken.None));
var info = await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, SymbolDescriptionOptions.Default, CancellationToken.None));
Assert.NotNull(info);
Assert.NotEqual(0, info.RelatedSpans.Length);

Expand All @@ -591,7 +590,7 @@ protected override async Task AssertContentIsAsync(
var streamingPresenter = workspace.ExportProvider.GetExport<IStreamingFindUsagesPresenter>();
var quickInfoItem = await IntellisenseQuickInfoBuilder.BuildItemAsync(
trackingSpan.Object, info, document,
threadingContext, operationExecutor,
ClassificationOptions.Default, threadingContext, operationExecutor,
AsynchronousOperationListenerProvider.NullListener,
streamingPresenter, CancellationToken.None);
var containerElement = quickInfoItem.Item as ContainerElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Commanding;
Expand All @@ -28,19 +29,22 @@ internal sealed class FindBaseSymbolsCommandHandler :
AbstractNavigationCommandHandler<FindBaseSymbolsCommandArgs>
{
private readonly IAsynchronousOperationListener _asyncListener;
private readonly IGlobalOptionService _globalOptions;

public override string DisplayName => nameof(FindBaseSymbolsCommandHandler);

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FindBaseSymbolsCommandHandler(
[ImportMany] IEnumerable<Lazy<IStreamingFindUsagesPresenter>> streamingPresenters,
IAsynchronousOperationListenerProvider listenerProvider)
IAsynchronousOperationListenerProvider listenerProvider,
IGlobalOptionService globalOptions)
: base(streamingPresenters)
{
Contract.ThrowIfNull(listenerProvider);

_asyncListener = listenerProvider.GetListener(FeatureAttribute.FindReferences);
_globalOptions = globalOptions;
}

protected override bool TryExecuteCommand(int caretPosition, Document document, CommandExecutionContext context)
Expand Down Expand Up @@ -83,7 +87,7 @@ private async Task StreamingFindBaseSymbolsAsync(
return;
}

var definitionItem = overriddenSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true);
var definitionItem = overriddenSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, includeHiddenLocations: true);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false);

// try getting the next one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading;
Expand All @@ -12,14 +11,15 @@
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation;
using Microsoft.VisualStudio.Utilities;
using Roslyn.Utilities;
using VSCommanding = Microsoft.VisualStudio.Commanding;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigationCommandHandlers
{
Expand All @@ -30,19 +30,22 @@ internal sealed class FindDerivedSymbolsCommandHandler :
AbstractNavigationCommandHandler<FindDerivedSymbolsCommandArgs>
{
private readonly IAsynchronousOperationListener _asyncListener;
private readonly IGlobalOptionService _globalOptions;

public override string DisplayName => nameof(FindDerivedSymbolsCommandHandler);

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FindDerivedSymbolsCommandHandler(
[ImportMany] IEnumerable<Lazy<IStreamingFindUsagesPresenter>> streamingPresenters,
IAsynchronousOperationListenerProvider listenerProvider)
IAsynchronousOperationListenerProvider listenerProvider,
IGlobalOptionService globalOptions)
: base(streamingPresenters)
{
Contract.ThrowIfNull(listenerProvider);

_asyncListener = listenerProvider.GetListener(FeatureAttribute.FindReferences);
_globalOptions = globalOptions;
}

protected override bool TryExecuteCommand(int caretPosition, Document document, CommandExecutionContext context)
Expand Down Expand Up @@ -105,7 +108,7 @@ private async Task FindDerivedSymbolsAsync(

foreach (var candidate in candidates)
{
var definitionItem = candidate.ToNonClassifiedDefinitionItem(document.Project.Solution, true);
var definitionItem = candidate.ToNonClassifiedDefinitionItem(document.Project.Solution, includeHiddenLocations: true);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Commanding;
Expand All @@ -32,19 +33,22 @@ internal sealed class FindExtensionMethodsCommandHandler :
AbstractNavigationCommandHandler<FindExtensionMethodsCommandArgs>
{
private readonly IAsynchronousOperationListener _asyncListener;
private readonly IGlobalOptionService _globalOptions;

public override string DisplayName => nameof(FindExtensionMethodsCommandHandler);

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FindExtensionMethodsCommandHandler(
[ImportMany] IEnumerable<Lazy<IStreamingFindUsagesPresenter>> streamingPresenters,
IAsynchronousOperationListenerProvider listenerProvider)
IAsynchronousOperationListenerProvider listenerProvider,
IGlobalOptionService globalOptions)
: base(streamingPresenters)
{
Contract.ThrowIfNull(listenerProvider);

_asyncListener = listenerProvider.GetListener(FeatureAttribute.FindReferences);
_globalOptions = globalOptions;
}

protected override bool TryExecuteCommand(int caretPosition, Document document, CommandExecutionContext context)
Expand Down Expand Up @@ -109,7 +113,7 @@ private async Task FindExtensionMethodsAsync(
{
var originatingProject = solution.GetProject(sourceDefinition.ContainingAssembly, cancellationToken);

var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true);
var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true);

await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation;
Expand All @@ -31,19 +32,22 @@ internal sealed class FindImplementingMembersCommandHandler :
AbstractNavigationCommandHandler<FindImplementingMembersCommandArgs>
{
private readonly IAsynchronousOperationListener _asyncListener;
private readonly IGlobalOptionService _globalOptions;

public override string DisplayName => nameof(FindImplementingMembersCommandHandler);

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FindImplementingMembersCommandHandler(
[ImportMany] IEnumerable<Lazy<IStreamingFindUsagesPresenter>> streamingPresenters,
IAsynchronousOperationListenerProvider listenerProvider)
IAsynchronousOperationListenerProvider listenerProvider,
IGlobalOptionService globalOptions)
: base(streamingPresenters)
{
Contract.ThrowIfNull(listenerProvider);

_asyncListener = listenerProvider.GetListener(FeatureAttribute.FindReferences);
_globalOptions = globalOptions;
}

protected override bool TryExecuteCommand(int caretPosition, Document document, CommandExecutionContext context)
Expand Down Expand Up @@ -131,7 +135,7 @@ private async Task FindImplementingMembersAsync(
}
}

private static async Task InspectInterfaceAsync(
private async Task InspectInterfaceAsync(
IFindUsagesContext context, INamedTypeSymbol interfaceSymbol, INamedTypeSymbol namedTypeSymbol, Project project, CancellationToken cancellationToken)
{
foreach (var interfaceMember in interfaceSymbol.GetMembers())
Expand All @@ -143,7 +147,7 @@ private static async Task InspectInterfaceAsync(
if (impl == null)
continue;

var definitionItem = impl.ToNonClassifiedDefinitionItem(project.Solution, true);
var definitionItem = impl.ToNonClassifiedDefinitionItem(project.Solution, includeHiddenLocations: true);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using VSCommanding = Microsoft.VisualStudio.Commanding;
using Microsoft.CodeAnalysis.Host.Mef;
using System.Threading;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigationCommandHandlers
{
Expand All @@ -29,19 +30,22 @@ internal sealed class FindMemberOverloadsCommandHandler :
AbstractNavigationCommandHandler<FindMemberOverloadsCommandArgs>
{
private readonly IAsynchronousOperationListener _asyncListener;
private readonly IGlobalOptionService _globalOptions;

public override string DisplayName => nameof(FindMemberOverloadsCommandHandler);

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FindMemberOverloadsCommandHandler(
[ImportMany] IEnumerable<Lazy<IStreamingFindUsagesPresenter>> streamingPresenters,
IAsynchronousOperationListenerProvider listenerProvider)
IAsynchronousOperationListenerProvider listenerProvider,
IGlobalOptionService globalOptions)
: base(streamingPresenters)
{
Contract.ThrowIfNull(listenerProvider);

_asyncListener = listenerProvider.GetListener(FeatureAttribute.FindReferences);
_globalOptions = globalOptions;
}

protected override bool TryExecuteCommand(int caretPosition, Document document, CommandExecutionContext context)
Expand Down
7 changes: 3 additions & 4 deletions src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Elfie.Diagnostics;
using Microsoft.CodeAnalysis.InlineHints;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Adornments;
using Microsoft.VisualStudio.Text.Classification;
Expand All @@ -35,7 +33,7 @@ namespace Microsoft.CodeAnalysis.Editor.InlineHints
/// This is the tag which implements the IntraTextAdornmentTag and is meant to create the UIElements that get shown
/// in the editor
/// </summary>
internal class InlineHintsTag : IntraTextAdornmentTag
internal sealed class InlineHintsTag : IntraTextAdornmentTag
{
public const string TagId = "inline hints";

Expand Down Expand Up @@ -101,6 +99,7 @@ public async Task<IReadOnlyCollection<object>> CreateDescriptionAsync(Cancellati
{
var context = new IntellisenseQuickInfoBuilderContext(
document,
_taggerProvider.GlobalOptions.GetClassificationOptions(document.Project.Language),
_taggerProvider.ThreadingContext,
_taggerProvider.OperationExecutor,
_taggerProvider.AsynchronousOperationListener,
Expand Down
Loading

0 comments on commit 1e30d36

Please sign in to comment.