Skip to content

Commit

Permalink
Add missing API to IVSTypeScriptDiagnosticService (#59751)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat authored Feb 25, 2022
1 parent 67a81ec commit e9d409e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImmutableArray<VSTypeScriptDiagnosticData>> GetPushDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken);

IDisposable RegisterDiagnosticsUpdatedEventHandler(Action<VSTypeScriptDiagnosticsUpdatedArgsWrapper> action);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,26 @@ public async Task<ImmutableArray<VSTypeScriptDiagnosticData>> 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<VSTypeScriptDiagnosticsUpdatedArgsWrapper> action)
=> new EventHandlerWrapper(_service, action);

private sealed class EventHandlerWrapper : IDisposable
{
private readonly IDiagnosticService _service;
private readonly EventHandler<DiagnosticsUpdatedArgs> _handler;

internal EventHandlerWrapper(IDiagnosticService service, Action<VSTypeScriptDiagnosticsUpdatedArgsWrapper> action)
{
_service = service;
_handler = (sender, args) => action(new VSTypeScriptDiagnosticsUpdatedArgsWrapper(args));
_service.DiagnosticsUpdated += _handler;
}

public void Dispose()
{
_service.DiagnosticsUpdated -= _handler;
}
}
}
}

0 comments on commit e9d409e

Please sign in to comment.