From e1aed08cc3ed14f491bd74157a360c614c220298 Mon Sep 17 00:00:00 2001 From: tmat Date: Thu, 24 Feb 2022 12:31:47 -0800 Subject: [PATCH] Add missing API to IVSTypeScriptDiagnosticService --- .../Api/IVSTypeScriptDiagnosticService.cs | 4 ++++ ...TypeScriptDiagnosticsUpdatedArgsWrapper.cs | 22 +++++++++++++++++++ .../VSTypeScriptDiagnosticService.cs | 21 ++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptDiagnosticsUpdatedArgsWrapper.cs diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptDiagnosticService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptDiagnosticService.cs index c32fb9c89a5ff..c3393483bdba4 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptDiagnosticService.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptDiagnosticService.cs @@ -2,14 +2,18 @@ // 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.Diagnostics; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { internal interface IVSTypeScriptDiagnosticService { Task> GetPushDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken); + + IDisposable RegisterDiagnosticsUpdatedEventHandler(Action action); } } diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptDiagnosticsUpdatedArgsWrapper.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptDiagnosticsUpdatedArgsWrapper.cs new file mode 100644 index 0000000000000..d328391d5e8e7 --- /dev/null +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptDiagnosticsUpdatedArgsWrapper.cs @@ -0,0 +1,22 @@ +// 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.Diagnostics; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal readonly struct VSTypeScriptDiagnosticsUpdatedArgsWrapper + { + internal readonly DiagnosticsUpdatedArgs UnderlyingObject; + + public VSTypeScriptDiagnosticsUpdatedArgsWrapper(DiagnosticsUpdatedArgs underlyingObject) + => UnderlyingObject = underlyingObject; + + public Solution? Solution + => UnderlyingObject.Solution; + + public DocumentId? DocumentId + => UnderlyingObject.DocumentId; + } +} diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDiagnosticService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDiagnosticService.cs index f39932bdce1c4..dfbf6de3db972 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDiagnosticService.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDiagnosticService.cs @@ -33,5 +33,26 @@ public async Task> GetPushDiagnostics var result = await _service.GetPushDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, _globalOptions.GetDiagnosticMode(InternalDiagnosticsOptions.NormalDiagnosticMode), cancellationToken).ConfigureAwait(false); return result.SelectAsArray(data => new VSTypeScriptDiagnosticData(data)); } + + public IDisposable RegisterDiagnosticsUpdatedEventHandler(Action action) + => new EventHandlerWrapper(_service, action); + + private sealed class EventHandlerWrapper : IDisposable + { + private readonly IDiagnosticService _service; + private readonly EventHandler _handler; + + internal EventHandlerWrapper(IDiagnosticService service, Action action) + { + _service = service; + _handler = (sender, args) => action(new VSTypeScriptDiagnosticsUpdatedArgsWrapper(args)); + _service.DiagnosticsUpdated += _handler; + } + + public void Dispose() + { + _service.DiagnosticsUpdated -= _handler; + } + } } }