From e3cabdc85b41eb03648828f74a6edf3c2dba190b Mon Sep 17 00:00:00 2001 From: tmat Date: Mon, 11 Apr 2022 15:35:46 -0700 Subject: [PATCH] Workaround --- .../VSTypeScriptCommentSelectionService.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs index 8de86e75c343a..86c991686eb9e 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs @@ -12,26 +12,39 @@ using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Text; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { [ExportLanguageService(typeof(ICommentSelectionService), InternalLanguageNames.TypeScript), Shared] internal sealed class VSTypeScriptCommentSelectionService : ICommentSelectionService { - private readonly IVSTypeScriptCommentSelectionServiceImplementation _impl; + private readonly IVSTypeScriptCommentSelectionServiceImplementation? _impl; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public VSTypeScriptCommentSelectionService(IVSTypeScriptCommentSelectionServiceImplementation impl) - => _impl = impl; + public VSTypeScriptCommentSelectionService( + // Optional to work around test issue: https://github.com/dotnet/roslyn/issues/60690 + [Import(AllowDefault = true)] IVSTypeScriptCommentSelectionServiceImplementation? impl) + { + _impl = impl; + } public async Task GetInfoAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) { + // Will never be null in product. + Contract.ThrowIfNull(_impl); + var info = await _impl.GetInfoAsync(document, textSpan, cancellationToken).ConfigureAwait(false); return info.UnderlyingObject; } public Task FormatAsync(Document document, ImmutableArray changes, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken) - => _impl.FormatAsync(document, changes, cancellationToken); + { + // Will never be null in product. + Contract.ThrowIfNull(_impl); + + return _impl.FormatAsync(document, changes, cancellationToken); + } } }