Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing API to IVSTypeScriptDiagnosticService #59751

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}