From 844d232a724a186b338456774990402514817387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Matou=C5=A1ek?= Date: Tue, 15 Feb 2022 13:31:09 -0800 Subject: [PATCH] Revert "Revert "Make solution options global (#59168)" (#59537)" This reverts commit 4de93eaaa560aaec7e86eb1623b9d7acb4da2d68. --- .../CSharp/GoToBase/CSharpGoToBaseService.cs | 6 +- .../CSharpGoToDefinitionService.cs | 1 + .../GoToDefinition/CSharpGoToSymbolService.cs | 3 +- .../CopyPasteAndPrintingClassifierTests.cs | 9 +- .../DiagnosticAnalyzerQuickInfoSourceTests.cs | 3 +- .../SyntacticQuickInfoSourceTests.cs | 9 +- .../FindBaseSymbolsCommandHandler.cs | 8 +- .../FindDerivedSymbolsCommandHandler.cs | 8 +- .../FindExtensionMethodsCommandHandler.cs | 8 +- .../FindImplementingMembersCommandHandler.cs | 8 +- .../FindMemberOverloadsCommandHandler.cs | 7 +- .../Core.Wpf/InlineHints/InlineHintsTag.cs | 7 +- .../FindUsages/FindUsagesOptionsStorage.cs | 6 +- .../AbstractGoToDefinitionService.cs | 1 + .../AbstractGoToSymbolService.cs | 1 + .../GoToDefinition/GoToDefinitionHelpers.cs | 1 + ...assificationBufferTaggerProvider.Tagger.cs | 27 +-- ...ntingClassificationBufferTaggerProvider.cs | 8 +- .../SemanticClassificationUtilities.cs | 3 +- ...emanticClassificationViewTaggerProvider.cs | 5 +- .../Formatting/FormattingOptionsMetadata.cs | 17 +- .../AsyncCompletion/CompletionSource.cs | 11 +- .../QuickInfo/IntellisenseQuickInfoBuilder.cs | 15 +- .../IntellisenseQuickInfoBuilderContext.cs | 4 + ...QuickInfoSourceProvider.QuickInfoSource.cs | 15 +- .../QuickInfo/QuickInfoSourceProvider.cs | 8 +- .../Completion/CompletionResolveHandler.cs | 6 +- .../Handlers/Hover/HoverHandler.cs | 21 +- .../References/FindUsagesLSPContext.cs | 221 +++++++++--------- .../InlineHintsDataTaggerProvider.cs | 26 +-- .../InlineHints/InlineHintsOptionsStorage.cs | 114 +++++++++ .../Core/QuickInfo/QuickInfoOptionsStorage.cs | 26 +++ .../SymbolDescriptionOptionsStorage.cs | 18 ++ .../GoToDefinition/GoToDefinitionTestsBase.vb | 25 +- ...stractIntellisenseQuickInfoBuilderTests.vb | 5 +- .../SymbolDescriptionServiceTests.vb | 2 +- .../Classification/AbstractClassifierTests.cs | 2 +- .../AbstractCompletionProviderTests.cs | 8 +- .../TestUtilities2/Intellisense/TestState.vb | 3 +- .../GoToBase/VisualBasicGoToBaseService.vb | 2 + .../VisualBasicGoToDefinitionService.vb | 1 + .../VisualBasicGoToSymbolService.vb | 3 +- .../ClassificationOptionsStorage.cs | 30 +++ ...stractFindUsagesService.ProgressAdapter.cs | 9 +- ...ctFindUsagesService_FindImplementations.cs | 2 +- .../IDefinitionsAndReferencesFactory.cs | 169 +++++++------- .../GoToBase/AbstractGoToBaseService.cs | 13 +- .../InheritanceMarginServiceHelpers.cs | 16 +- .../InlineHints/InlineHintsOptions.cs | 19 +- .../InlineParameterHintsOptions.cs | 109 ++------- .../InlineHints/InlineTypeHintsOptions.cs | 69 +----- .../SymbolDescriptionOptions.cs | 9 - .../Portable/QuickInfo/QuickInfoOptions.cs | 49 +--- .../StackTraceExplorerService.cs | 1 + .../StackTraceExplorerUtilities.cs | 13 +- .../SemanticTokens/SemanticTokensHelpers.cs | 3 +- .../SemanticTokensRangeHandler.cs | 12 +- .../SemanticTokensRangeTests.cs | 16 +- .../Lsif/Generator/CompilerInvocation.cs | 12 +- src/Features/Lsif/Generator/Generator.cs | 26 ++- .../Lsif/Generator/GeneratorOptions.cs | 18 ++ ...LanguageServerIndexFormat.Generator.csproj | 4 + src/Features/Lsif/Generator/Program.cs | 4 +- .../GeneratorTest/Utilities/TestLsifOutput.vb | 2 +- .../OmniSharpInlineHintsService.cs | 50 ---- .../Razor/IRazorDocumentExcerptService.cs | 6 - .../RazorDocumentExcerptServiceWrapper.cs | 28 +-- .../RazorDocumentServiceProviderWrapper.cs | 14 +- .../RegexClassifierBenchmarks.cs | 3 +- .../ClassificationBenchmarks.cs | 3 +- .../Options/AdvancedOptionPageControl.xaml.cs | 44 ++-- .../RemoteCodeLensReferencesService.cs | 14 +- ...bstractTableDataSourceFindUsagesContext.cs | 4 +- .../Entries/DocumentSpanEntry.cs | 3 +- ...ntainedDocument.DocumentServiceProvider.cs | 7 +- .../Implementation/Venus/ContainedLanguage.cs | 31 +-- .../Venus/ContainedLanguage`2.cs | 71 ------ .../SyntaxTreeConfigurationOptions.cs | 39 ---- ...ualStudioSyntaxTreeConfigurationService.cs | 19 +- .../ValueTrackedTreeItemViewModel.cs | 10 +- .../ValueTrackingCommandHandler.cs | 10 +- .../Core/Test/Venus/DocumentServiceTests.vb | 9 +- .../Venus/DocumentService_IntegrationTests.vb | 4 +- .../Options/AdvancedOptionPageControl.xaml.vb | 30 +-- .../Extensions/SymbolExtensions.cs | 3 +- .../Completion/CompletionResolveHandler.cs | 10 +- .../Handler/Hover/HoverHandler.cs | 12 +- .../Classification/ClassificationOptions.cs | 55 +---- .../Portable/Classification/Classifier.cs | 10 +- .../IDocumentExcerptService.cs | 6 +- 90 files changed, 804 insertions(+), 978 deletions(-) create mode 100644 src/EditorFeatures/Core/InlineHints/InlineHintsOptionsStorage.cs create mode 100644 src/EditorFeatures/Core/QuickInfo/QuickInfoOptionsStorage.cs create mode 100644 src/EditorFeatures/Core/SymbolDisplay/SymbolDescriptionOptionsStorage.cs create mode 100644 src/Features/Core/Portable/Completion/ClassificationOptionsStorage.cs create mode 100644 src/Features/Lsif/Generator/GeneratorOptions.cs delete mode 100644 src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs delete mode 100644 src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage`2.cs delete mode 100644 src/VisualStudio/Core/Def/Telemetry/SyntaxTreeConfigurationOptions.cs diff --git a/src/EditorFeatures/CSharp/GoToBase/CSharpGoToBaseService.cs b/src/EditorFeatures/CSharp/GoToBase/CSharpGoToBaseService.cs index 2a27d699a995b..bb742d54361d7 100644 --- a/src/EditorFeatures/CSharp/GoToBase/CSharpGoToBaseService.cs +++ b/src/EditorFeatures/CSharp/GoToBase/CSharpGoToBaseService.cs @@ -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.GoToBase; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.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() + : base() { } } diff --git a/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToDefinitionService.cs b/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToDefinitionService.cs index 80294aad2ccbd..ea9f2776eaf37 100644 --- a/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToDefinitionService.cs +++ b/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToDefinitionService.cs @@ -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 { diff --git a/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToSymbolService.cs b/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToSymbolService.cs index cb7c9793e0b98..d8dacdc07cb5b 100644 --- a/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToSymbolService.cs +++ b/src/EditorFeatures/CSharp/GoToDefinition/CSharpGoToSymbolService.cs @@ -7,11 +7,12 @@ 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)] diff --git a/src/EditorFeatures/CSharpTest/Classification/CopyPasteAndPrintingClassifierTests.cs b/src/EditorFeatures/CSharpTest/Classification/CopyPasteAndPrintingClassifierTests.cs index 62457ed87a60a..739373c2994e8 100644 --- a/src/EditorFeatures/CSharpTest/Classification/CopyPasteAndPrintingClassifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/CopyPasteAndPrintingClassifierTests.cs @@ -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(); + var listenerProvider = workspace.GetService(); var provider = new CopyPasteAndPrintingClassificationBufferTaggerProvider( - workspace.ExportProvider.GetExportedValue(), - workspace.ExportProvider.GetExportedValue(), - listenerProvider); + workspace.GetService(), + workspace.GetService(), + listenerProvider, + workspace.GlobalOptions); var tagger = provider.CreateTagger(document.GetTextBuffer())!; using var disposable = (IDisposable)tagger; diff --git a/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs b/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs index 2ab0a601f225d..59ee0d46f5c76 100644 --- a/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/QuickInfo/DiagnosticAnalyzerQuickInfoSourceTests.cs @@ -193,8 +193,7 @@ private static async Task GetQuickinfo(TestWorkspace workspace, D { var diagnosticAnalyzerService = workspace.ExportProvider.GetExportedValue(); 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; } diff --git a/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs b/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs index d7e1c836f5b25..0bb441b549c46 100644 --- a/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/QuickInfo/SyntacticQuickInfoSourceTests.cs @@ -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; @@ -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( @@ -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); @@ -591,7 +590,7 @@ protected override async Task AssertContentIsAsync( var streamingPresenter = workspace.ExportProvider.GetExport(); 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; diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs index 5e633f238c4c6..43a1e8789ef3c 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs @@ -11,6 +11,7 @@ using Microsoft.CodeAnalysis.FindUsages; 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; @@ -28,6 +29,7 @@ internal sealed class FindBaseSymbolsCommandHandler : AbstractNavigationCommandHandler { private readonly IAsynchronousOperationListener _asyncListener; + private readonly IGlobalOptionService _globalOptions; public override string DisplayName => nameof(FindBaseSymbolsCommandHandler); @@ -35,12 +37,14 @@ internal sealed class FindBaseSymbolsCommandHandler : [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public FindBaseSymbolsCommandHandler( [ImportMany] IEnumerable> 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) @@ -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 diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs index a44978f3fc2ab..7076795e0c28e 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs @@ -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; @@ -11,15 +10,16 @@ using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.FindSymbols; +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; using Microsoft.VisualStudio.Utilities; using Roslyn.Utilities; using VSCommanding = Microsoft.VisualStudio.Commanding; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.FindUsages; namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigationCommandHandlers { @@ -105,7 +105,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); } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs index 1a8ec8d3d0750..c56709e12897c 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs @@ -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.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Commanding; @@ -32,6 +33,7 @@ internal sealed class FindExtensionMethodsCommandHandler : AbstractNavigationCommandHandler { private readonly IAsynchronousOperationListener _asyncListener; + private readonly IGlobalOptionService _globalOptions; public override string DisplayName => nameof(FindExtensionMethodsCommandHandler); @@ -39,12 +41,14 @@ internal sealed class FindExtensionMethodsCommandHandler : [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public FindExtensionMethodsCommandHandler( [ImportMany] IEnumerable> 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) @@ -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); } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs index daa41f3df2dc6..52d5ed0de7671 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs @@ -14,6 +14,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; @@ -30,6 +31,7 @@ internal sealed class FindImplementingMembersCommandHandler : AbstractNavigationCommandHandler { private readonly IAsynchronousOperationListener _asyncListener; + private readonly IGlobalOptionService _globalOptions; public override string DisplayName => nameof(FindImplementingMembersCommandHandler); @@ -37,12 +39,14 @@ internal sealed class FindImplementingMembersCommandHandler : [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public FindImplementingMembersCommandHandler( [ImportMany] IEnumerable> 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) @@ -142,7 +146,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); } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs index 79a8ce4b9885b..a8a782ea2a5bd 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs @@ -3,12 +3,14 @@ // 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.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.ErrorReporting; +using Microsoft.CodeAnalysis.FindUsages; +using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Commanding; @@ -16,9 +18,6 @@ using Microsoft.VisualStudio.Utilities; using Roslyn.Utilities; using VSCommanding = Microsoft.VisualStudio.Commanding; -using Microsoft.CodeAnalysis.Host.Mef; -using System.Threading; -using Microsoft.CodeAnalysis.FindUsages; namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigationCommandHandlers { diff --git a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTag.cs b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTag.cs index 08d1d55eed9bb..a1cac5cc9174f 100644 --- a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTag.cs +++ b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTag.cs @@ -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; @@ -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 /// - internal class InlineHintsTag : IntraTextAdornmentTag + internal sealed class InlineHintsTag : IntraTextAdornmentTag { public const string TagId = "inline hints"; @@ -101,6 +99,7 @@ public async Task> CreateDescriptionAsync(Cancellati { var context = new IntellisenseQuickInfoBuilderContext( document, + _taggerProvider.GlobalOptions.GetClassificationOptions(document.Project.Language), _taggerProvider.ThreadingContext, _taggerProvider.OperationExecutor, _taggerProvider.AsynchronousOperationListener, diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesOptionsStorage.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesOptionsStorage.cs index ee400a4316629..da4c02aa5f3df 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesOptionsStorage.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesOptionsStorage.cs @@ -3,15 +3,13 @@ // See the LICENSE file in the project root for more information. using Microsoft.CodeAnalysis.Options; -using System; +using Microsoft.CodeAnalysis.Classification; namespace Microsoft.CodeAnalysis.FindUsages { internal static class FindUsagesOptionsStorage { -#pragma warning disable IDE0060 // Remove unused parameter -- TODO public static FindUsagesOptions GetFindUsagesOptions(this IGlobalOptionService globalOptions, string language) - => throw new NotImplementedException(); -#pragma warning restore IDE0060 // Remove unused parameter + => new(ClassificationOptions: globalOptions.GetClassificationOptions(language)); } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index bbd428b45b0aa..fe6e15bc65e30 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.GoToDefinition; using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Navigation; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index cacd8843db3c7..37a8ade70b4b9 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.GoToDefinition; using Microsoft.CodeAnalysis.Shared.Extensions; +using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index f560bae5c506d..17439faba4a3f 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -16,6 +16,7 @@ using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.GoToDefinition; using Microsoft.CodeAnalysis.Navigation; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; diff --git a/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.Tagger.cs b/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.Tagger.cs index 00d2db2548ed0..0bb1a0b91404f 100644 --- a/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.Tagger.cs +++ b/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.Tagger.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Tagging; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Tagging; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text; @@ -23,11 +24,12 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Classification { internal partial class CopyPasteAndPrintingClassificationBufferTaggerProvider { - private class Tagger : ForegroundThreadAffinitizedObject, IAccurateTagger, IDisposable + private sealed class Tagger : ForegroundThreadAffinitizedObject, IAccurateTagger, IDisposable { private readonly CopyPasteAndPrintingClassificationBufferTaggerProvider _owner; private readonly ITextBuffer _subjectBuffer; private readonly ITaggerEventSource _eventSource; + private readonly IGlobalOptionService _globalOptions; // State for the tagger. Can be accessed from any thread. Access should be protected by _gate. @@ -38,11 +40,13 @@ private class Tagger : ForegroundThreadAffinitizedObject, IAccurateTagger> GetAllTags(NormalizedSnapshotSp if (document == null) return Array.Empty>(); + var classificationService = document.GetLanguageService(); + if (classificationService == null) + return Array.Empty>(); + // We want to classify from the start of the first requested span to the end of the // last requested span. var spanToTag = new SnapshotSpan(snapshot, Span.FromBounds(spans.First().Start, spans.Last().End)); @@ -125,8 +133,10 @@ public IEnumerable> GetAllTags(NormalizedSnapshotSp { // Our cache is not there, or is out of date. We need to compute the up to date results. var context = new TaggerContext(document, snapshot); - this.ThreadingContext.JoinableTaskFactory.Run( - () => ProduceTagsAsync(context, new DocumentSnapshotSpan(document, spanToTag), _owner._typeMap, cancellationToken)); + var options = _globalOptions.GetClassificationOptions(document.Project.Language); + + ThreadingContext.JoinableTaskFactory.Run( + () => SemanticClassificationUtilities.ProduceTagsAsync(context, new DocumentSnapshotSpan(document, spanToTag), classificationService, _owner._typeMap, options, cancellationToken)); cachedTaggedSpan = spanToTag; cachedTags = new TagSpanIntervalTree(snapshot.TextBuffer, SpanTrackingMode.EdgeExclusive, context.tagSpans); @@ -151,15 +161,6 @@ private void GetCachedInfo(out SnapshotSpan? cachedTaggedSpan, out TagSpanInterv cachedTags = _cachedTags; } } - - private static Task ProduceTagsAsync( - TaggerContext context, DocumentSnapshotSpan documentSpan, ClassificationTypeMap typeMap, CancellationToken cancellationToken) - { - var classificationService = documentSpan.Document.GetLanguageService(); - return classificationService != null - ? SemanticClassificationUtilities.ProduceTagsAsync(context, documentSpan, classificationService, typeMap, cancellationToken) - : Task.CompletedTask; - } } } } diff --git a/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.cs index a6118f3c23c73..6b209997194fb 100644 --- a/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Classification/CopyPasteAndPrintingClassificationBufferTaggerProvider.cs @@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Notification; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Tagging; @@ -30,17 +31,20 @@ internal partial class CopyPasteAndPrintingClassificationBufferTaggerProvider : { private readonly IAsynchronousOperationListener _asyncListener; private readonly ClassificationTypeMap _typeMap; + private readonly IGlobalOptionService _globalOptions; [ImportingConstructor] [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] public CopyPasteAndPrintingClassificationBufferTaggerProvider( IThreadingContext threadingContext, ClassificationTypeMap typeMap, - IAsynchronousOperationListenerProvider listenerProvider) + IAsynchronousOperationListenerProvider listenerProvider, + IGlobalOptionService globalOptions) : base(threadingContext) { _typeMap = typeMap; _asyncListener = listenerProvider.GetListener(FeatureAttribute.Classification); + _globalOptions = globalOptions; } public IAccurateTagger? CreateTagger(ITextBuffer buffer) where T : ITag @@ -54,7 +58,7 @@ public CopyPasteAndPrintingClassificationBufferTaggerProvider( return null; } - return new Tagger(this, buffer, _asyncListener) as IAccurateTagger; + return new Tagger(this, buffer, _asyncListener, _globalOptions) as IAccurateTagger; } ITagger? ITaggerProvider.CreateTagger(ITextBuffer buffer) diff --git a/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationUtilities.cs b/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationUtilities.cs index 5033212ed5266..3302968e9374f 100644 --- a/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationUtilities.cs +++ b/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationUtilities.cs @@ -33,14 +33,13 @@ public static async Task ProduceTagsAsync( DocumentSnapshotSpan spanToTag, IClassificationService classificationService, ClassificationTypeMap typeMap, + ClassificationOptions options, CancellationToken cancellationToken) { var document = spanToTag.Document; if (document == null) return; - var options = ClassificationOptions.From(document.Project); - // Don't block getting classifications on building the full compilation. This may take a significant amount // of time and can cause a very latency sensitive operation (copying) to block the user while we wait on this // work to happen. diff --git a/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs index 85b5fb1f4e261..7756afd80d4f4 100644 --- a/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs @@ -76,7 +76,7 @@ protected override ITaggerEventSource CreateEventSource(ITextView textView, ITex TaggerEventSources.OnViewSpanChanged(ThreadingContext, textView), TaggerEventSources.OnWorkspaceChanged(subjectBuffer, this.AsyncListener), TaggerEventSources.OnDocumentActiveContextChanged(subjectBuffer), - TaggerEventSources.OnOptionChanged(subjectBuffer, ClassificationOptions.Metadata.ClassifyReassignedVariables)); + TaggerEventSources.OnOptionChanged(subjectBuffer, ClassificationOptionsStorage.ClassifyReassignedVariables)); } protected override IEnumerable GetSpansToTag(ITextView textView, ITextBuffer subjectBuffer) @@ -126,8 +126,9 @@ protected override Task ProduceTagsAsync( return Task.CompletedTask; } + var classificationOptions = _globalOptions.GetClassificationOptions(document.Project.Language); return SemanticClassificationUtilities.ProduceTagsAsync( - context, spanToTag, classificationService, _typeMap, cancellationToken); + context, spanToTag, classificationService, _typeMap, classificationOptions, cancellationToken); } } } diff --git a/src/EditorFeatures/Core/Implementation/Formatting/FormattingOptionsMetadata.cs b/src/EditorFeatures/Core/Implementation/Formatting/FormattingOptionsMetadata.cs index 9c607691ff476..7f06fe036fb76 100644 --- a/src/EditorFeatures/Core/Implementation/Formatting/FormattingOptionsMetadata.cs +++ b/src/EditorFeatures/Core/Implementation/Formatting/FormattingOptionsMetadata.cs @@ -2,27 +2,12 @@ // 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.Composition; -using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting { - [ExportSolutionOptionProvider, Shared] - internal sealed class FormattingOptionsMetadata : IOptionProvider + internal sealed class FormattingOptionsMetadata { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public FormattingOptionsMetadata() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - FormatOnPaste); - private const string FeatureName = "FormattingOptions"; public static readonly PerLanguageOption2 FormatOnPaste = diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs index 7aaeee93c280d..9244dd9679f20 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/AsyncCompletion/CompletionSource.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Completion; using Microsoft.CodeAnalysis.Completion.Providers; +using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; @@ -506,14 +507,16 @@ private static void AddPropertiesToSession(IAsyncCompletionSession session, Comp if (service == null) return null; - var options = _globalOptions.GetCompletionOptions(document.Project.Language); - var displayOptions = SymbolDescriptionOptions.From(document.Project); - var description = await service.GetDescriptionAsync(document, roslynItem, options, displayOptions, cancellationToken).ConfigureAwait(false); + var completionOptions = _globalOptions.GetCompletionOptions(document.Project.Language); + var displayOptions = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language); + var description = await service.GetDescriptionAsync(document, roslynItem, completionOptions, displayOptions, cancellationToken).ConfigureAwait(false); if (description == null) return null; + var classificationOptions = _globalOptions.GetClassificationOptions(document.Project.Language); + var context = new IntellisenseQuickInfoBuilderContext( - document, ThreadingContext, _operationExecutor, _asyncListener, _streamingPresenter); + document, classificationOptions, ThreadingContext, _operationExecutor, _asyncListener, _streamingPresenter); var elements = IntelliSense.Helpers.BuildInteractiveTextElements(description.TaggedParts, context).ToArray(); if (elements.Length == 0) diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilder.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilder.cs index 28055ba350ec6..6a4ae8f5c86ed 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilder.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilder.cs @@ -13,9 +13,9 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Formatting; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.QuickInfo; using Microsoft.CodeAnalysis.Shared.TestHooks; -using Microsoft.CodeAnalysis.Storage; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Adornments; using Microsoft.VisualStudio.Utilities; @@ -26,7 +26,8 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo { internal static class IntellisenseQuickInfoBuilder { - private static async Task BuildInteractiveContentAsync(CodeAnalysisQuickInfoItem quickInfoItem, + private static async Task BuildInteractiveContentAsync( + CodeAnalysisQuickInfoItem quickInfoItem, IntellisenseQuickInfoBuilderContext? context, CancellationToken cancellationToken) { @@ -99,15 +100,14 @@ private static async Task BuildInteractiveContentAsync(CodeAna .SelectMany(s => Helpers.BuildInteractiveTextElements(s.TaggedParts, context))); // build text for RelatedSpan - if (quickInfoItem.RelatedSpans.Any() && context?.Document is Document document) + if (quickInfoItem.RelatedSpans.Any() && context != null) { - var classificationOptions = ClassificationOptions.From(document.Project); - + var document = context.Document; var textRuns = new List(); var spanSeparatorNeededBefore = false; foreach (var span in quickInfoItem.RelatedSpans) { - var classifiedSpans = await ClassifierHelper.GetClassifiedSpansAsync(document, span, classificationOptions, cancellationToken).ConfigureAwait(false); + var classifiedSpans = await ClassifierHelper.GetClassifiedSpansAsync(document, span, context.ClassificationOptions, cancellationToken).ConfigureAwait(false); var tabSize = document.Project.Solution.Options.GetOption(FormattingOptions.TabSize, document.Project.Language); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); @@ -140,13 +140,14 @@ internal static async Task BuildItemAsync( ITrackingSpan trackingSpan, CodeAnalysisQuickInfoItem quickInfoItem, Document document, + ClassificationOptions classificationOptions, IThreadingContext threadingContext, IUIThreadOperationExecutor operationExecutor, IAsynchronousOperationListener asyncListener, Lazy streamingPresenter, CancellationToken cancellationToken) { - var context = new IntellisenseQuickInfoBuilderContext(document, threadingContext, operationExecutor, asyncListener, streamingPresenter); + var context = new IntellisenseQuickInfoBuilderContext(document, classificationOptions, threadingContext, operationExecutor, asyncListener, streamingPresenter); var content = await BuildInteractiveContentAsync(quickInfoItem, context, cancellationToken).ConfigureAwait(false); return new IntellisenseQuickInfoItem(trackingSpan, content); diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilderContext.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilderContext.cs index 1ea0c1ebecc2d..f83ba2239c952 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilderContext.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/IntellisenseQuickInfoBuilderContext.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Shared.TestHooks; +using Microsoft.CodeAnalysis.Classification; using Microsoft.VisualStudio.Utilities; namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo @@ -17,12 +18,14 @@ internal sealed class IntellisenseQuickInfoBuilderContext { public IntellisenseQuickInfoBuilderContext( Document document, + ClassificationOptions classificationOptions, IThreadingContext? threadingContext, IUIThreadOperationExecutor? operationExecutor, IAsynchronousOperationListener? asynchronousOperationListener, Lazy? streamingPresenter) { Document = document; + ClassificationOptions = classificationOptions; ThreadingContext = threadingContext; OperationExecutor = operationExecutor; StreamingPresenter = streamingPresenter; @@ -30,6 +33,7 @@ public IntellisenseQuickInfoBuilderContext( } public Document Document { get; } + public ClassificationOptions ClassificationOptions { get; } public IThreadingContext? ThreadingContext { get; } public IUIThreadOperationExecutor? OperationExecutor { get; } public IAsynchronousOperationListener? AsynchronousOperationListener { get; } diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.QuickInfoSource.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.QuickInfoSource.cs index 6988656fe0bbc..acad4c42dbb00 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.QuickInfoSource.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.QuickInfoSource.cs @@ -7,6 +7,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; @@ -14,6 +15,7 @@ using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.QuickInfo; using Microsoft.CodeAnalysis.Shared.TestHooks; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text.Shared.Extensions; using Microsoft.VisualStudio.Language.Intellisense; @@ -27,26 +29,29 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo { internal partial class QuickInfoSourceProvider { - private class QuickInfoSource : IAsyncQuickInfoSource + private sealed class QuickInfoSource : IAsyncQuickInfoSource { private readonly ITextBuffer _subjectBuffer; private readonly IThreadingContext _threadingContext; private readonly IUIThreadOperationExecutor _operationExecutor; private readonly IAsynchronousOperationListener _asyncListener; private readonly Lazy _streamingPresenter; + private readonly IGlobalOptionService _globalOptions; public QuickInfoSource( ITextBuffer subjectBuffer, IThreadingContext threadingContext, IUIThreadOperationExecutor operationExecutor, IAsynchronousOperationListener asyncListener, - Lazy streamingPresenter) + Lazy streamingPresenter, + IGlobalOptionService globalOptions) { _subjectBuffer = subjectBuffer; _threadingContext = threadingContext; _operationExecutor = operationExecutor; _asyncListener = asyncListener; _streamingPresenter = streamingPresenter; + _globalOptions = globalOptions; } public async Task GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) @@ -70,14 +75,16 @@ public async Task GetQuickInfoItemAsync(IAsyncQuickIn { cancellationToken.ThrowIfCancellationRequested(); - var options = SymbolDescriptionOptions.From(document.Project); + var options = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language); var item = await service.GetQuickInfoAsync(document, triggerPoint.Value, options, cancellationToken).ConfigureAwait(false); if (item != null) { var textVersion = snapshot.Version; var trackingSpan = textVersion.CreateTrackingSpan(item.Span.ToSpan(), SpanTrackingMode.EdgeInclusive); + var classificationOptions = _globalOptions.GetClassificationOptions(document.Project.Language); + return await IntellisenseQuickInfoBuilder.BuildItemAsync( - trackingSpan, item, document, + trackingSpan, item, document, classificationOptions, _threadingContext, _operationExecutor, _asyncListener, _streamingPresenter, cancellationToken).ConfigureAwait(false); } diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.cs index f77a9a333b724..cd9681af7641f 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/QuickInfoSourceProvider.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Text; @@ -26,6 +27,7 @@ internal partial class QuickInfoSourceProvider : IAsyncQuickInfoSourceProvider private readonly IUIThreadOperationExecutor _operationExecutor; private readonly Lazy _streamingPresenter; private readonly IAsynchronousOperationListener _listener; + private readonly IGlobalOptionService _globalOptions; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] @@ -33,12 +35,14 @@ public QuickInfoSourceProvider( IThreadingContext threadingContext, IUIThreadOperationExecutor operationExecutor, IAsynchronousOperationListenerProvider listenerProvider, - Lazy streamingPresenter) + Lazy streamingPresenter, + IGlobalOptionService globalOptions) { _threadingContext = threadingContext; _operationExecutor = operationExecutor; _streamingPresenter = streamingPresenter; _listener = listenerProvider.GetListener(FeatureAttribute.QuickInfo); + _globalOptions = globalOptions; } public IAsyncQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) @@ -47,7 +51,7 @@ public IAsyncQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) return null; return new QuickInfoSource( - textBuffer, _threadingContext, _operationExecutor, _listener, _streamingPresenter); + textBuffer, _threadingContext, _operationExecutor, _listener, _streamingPresenter, _globalOptions); } } } diff --git a/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Completion/CompletionResolveHandler.cs b/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Completion/CompletionResolveHandler.cs index c37774864dc6f..5918dc976d3a4 100644 --- a/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Completion/CompletionResolveHandler.cs +++ b/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Completion/CompletionResolveHandler.cs @@ -67,9 +67,9 @@ public CompletionResolveHandler(IGlobalOptionService globalOptions, CompletionLi return completionItem; } - var options = _globalOptions.GetCompletionOptions(document.Project.Language); - var displayOptions = SymbolDescriptionOptions.From(document.Project); - var description = await completionService.GetDescriptionAsync(document, selectedItem, options, displayOptions, cancellationToken).ConfigureAwait(false)!; + var completionOptions = _globalOptions.GetCompletionOptions(document.Project.Language); + var displayOptions = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language); + var description = await completionService.GetDescriptionAsync(document, selectedItem, completionOptions, displayOptions, cancellationToken).ConfigureAwait(false)!; if (description != null) { var supportsVSExtensions = context.ClientCapabilities.HasVisualStudioLspCapability(); diff --git a/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Hover/HoverHandler.cs b/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Hover/HoverHandler.cs index 8af9a9e84fd97..388a2f00d07a3 100644 --- a/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Hover/HoverHandler.cs +++ b/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Hover/HoverHandler.cs @@ -9,11 +9,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageServices; -using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.QuickInfo; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -28,12 +29,15 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler /// [ExportRoslynLanguagesLspRequestHandlerProvider, Shared] [ProvidesMethod(Methods.TextDocumentHoverName)] - internal class HoverHandler : AbstractStatelessRequestHandler + internal sealed class HoverHandler : AbstractStatelessRequestHandler { + private readonly IGlobalOptionService _globalOptions; + [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public HoverHandler() + public HoverHandler(IGlobalOptionService globalOptions) { + _globalOptions = globalOptions; } public override string Method => Methods.TextDocumentHoverName; @@ -50,15 +54,16 @@ public HoverHandler() var position = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(request.Position), cancellationToken).ConfigureAwait(false); var quickInfoService = document.Project.LanguageServices.GetRequiredService(); - var options = SymbolDescriptionOptions.From(document.Project); + var options = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language); var info = await quickInfoService.GetQuickInfoAsync(document, position, options, cancellationToken).ConfigureAwait(false); if (info == null) { return null; } + var classificationOptions = _globalOptions.GetClassificationOptions(document.Project.Language); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); - return await GetHoverAsync(info, text, document.Project.Language, document, context.ClientCapabilities, cancellationToken).ConfigureAwait(false); + return await GetHoverAsync(info, text, document.Project.Language, document, classificationOptions, context.ClientCapabilities, cancellationToken).ConfigureAwait(false); } internal static async Task GetHoverAsync( @@ -80,7 +85,7 @@ public HoverHandler() } var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); - return await GetHoverAsync(info, text, semanticModel.Language, document: null, clientCapabilities: null, cancellationToken).ConfigureAwait(false); + return await GetHoverAsync(info, text, semanticModel.Language, document: null, classificationOptions: null, clientCapabilities: null, cancellationToken).ConfigureAwait(false); } private static async Task GetHoverAsync( @@ -88,9 +93,12 @@ private static async Task GetHoverAsync( SourceText text, string language, Document? document, + ClassificationOptions? classificationOptions, ClientCapabilities? clientCapabilities, CancellationToken cancellationToken) { + Contract.ThrowIfFalse(document is null == (classificationOptions == null)); + var supportsVSExtensions = clientCapabilities.HasVisualStudioLspCapability(); if (supportsVSExtensions) @@ -99,6 +107,7 @@ private static async Task GetHoverAsync( ? null : new IntellisenseQuickInfoBuilderContext( document, + classificationOptions!.Value, threadingContext: null, operationExecutor: null, asynchronousOperationListener: null, diff --git a/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/References/FindUsagesLSPContext.cs b/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/References/FindUsagesLSPContext.cs index 3da4dac625de0..ba63a8e002012 100644 --- a/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/References/FindUsagesLSPContext.cs +++ b/src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/References/FindUsagesLSPContext.cs @@ -111,8 +111,8 @@ public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition // Creating a new VSReferenceItem for the definition var definitionItem = await GenerateVSReferenceItemAsync( - _id, definitionId: _id, _document, _position, definition.SourceSpans.FirstOrNull(), - definition.DisplayableProperties, _metadataAsSourceFileService, definition.GetClassifiedText(), + definitionId: _id, definition.SourceSpans.FirstOrNull(), + definition.DisplayableProperties, definition.GetClassifiedText(), definition.Tags.GetFirstGlyph(), symbolUsageInfo: null, isWrittenTo: false, cancellationToken).ConfigureAwait(false); if (definitionItem != null) @@ -159,8 +159,8 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere // Creating a new VSReferenceItem for the reference var referenceItem = await GenerateVSReferenceItemAsync( - _id, definitionId, _document, _position, reference.SourceSpan, - reference.AdditionalProperties, _metadataAsSourceFileService, definitionText: null, + definitionId, reference.SourceSpan, + reference.AdditionalProperties, definitionText: null, definitionGlyph: Glyph.None, reference.SymbolUsageInfo, reference.IsWrittenTo, cancellationToken).ConfigureAwait(false); if (referenceItem != null) @@ -170,25 +170,21 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere } } - private static async Task GenerateVSReferenceItemAsync( - int id, + private async Task GenerateVSReferenceItemAsync( int? definitionId, - Document document, - int position, DocumentSpan? documentSpan, ImmutableDictionary properties, - IMetadataAsSourceFileService metadataAsSourceFileService, ClassifiedTextElement? definitionText, Glyph definitionGlyph, SymbolUsageInfo? symbolUsageInfo, bool isWrittenTo, CancellationToken cancellationToken) { - var location = await ComputeLocationAsync(document, position, documentSpan, metadataAsSourceFileService, cancellationToken).ConfigureAwait(false); + var location = await ComputeLocationAsync(documentSpan, cancellationToken).ConfigureAwait(false); // Getting the text for the Text property. If we somehow can't compute the text, that means we're probably dealing with a metadata // reference, and those don't show up in the results list in Roslyn FAR anyway. - var text = await ComputeTextAsync(id, definitionId, documentSpan, definitionText, isWrittenTo, cancellationToken).ConfigureAwait(false); + var text = await ComputeTextAsync(definitionId, documentSpan, definitionText, isWrittenTo, cancellationToken).ConfigureAwait(false); if (text == null) { return null; @@ -202,7 +198,7 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere DefinitionText = definitionText, // Only definitions should have a non-null DefinitionText DefinitionIcon = definitionGlyph.GetImageElement(), DisplayPath = location?.Uri.LocalPath, - Id = id, + Id = _id, Kind = symbolUsageInfo.HasValue ? ProtocolConversions.SymbolUsageInfoToReferenceKinds(symbolUsageInfo.Value) : Array.Empty(), ResolutionStatus = VSInternalResolutionStatusKind.ConfirmedAsReference, Text = text, @@ -227,130 +223,125 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere result.ContainingType = referenceContainingType; return result; + } - // Local functions - static async Task ComputeLocationAsync( - Document document, - int position, - DocumentSpan? documentSpan, - IMetadataAsSourceFileService metadataAsSourceFileService, - CancellationToken cancellationToken) + private async Task ComputeLocationAsync(DocumentSpan? documentSpan, CancellationToken cancellationToken) + { + // If we have no document span, our location may be in metadata. + if (documentSpan != null) { - // If we have no document span, our location may be in metadata. - if (documentSpan != null) - { - // We do have a document span, so compute location normally. - return await ProtocolConversions.DocumentSpanToLocationAsync(documentSpan.Value, cancellationToken).ConfigureAwait(false); - } + // We do have a document span, so compute location normally. + return await ProtocolConversions.DocumentSpanToLocationAsync(documentSpan.Value, cancellationToken).ConfigureAwait(false); + } - // If we have no document span, our location may be in metadata or may be a namespace. - var symbol = await SymbolFinder.FindSymbolAtPositionAsync(document, position, cancellationToken).ConfigureAwait(false); - if (symbol == null || symbol.Locations.IsEmpty || symbol.Kind == SymbolKind.Namespace) - { - // Either: - // (1) We couldn't find the location in metadata and it's not in any of our known documents. - // (2) The symbol is a namespace (and therefore has no location). - return null; - } + // If we have no document span, our location may be in metadata or may be a namespace. + var symbol = await SymbolFinder.FindSymbolAtPositionAsync(_document, _position, cancellationToken).ConfigureAwait(false); + if (symbol == null || symbol.Locations.IsEmpty || symbol.Kind == SymbolKind.Namespace) + { + // Either: + // (1) We couldn't find the location in metadata and it's not in any of our known documents. + // (2) The symbol is a namespace (and therefore has no location). + return null; + } - var declarationFile = await metadataAsSourceFileService.GetGeneratedFileAsync( - document.Project, symbol, signaturesOnly: true, allowDecompilation: false, cancellationToken).ConfigureAwait(false); + var declarationFile = await _metadataAsSourceFileService.GetGeneratedFileAsync( + _document.Project, symbol, signaturesOnly: true, allowDecompilation: false, cancellationToken).ConfigureAwait(false); - var linePosSpan = declarationFile.IdentifierLocation.GetLineSpan().Span; + var linePosSpan = declarationFile.IdentifierLocation.GetLineSpan().Span; - if (string.IsNullOrEmpty(declarationFile.FilePath)) - { - return null; - } + if (string.IsNullOrEmpty(declarationFile.FilePath)) + { + return null; + } - try - { - return new LSP.Location - { - Uri = ProtocolConversions.GetUriFromFilePath(declarationFile.FilePath), - Range = ProtocolConversions.LinePositionToRange(linePosSpan), - }; - } - catch (UriFormatException e) when (FatalError.ReportAndCatch(e)) + try + { + return new LSP.Location { - // We might reach this point if the file path is formatted incorrectly. - return null; - } + Uri = ProtocolConversions.GetUriFromFilePath(declarationFile.FilePath), + Range = ProtocolConversions.LinePositionToRange(linePosSpan), + }; } + catch (UriFormatException e) when (FatalError.ReportAndCatch(e)) + { + // We might reach this point if the file path is formatted incorrectly. + return null; + } + } - static async Task ComputeTextAsync( - int id, int? definitionId, - DocumentSpan? documentSpan, - ClassifiedTextElement? definitionText, - bool isWrittenTo, - CancellationToken cancellationToken) + private async Task ComputeTextAsync( + int? definitionId, + DocumentSpan? documentSpan, + ClassifiedTextElement? definitionText, + bool isWrittenTo, + CancellationToken cancellationToken) + { + // General case + if (documentSpan != null) { - // General case - if (documentSpan != null) - { - var document = documentSpan.Value.Document; - var classificationOptions = ClassificationOptions.From(document.Project); + var document = documentSpan.Value.Document; + var options = await GetOptionsAsync(document.Project.Language, cancellationToken).ConfigureAwait(false); - var classifiedSpansAndHighlightSpan = await ClassifiedSpansAndHighlightSpanFactory.ClassifyAsync( - documentSpan.Value, classificationOptions, cancellationToken).ConfigureAwait(false); + var classifiedSpansAndHighlightSpan = await ClassifiedSpansAndHighlightSpanFactory.ClassifyAsync( + documentSpan.Value, options.ClassificationOptions, cancellationToken).ConfigureAwait(false); - var classifiedSpans = classifiedSpansAndHighlightSpan.ClassifiedSpans; - var docText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); - var classifiedTextRuns = GetClassifiedTextRuns(id, definitionId, documentSpan.Value, isWrittenTo, classifiedSpans, docText); + var classifiedSpans = classifiedSpansAndHighlightSpan.ClassifiedSpans; + var docText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); + var classifiedTextRuns = GetClassifiedTextRuns(_id, definitionId, documentSpan.Value, isWrittenTo, classifiedSpans, docText); - return new ClassifiedTextElement(classifiedTextRuns.ToArray()); - } - // Certain definitions may not have a DocumentSpan, such as namespace and metadata definitions - else if (id == definitionId) - { - return definitionText; - } + return new ClassifiedTextElement(classifiedTextRuns.ToArray()); + } - return null; + // Certain definitions may not have a DocumentSpan, such as namespace and metadata definitions + if (_id == definitionId) + { + return definitionText; + } + + return null; + } + + private static ClassifiedTextRun[] GetClassifiedTextRuns( + int id, + int? definitionId, + DocumentSpan documentSpan, + bool isWrittenTo, + ImmutableArray classifiedSpans, + SourceText docText) + { + using var _ = ArrayBuilder.GetInstance(out var classifiedTextRuns); + foreach (var span in classifiedSpans) + { + // Default case: Don't highlight. For example, if the user invokes FAR on 'x' in 'var x = 1', then 'var', + // '=', and '1' should not be highlighted. + string? markerTagType = null; - // Nested local functions - static ClassifiedTextRun[] GetClassifiedTextRuns( - int id, int? definitionId, - DocumentSpan documentSpan, - bool isWrittenTo, - ImmutableArray classifiedSpans, - SourceText docText) + // Case 1: Highlight this span of text. For example, if the user invokes FAR on 'x' in 'var x = 1', + // then 'x' should be highlighted. + if (span.TextSpan == documentSpan.SourceSpan) { - using var _ = ArrayBuilder.GetInstance(out var classifiedTextRuns); - foreach (var span in classifiedSpans) + // Case 1a: Highlight a definition + if (id == definitionId) { - // Default case: Don't highlight. For example, if the user invokes FAR on 'x' in 'var x = 1', then 'var', - // '=', and '1' should not be highlighted. - string? markerTagType = null; - - // Case 1: Highlight this span of text. For example, if the user invokes FAR on 'x' in 'var x = 1', - // then 'x' should be highlighted. - if (span.TextSpan == documentSpan.SourceSpan) - { - // Case 1a: Highlight a definition - if (id == definitionId) - { - markerTagType = DefinitionHighlightTag.TagId; - } - // Case 1b: Highlight a written reference - else if (isWrittenTo) - { - markerTagType = WrittenReferenceHighlightTag.TagId; - } - // Case 1c: Highlight a read reference - else - { - markerTagType = ReferenceHighlightTag.TagId; - } - } - - classifiedTextRuns.Add(new ClassifiedTextRun( - span.ClassificationType, docText.ToString(span.TextSpan), ClassifiedTextRunStyle.Plain, markerTagType)); + markerTagType = DefinitionHighlightTag.TagId; + } + // Case 1b: Highlight a written reference + else if (isWrittenTo) + { + markerTagType = WrittenReferenceHighlightTag.TagId; + } + // Case 1c: Highlight a read reference + else + { + markerTagType = ReferenceHighlightTag.TagId; } - - return classifiedTextRuns.ToArray(); } + + classifiedTextRuns.Add(new ClassifiedTextRun( + span.ClassificationType, docText.ToString(span.TextSpan), ClassifiedTextRunStyle.Plain, markerTagType)); } + + return classifiedTextRuns.ToArray(); } private ValueTask ReportReferencesAsync(ImmutableArray referencesToReport, CancellationToken cancellationToken) diff --git a/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs b/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs index e812f239b9a99..dc77a8beef900 100644 --- a/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs +++ b/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs @@ -66,18 +66,18 @@ protected override ITaggerEventSource CreateEventSource(ITextView textViewOpt, I TaggerEventSources.OnViewSpanChanged(ThreadingContext, textViewOpt), TaggerEventSources.OnWorkspaceChanged(subjectBuffer, _listener), TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsGlobalStateOption.DisplayAllOverride), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.EnabledForParameters), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForLiteralParameters), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForIndexerParameters), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForObjectCreationParameters), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForOtherParameters), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchMethodIntent), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.SuppressForParametersThatDifferOnlyBySuffix), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchArgumentName), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.EnabledForTypes), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.ForImplicitVariableTypes), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.ForLambdaParameterTypes), - TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.ForImplicitObjectCreation)); + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.EnabledForParameters), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForLiteralParameters), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForIndexerParameters), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForObjectCreationParameters), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForOtherParameters), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.SuppressForParametersThatMatchMethodIntent), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.SuppressForParametersThatDifferOnlyBySuffix), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.SuppressForParametersThatMatchArgumentName), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.EnabledForTypes), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForImplicitVariableTypes), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForLambdaParameterTypes), + TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForImplicitObjectCreation)); } protected override IEnumerable GetSpansToTag(ITextView textView, ITextBuffer subjectBuffer) @@ -107,7 +107,7 @@ protected override async Task ProduceTagsAsync( if (service == null) return; - var options = InlineHintsOptions.From(document.Project); + var options = GlobalOptions.GetInlineHintsOptions(document.Project.Language); var snapshotSpan = documentSnapshotSpan.SnapshotSpan; var hints = await service.GetInlineHintsAsync(document, snapshotSpan.Span.ToTextSpan(), options, cancellationToken).ConfigureAwait(false); diff --git a/src/EditorFeatures/Core/InlineHints/InlineHintsOptionsStorage.cs b/src/EditorFeatures/Core/InlineHints/InlineHintsOptionsStorage.cs new file mode 100644 index 0000000000000..0563859fdef8c --- /dev/null +++ b/src/EditorFeatures/Core/InlineHints/InlineHintsOptionsStorage.cs @@ -0,0 +1,114 @@ +// 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 Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; + +namespace Microsoft.CodeAnalysis.InlineHints +{ + internal static class InlineHintsOptionsStorage + { + public static InlineHintsOptions GetInlineHintsOptions(this IGlobalOptionService globalOptions, string language) + => new( + ParameterOptions: globalOptions.GetInlineParameterHintsOptions(language), + TypeOptions: globalOptions.GetInlineTypeHintsOptions(language), + DisplayOptions: globalOptions.GetSymbolDescriptionOptions(language)); + + public static InlineParameterHintsOptions GetInlineParameterHintsOptions(this IGlobalOptionService globalOptions, string language) + => new( + EnabledForParameters: globalOptions.GetOption(EnabledForParameters, language), + ForLiteralParameters: globalOptions.GetOption(ForLiteralParameters, language), + ForIndexerParameters: globalOptions.GetOption(ForIndexerParameters, language), + ForObjectCreationParameters: globalOptions.GetOption(ForObjectCreationParameters, language), + ForOtherParameters: globalOptions.GetOption(ForOtherParameters, language), + SuppressForParametersThatDifferOnlyBySuffix: globalOptions.GetOption(SuppressForParametersThatDifferOnlyBySuffix, language), + SuppressForParametersThatMatchMethodIntent: globalOptions.GetOption(SuppressForParametersThatMatchMethodIntent, language), + SuppressForParametersThatMatchArgumentName: globalOptions.GetOption(SuppressForParametersThatMatchArgumentName, language)); + + public static InlineTypeHintsOptions GetInlineTypeHintsOptions(this IGlobalOptionService globalOptions, string language) + => new( + EnabledForTypes: globalOptions.GetOption(EnabledForTypes, language), + ForImplicitVariableTypes: globalOptions.GetOption(ForImplicitVariableTypes, language), + ForLambdaParameterTypes: globalOptions.GetOption(ForLambdaParameterTypes, language), + ForImplicitObjectCreation: globalOptions.GetOption(ForImplicitObjectCreation, language)); + + private const string FeatureName = "InlineHintsOptions"; + + // Parameter hints + + public static readonly PerLanguageOption2 EnabledForParameters = + new(FeatureName, + nameof(EnabledForParameters), + InlineParameterHintsOptions.Default.EnabledForParameters, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints")); + + public static readonly PerLanguageOption2 ForLiteralParameters = + new(FeatureName, + nameof(ForLiteralParameters), + InlineParameterHintsOptions.Default.ForLiteralParameters, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForLiteralParameters")); + + public static readonly PerLanguageOption2 ForIndexerParameters = + new(FeatureName, + nameof(ForIndexerParameters), + InlineParameterHintsOptions.Default.ForIndexerParameters, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForArrayIndexers")); + + public static readonly PerLanguageOption2 ForObjectCreationParameters = + new(FeatureName, + nameof(ForObjectCreationParameters), + InlineParameterHintsOptions.Default.ForObjectCreationParameters, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForObjectCreationParameters")); + + public static readonly PerLanguageOption2 ForOtherParameters = + new(FeatureName, + nameof(ForOtherParameters), + InlineParameterHintsOptions.Default.ForOtherParameters, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForOtherParameters")); + + public static readonly PerLanguageOption2 SuppressForParametersThatDifferOnlyBySuffix = + new(FeatureName, + nameof(SuppressForParametersThatDifferOnlyBySuffix), + InlineParameterHintsOptions.Default.SuppressForParametersThatDifferOnlyBySuffix, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatDifferOnlyBySuffix")); + + public static readonly PerLanguageOption2 SuppressForParametersThatMatchMethodIntent = + new(FeatureName, + nameof(SuppressForParametersThatMatchMethodIntent), + InlineParameterHintsOptions.Default.SuppressForParametersThatMatchMethodIntent, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchMethodIntent")); + + public static readonly PerLanguageOption2 SuppressForParametersThatMatchArgumentName = + new(FeatureName, + nameof(SuppressForParametersThatMatchArgumentName), + InlineParameterHintsOptions.Default.SuppressForParametersThatMatchArgumentName, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchArgumentName")); + + // Type Hints + + public static readonly PerLanguageOption2 EnabledForTypes = + new(FeatureName, + nameof(EnabledForTypes), + defaultValue: InlineTypeHintsOptions.Default.EnabledForTypes, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints")); + + public static readonly PerLanguageOption2 ForImplicitVariableTypes = + new(FeatureName, + nameof(ForImplicitVariableTypes), + defaultValue: InlineTypeHintsOptions.Default.ForImplicitVariableTypes, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitVariableTypes")); + + public static readonly PerLanguageOption2 ForLambdaParameterTypes = + new(FeatureName, + nameof(ForLambdaParameterTypes), + defaultValue: InlineTypeHintsOptions.Default.ForLambdaParameterTypes, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForLambdaParameterTypes")); + + public static readonly PerLanguageOption2 ForImplicitObjectCreation = + new(FeatureName, + nameof(ForImplicitObjectCreation), + defaultValue: InlineTypeHintsOptions.Default.ForImplicitObjectCreation, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitObjectCreation")); + } +} diff --git a/src/EditorFeatures/Core/QuickInfo/QuickInfoOptionsStorage.cs b/src/EditorFeatures/Core/QuickInfo/QuickInfoOptionsStorage.cs new file mode 100644 index 0000000000000..7eefba5b325fb --- /dev/null +++ b/src/EditorFeatures/Core/QuickInfo/QuickInfoOptionsStorage.cs @@ -0,0 +1,26 @@ +// 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 Microsoft.CodeAnalysis.Options; + +namespace Microsoft.CodeAnalysis.QuickInfo +{ + internal static class QuickInfoOptionsStorage + { + public static QuickInfoOptions GetQuickInfoOptions(this IGlobalOptionService globalOptions, string? language) + => new( + ShowRemarksInQuickInfo: globalOptions.GetOption(ShowRemarksInQuickInfo, language), + IncludeNavigationHintsInQuickInfo: globalOptions.GetOption(IncludeNavigationHintsInQuickInfo)); + + private const string FeatureName = "QuickInfoOptions"; + + public static readonly PerLanguageOption2 ShowRemarksInQuickInfo = new( + FeatureName, "ShowRemarksInQuickInfo", QuickInfoOptions.Default.ShowRemarksInQuickInfo, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowRemarks")); + + public static readonly Option2 IncludeNavigationHintsInQuickInfo = new( + FeatureName, "IncludeNavigationHintsInQuickInfo", QuickInfoOptions.Default.IncludeNavigationHintsInQuickInfo, + storageLocation: new RoamingProfileStorageLocation("TextEditor.Specific.IncludeNavigationHintsInQuickInfo")); + } +} diff --git a/src/EditorFeatures/Core/SymbolDisplay/SymbolDescriptionOptionsStorage.cs b/src/EditorFeatures/Core/SymbolDisplay/SymbolDescriptionOptionsStorage.cs new file mode 100644 index 0000000000000..559eeb744fb98 --- /dev/null +++ b/src/EditorFeatures/Core/SymbolDisplay/SymbolDescriptionOptionsStorage.cs @@ -0,0 +1,18 @@ +// 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 Microsoft.CodeAnalysis.Classification; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.QuickInfo; + +namespace Microsoft.CodeAnalysis.LanguageServices +{ + internal static class SymbolDescriptionOptionsStorage + { + public static SymbolDescriptionOptions GetSymbolDescriptionOptions(this IGlobalOptionService globalOptions, string language) + => new( + QuickInfoOptions: globalOptions.GetQuickInfoOptions(language), + ClassificationOptions: globalOptions.GetClassificationOptions(language)); + } +} diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index b2478a1aa7f65..7261387825995 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -10,14 +10,14 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition Imports Microsoft.CodeAnalysis.Navigation +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.VisualStudio.Text Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Public Class GoToDefinitionTestsBase - Private Shared Sub Test( + Public Shared Sub Test( workspaceDefinition As XElement, - expectedResult As Boolean, - executeOnDocument As Func(Of Document, Integer, IThreadingContext, IStreamingFindUsagesPresenter, Boolean)) + Optional expectedResult As Boolean = True) Using workspace = TestWorkspace.Create(workspaceDefinition, composition:=GoToTestHelpers.Composition) Dim solution = workspace.CurrentSolution Dim cursorDocument = workspace.Documents.First(Function(d) d.CursorPosition.HasValue) @@ -41,7 +41,12 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Dim presenterCalled As Boolean = False Dim threadingContext = workspace.ExportProvider.GetExportedValue(Of IThreadingContext)() Dim presenter = New MockStreamingFindUsagesPresenter(workspace.GlobalOptions, Sub() presenterCalled = True) - Dim actualResult = executeOnDocument(document, cursorPosition, threadingContext, presenter) + + Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp, + DirectCast(New CSharpGoToDefinitionService(threadingContext, presenter), IGoToDefinitionService), + New VisualBasicGoToDefinitionService(threadingContext, presenter)) + + Dim actualResult = goToDefService.TryGoToDefinition(document, cursorPosition, CancellationToken.None) Assert.Equal(expectedResult, actualResult) @@ -110,17 +115,5 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition End Using End Sub - - Friend Shared Sub Test(workspaceDefinition As XElement, Optional expectedResult As Boolean = True) - Test(workspaceDefinition, expectedResult, - Function(document, cursorPosition, threadingContext, presenter) - Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp, - DirectCast(New CSharpGoToDefinitionService(threadingContext, presenter), IGoToDefinitionService), - New VisualBasicGoToDefinitionService(threadingContext, presenter)) - - Return goToDefService.TryGoToDefinition(document, cursorPosition, CancellationToken.None) - End Function) - End Sub - End Class End Namespace diff --git a/src/EditorFeatures/Test2/IntelliSense/AbstractIntellisenseQuickInfoBuilderTests.vb b/src/EditorFeatures/Test2/IntelliSense/AbstractIntellisenseQuickInfoBuilderTests.vb index b569aa20e4b83..8ab07d30a0f9d 100644 --- a/src/EditorFeatures/Test2/IntelliSense/AbstractIntellisenseQuickInfoBuilderTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/AbstractIntellisenseQuickInfoBuilderTests.vb @@ -50,7 +50,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim streamingPresenter = workspace.ExportProvider.GetExport(Of IStreamingFindUsagesPresenter)() Return Await IntellisenseQuickInfoBuilder.BuildItemAsync( trackingSpan.Object, quickInfoItem, document, - threadingContext, operationExecutor, + ClassificationOptions.Default, threadingContext, operationExecutor, AsynchronousOperationListenerProvider.NullListener, streamingPresenter, CancellationToken.None) End Using @@ -77,9 +77,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim threadingContext = workspace.ExportProvider.GetExportedValue(Of IThreadingContext)() Dim operationExecutor = workspace.ExportProvider.GetExportedValue(Of IUIThreadOperationExecutor)() Dim streamingPresenter = workspace.ExportProvider.GetExport(Of IStreamingFindUsagesPresenter)() + Dim classificationOptions = workspace.GlobalOptions.GetClassificationOptions(document.Project.Language) Return Await IntellisenseQuickInfoBuilder.BuildItemAsync( trackingSpan.Object, codeAnalysisQuickInfoItem, document, - threadingContext, operationExecutor, + classificationOptions, threadingContext, operationExecutor, AsynchronousOperationListenerProvider.NullListener, streamingPresenter, CancellationToken.None) End Using diff --git a/src/EditorFeatures/Test2/Workspaces/SymbolDescriptionServiceTests.vb b/src/EditorFeatures/Test2/Workspaces/SymbolDescriptionServiceTests.vb index 71821914edf27..4fb6a0cbb13ef 100644 --- a/src/EditorFeatures/Test2/Workspaces/SymbolDescriptionServiceTests.vb +++ b/src/EditorFeatures/Test2/Workspaces/SymbolDescriptionServiceTests.vb @@ -27,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Dim symbolDescriptionService = languageServiceProvider.GetService(Of ISymbolDisplayService)() - Dim options = SymbolDescriptionOptions.From(document.Project) + Dim options = SymbolDescriptionOptions.Default Dim actualDescription = Await symbolDescriptionService.ToDescriptionStringAsync(semanticModel, cursorPosition, symbol, options) Assert.Equal(expectedDescription, actualDescription) diff --git a/src/EditorFeatures/TestUtilities/Classification/AbstractClassifierTests.cs b/src/EditorFeatures/TestUtilities/Classification/AbstractClassifierTests.cs index 1001e756a9598..47fea4a45c791 100644 --- a/src/EditorFeatures/TestUtilities/Classification/AbstractClassifierTests.cs +++ b/src/EditorFeatures/TestUtilities/Classification/AbstractClassifierTests.cs @@ -263,7 +263,7 @@ protected async Task TestInNamespaceAsync( protected static async Task> GetSemanticClassificationsAsync(Document document, TextSpan span) { var service = document.GetRequiredLanguageService(); - var options = ClassificationOptions.From(document.Project); + var options = ClassificationOptions.Default; using var _ = ArrayBuilder.GetInstance(out var result); await service.AddSemanticClassificationsAsync(document, span, options, result, CancellationToken.None); diff --git a/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs b/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs index 446013410a669..45a2fbeac3e1c 100644 --- a/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs @@ -156,7 +156,7 @@ private protected async Task CheckResultsAsync( } var options = GetCompletionOptions(); - var displayOptions = SymbolDescriptionOptions.From(document.Project); + var displayOptions = SymbolDescriptionOptions.Default; var completionService = GetCompletionService(document.Project); var completionList = await GetCompletionListAsync(completionService, document, position, trigger, options); var items = completionList.Items; @@ -800,7 +800,7 @@ private async Task VerifyItemWithReferenceWorkerAsync( var document = solution.GetDocument(documentId); var options = GetCompletionOptions(); - var displayOptions = SymbolDescriptionOptions.From(document.Project); + var displayOptions = SymbolDescriptionOptions.Default; var triggerInfo = RoslynCompletion.CompletionTrigger.Invoke; var completionService = GetCompletionService(document.Project); @@ -856,7 +856,7 @@ private async Task VerifyItemWithMscorlib45WorkerAsync( var solution = testWorkspace.CurrentSolution; var documentId = testWorkspace.Documents.Single(d => d.Name == "SourceDocument").Id; var document = solution.GetDocument(documentId); - var displayOptions = SymbolDescriptionOptions.From(document.Project); + var displayOptions = SymbolDescriptionOptions.Default; var triggerInfo = RoslynCompletion.CompletionTrigger.Invoke; var completionService = GetCompletionService(document.Project); @@ -888,7 +888,7 @@ protected async Task VerifyItemInLinkedFilesAsync(string xmlString, string expec var textContainer = testWorkspace.Documents.First().GetTextBuffer().AsTextContainer(); var currentContextDocumentId = testWorkspace.GetDocumentIdInCurrentContext(textContainer); var document = solution.GetDocument(currentContextDocumentId); - var displayOptions = SymbolDescriptionOptions.From(document.Project); + var displayOptions = SymbolDescriptionOptions.Default; var triggerInfo = RoslynCompletion.CompletionTrigger.Invoke; var completionService = GetCompletionService(document.Project); diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index 6e421c9689479..f7e9b9e8dde1d 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -451,8 +451,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim service = CompletionService.GetService(document) Dim roslynItem = GetSelectedItem() Dim options = CompletionOptions.Default - Dim displayOptions = SymbolDescriptionOptions.From(document.Project) - Return Await service.GetDescriptionAsync(document, roslynItem, options, displayOptions) + Return Await service.GetDescriptionAsync(document, roslynItem, options, SymbolDescriptionOptions.Default) End Function Public Sub AssertCompletionItemExpander(isAvailable As Boolean, isSelected As Boolean) diff --git a/src/EditorFeatures/VisualBasic/GoToBase/VisualBasicGoToBaseService.vb b/src/EditorFeatures/VisualBasic/GoToBase/VisualBasicGoToBaseService.vb index c69c2b91d5cbc..19ca552b051f8 100644 --- a/src/EditorFeatures/VisualBasic/GoToBase/VisualBasicGoToBaseService.vb +++ b/src/EditorFeatures/VisualBasic/GoToBase/VisualBasicGoToBaseService.vb @@ -5,6 +5,7 @@ Imports System.Composition Imports Microsoft.CodeAnalysis.GoToBase Imports Microsoft.CodeAnalysis.Host.Mef +Imports Microsoft.CodeAnalysis.Options Namespace Microsoft.CodeAnalysis.VisualBasic.GoToBase @@ -14,6 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GoToBase Public Sub New() + MyBase.New() End Sub End Class End Namespace diff --git a/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToDefinitionService.vb b/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToDefinitionService.vb index 0a25dae688ae7..ce029770b6ef3 100644 --- a/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToDefinitionService.vb +++ b/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToDefinitionService.vb @@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.Editor.GoToDefinition Imports Microsoft.CodeAnalysis.Editor.Host Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Host.Mef +Imports Microsoft.CodeAnalysis.Options Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition diff --git a/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToSymbolService.vb b/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToSymbolService.vb index 3e659db1a51c2..6caf05540eb9f 100644 --- a/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToSymbolService.vb +++ b/src/EditorFeatures/VisualBasic/GoToDefinition/VisualBasicGoToSymbolService.vb @@ -6,10 +6,11 @@ Imports System.Composition Imports Microsoft.CodeAnalysis.Editor.GoToDefinition Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Host.Mef +Imports Microsoft.CodeAnalysis.Options Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition - Friend Class VisualBasicGoToSymbolService + Friend NotInheritable Class VisualBasicGoToSymbolService Inherits AbstractGoToSymbolService diff --git a/src/Features/Core/Portable/Completion/ClassificationOptionsStorage.cs b/src/Features/Core/Portable/Completion/ClassificationOptionsStorage.cs new file mode 100644 index 0000000000000..9420003e28fb9 --- /dev/null +++ b/src/Features/Core/Portable/Completion/ClassificationOptionsStorage.cs @@ -0,0 +1,30 @@ +// 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 Microsoft.CodeAnalysis.Options; + +namespace Microsoft.CodeAnalysis.Classification +{ + // TODO: Move to EditorFeatures https://github.com/dotnet/roslyn/issues/59184 + internal static class ClassificationOptionsStorage + { + public static ClassificationOptions GetClassificationOptions(this IGlobalOptionService globalOptions, string language) + => new( + ClassifyReassignedVariables: globalOptions.GetOption(ClassifyReassignedVariables, language), + ColorizeRegexPatterns: globalOptions.GetOption(ColorizeRegexPatterns, language), + ColorizeJsonPatterns: globalOptions.GetOption(ColorizeJsonPatterns, language)); + + public static PerLanguageOption2 ClassifyReassignedVariables = + new("ClassificationOptions", "ClassifyReassignedVariables", ClassificationOptions.Default.ClassifyReassignedVariables, + storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.ClassificationOptions.ClassifyReassignedVariables")); + + public static PerLanguageOption2 ColorizeRegexPatterns = + new("RegularExpressionsOptions", "ColorizeRegexPatterns", ClassificationOptions.Default.ColorizeRegexPatterns, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorizeRegexPatterns")); + + public static PerLanguageOption2 ColorizeJsonPatterns = + new("JsonFeatureOptions", "ColorizeJsonPatterns", ClassificationOptions.Default.ColorizeJsonPatterns, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorizeJsonPatterns")); + } +} diff --git a/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index d5e481db581db..36f4b2c530487 100644 --- a/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -41,12 +41,10 @@ public FindLiteralsProgressAdapter( public async ValueTask OnReferenceFoundAsync(Document document, TextSpan span, CancellationToken cancellationToken) { - // TODO: - // var options = await _context.GetOptionsAsync(document.Project.Language, cancellationToken).ConfigureAwait(false); - var classificationOptions = ClassificationOptions.From(document.Project); + var options = await _context.GetOptionsAsync(document.Project.Language, cancellationToken).ConfigureAwait(false); var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( - document, span, classificationOptions, cancellationToken).ConfigureAwait(false); + document, span, options.ClassificationOptions, cancellationToken).ConfigureAwait(false); await _context.OnReferenceFoundAsync( new SourceReferenceItem(_definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false); @@ -105,10 +103,11 @@ private async ValueTask GetDefinitionItemAsync(SymbolGroup group if (!_definitionToItem.TryGetValue(group, out var definitionItem)) { definitionItem = await group.ToClassifiedDefinitionItemAsync( + _context, _solution, + _options, isPrimary: _definitionToItem.Count == 0, includeHiddenLocations: false, - _options, cancellationToken).ConfigureAwait(false); _definitionToItem[group] = definitionItem; diff --git a/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindImplementations.cs b/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindImplementations.cs index 45a50f3e08c94..736573cc2a9ef 100644 --- a/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindImplementations.cs +++ b/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindImplementations.cs @@ -84,7 +84,7 @@ await context.SetSearchTitleAsync( foreach (var implementation in implementations) { var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( - solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false); + context, solution, FindReferencesSearchOptions.Default, isPrimary: true, includeHiddenLocations: false, cancellationToken).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } diff --git a/src/Features/Core/Portable/FindUsages/IDefinitionsAndReferencesFactory.cs b/src/Features/Core/Portable/FindUsages/IDefinitionsAndReferencesFactory.cs index 3241ee68cbfac..9cb9e83ca5d2a 100644 --- a/src/Features/Core/Portable/FindUsages/IDefinitionsAndReferencesFactory.cs +++ b/src/Features/Core/Portable/FindUsages/IDefinitionsAndReferencesFactory.cs @@ -15,9 +15,9 @@ using Microsoft.CodeAnalysis.FindSymbols.Finders; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.Shared.Extensions; +using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.FindUsages @@ -59,64 +59,58 @@ public static DefinitionItem ToNonClassifiedDefinitionItem( this ISymbol definition, Solution solution, bool includeHiddenLocations) - { - // Because we're passing in 'false' for 'includeClassifiedSpans', this won't ever have - // to actually do async work. This is because the only asynchrony is when we are trying - // to compute the classified spans for the locations of the definition. So it's totally - // fine to pass in CancellationToken.None and block on the result. - return ToDefinitionItemAsync( - definition, solution, isPrimary: false, includeHiddenLocations, includeClassifiedSpans: false, - options: FindReferencesSearchOptions.Default, cancellationToken: CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None); - } + => ToNonClassifiedDefinitionItem(definition, solution, FindReferencesSearchOptions.Default, includeHiddenLocations); - public static Task ToNonClassifiedDefinitionItemAsync( + public static DefinitionItem ToNonClassifiedDefinitionItem( this ISymbol definition, Solution solution, - bool includeHiddenLocations, - CancellationToken cancellationToken) - { - return ToDefinitionItemAsync( - definition, solution, isPrimary: false, includeHiddenLocations, includeClassifiedSpans: false, - options: FindReferencesSearchOptions.Default with { UnidirectionalHierarchyCascade = true }, cancellationToken); - } + FindReferencesSearchOptions options, + bool includeHiddenLocations) + => ToNonClassifiedDefinitionItem(definition, definition.Locations, solution, options, isPrimary: false, includeHiddenLocations); - public static Task ToClassifiedDefinitionItemAsync( + private static DefinitionItem ToNonClassifiedDefinitionItem( + ISymbol definition, + ImmutableArray locations, + Solution solution, + FindReferencesSearchOptions options, + bool isPrimary, + bool includeHiddenLocations) + => ToDefinitionItem(definition, TryGetSourceLocations(definition, solution, locations, includeHiddenLocations), solution, options, isPrimary); + + public static async ValueTask ToClassifiedDefinitionItemAsync( this ISymbol definition, + IFindUsagesContext context, Solution solution, + FindReferencesSearchOptions options, bool isPrimary, bool includeHiddenLocations, - FindReferencesSearchOptions options, CancellationToken cancellationToken) { - return ToDefinitionItemAsync( - definition, solution, isPrimary, - includeHiddenLocations, includeClassifiedSpans: true, - options, cancellationToken); + var unclassifiedSpans = TryGetSourceLocations(definition, solution, definition.Locations, includeHiddenLocations); + var classifiedSpans = unclassifiedSpans.IsDefault ? default : await ClassifyDocumentSpansAsync(context, unclassifiedSpans, cancellationToken).ConfigureAwait(false); + + return ToDefinitionItem(definition, classifiedSpans, solution, options, isPrimary); } - public static Task ToClassifiedDefinitionItemAsync( - this SymbolGroup group, Solution solution, bool isPrimary, bool includeHiddenLocations, FindReferencesSearchOptions options, CancellationToken cancellationToken) + public static async ValueTask ToClassifiedDefinitionItemAsync( + this SymbolGroup group, IFindUsagesContext context, Solution solution, FindReferencesSearchOptions options, bool isPrimary, bool includeHiddenLocations, CancellationToken cancellationToken) { // Make a single definition item that knows about all the locations of all the symbols in the group. + var definition = group.Symbols.First(); + var allLocations = group.Symbols.SelectMany(s => s.Locations).ToImmutableArray(); - return ToDefinitionItemAsync(group.Symbols.First(), allLocations, solution, isPrimary, includeHiddenLocations, includeClassifiedSpans: true, options, cancellationToken); - } + var unclassifiedSpans = TryGetSourceLocations(definition, solution, allLocations, includeHiddenLocations); + var classifiedSpans = unclassifiedSpans.IsDefault ? default : await ClassifyDocumentSpansAsync(context, unclassifiedSpans, cancellationToken).ConfigureAwait(false); - private static Task ToDefinitionItemAsync( - ISymbol definition, Solution solution, bool isPrimary, bool includeHiddenLocations, bool includeClassifiedSpans, FindReferencesSearchOptions options, CancellationToken cancellationToken) - { - return ToDefinitionItemAsync(definition, definition.Locations, solution, isPrimary, includeHiddenLocations, includeClassifiedSpans, options, cancellationToken); + return ToDefinitionItem(definition, classifiedSpans, solution, options, isPrimary); } - private static async Task ToDefinitionItemAsync( + private static DefinitionItem ToDefinitionItem( ISymbol definition, - ImmutableArray locations, + ImmutableArray sourceLocations, Solution solution, - bool isPrimary, - bool includeHiddenLocations, - bool includeClassifiedSpans, FindReferencesSearchOptions options, - CancellationToken cancellationToken) + bool isPrimary) { // Ensure we're working with the original definition for the symbol. I.e. When we're // creating definition items, we want to create them for types like Dictionary @@ -140,45 +134,14 @@ private static async Task ToDefinitionItemAsync( var properties = GetProperties(definition, isPrimary); - // If it's a namespace, don't create any normal location. Namespaces - // come from many different sources, but we'll only show a single - // root definition node for it. That node won't be navigable. - using var sourceLocations = TemporaryArray.Empty; - if (definition.Kind != SymbolKind.Namespace) + if (sourceLocations.IsDefault) { - foreach (var location in locations) - { - if (location.IsInMetadata) - { - return DefinitionItem.CreateMetadataDefinition( - tags, displayParts, nameDisplayParts, solution, - definition, properties, displayIfNoReferences); - } - else if (location.IsInSource) - { - if (!location.IsVisibleSourceLocation() && - !includeHiddenLocations) - { - continue; - } - - var document = solution.GetDocument(location.SourceTree); - if (document != null) - { - var classificationOptions = ClassificationOptions.From(document.Project); - - var documentLocation = !includeClassifiedSpans - ? new DocumentSpan(document, location.SourceSpan) - : await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( - document, location.SourceSpan, classificationOptions, cancellationToken).ConfigureAwait(false); - - sourceLocations.Add(documentLocation); - } - } - } + return DefinitionItem.CreateMetadataDefinition( + tags, displayParts, nameDisplayParts, solution, + definition, properties, displayIfNoReferences); } - if (sourceLocations.Count == 0) + if (sourceLocations.IsEmpty) { // If we got no definition locations, then create a sentinel one // that we can display but which will not allow navigation. @@ -191,10 +154,58 @@ private static async Task ToDefinitionItemAsync( var displayableProperties = AbstractReferenceFinder.GetAdditionalFindUsagesProperties(definition); return DefinitionItem.Create( - tags, displayParts, sourceLocations.ToImmutableAndClear(), + tags, displayParts, sourceLocations, nameDisplayParts, properties, displayableProperties, displayIfNoReferences); } + private static ImmutableArray TryGetSourceLocations(ISymbol definition, Solution solution, ImmutableArray locations, bool includeHiddenLocations) + { + // If it's a namespace, don't create any normal location. Namespaces + // come from many different sources, but we'll only show a single + // root definition node for it. That node won't be navigable. + if (definition.Kind == SymbolKind.Namespace) + { + return ImmutableArray.Empty; + } + + // If it's a namespace, don't create any normal location. Namespaces + // come from many different sources, but we'll only show a single + // root definition node for it. That node won't be navigable. + using var sourceLocations = TemporaryArray.Empty; + + foreach (var location in locations) + { + if (location.IsInMetadata) + { + return default; + } + + if (location.IsInSource) + { + if (!location.IsVisibleSourceLocation() && + !includeHiddenLocations) + { + continue; + } + + var document = solution.GetDocument(location.SourceTree); + if (document != null) + { + sourceLocations.Add(new DocumentSpan(document, location.SourceSpan)); + } + } + } + + return sourceLocations.ToImmutableAndClear(); + } + + private static ValueTask> ClassifyDocumentSpansAsync(IFindUsagesContext context, ImmutableArray unclassifiedSpans, CancellationToken cancellationToken) + => unclassifiedSpans.SelectAsArrayAsync(async (documentSpan, context, cancellationToken) => + { + var options = await context.GetOptionsAsync(documentSpan.Document.Project.Language, cancellationToken).ConfigureAwait(false); + return await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync(documentSpan.Document, documentSpan.SourceSpan, options.ClassificationOptions, cancellationToken).ConfigureAwait(false); + }, context, cancellationToken); + private static ImmutableDictionary GetProperties(ISymbol definition, bool isPrimary) { var properties = ImmutableDictionary.Empty; @@ -226,9 +237,7 @@ private static ImmutableDictionary GetProperties(ISymbol definit public static async Task TryCreateSourceReferenceItemAsync( this ReferenceLocation referenceLocation, -#pragma warning disable IDE0060 // Remove unused parameter TODO IFindUsagesContext context, -#pragma warning restore IDE0060 // Remove unused parameter DefinitionItem definitionItem, bool includeHiddenLocations, CancellationToken cancellationToken) @@ -245,12 +254,10 @@ private static ImmutableDictionary GetProperties(ISymbol definit var document = referenceLocation.Document; var sourceSpan = location.SourceSpan; - // TODO: - // var options = await context.GetOptionsAsync(document.Project.Language, cancellationToken).ConfigureAwait(false); - var classificationOptions = ClassificationOptions.From(document.Project); + var options = await context.GetOptionsAsync(document.Project.Language, cancellationToken).ConfigureAwait(false); var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( - document, sourceSpan, classificationOptions, cancellationToken).ConfigureAwait(false); + document, sourceSpan, options.ClassificationOptions, cancellationToken).ConfigureAwait(false); return new SourceReferenceItem(definitionItem, documentSpan, referenceLocation.SymbolUsageInfo, referenceLocation.AdditionalProperties); } diff --git a/src/Features/Core/Portable/GoToBase/AbstractGoToBaseService.cs b/src/Features/Core/Portable/GoToBase/AbstractGoToBaseService.cs index e54e30b177fdb..bb6c43ca0113d 100644 --- a/src/Features/Core/Portable/GoToBase/AbstractGoToBaseService.cs +++ b/src/Features/Core/Portable/GoToBase/AbstractGoToBaseService.cs @@ -2,18 +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.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindUsages; +using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.GoToBase { - internal abstract partial class AbstractGoToBaseService : IGoToBaseService + internal abstract class AbstractGoToBaseService : IGoToBaseService { + protected AbstractGoToBaseService() + { + } + public async Task FindBasesAsync(IFindUsagesContext context, Document document, int position, CancellationToken cancellationToken) { var symbolAndProjectOpt = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync( @@ -48,7 +51,7 @@ await context.SetSearchTitleAsync( if (sourceDefinition != null) { var definitionItem = await sourceDefinition.ToClassifiedDefinitionItemAsync( - solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false); + context, solution, FindReferencesSearchOptions.Default, isPrimary: true, includeHiddenLocations: false, cancellationToken: cancellationToken).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); found = true; @@ -56,7 +59,7 @@ await context.SetSearchTitleAsync( else if (baseSymbol.Locations.Any(l => l.IsInMetadata)) { var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem( - solution, includeHiddenLocations: true); + solution, FindReferencesSearchOptions.Default, includeHiddenLocations: true); await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); found = true; } diff --git a/src/Features/Core/Portable/InheritanceMargin/InheritanceMarginServiceHelpers.cs b/src/Features/Core/Portable/InheritanceMargin/InheritanceMarginServiceHelpers.cs index 499d0d7f2c881..fa720ed555fe8 100644 --- a/src/Features/Core/Portable/InheritanceMargin/InheritanceMarginServiceHelpers.cs +++ b/src/Features/Core/Portable/InheritanceMargin/InheritanceMarginServiceHelpers.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindSymbols.FindReferences; using Microsoft.CodeAnalysis.FindUsages; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Remote; using Microsoft.CodeAnalysis.Shared.Extensions; @@ -39,7 +40,7 @@ public static async ValueTask> ImmutableArray<(SymbolKey symbolKey, int lineNumber)> symbolKeyAndLineNumbers, CancellationToken cancellationToken) { - var remoteClient = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); + var remoteClient = await RemoteHostClient.TryGetClientAsync(solution.Workspace.Services, cancellationToken).ConfigureAwait(false); if (remoteClient != null) { // Here the line number is also passed to the remote process. It is done in this way because @@ -362,10 +363,7 @@ private static async ValueTask CreateInherita targetSymbol = symbolInSource ?? targetSymbol; // Right now the targets are not shown in a classified way. - var definition = await ToSlimDefinitionItemAsync( - targetSymbol, - solution, - cancellationToken: cancellationToken).ConfigureAwait(false); + var definition = ToSlimDefinitionItem(targetSymbol, solution); var displayName = targetSymbol.ToDisplayString(s_displayFormat); @@ -503,16 +501,16 @@ private static async Task> GetDerivedTypesAndIm /// Otherwise, create the full non-classified DefinitionItem. Because in such case we want to display all the locations to the user /// by reusing the FAR window. /// - private static async Task ToSlimDefinitionItemAsync(ISymbol symbol, Solution solution, CancellationToken cancellationToken) + private static DefinitionItem ToSlimDefinitionItem(ISymbol symbol, Solution solution) { RoslynDebug.Assert(IsNavigableSymbol(symbol)); var locations = symbol.Locations; if (locations.Length > 1) { - return await symbol.ToNonClassifiedDefinitionItemAsync( + return symbol.ToNonClassifiedDefinitionItem( solution, - includeHiddenLocations: false, - cancellationToken: cancellationToken).ConfigureAwait(false); + FindReferencesSearchOptions.Default with { UnidirectionalHierarchyCascade = true }, + includeHiddenLocations: false); } if (locations.Length == 1) diff --git a/src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs b/src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs index a2a2396a324d0..6989aae1efb36 100644 --- a/src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs +++ b/src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs @@ -2,23 +2,14 @@ // 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.Runtime.Serialization; using Microsoft.CodeAnalysis.LanguageServices; -using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.InlineHints { + [DataContract] internal readonly record struct InlineHintsOptions( - InlineParameterHintsOptions ParameterOptions, - InlineTypeHintsOptions TypeOptions, - SymbolDescriptionOptions DisplayOptions) - { - public static InlineHintsOptions From(Project project) - => From(project.Solution.Options, project.Language); - - public static InlineHintsOptions From(OptionSet options, string language) - => new( - ParameterOptions: InlineParameterHintsOptions.From(options, language), - TypeOptions: InlineTypeHintsOptions.From(options, language), - DisplayOptions: SymbolDescriptionOptions.From(options, language)); - } + [property: DataMember(Order = 0)] InlineParameterHintsOptions ParameterOptions, + [property: DataMember(Order = 1)] InlineTypeHintsOptions TypeOptions, + [property: DataMember(Order = 2)] SymbolDescriptionOptions DisplayOptions); } diff --git a/src/Features/Core/Portable/InlineHints/InlineParameterHintsOptions.cs b/src/Features/Core/Portable/InlineHints/InlineParameterHintsOptions.cs index 5eec066d24f12..77f3a006ef6b0 100644 --- a/src/Features/Core/Portable/InlineHints/InlineParameterHintsOptions.cs +++ b/src/Features/Core/Portable/InlineHints/InlineParameterHintsOptions.cs @@ -2,107 +2,26 @@ // 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.Composition; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; +using System.Runtime.Serialization; namespace Microsoft.CodeAnalysis.InlineHints { + [DataContract] internal readonly record struct InlineParameterHintsOptions( - bool EnabledForParameters, - bool ForLiteralParameters, - bool ForIndexerParameters, - bool ForObjectCreationParameters, - bool ForOtherParameters, - bool SuppressForParametersThatDifferOnlyBySuffix, - bool SuppressForParametersThatMatchMethodIntent, - bool SuppressForParametersThatMatchArgumentName) + [property: DataMember(Order = 0)] bool EnabledForParameters = false, + [property: DataMember(Order = 1)] bool ForLiteralParameters = true, + [property: DataMember(Order = 2)] bool ForIndexerParameters = true, + [property: DataMember(Order = 3)] bool ForObjectCreationParameters = true, + [property: DataMember(Order = 4)] bool ForOtherParameters = false, + [property: DataMember(Order = 5)] bool SuppressForParametersThatDifferOnlyBySuffix = true, + [property: DataMember(Order = 6)] bool SuppressForParametersThatMatchMethodIntent = true, + [property: DataMember(Order = 7)] bool SuppressForParametersThatMatchArgumentName = true) { - public static InlineParameterHintsOptions From(Project project) - => From(project.Solution.Options, project.Language); - - public static InlineParameterHintsOptions From(OptionSet options, string language) - => new( - EnabledForParameters: options.GetOption(Metadata.EnabledForParameters, language), - ForLiteralParameters: options.GetOption(Metadata.ForLiteralParameters, language), - ForIndexerParameters: options.GetOption(Metadata.ForIndexerParameters, language), - ForObjectCreationParameters: options.GetOption(Metadata.ForObjectCreationParameters, language), - ForOtherParameters: options.GetOption(Metadata.ForOtherParameters, language), - SuppressForParametersThatDifferOnlyBySuffix: options.GetOption(Metadata.SuppressForParametersThatDifferOnlyBySuffix, language), - SuppressForParametersThatMatchMethodIntent: options.GetOption(Metadata.SuppressForParametersThatMatchMethodIntent, language), - SuppressForParametersThatMatchArgumentName: options.GetOption(Metadata.SuppressForParametersThatMatchArgumentName, language)); - - [ExportSolutionOptionProvider, Shared] - internal sealed class Metadata : IOptionProvider + public InlineParameterHintsOptions() + : this(EnabledForParameters: false) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Metadata() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - EnabledForParameters, - ForLiteralParameters, - ForIndexerParameters, - ForObjectCreationParameters, - ForOtherParameters, - SuppressForParametersThatDifferOnlyBySuffix, - SuppressForParametersThatMatchMethodIntent, - SuppressForParametersThatMatchArgumentName); - - private const string FeatureName = "InlineHintsOptions"; - - public static readonly PerLanguageOption2 EnabledForParameters = - new(FeatureName, - nameof(EnabledForParameters), - defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints")); - - public static readonly PerLanguageOption2 ForLiteralParameters = - new(FeatureName, - nameof(ForLiteralParameters), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForLiteralParameters")); - - public static readonly PerLanguageOption2 ForObjectCreationParameters = - new(FeatureName, - nameof(ForObjectCreationParameters), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForObjectCreationParameters")); - - public static readonly PerLanguageOption2 ForOtherParameters = - new(FeatureName, - nameof(ForOtherParameters), - defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForOtherParameters")); - - public static readonly PerLanguageOption2 ForIndexerParameters = - new(FeatureName, - nameof(ForIndexerParameters), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForArrayIndexers")); - - public static readonly PerLanguageOption2 SuppressForParametersThatDifferOnlyBySuffix = - new(FeatureName, - nameof(SuppressForParametersThatDifferOnlyBySuffix), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatDifferOnlyBySuffix")); - - public static readonly PerLanguageOption2 SuppressForParametersThatMatchMethodIntent = - new(FeatureName, - nameof(SuppressForParametersThatMatchMethodIntent), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchMethodIntent")); - - public static readonly PerLanguageOption2 SuppressForParametersThatMatchArgumentName = - new(FeatureName, - nameof(SuppressForParametersThatMatchArgumentName), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchArgumentName")); } + + public static readonly InlineParameterHintsOptions Default = new(); } } diff --git a/src/Features/Core/Portable/InlineHints/InlineTypeHintsOptions.cs b/src/Features/Core/Portable/InlineHints/InlineTypeHintsOptions.cs index a3fab02d85102..5043536f63a77 100644 --- a/src/Features/Core/Portable/InlineHints/InlineTypeHintsOptions.cs +++ b/src/Features/Core/Portable/InlineHints/InlineTypeHintsOptions.cs @@ -2,71 +2,22 @@ // 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.Composition; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; +using System.Runtime.Serialization; namespace Microsoft.CodeAnalysis.InlineHints { + [DataContract] internal readonly record struct InlineTypeHintsOptions( - bool EnabledForTypes, - bool ForImplicitVariableTypes, - bool ForLambdaParameterTypes, - bool ForImplicitObjectCreation) + [property: DataMember(Order = 0)] bool EnabledForTypes = false, + [property: DataMember(Order = 1)] bool ForImplicitVariableTypes = true, + [property: DataMember(Order = 2)] bool ForLambdaParameterTypes = true, + [property: DataMember(Order = 3)] bool ForImplicitObjectCreation = true) { - public static InlineTypeHintsOptions From(Project project) - => From(project.Solution.Options, project.Language); - - public static InlineTypeHintsOptions From(OptionSet options, string language) - => new( - EnabledForTypes: options.GetOption(Metadata.EnabledForTypes, language), - ForImplicitVariableTypes: options.GetOption(Metadata.ForImplicitVariableTypes, language), - ForLambdaParameterTypes: options.GetOption(Metadata.ForLambdaParameterTypes, language), - ForImplicitObjectCreation: options.GetOption(Metadata.ForImplicitObjectCreation, language)); - - [ExportSolutionOptionProvider, Shared] - internal sealed class Metadata : IOptionProvider + public InlineTypeHintsOptions() + : this(EnabledForTypes: false) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Metadata() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - EnabledForTypes, - ForImplicitVariableTypes, - ForLambdaParameterTypes, - ForImplicitObjectCreation); - - private const string FeatureName = "InlineHintsOptions"; - - public static readonly PerLanguageOption2 EnabledForTypes = - new(FeatureName, - nameof(EnabledForTypes), - defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints")); - - public static readonly PerLanguageOption2 ForImplicitVariableTypes = - new(FeatureName, - nameof(ForImplicitVariableTypes), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitVariableTypes")); - - public static readonly PerLanguageOption2 ForLambdaParameterTypes = - new(FeatureName, - nameof(ForLambdaParameterTypes), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForLambdaParameterTypes")); - - public static readonly PerLanguageOption2 ForImplicitObjectCreation = - new(FeatureName, - nameof(ForImplicitObjectCreation), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitObjectCreation")); } + + public static readonly InlineTypeHintsOptions Default = new(); } } diff --git a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/SymbolDescriptionOptions.cs b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/SymbolDescriptionOptions.cs index 83bc38eccad52..3530c39a61606 100644 --- a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/SymbolDescriptionOptions.cs +++ b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/SymbolDescriptionOptions.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using Microsoft.CodeAnalysis.Classification; -using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.QuickInfo; namespace Microsoft.CodeAnalysis.LanguageServices @@ -16,13 +15,5 @@ public static readonly SymbolDescriptionOptions Default = new( QuickInfoOptions: QuickInfoOptions.Default, ClassificationOptions: ClassificationOptions.Default); - - public static SymbolDescriptionOptions From(Project project) - => From(project.Solution.Options, project.Language); - - public static SymbolDescriptionOptions From(OptionSet options, string language) - => new( - QuickInfoOptions: QuickInfoOptions.From(options, language), - ClassificationOptions: ClassificationOptions.From(options, language)); } } diff --git a/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs b/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs index 96bf53f33c547..9542c46d2ea0e 100644 --- a/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs +++ b/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs @@ -2,55 +2,20 @@ // 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.Composition; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; +using System.Runtime.Serialization; namespace Microsoft.CodeAnalysis.QuickInfo { + [DataContract] internal readonly record struct QuickInfoOptions( - bool ShowRemarksInQuickInfo, - bool IncludeNavigationHintsInQuickInfo) + [property: DataMember(Order = 0)] bool ShowRemarksInQuickInfo = true, + [property: DataMember(Order = 1)] bool IncludeNavigationHintsInQuickInfo = true) { - [ExportSolutionOptionProvider, Shared] - internal sealed class Metadata : IOptionProvider + public QuickInfoOptions() + : this(ShowRemarksInQuickInfo: true) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Metadata() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - ShowRemarksInQuickInfo, - IncludeNavigationHintsInQuickInfo); - - private const string FeatureName = "QuickInfoOptions"; - - public static readonly PerLanguageOption2 ShowRemarksInQuickInfo = new( - FeatureName, "ShowRemarksInQuickInfo", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowRemarks")); - - public static readonly Option2 IncludeNavigationHintsInQuickInfo = new( - FeatureName, "IncludeNavigationHintsInQuickInfo", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.Specific.IncludeNavigationHintsInQuickInfo")); } - public static readonly QuickInfoOptions Default - = new( - ShowRemarksInQuickInfo: Metadata.ShowRemarksInQuickInfo.DefaultValue, - IncludeNavigationHintsInQuickInfo: Metadata.IncludeNavigationHintsInQuickInfo.DefaultValue); - - public static QuickInfoOptions From(Project project) - => From(project.Solution.Options, project.Language); - - public static QuickInfoOptions From(OptionSet options, string? language) - => new( - ShowRemarksInQuickInfo: options.GetOption(Metadata.ShowRemarksInQuickInfo, language), - IncludeNavigationHintsInQuickInfo: options.GetOption(Metadata.IncludeNavigationHintsInQuickInfo)); - + public static readonly QuickInfoOptions Default = new(); } } diff --git a/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerService.cs b/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerService.cs index 559595051f36a..719ba0d1bc6af 100644 --- a/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerService.cs +++ b/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerService.cs @@ -11,6 +11,7 @@ using Microsoft.CodeAnalysis.EmbeddedLanguages.StackFrame; using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Remote; using Roslyn.Utilities; diff --git a/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerUtilities.cs b/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerUtilities.cs index b1dd486a7cee2..b21e94b754e50 100644 --- a/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerUtilities.cs +++ b/src/Features/Core/Portable/StackTraceExplorer/StackTraceExplorerUtilities.cs @@ -5,7 +5,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.EmbeddedLanguages.StackFrame; +using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindUsages; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -61,7 +63,7 @@ internal static class StackTraceExplorerUtilities var method = await TryGetBestMatchAsync(project, fullyQualifiedTypeName, methodNode, methodArguments, methodTypeArguments, cancellationToken).ConfigureAwait(false); if (method is not null) { - return await GetDefinitionAsync(method).ConfigureAwait(false); + return GetDefinition(method); } } else @@ -79,7 +81,7 @@ internal static class StackTraceExplorerUtilities var method = await TryGetBestMatchAsync(project, fullyQualifiedTypeName, methodNode, methodArguments, methodTypeArguments, cancellationToken).ConfigureAwait(false); if (method is not null) { - return await GetDefinitionAsync(method).ConfigureAwait(false); + return GetDefinition(method); } } @@ -89,7 +91,7 @@ internal static class StackTraceExplorerUtilities // Local Functions // - Task GetDefinitionAsync(IMethodSymbol method) + DefinitionItem GetDefinition(IMethodSymbol method) { ISymbol symbol = method; if (symbolPart == StackFrameSymbolPart.ContainingType) @@ -97,7 +99,10 @@ Task GetDefinitionAsync(IMethodSymbol method) symbol = method.ContainingType; } - return symbol.ToNonClassifiedDefinitionItemAsync(solution, includeHiddenLocations: true, cancellationToken); + return symbol.ToNonClassifiedDefinitionItem( + solution, + FindReferencesSearchOptions.Default with { UnidirectionalHierarchyCascade = true }, + includeHiddenLocations: true); } } diff --git a/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs b/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs index 0a0382b980f8b..ab28f71a1f81c 100644 --- a/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs +++ b/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs @@ -134,6 +134,7 @@ static SemanticTokensHelpers() Document document, Dictionary tokenTypesToIndex, LSP.Range? range, + ClassificationOptions options, bool includeSyntacticClassifications, CancellationToken cancellationToken) { @@ -151,8 +152,6 @@ static SemanticTokensHelpers() var isFinalized = document.Project.TryGetCompilation(out var compilation) && compilation == semanticModel.Compilation; document = frozenDocument; - var options = ClassificationOptions.From(document.Project); - var classifiedSpans = await GetClassifiedSpansForDocumentAsync( document, textSpan, options, includeSyntacticClassifications, cancellationToken).ConfigureAwait(false); diff --git a/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs b/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs index d2ff7b10ab2ae..2f9513c825157 100644 --- a/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs @@ -6,7 +6,9 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Roslyn.Utilities; using LSP = Microsoft.VisualStudio.LanguageServer.Protocol; @@ -18,8 +20,10 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens /// [ExportRoslynLanguagesLspRequestHandlerProvider, Shared] [ProvidesMethod(Methods.TextDocumentSemanticTokensRangeName)] - internal class SemanticTokensRangeHandler : AbstractStatelessRequestHandler + internal sealed class SemanticTokensRangeHandler : AbstractStatelessRequestHandler { + private readonly IGlobalOptionService _globalOptions; + public override string Method => LSP.Methods.TextDocumentSemanticTokensRangeName; public override bool MutatesSolutionState => false; @@ -27,8 +31,9 @@ internal class SemanticTokensRangeHandler : AbstractStatelessRequestHandler CreateFromJsonAsync(string jsonCont analyzerReferences: parsedCommandLine.AnalyzerReferences.Select(r => new AnalyzerFileReference(r.FilePath, analyzerLoader))) .WithAnalyzerConfigDocuments(parsedCommandLine.AnalyzerConfigPaths.Select(CreateDocumentInfo)); - workspace.AddProject(projectInfo); + var solution = workspace.CurrentSolution.AddProject(projectInfo); + var compilation = await solution.GetRequiredProject(projectId).GetRequiredCompilationAsync(CancellationToken.None); + var options = GeneratorOptions.Default; - var compilation = await workspace.CurrentSolution.GetProject(projectId)!.GetRequiredCompilationAsync(CancellationToken.None); - - return new CompilerInvocation(compilation, languageServices, invocationInfo.ProjectFilePath, workspace.CurrentSolution.Options); + return new CompilerInvocation(compilation, languageServices, invocationInfo.ProjectFilePath, options); // Local methods: DocumentInfo CreateDocumentInfo(string unmappedPath) diff --git a/src/Features/Lsif/Generator/Generator.cs b/src/Features/Lsif/Generator/Generator.cs index 7a7274f736a6f..310d6729103db 100644 --- a/src/Features/Lsif/Generator/Generator.cs +++ b/src/Features/Lsif/Generator/Generator.cs @@ -14,9 +14,6 @@ using Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.ResultSetTracking; using Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Writing; using Microsoft.CodeAnalysis.LanguageServices; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.QuickInfo; -using Microsoft.CodeAnalysis.Structure; using Roslyn.Utilities; using Methods = Microsoft.VisualStudio.LanguageServer.Protocol.Methods; @@ -52,7 +49,7 @@ public static Generator CreateAndWriteCapabilitiesVertex(ILsifJsonWriter lsifJso return generator; } - public async Task GenerateForCompilationAsync(Compilation compilation, string projectPath, HostLanguageServices languageServices, OptionSet options) + public async Task GenerateForCompilationAsync(Compilation compilation, string projectPath, HostLanguageServices languageServices, GeneratorOptions options) { var projectVertex = new Graph.LsifProject(kind: GetLanguageKind(compilation.Language), new Uri(projectPath), _idFactory); _lsifJsonWriter.Write(projectVertex); @@ -68,9 +65,16 @@ public async Task GenerateForCompilationAsync(Compilation compilation, string pr // Disable navigation hints in quick info as computing them both takes too long, and they're never // even emitted in the final lsif hover information. - var workspace = languageServices.WorkspaceServices.Workspace; - workspace.SetOptions(workspace.Options.WithChangedOption( - QuickInfoOptions.Metadata.IncludeNavigationHintsInQuickInfo, false)); + options = options with + { + SymbolDescriptionOptions = options.SymbolDescriptionOptions with + { + QuickInfoOptions = options.SymbolDescriptionOptions.QuickInfoOptions with + { + IncludeNavigationHintsInQuickInfo = false + } + } + }; var tasks = new List(); foreach (var syntaxTree in compilation.SyntaxTrees) @@ -115,7 +119,7 @@ public async Task GenerateForCompilationAsync(Compilation compilation, string pr private static async Task> GenerateForDocumentAsync( SemanticModel semanticModel, HostLanguageServices languageServices, - OptionSet options, + GeneratorOptions options, IResultSetTracker topLevelSymbolsResultSetTracker, ILsifJsonWriter lsifJsonWriter, IdFactory idFactory) @@ -235,8 +239,7 @@ SymbolKind.RangeVariable or // See https://github.com/Microsoft/language-server-protocol/blob/main/indexFormat/specification.md#resultset for an example. if (symbolResultsTracker.ResultSetNeedsInformationalEdgeAdded(symbolForLinkedResultSet, Methods.TextDocumentHoverName)) { - var displayOptions = SymbolDescriptionOptions.From(options, languageServices.Language); - var hover = await HoverHandler.GetHoverAsync(semanticModel, syntaxToken.SpanStart, displayOptions, languageServices, CancellationToken.None); + var hover = await HoverHandler.GetHoverAsync(semanticModel, syntaxToken.SpanStart, options.SymbolDescriptionOptions, languageServices, CancellationToken.None); if (hover != null) { var hoverResult = new HoverResult(hover, idFactory); @@ -250,8 +253,7 @@ SymbolKind.RangeVariable or lsifJsonWriter.Write(Edge.Create("contains", documentVertex.GetId(), rangeVertices, idFactory)); // Write the folding ranges for the document. - var blockStructureOptions = BlockStructureOptions.From(options, languageServices.Language, isMetadataAsSource: false); - var foldingRanges = FoldingRangesHandler.GetFoldingRanges(syntaxTree, languageServices, blockStructureOptions, CancellationToken.None); + var foldingRanges = FoldingRangesHandler.GetFoldingRanges(syntaxTree, languageServices, options.BlockStructureOptions, CancellationToken.None); var foldingRangeResult = new FoldingRangeResult(foldingRanges, idFactory); lsifJsonWriter.Write(foldingRangeResult); lsifJsonWriter.Write(Edge.Create(Methods.TextDocumentFoldingRangeName, documentVertex.GetId(), foldingRangeResult.GetId(), idFactory)); diff --git a/src/Features/Lsif/Generator/GeneratorOptions.cs b/src/Features/Lsif/Generator/GeneratorOptions.cs new file mode 100644 index 0000000000000..4f008e6c6abe5 --- /dev/null +++ b/src/Features/Lsif/Generator/GeneratorOptions.cs @@ -0,0 +1,18 @@ +// 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 Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Structure; + +namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator +{ + internal readonly record struct GeneratorOptions( + SymbolDescriptionOptions SymbolDescriptionOptions, + BlockStructureOptions BlockStructureOptions) + { + public static readonly GeneratorOptions Default = + new(SymbolDescriptionOptions.Default, + BlockStructureOptions.Default); + } +} diff --git a/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj b/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj index fac7fa750c327..cd51006b9d436 100644 --- a/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj +++ b/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj @@ -41,6 +41,10 @@ + + + + diff --git a/src/Features/Lsif/Generator/Program.cs b/src/Features/Lsif/Generator/Program.cs index 6a87fa727d830..2b98744299bb5 100644 --- a/src/Features/Lsif/Generator/Program.cs +++ b/src/Features/Lsif/Generator/Program.cs @@ -135,6 +135,8 @@ private static async Task GenerateWithMSBuildLocatedAsync( var solution = await openAsync(msbuildWorkspace); + var options = GeneratorOptions.Default; + await logFile.WriteLineAsync($"Load completed in {solutionLoadStopwatch.Elapsed.ToDisplayString()}."); var lsifGenerator = Generator.CreateAndWriteCapabilitiesVertex(lsifWriter); @@ -151,7 +153,7 @@ private static async Task GenerateWithMSBuildLocatedAsync( await logFile.WriteLineAsync($"Fetch of compilation for {project.FilePath} completed in {compilationCreationStopwatch.Elapsed.ToDisplayString()}."); var generationForProjectStopwatch = Stopwatch.StartNew(); - await lsifGenerator.GenerateForCompilationAsync(compilation, project.FilePath, project.LanguageServices, project.Solution.Options); + await lsifGenerator.GenerateForCompilationAsync(compilation, project.FilePath, project.LanguageServices, options); generationForProjectStopwatch.Stop(); totalTimeInGenerationPhase += generationForProjectStopwatch.Elapsed; diff --git a/src/Features/Lsif/GeneratorTest/Utilities/TestLsifOutput.vb b/src/Features/Lsif/GeneratorTest/Utilities/TestLsifOutput.vb index 8a10939d1cf69..643b46cdf3c05 100644 --- a/src/Features/Lsif/GeneratorTest/Utilities/TestLsifOutput.vb +++ b/src/Features/Lsif/GeneratorTest/Utilities/TestLsifOutput.vb @@ -35,7 +35,7 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests.U ' Assert we don't have any errors to prevent any typos in the tests Assert.Empty(compilation.GetDiagnostics().Where(Function(d) d.Severity = DiagnosticSeverity.Error)) - Await lsifGenerator.GenerateForCompilationAsync(compilation, project.FilePath, project.LanguageServices, project.Solution.Options) + Await lsifGenerator.GenerateForCompilationAsync(compilation, project.FilePath, project.LanguageServices, GeneratorOptions.Default) Next End Function diff --git a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs deleted file mode 100644 index 01c26617fcc5b..0000000000000 --- a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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.Immutable; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.InlineHints; -using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Text; - -namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.InlineHints -{ - internal static class OmniSharpInlineHintsService - { - public static async Task> GetInlineHintsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) - { - var service = document.GetRequiredLanguageService(); - var options = InlineHintsOptions.From(document.Project); - - var hints = await service.GetInlineHintsAsync(document, textSpan, options, cancellationToken).ConfigureAwait(false); - return hints.SelectAsArray(static h => new OmniSharpInlineHint( - h.Span, - h.DisplayParts, - (document, cancellationToken) => h.GetDescriptionAsync(document, cancellationToken))); - } - } - - internal readonly struct OmniSharpInlineHint - { - private readonly Func>> _getDescriptionAsync; - - public OmniSharpInlineHint( - TextSpan span, - ImmutableArray displayParts, - Func>> getDescriptionAsync) - { - Span = span; - DisplayParts = displayParts; - _getDescriptionAsync = getDescriptionAsync; - } - - public readonly TextSpan Span { get; } - public readonly ImmutableArray DisplayParts { get; } - - public Task> GetDescrptionAsync(Document document, CancellationToken cancellationToken) - => _getDescriptionAsync.Invoke(document, cancellationToken); - } -} diff --git a/src/Tools/ExternalAccess/Razor/IRazorDocumentExcerptService.cs b/src/Tools/ExternalAccess/Razor/IRazorDocumentExcerptService.cs index fed026d507d1c..8f108e50f09d8 100644 --- a/src/Tools/ExternalAccess/Razor/IRazorDocumentExcerptService.cs +++ b/src/Tools/ExternalAccess/Razor/IRazorDocumentExcerptService.cs @@ -9,12 +9,6 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor { - [Obsolete("Use IRazorDocumentExcerptServiceImplementation instead")] - internal interface IRazorDocumentExcerptService - { - Task TryExcerptAsync(Document document, TextSpan span, RazorExcerptMode mode, CancellationToken cancellationToken); - } - internal interface IRazorDocumentExcerptServiceImplementation { Task TryExcerptAsync(Document document, TextSpan span, RazorExcerptMode mode, RazorClassificationOptionsWrapper options, CancellationToken cancellationToken); diff --git a/src/Tools/ExternalAccess/Razor/RazorDocumentExcerptServiceWrapper.cs b/src/Tools/ExternalAccess/Razor/RazorDocumentExcerptServiceWrapper.cs index 10dccf7614aa3..ff0cdfc1b8e6b 100644 --- a/src/Tools/ExternalAccess/Razor/RazorDocumentExcerptServiceWrapper.cs +++ b/src/Tools/ExternalAccess/Razor/RazorDocumentExcerptServiceWrapper.cs @@ -2,8 +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.ComponentModel; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Classification; @@ -15,19 +13,12 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor { internal sealed class RazorDocumentExcerptServiceWrapper : IDocumentExcerptService { - [Obsolete] - private readonly IRazorDocumentExcerptService? _legacyRazorDocumentExcerptService; - - private readonly IRazorDocumentExcerptServiceImplementation? _impl; - - [Obsolete] - public RazorDocumentExcerptServiceWrapper(IRazorDocumentExcerptService razorDocumentExcerptService) - => _legacyRazorDocumentExcerptService = razorDocumentExcerptService; + private readonly IRazorDocumentExcerptServiceImplementation _impl; public RazorDocumentExcerptServiceWrapper(IRazorDocumentExcerptServiceImplementation impl) => _impl = impl; - public async Task TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, CancellationToken cancellationToken) + public async Task TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, ClassificationOptions classificationOptions, CancellationToken cancellationToken) { var razorMode = mode switch { @@ -36,20 +27,7 @@ public RazorDocumentExcerptServiceWrapper(IRazorDocumentExcerptServiceImplementa _ => throw ExceptionUtilities.UnexpectedValue(mode), }; - RazorExcerptResult? result; - if (_impl != null) - { - var options = ClassificationOptions.From(document.Project); - result = await _impl.TryExcerptAsync(document, span, razorMode, new RazorClassificationOptionsWrapper(options), cancellationToken).ConfigureAwait(false); - } - else - { -#pragma warning disable CS0612 // Type or member is obsolete - Contract.ThrowIfNull(_legacyRazorDocumentExcerptService); - result = await _legacyRazorDocumentExcerptService.TryExcerptAsync(document, span, razorMode, cancellationToken).ConfigureAwait(false); -#pragma warning restore - } - + var result = await _impl.TryExcerptAsync(document, span, razorMode, new RazorClassificationOptionsWrapper(classificationOptions), cancellationToken).ConfigureAwait(false); var razorExcerpt = result.Value; return new ExcerptResult(razorExcerpt.Content, razorExcerpt.MappedSpan, razorExcerpt.ClassifiedSpans, razorExcerpt.Document, razorExcerpt.Span); } diff --git a/src/Tools/ExternalAccess/Razor/RazorDocumentServiceProviderWrapper.cs b/src/Tools/ExternalAccess/Razor/RazorDocumentServiceProviderWrapper.cs index b490d3b5c7089..d2817e421d4d0 100644 --- a/src/Tools/ExternalAccess/Razor/RazorDocumentServiceProviderWrapper.cs +++ b/src/Tools/ExternalAccess/Razor/RazorDocumentServiceProviderWrapper.cs @@ -51,19 +51,7 @@ public RazorDocumentServiceProviderWrapper(IRazorDocumentServiceProvider innerDo static documentServiceProvider => { var impl = documentServiceProvider.GetService(); - if (impl != null) - { - return new RazorDocumentExcerptServiceWrapper(impl); - } - -#pragma warning disable CS0612, CS0618 // Type or member is obsolete - var legacyImpl = documentServiceProvider.GetService(); - if (legacyImpl != null) - { - return new RazorDocumentExcerptServiceWrapper(legacyImpl); - } -#pragma warning restore - return null; + return (impl != null) ? new RazorDocumentExcerptServiceWrapper(impl) : null; }, _innerDocumentServiceProvider); diff --git a/src/Tools/IdeBenchmarks/RegexClassifierBenchmarks.cs b/src/Tools/IdeBenchmarks/RegexClassifierBenchmarks.cs index a544e61846fa2..c05367103a6ae 100644 --- a/src/Tools/IdeBenchmarks/RegexClassifierBenchmarks.cs +++ b/src/Tools/IdeBenchmarks/RegexClassifierBenchmarks.cs @@ -84,12 +84,11 @@ protected static async Task> GetSemanticClassific var extensionManager = document.Project.Solution.Workspace.Services.GetService(); var results = ArrayBuilder.GetInstance(); - var options = ClassificationOptions.From(document.Project); await service.AddSemanticClassificationsAsync( document, span, - options, + ClassificationOptions.Default, extensionManager.CreateNodeExtensionGetter(classifiers, c => c.SyntaxNodeTypes), extensionManager.CreateTokenExtensionGetter(classifiers, c => c.SyntaxTokenKinds), results, diff --git a/src/Tools/IdeCoreBenchmarks/ClassificationBenchmarks.cs b/src/Tools/IdeCoreBenchmarks/ClassificationBenchmarks.cs index 7b84beec18987..2f7788914422c 100644 --- a/src/Tools/IdeCoreBenchmarks/ClassificationBenchmarks.cs +++ b/src/Tools/IdeCoreBenchmarks/ClassificationBenchmarks.cs @@ -99,9 +99,8 @@ private async Task LoadSolutionAsync() protected static async Task> GetSemanticClassificationsAsync(Document document, TextSpan span) { var service = document.GetRequiredLanguageService(); - var options = ClassificationOptions.From(document.Project); using var _ = ArrayBuilder.GetInstance(out var result); - await service.AddSemanticClassificationsAsync(document, span, options, result, CancellationToken.None); + await service.AddSemanticClassificationsAsync(document, span, ClassificationOptions.Default, result, CancellationToken.None); return result.ToImmutable(); } diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index 016306b63d84c..ccd55129ca133 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -93,7 +93,7 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(InsertSlashSlashAtTheStartOfNewLinesWhenWritingSingleLineComments, SplitStringLiteralOptions.Enabled, LanguageNames.CSharp); BindToOption(InsertAsteriskAtTheStartOfNewLinesWhenWritingBlockComments, FeatureOnOffOptions.AutoInsertBlockCommentStartString, LanguageNames.CSharp); - BindToOption(ShowRemarksInQuickInfo, QuickInfoOptions.Metadata.ShowRemarksInQuickInfo, LanguageNames.CSharp); + BindToOption(ShowRemarksInQuickInfo, QuickInfoOptionsStorage.ShowRemarksInQuickInfo, LanguageNames.CSharp); BindToOption(DisplayLineSeparators, FeatureOnOffOptions.LineSeparator, LanguageNames.CSharp); // Quick Actions @@ -108,7 +108,7 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(EnableHighlightKeywords, FeatureOnOffOptions.KeywordHighlighting, LanguageNames.CSharp); BindToOption(RenameTrackingPreview, FeatureOnOffOptions.RenameTrackingPreview, LanguageNames.CSharp); - BindToOption(Underline_reassigned_variables, ClassificationOptions.Metadata.ClassifyReassignedVariables, LanguageNames.CSharp); + BindToOption(Underline_reassigned_variables, ClassificationOptionsStorage.ClassifyReassignedVariables, LanguageNames.CSharp); BindToOption(Enable_all_features_in_opened_files_from_source_generators, SourceGeneratedFileManager.Options.EnableOpeningInWorkspace, () => { // If the option has not been set by the user, check if the option is enabled from experimentation. @@ -126,12 +126,12 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(Report_invalid_placeholders_in_string_dot_format_calls, ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls, LanguageNames.CSharp); - BindToOption(Colorize_regular_expressions, ClassificationOptions.Metadata.ColorizeRegexPatterns, LanguageNames.CSharp); + BindToOption(Colorize_regular_expressions, ClassificationOptionsStorage.ColorizeRegexPatterns, LanguageNames.CSharp); BindToOption(Report_invalid_regular_expressions, RegularExpressionsOptions.ReportInvalidRegexPatterns, LanguageNames.CSharp); BindToOption(Highlight_related_regular_expression_components_under_cursor, RegularExpressionsOptions.HighlightRelatedRegexComponentsUnderCursor, LanguageNames.CSharp); BindToOption(Show_completion_list, CompletionOptionsStorage.ProvideRegexCompletions, LanguageNames.CSharp); - BindToOption(Colorize_JSON_strings, ClassificationOptions.Metadata.ColorizeJsonPatterns, LanguageNames.CSharp); + BindToOption(Colorize_JSON_strings, ClassificationOptionsStorage.ColorizeJsonPatterns, LanguageNames.CSharp); BindToOption(Report_invalid_JSON_strings, JsonFeatureOptions.ReportInvalidJsonPatterns, LanguageNames.CSharp); BindToOption(Highlight_related_JSON_components_under_cursor, JsonFeatureOptions.HighlightRelatedJsonComponentsUnderCursor, LanguageNames.CSharp); @@ -140,19 +140,19 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(DisplayAllHintsWhilePressingAltF1, InlineHintsViewOptions.DisplayAllHintsWhilePressingAltF1); BindToOption(ColorHints, InlineHintsViewOptions.ColorHints, LanguageNames.CSharp); - BindToOption(DisplayInlineParameterNameHints, InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForLiterals, InlineParameterHintsOptions.Metadata.ForLiteralParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForNewExpressions, InlineParameterHintsOptions.Metadata.ForObjectCreationParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForEverythingElse, InlineParameterHintsOptions.Metadata.ForOtherParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForIndexers, InlineParameterHintsOptions.Metadata.ForIndexerParameters, LanguageNames.CSharp); - BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchMethodIntent, LanguageNames.CSharp); - BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineParameterHintsOptions.Metadata.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.CSharp); - BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchArgumentName, LanguageNames.CSharp); + BindToOption(DisplayInlineParameterNameHints, InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForLiterals, InlineHintsOptionsStorage.ForLiteralParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForNewExpressions, InlineHintsOptionsStorage.ForObjectCreationParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForEverythingElse, InlineHintsOptionsStorage.ForOtherParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForIndexers, InlineHintsOptionsStorage.ForIndexerParameters, LanguageNames.CSharp); + BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineHintsOptionsStorage.SuppressForParametersThatMatchMethodIntent, LanguageNames.CSharp); + BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineHintsOptionsStorage.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.CSharp); + BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineHintsOptionsStorage.SuppressForParametersThatMatchArgumentName, LanguageNames.CSharp); - BindToOption(DisplayInlineTypeHints, InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp); - BindToOption(ShowHintsForVariablesWithInferredTypes, InlineTypeHintsOptions.Metadata.ForImplicitVariableTypes, LanguageNames.CSharp); - BindToOption(ShowHintsForLambdaParameterTypes, InlineTypeHintsOptions.Metadata.ForLambdaParameterTypes, LanguageNames.CSharp); - BindToOption(ShowHintsForImplicitObjectCreation, InlineTypeHintsOptions.Metadata.ForImplicitObjectCreation, LanguageNames.CSharp); + BindToOption(DisplayInlineTypeHints, InlineHintsOptionsStorage.EnabledForTypes, LanguageNames.CSharp); + BindToOption(ShowHintsForVariablesWithInferredTypes, InlineHintsOptionsStorage.ForImplicitVariableTypes, LanguageNames.CSharp); + BindToOption(ShowHintsForLambdaParameterTypes, InlineHintsOptionsStorage.ForLambdaParameterTypes, LanguageNames.CSharp); + BindToOption(ShowHintsForImplicitObjectCreation, InlineHintsOptionsStorage.ForImplicitObjectCreation, LanguageNames.CSharp); // Leave the null converter here to make sure if the option value is get from the storage (if it is null), the feature will be enabled BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.CSharp, () => true); @@ -232,7 +232,7 @@ private void Enable_pull_diagnostics_experimental_requires_restart_Indeterminate private void UpdateInlineHintsOptions() { - var enabledForParameters = this.OptionStore.GetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp); + var enabledForParameters = this.OptionStore.GetOption(InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.CSharp); ShowHintsForLiterals.IsEnabled = enabledForParameters; ShowHintsForNewExpressions.IsEnabled = enabledForParameters; ShowHintsForEverythingElse.IsEnabled = enabledForParameters; @@ -241,7 +241,7 @@ private void UpdateInlineHintsOptions() SuppressHintsWhenParameterNamesDifferOnlyBySuffix.IsEnabled = enabledForParameters; SuppressHintsWhenParameterNamesMatchArgumentNames.IsEnabled = enabledForParameters; - var enabledForTypes = this.OptionStore.GetOption(InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp); + var enabledForTypes = this.OptionStore.GetOption(InlineHintsOptionsStorage.EnabledForTypes, LanguageNames.CSharp); ShowHintsForVariablesWithInferredTypes.IsEnabled = enabledForTypes; ShowHintsForLambdaParameterTypes.IsEnabled = enabledForTypes; ShowHintsForImplicitObjectCreation.IsEnabled = enabledForTypes; @@ -249,25 +249,25 @@ private void UpdateInlineHintsOptions() private void DisplayInlineParameterNameHints_Checked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp, true); + this.OptionStore.SetOption(InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.CSharp, true); UpdateInlineHintsOptions(); } private void DisplayInlineParameterNameHints_Unchecked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp, false); + this.OptionStore.SetOption(InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.CSharp, false); UpdateInlineHintsOptions(); } private void DisplayInlineTypeHints_Checked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp, true); + this.OptionStore.SetOption(InlineHintsOptionsStorage.EnabledForTypes, LanguageNames.CSharp, true); UpdateInlineHintsOptions(); } private void DisplayInlineTypeHints_Unchecked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp, false); + this.OptionStore.SetOption(InlineHintsOptionsStorage.EnabledForTypes, LanguageNames.CSharp, false); UpdateInlineHintsOptions(); } } diff --git a/src/VisualStudio/Core/Def/Implementation/CodeLens/RemoteCodeLensReferencesService.cs b/src/VisualStudio/Core/Def/Implementation/CodeLens/RemoteCodeLensReferencesService.cs index d28f640f45551..61b9851efeb38 100644 --- a/src/VisualStudio/Core/Def/Implementation/CodeLens/RemoteCodeLensReferencesService.cs +++ b/src/VisualStudio/Core/Def/Implementation/CodeLens/RemoteCodeLensReferencesService.cs @@ -9,10 +9,12 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.CodeLens; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Remote; using Microsoft.CodeAnalysis.Text; @@ -23,10 +25,13 @@ namespace Microsoft.VisualStudio.LanguageServices.CodeLens [ExportWorkspaceService(typeof(ICodeLensReferencesService), layer: ServiceLayer.Host), Shared] internal sealed class RemoteCodeLensReferencesService : ICodeLensReferencesService { + private readonly IGlobalOptionService _globalOptions; + [ImportingConstructor] [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public RemoteCodeLensReferencesService() + public RemoteCodeLensReferencesService(IGlobalOptionService globalOptions) { + _globalOptions = globalOptions; } public ValueTask GetProjectCodeLensVersionAsync(Solution solution, ProjectId projectId, CancellationToken cancellationToken) @@ -131,7 +136,7 @@ public ValueTask GetProjectCodeLensVersionAsync(Solution solution, } } - private static async Task> FixUpDescriptorsAsync( + private async Task> FixUpDescriptorsAsync( Solution solution, ImmutableArray descriptors, CancellationToken cancellationToken) { using var _ = ArrayBuilder.GetInstance(out var list); @@ -175,8 +180,9 @@ private static async Task> FixUpDesc continue; } - var referenceExcerpt = await excerpter.TryExcerptAsync(document, span, ExcerptMode.SingleLine, cancellationToken).ConfigureAwait(false); - var tooltipExcerpt = await excerpter.TryExcerptAsync(document, span, ExcerptMode.Tooltip, cancellationToken).ConfigureAwait(false); + var classificationOptions = _globalOptions.GetClassificationOptions(document.Project.Language); + var referenceExcerpt = await excerpter.TryExcerptAsync(document, span, ExcerptMode.SingleLine, classificationOptions, cancellationToken).ConfigureAwait(false); + var tooltipExcerpt = await excerpter.TryExcerptAsync(document, span, ExcerptMode.Tooltip, classificationOptions, cancellationToken).ConfigureAwait(false); var (text, start, length) = GetReferenceInfo(referenceExcerpt, descriptor); var (before1, before2, after1, after2) = GetReferenceTexts(referenceExcerpt, tooltipExcerpt, descriptor); diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index 0accad77828d9..05a7bc6ef1f08 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -352,7 +352,7 @@ public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definitio CancellationToken cancellationToken) { var document = documentSpan.Document; - var options = ClassificationOptions.From(document.Project); + var options = _globalOptions.GetClassificationOptions(document.Project.Language); var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var (excerptResult, lineText) = await ExcerptAsync(sourceText, documentSpan, options, cancellationToken).ConfigureAwait(false); @@ -387,7 +387,7 @@ public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definitio var excerptService = documentSpan.Document.Services.GetService(); if (excerptService != null) { - var result = await excerptService.TryExcerptAsync(documentSpan.Document, documentSpan.SourceSpan, ExcerptMode.SingleLine, cancellationToken).ConfigureAwait(false); + var result = await excerptService.TryExcerptAsync(documentSpan.Document, documentSpan.SourceSpan, ExcerptMode.SingleLine, options, cancellationToken).ConfigureAwait(false); if (result != null) { return (result.Value, AbstractDocumentSpanEntry.GetLineContainingPosition(result.Value.Content, result.Value.MappedSpan.Start)); diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs index 9e13aa45320f5..a4ee794ebe11b 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs @@ -226,7 +226,8 @@ private DisposableToolTip CreateDisposableToolTip(Document document, TextSpan so var excerptService = document.Services.GetService(); if (excerptService != null) { - var excerpt = Presenter.ThreadingContext.JoinableTaskFactory.Run(() => excerptService.TryExcerptAsync(document, sourceSpan, ExcerptMode.Tooltip, CancellationToken.None)); + var classificationOptions = Presenter._globalOptions.GetClassificationOptions(document.Project.Language); + var excerpt = Presenter.ThreadingContext.JoinableTaskFactory.Run(() => excerptService.TryExcerptAsync(document, sourceSpan, ExcerptMode.Tooltip, classificationOptions, CancellationToken.None)); if (excerpt != null) { // get tooltip from excerpt service diff --git a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocument.DocumentServiceProvider.cs b/src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocument.DocumentServiceProvider.cs index ec2af8bb6c4b3..63baee6048d2b 100644 --- a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocument.DocumentServiceProvider.cs +++ b/src/VisualStudio/Core/Def/Implementation/Venus/ContainedDocument.DocumentServiceProvider.cs @@ -126,14 +126,14 @@ public override async Task> MapSpansAsync( } } - private class DocumentExcerpter : IDocumentExcerptService + private sealed class DocumentExcerpter : IDocumentExcerptService { private readonly ITextBuffer _primaryBuffer; public DocumentExcerpter(ITextBuffer primaryBuffer) => _primaryBuffer = primaryBuffer; - public async Task TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, CancellationToken cancellationToken) + public async Task TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, ClassificationOptions classificationOptions, CancellationToken cancellationToken) { // REVIEW: for now, we keep document here due to open file case, otherwise, we need to create new DocumentExcerpter for every char user types. var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); @@ -165,8 +165,7 @@ public DocumentExcerpter(ITextBuffer primaryBuffer) return null; } - var options = ClassificationOptions.From(document.Project); - var classifiedSpansOnContent = await GetClassifiedSpansOnContentAsync(document, roslynSnapshot, contentSpanOnPrimarySnapshot.Value, options, cancellationToken).ConfigureAwait(false); + var classifiedSpansOnContent = await GetClassifiedSpansOnContentAsync(document, roslynSnapshot, contentSpanOnPrimarySnapshot.Value, classificationOptions, cancellationToken).ConfigureAwait(false); // the default implementation has no idea how to classify the primary snapshot return new ExcerptResult(content, spanOnContent, classifiedSpansOnContent, document, span); diff --git a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage.cs b/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage.cs index 25ee249b8db8e..5c9941cab3d4f 100644 --- a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage.cs +++ b/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Formatting.Rules; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.Editor; @@ -66,28 +67,6 @@ internal partial class ContainedLanguage // flickering. private readonly ITagAggregator _bufferTagAggregator; - [Obsolete("This is a compatibility shim for TypeScript; please do not use it.")] - internal ContainedLanguage( - IVsTextBufferCoordinator bufferCoordinator, - IComponentModel componentModel, - VisualStudioProject? project, - IVsHierarchy hierarchy, - uint itemid, - VisualStudioProjectTracker? projectTrackerOpt, - ProjectId projectId, - Guid languageServiceGuid, - AbstractFormattingRule? vbHelperFormattingRule = null) - : this(bufferCoordinator, - componentModel, - projectTrackerOpt?.Workspace ?? componentModel.GetService(), - projectId, - project, - GetFilePathFromHierarchyAndItemId(hierarchy, itemid), - languageServiceGuid, - vbHelperFormattingRule) - { - } - public static string GetFilePathFromHierarchyAndItemId(IVsHierarchy hierarchy, uint itemid) { if (!ErrorHandler.Succeeded(((IVsProject)hierarchy).GetMkDocument(itemid, out var filePath))) @@ -114,12 +93,12 @@ internal ContainedLanguage( Guid languageServiceGuid, AbstractFormattingRule? vbHelperFormattingRule = null) { - this.BufferCoordinator = bufferCoordinator; - this.ComponentModel = componentModel; - this.Project = project; + BufferCoordinator = bufferCoordinator; + ComponentModel = componentModel; + Project = project; _languageServiceGuid = languageServiceGuid; - this.Workspace = workspace; + Workspace = workspace; _editorAdaptersFactoryService = componentModel.GetService(); _diagnosticAnalyzerService = componentModel.GetService(); diff --git a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage`2.cs b/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage`2.cs deleted file mode 100644 index 968bd47b00949..0000000000000 --- a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguage`2.cs +++ /dev/null @@ -1,71 +0,0 @@ -// 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. - -#nullable disable - -using System; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Formatting.Rules; -using Microsoft.VisualStudio.ComponentModelHost; -using Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService; -using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TextManager.Interop; -using Roslyn.Utilities; - -namespace Microsoft.VisualStudio.LanguageServices.Implementation.Venus -{ - [Obsolete("This is a compatibility shim for TypeScript; please do not use it.")] - internal partial class ContainedLanguage : ContainedLanguage - where TPackage : AbstractPackage - where TLanguageService : AbstractLanguageService - { - [Obsolete("This is a compatibility shim for TypeScript; please do not use it.")] - public ContainedLanguage( - IVsTextBufferCoordinator bufferCoordinator, - IComponentModel componentModel, - AbstractProject project, - IVsHierarchy hierarchy, - uint itemid, - TLanguageService languageService, - SourceCodeKind sourceCodeKind, - IFormattingRule vbHelperFormattingRule, - Workspace workspace) - : base(bufferCoordinator, - componentModel, - project.VisualStudioProject, - hierarchy, - itemid, - project.ProjectTracker, - project.Id, - languageService.LanguageServiceId, - vbHelperFormattingRule: null) - { - Contract.ThrowIfTrue(vbHelperFormattingRule != null); - } - - [Obsolete("This is a compatibility shim for TypeScript; please do not use it.")] - public ContainedLanguage( - IVsTextBufferCoordinator bufferCoordinator, - IComponentModel componentModel, - AbstractProject project, - IVsHierarchy hierarchy, - uint itemid, - TLanguageService languageService, - SourceCodeKind sourceCodeKind, - IFormattingRule vbHelperFormattingRule) - : base(bufferCoordinator, - componentModel, - project.VisualStudioProject, - hierarchy, - itemid, - projectTrackerOpt: null, - project.VisualStudioProject.Id, - languageService.LanguageServiceId, - vbHelperFormattingRule: null) - { - Contract.ThrowIfTrue(vbHelperFormattingRule != null); - } - } -} diff --git a/src/VisualStudio/Core/Def/Telemetry/SyntaxTreeConfigurationOptions.cs b/src/VisualStudio/Core/Def/Telemetry/SyntaxTreeConfigurationOptions.cs deleted file mode 100644 index 8fbc9f8ad1437..0000000000000 --- a/src/VisualStudio/Core/Def/Telemetry/SyntaxTreeConfigurationOptions.cs +++ /dev/null @@ -1,39 +0,0 @@ -// 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.Immutable; -using System.Composition; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; - -namespace Microsoft.CodeAnalysis -{ - [ExportSolutionOptionProvider, Shared] - internal class WorkspaceConfigurationOptions : IOptionProvider - { - /// - /// Disables if the workspace creates recoverable trees when from its s. - /// - public static readonly Option2 DisableRecoverableTrees = new( - nameof(WorkspaceConfigurationOptions), nameof(DisableRecoverableTrees), defaultValue: false, - new FeatureFlagStorageLocation("Roslyn.DisableRecoverableTrees")); - - public static readonly Option2 DisableProjectCacheService = new( - nameof(WorkspaceConfigurationOptions), nameof(DisableProjectCacheService), defaultValue: false, - new FeatureFlagStorageLocation("Roslyn.DisableProjectCacheService")); - - ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( - DisableRecoverableTrees, - DisableProjectCacheService); - - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public WorkspaceConfigurationOptions() - { - } - } -} diff --git a/src/VisualStudio/Core/Def/Telemetry/VisualStudioSyntaxTreeConfigurationService.cs b/src/VisualStudio/Core/Def/Telemetry/VisualStudioSyntaxTreeConfigurationService.cs index 31e10e705f76a..603f0002cff4a 100644 --- a/src/VisualStudio/Core/Def/Telemetry/VisualStudioSyntaxTreeConfigurationService.cs +++ b/src/VisualStudio/Core/Def/Telemetry/VisualStudioSyntaxTreeConfigurationService.cs @@ -3,13 +3,11 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Immutable; using System.Composition; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; namespace Microsoft.VisualStudio.LanguageServices.Telemetry { @@ -31,29 +29,18 @@ public bool DisableRecoverableTrees public bool DisableProjectCacheService => _globalOptions.GetOption(OptionsMetadata.DisableProjectCacheService); - [ExportSolutionOptionProvider, Shared] - internal sealed class OptionsMetadata : IOptionProvider + internal sealed class OptionsMetadata { /// /// Disables if the workspace creates recoverable trees when from its s. /// public static readonly Option2 DisableRecoverableTrees = new( - nameof(WorkspaceConfigurationOptions), nameof(DisableRecoverableTrees), defaultValue: false, + "WorkspaceConfigurationOptions", "DisableRecoverableTrees", defaultValue: false, new FeatureFlagStorageLocation("Roslyn.DisableRecoverableTrees")); public static readonly Option2 DisableProjectCacheService = new( - nameof(WorkspaceConfigurationOptions), nameof(DisableProjectCacheService), defaultValue: false, + "WorkspaceConfigurationOptions", "DisableProjectCacheService", defaultValue: false, new FeatureFlagStorageLocation("Roslyn.DisableProjectCacheService")); - - ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( - DisableRecoverableTrees, - DisableProjectCacheService); - - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public OptionsMetadata() - { - } } } } diff --git a/src/VisualStudio/Core/Def/ValueTracking/ValueTrackedTreeItemViewModel.cs b/src/VisualStudio/Core/Def/ValueTracking/ValueTrackedTreeItemViewModel.cs index f9a04d1304437..945ae9e206746 100644 --- a/src/VisualStudio/Core/Def/ValueTracking/ValueTrackedTreeItemViewModel.cs +++ b/src/VisualStudio/Core/Def/ValueTracking/ValueTrackedTreeItemViewModel.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.ValueTracking; using Microsoft.VisualStudio.Language.Intellisense; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.VisualStudio.Shell; using Microsoft.CodeAnalysis.Classification; @@ -25,6 +24,7 @@ internal sealed class ValueTrackedTreeItemViewModel : TreeItemViewModel private readonly IGlyphService _glyphService; private readonly IValueTrackingService _valueTrackingService; private readonly ValueTrackedItem _trackedItem; + private readonly IGlobalOptionService _globalOptions; public override bool IsNodeExpanded { @@ -43,6 +43,7 @@ private ValueTrackedTreeItemViewModel( ValueTrackingTreeViewModel treeViewModel, IGlyphService glyphService, IValueTrackingService valueTrackingService, + IGlobalOptionService globalOptions, IThreadingContext threadingContext, string fileName, ImmutableArray children) @@ -64,6 +65,7 @@ private ValueTrackedTreeItemViewModel( _solution = solution; _glyphService = glyphService; _valueTrackingService = valueTrackingService; + _globalOptions = globalOptions; if (children.IsEmpty) { @@ -84,13 +86,14 @@ internal static async ValueTask CreateAsync( ValueTrackingTreeViewModel treeViewModel, IGlyphService glyphService, IValueTrackingService valueTrackingService, + IGlobalOptionService globalOptions, IThreadingContext threadingContext, CancellationToken cancellationToken) { var document = solution.GetRequiredDocument(item.DocumentId); var fileName = document.FilePath ?? document.Name; - var options = ClassificationOptions.From(document.Project); + var options = globalOptions.GetClassificationOptions(document.Project.Language); var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync(document, item.Span, options, cancellationToken).ConfigureAwait(false); var classificationResult = await ClassifiedSpansAndHighlightSpanFactory.ClassifyAsync(documentSpan, options, cancellationToken).ConfigureAwait(false); var classifiedSpans = classificationResult.ClassifiedSpans; @@ -102,6 +105,7 @@ internal static async ValueTask CreateAsync( treeViewModel, glyphService, valueTrackingService, + globalOptions, threadingContext, fileName, children: ImmutableArray.Empty); @@ -169,7 +173,7 @@ private async Task> CalculateChildrenAsync(Can cancellationToken).ConfigureAwait(false); return await valueTrackedItems.SelectAsArrayAsync((item, cancellationToken) => - CreateAsync(_solution, item, TreeViewModel, _glyphService, _valueTrackingService, ThreadingContext, cancellationToken), cancellationToken).ConfigureAwait(false); + CreateAsync(_solution, item, TreeViewModel, _glyphService, _valueTrackingService, _globalOptions, ThreadingContext, cancellationToken), cancellationToken).ConfigureAwait(false); } } } diff --git a/src/VisualStudio/Core/Def/ValueTracking/ValueTrackingCommandHandler.cs b/src/VisualStudio/Core/Def/ValueTracking/ValueTrackingCommandHandler.cs index e77986635bc75..735d18a399119 100644 --- a/src/VisualStudio/Core/Def/ValueTracking/ValueTrackingCommandHandler.cs +++ b/src/VisualStudio/Core/Def/ValueTracking/ValueTrackingCommandHandler.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.ValueTracking; @@ -41,6 +42,7 @@ internal class ValueTrackingCommandHandler : ICommandHandler "Go to value tracking"; @@ -154,11 +158,11 @@ private async Task ShowToolWindowAsync(ITextView textView, ISymbol selectedSymbo var childItems = await valueTrackingService.TrackValueSourceAsync(solution, item, cancellationToken).ConfigureAwait(false); var childViewModels = await childItems.SelectAsArrayAsync((item, cancellationToken) => - ValueTrackedTreeItemViewModel.CreateAsync(solution, item, toolWindow.ViewModel, _glyphService, valueTrackingService, _threadingContext, cancellationToken), cancellationToken).ConfigureAwait(false); + ValueTrackedTreeItemViewModel.CreateAsync(solution, item, toolWindow.ViewModel, _glyphService, valueTrackingService, _globalOptions, _threadingContext, cancellationToken), cancellationToken).ConfigureAwait(false); RoslynDebug.AssertNotNull(location.SourceTree); var document = solution.GetRequiredDocument(location.SourceTree); - var options = ClassificationOptions.From(document.Project); + var options = _globalOptions.GetClassificationOptions(document.Project.Language); var sourceText = await location.SourceTree.GetTextAsync(cancellationToken).ConfigureAwait(false); var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync(document, location.SourceSpan, options, cancellationToken).ConfigureAwait(false); diff --git a/src/VisualStudio/Core/Test/Venus/DocumentServiceTests.vb b/src/VisualStudio/Core/Test/Venus/DocumentServiceTests.vb index dcb7bc67b4e56..b33a5fcb23484 100644 --- a/src/VisualStudio/Core/Test/Venus/DocumentServiceTests.vb +++ b/src/VisualStudio/Core/Test/Venus/DocumentServiceTests.vb @@ -4,6 +4,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis +Imports Microsoft.CodeAnalysis.Classification Imports Microsoft.CodeAnalysis.Editor.UnitTests Imports Microsoft.CodeAnalysis.Editor.UnitTests.Classification Imports Microsoft.CodeAnalysis.Editor.UnitTests.Classification.FormattedClassifications @@ -115,7 +116,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Venus Dim service = New ContainedDocument.DocumentServiceProvider(projectedDocument.GetTextBuffer()) Dim excerptService = service.GetService(Of IDocumentExcerptService) - Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.SingleLine, CancellationToken.None) + Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.SingleLine, ClassificationOptions.Default, CancellationToken.None) Assert.True(result.HasValue) Dim content = result.Value.Content.ToString() @@ -154,7 +155,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Venus Dim excerptService = service.GetService(Of IDocumentExcerptService) ' make sure single line buffer doesn't throw on ExcerptMode.Tooltip - Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.Tooltip, CancellationToken.None) + Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.Tooltip, ClassificationOptions.Default, CancellationToken.None) Assert.True(result.HasValue) Dim content = result.Value.Content.ToString() @@ -201,7 +202,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Venus Dim service = New ContainedDocument.DocumentServiceProvider(projectedDocument.GetTextBuffer()) Dim excerptService = service.GetService(Of IDocumentExcerptService) - Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.Tooltip, CancellationToken.None) + Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.Tooltip, ClassificationOptions.Default, CancellationToken.None) Assert.True(result.HasValue) Dim content = result.Value.Content.ToString() @@ -254,7 +255,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Venus Dim service = New ContainedDocument.DocumentServiceProvider(projectedDocument.GetTextBuffer()) Dim excerptService = service.GetService(Of IDocumentExcerptService) - Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.SingleLine, CancellationToken.None) + Dim result = Await excerptService.TryExcerptAsync(workspace.CurrentSolution.GetDocument(subjectDocument.Id), GetNamedSpan(subjectDocument), ExcerptMode.SingleLine, ClassificationOptions.Default, CancellationToken.None) Assert.True(result.HasValue) Dim content = result.Value.Content.ToString() diff --git a/src/VisualStudio/Core/Test/Venus/DocumentService_IntegrationTests.vb b/src/VisualStudio/Core/Test/Venus/DocumentService_IntegrationTests.vb index a018f172cbfe7..39787dd58804c 100644 --- a/src/VisualStudio/Core/Test/Venus/DocumentService_IntegrationTests.vb +++ b/src/VisualStudio/Core/Test/Venus/DocumentService_IntegrationTests.vb @@ -134,7 +134,7 @@ class {|Definition:C1|} Using workspace = TestWorkspace.Create(input, documentServiceProvider:=TestDocumentServiceProvider.Instance) - Dim codelensService = New RemoteCodeLensReferencesService() + Dim codelensService = New RemoteCodeLensReferencesService(workspace.GlobalOptions) Dim originalDocument = workspace.Documents.First(Function(d) d.AnnotatedSpans.ContainsKey("Original")) @@ -304,7 +304,7 @@ class { } Public Shared ReadOnly Instance As Excerpter = New Excerpter() - Public Async Function TryExcerptAsync(document As Document, span As TextSpan, mode As ExcerptMode, cancellationToken As CancellationToken) As Task(Of ExcerptResult?) Implements IDocumentExcerptService.TryExcerptAsync + Public Async Function TryExcerptAsync(document As Document, span As TextSpan, mode As ExcerptMode, classificationOptions As ClassificationOptions, cancellationToken As CancellationToken) As Task(Of ExcerptResult?) Implements IDocumentExcerptService.TryExcerptAsync Dim testWorkspace = DirectCast(document.Project.Solution.Workspace, TestWorkspace) Dim testDocument = testWorkspace.GetTestDocument(document.Id) diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 3aa576ed24e8f..5e96a8b468072 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -107,9 +107,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options BindToOption(EnableLineCommit, FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic) BindToOption(AutomaticInsertionOfInterfaceAndMustOverrideMembers, FeatureOnOffOptions.AutomaticInsertionOfAbstractOrInterfaceMembers, LanguageNames.VisualBasic) BindToOption(RenameTrackingPreview, FeatureOnOffOptions.RenameTrackingPreview, LanguageNames.VisualBasic) - BindToOption(ShowRemarksInQuickInfo, QuickInfoOptions.Metadata.ShowRemarksInQuickInfo, LanguageNames.VisualBasic) + BindToOption(ShowRemarksInQuickInfo, QuickInfoOptionsStorage.ShowRemarksInQuickInfo, LanguageNames.VisualBasic) BindToOption(Report_invalid_placeholders_in_string_dot_format_calls, ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls, LanguageNames.VisualBasic) - BindToOption(Underline_reassigned_variables, ClassificationOptions.Metadata.ClassifyReassignedVariables, LanguageNames.VisualBasic) + BindToOption(Underline_reassigned_variables, ClassificationOptionsStorage.ClassifyReassignedVariables, LanguageNames.VisualBasic) ' Go To Definition BindToOption(NavigateToObjectBrowser, VisualStudioNavigationOptions.NavigateToObjectBrowser, LanguageNames.VisualBasic) @@ -120,12 +120,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options End Function) ' Regular expressions - BindToOption(Colorize_regular_expressions, ClassificationOptions.Metadata.ColorizeRegexPatterns, LanguageNames.VisualBasic) + BindToOption(Colorize_regular_expressions, ClassificationOptionsStorage.ColorizeRegexPatterns, LanguageNames.VisualBasic) BindToOption(Report_invalid_regular_expressions, RegularExpressionsOptions.ReportInvalidRegexPatterns, LanguageNames.VisualBasic) BindToOption(Highlight_related_regular_expression_components_under_cursor, RegularExpressionsOptions.HighlightRelatedRegexComponentsUnderCursor, LanguageNames.VisualBasic) BindToOption(Show_completion_list, CompletionOptionsStorage.ProvideRegexCompletions, LanguageNames.VisualBasic) - BindToOption(Colorize_JSON_strings, ClassificationOptions.Metadata.ColorizeJsonPatterns, LanguageNames.VisualBasic) + BindToOption(Colorize_JSON_strings, ClassificationOptionsStorage.ColorizeJsonPatterns, LanguageNames.VisualBasic) BindToOption(Report_invalid_JSON_strings, JsonFeatureOptions.ReportInvalidJsonPatterns, LanguageNames.VisualBasic) BindToOption(Highlight_related_JSON_components_under_cursor, JsonFeatureOptions.HighlightRelatedJsonComponentsUnderCursor, LanguageNames.VisualBasic) @@ -146,14 +146,14 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options BindToOption(DisplayAllHintsWhilePressingAltF1, InlineHintsViewOptions.DisplayAllHintsWhilePressingAltF1) BindToOption(ColorHints, InlineHintsViewOptions.ColorHints, LanguageNames.VisualBasic) - BindToOption(DisplayInlineParameterNameHints, InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForLiterals, InlineParameterHintsOptions.Metadata.ForLiteralParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForNewExpressions, InlineParameterHintsOptions.Metadata.ForObjectCreationParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForEverythingElse, InlineParameterHintsOptions.Metadata.ForOtherParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForIndexers, InlineParameterHintsOptions.Metadata.ForIndexerParameters, LanguageNames.VisualBasic) - BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchMethodIntent, LanguageNames.VisualBasic) - BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineParameterHintsOptions.Metadata.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.VisualBasic) - BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchArgumentName, LanguageNames.VisualBasic) + BindToOption(DisplayInlineParameterNameHints, InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForLiterals, InlineHintsOptionsStorage.ForLiteralParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForNewExpressions, InlineHintsOptionsStorage.ForObjectCreationParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForEverythingElse, InlineHintsOptionsStorage.ForOtherParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForIndexers, InlineHintsOptionsStorage.ForIndexerParameters, LanguageNames.VisualBasic) + BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineHintsOptionsStorage.SuppressForParametersThatMatchMethodIntent, LanguageNames.VisualBasic) + BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineHintsOptionsStorage.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.VisualBasic) + BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineHintsOptionsStorage.SuppressForParametersThatMatchArgumentName, LanguageNames.VisualBasic) BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.VisualBasic, Function() @@ -179,7 +179,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options End Sub Private Sub UpdateInlineHintsOptions() - Dim enabledForParameters = Me.OptionStore.GetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic) <> False + Dim enabledForParameters = Me.OptionStore.GetOption(InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.VisualBasic) <> False ShowHintsForLiterals.IsEnabled = enabledForParameters ShowHintsForNewExpressions.IsEnabled = enabledForParameters ShowHintsForEverythingElse.IsEnabled = enabledForParameters @@ -190,12 +190,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options End Sub Private Sub DisplayInlineParameterNameHints_Checked() - Me.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic, True) + Me.OptionStore.SetOption(InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.VisualBasic, True) UpdateInlineHintsOptions() End Sub Private Sub DisplayInlineParameterNameHints_Unchecked() - Me.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic, False) + Me.OptionStore.SetOption(InlineHintsOptionsStorage.EnabledForParameters, LanguageNames.VisualBasic, False) UpdateInlineHintsOptions() End Sub End Class diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Extensions/SymbolExtensions.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Extensions/SymbolExtensions.cs index 4319c7d558b2d..e2f9e178be106 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Extensions/SymbolExtensions.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Extensions/SymbolExtensions.cs @@ -21,7 +21,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Xaml.Implementation.LanguageSe { internal static class SymbolExtensions { - public static async Task> GetDescriptionAsync(this ISymbol symbol, TextDocument document, CancellationToken cancellationToken) + public static async Task> GetDescriptionAsync(this ISymbol symbol, TextDocument document, SymbolDescriptionOptions options, CancellationToken cancellationToken) { if (symbol == null) { @@ -55,7 +55,6 @@ public static async Task> GetDescriptionAsync(this ISymb } var services = codeProject.Solution.Workspace.Services; - var options = SymbolDescriptionOptions.From(document.Project); var quickInfo = await QuickInfoUtilities.CreateQuickInfoItemAsync(services, semanticModel, span: default, ImmutableArray.Create(symbol), options, cancellationToken).ConfigureAwait(false); var builder = new List(); foreach (var section in quickInfo.Sections) diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionResolveHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionResolveHandler.cs index 0714f5e8ad27a..4bbf661b4a744 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionResolveHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionResolveHandler.cs @@ -10,6 +10,8 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.Xaml; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.LanguageServer; using Microsoft.CodeAnalysis.LanguageServer.Handler; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -29,6 +31,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Xaml.LanguageServer.Handler [ProvidesMethod(LSP.Methods.TextDocumentCompletionResolveName)] internal class CompletionResolveHandler : AbstractStatelessRequestHandler { + private readonly IGlobalOptionService _globalOptions; + public override string Method => LSP.Methods.TextDocumentCompletionResolveName; public override bool MutatesSolutionState => false; @@ -36,8 +40,9 @@ internal class CompletionResolveHandler : AbstractStatelessRequestHandler null; @@ -77,7 +82,8 @@ public CompletionResolveHandler() return completionItem; } - var description = await symbol.GetDescriptionAsync(document, cancellationToken).ConfigureAwait(false); + var options = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language); + var description = await symbol.GetDescriptionAsync(document, options, cancellationToken).ConfigureAwait(false); vsCompletionItem.Description = new ClassifiedTextElement(description.Select(tp => new ClassifiedTextRun(tp.Tag.ToClassificationTypeName(), tp.Text))); return vsCompletionItem; diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Hover/HoverHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Hover/HoverHandler.cs index c4596601b081a..23c0be4fd7e7d 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Hover/HoverHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Hover/HoverHandler.cs @@ -11,8 +11,10 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.Xaml; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.LanguageServer; using Microsoft.CodeAnalysis.LanguageServer.Handler; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.LanguageServices.Xaml.Features.QuickInfo; @@ -23,12 +25,15 @@ namespace Microsoft.VisualStudio.LanguageServices.Xaml.LanguageServer.Handler { [ExportLspRequestHandlerProvider(StringConstants.XamlLanguageName), Shared] [ProvidesMethod(Methods.TextDocumentHoverName)] - internal class HoverHandler : AbstractStatelessRequestHandler + internal sealed class HoverHandler : AbstractStatelessRequestHandler { + private readonly IGlobalOptionService _globalOptions; + [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public HoverHandler() + public HoverHandler(IGlobalOptionService globalOptions) { + _globalOptions = globalOptions; } public override string Method => Methods.TextDocumentHoverName; @@ -63,7 +68,8 @@ public HoverHandler() var descriptionBuilder = new List(info.Description); if (info.Symbol != null) { - var description = await info.Symbol.GetDescriptionAsync(document, cancellationToken).ConfigureAwait(false); + var options = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language); + var description = await info.Symbol.GetDescriptionAsync(document, options, cancellationToken).ConfigureAwait(false); if (description.Any()) { if (descriptionBuilder.Any()) diff --git a/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs b/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs index 1c5ab2818eb69..47b4b8acad570 100644 --- a/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs +++ b/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs @@ -2,64 +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. -using System; -using System.Collections.Immutable; -using System.Composition; using System.Runtime.Serialization; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; namespace Microsoft.CodeAnalysis.Classification { [DataContract] internal readonly record struct ClassificationOptions( - [property: DataMember(Order = 0)] bool ClassifyReassignedVariables, - [property: DataMember(Order = 1)] bool ColorizeRegexPatterns, - [property: DataMember(Order = 2)] bool ColorizeJsonPatterns) + [property: DataMember(Order = 0)] bool ClassifyReassignedVariables = false, + [property: DataMember(Order = 1)] bool ColorizeRegexPatterns = true, + [property: DataMember(Order = 2)] bool ColorizeJsonPatterns = true) { - [ExportSolutionOptionProvider, Shared] - internal sealed class Metadata : IOptionProvider + public ClassificationOptions() + : this(ClassifyReassignedVariables: false) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Metadata() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - ClassifyReassignedVariables, - ColorizeRegexPatterns, - ColorizeJsonPatterns); - - private const string FeatureName = "ClassificationOptions"; - - public static PerLanguageOption2 ClassifyReassignedVariables = - new(FeatureName, "ClassifyReassignedVariables", defaultValue: false, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.ClassificationOptions.ClassifyReassignedVariables")); - - public static PerLanguageOption2 ColorizeRegexPatterns = - new("RegularExpressionsOptions", "ColorizeRegexPatterns", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorizeRegexPatterns")); - - public static PerLanguageOption2 ColorizeJsonPatterns = - new("JsonFeatureOptions", "ColorizeJsonPatterns", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorizeJsonPatterns")); } - public static readonly ClassificationOptions Default - = new( - ClassifyReassignedVariables: Metadata.ClassifyReassignedVariables.DefaultValue, - ColorizeRegexPatterns: Metadata.ColorizeRegexPatterns.DefaultValue, - ColorizeJsonPatterns: Metadata.ColorizeJsonPatterns.DefaultValue); - - public static ClassificationOptions From(Project project) - => From(project.Solution.Options, project.Language); - - public static ClassificationOptions From(OptionSet options, string language) - => new( - ClassifyReassignedVariables: options.GetOption(Metadata.ClassifyReassignedVariables, language), - ColorizeRegexPatterns: options.GetOption(Metadata.ColorizeRegexPatterns, language), - ColorizeJsonPatterns: options.GetOption(Metadata.ColorizeJsonPatterns, language)); + public static readonly ClassificationOptions Default = new(); } } diff --git a/src/Workspaces/Core/Portable/Classification/Classifier.cs b/src/Workspaces/Core/Portable/Classification/Classifier.cs index 8d1bd995e6862..cf932212e2e42 100644 --- a/src/Workspaces/Core/Portable/Classification/Classifier.cs +++ b/src/Workspaces/Core/Portable/Classification/Classifier.cs @@ -26,8 +26,9 @@ public static async Task> GetClassifiedSpansAsync( CancellationToken cancellationToken = default) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); - var options = ClassificationOptions.From(document.Project); - return GetClassifiedSpans(document.Project.Solution.Workspace.Services, semanticModel, textSpan, options, cancellationToken); + + // public options do not affect classification: + return GetClassifiedSpans(document.Project.Solution.Workspace.Services, semanticModel, textSpan, ClassificationOptions.Default, cancellationToken); } /// @@ -44,7 +45,10 @@ public static IEnumerable GetClassifiedSpans( TextSpan textSpan, Workspace workspace, CancellationToken cancellationToken = default) - => GetClassifiedSpans(workspace.Services, semanticModel, textSpan, ClassificationOptions.From(workspace.CurrentSolution.Options, semanticModel.Language), cancellationToken); + { + // public options do not affect classification: + return GetClassifiedSpans(workspace.Services, semanticModel, textSpan, ClassificationOptions.Default, cancellationToken); + } internal static IEnumerable GetClassifiedSpans( HostWorkspaceServices workspaceServices, diff --git a/src/Workspaces/Core/Portable/Workspace/Host/DocumentService/IDocumentExcerptService.cs b/src/Workspaces/Core/Portable/Workspace/Host/DocumentService/IDocumentExcerptService.cs index a3ad14eda6cbb..6b3a74af3da35 100644 --- a/src/Workspaces/Core/Portable/Workspace/Host/DocumentService/IDocumentExcerptService.cs +++ b/src/Workspaces/Core/Portable/Workspace/Host/DocumentService/IDocumentExcerptService.cs @@ -22,7 +22,7 @@ internal interface IDocumentExcerptService : IDocumentService /// /// the result might not be an exact copy of the given source or contains more then given span /// - Task TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, CancellationToken cancellationToken); + Task TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, ClassificationOptions classificationOptions, CancellationToken cancellationToken); } /// @@ -57,14 +57,14 @@ internal struct ExcerptResult /// /// this excerpt is from /// - /// should be same document in + /// should be same document in /// public readonly Document Document; /// /// span on this excerpt is from /// - /// should be same text span in + /// should be same text span in /// public readonly TextSpan Span;