-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Remove legacy IDiagnosticService #72660
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,21 @@ | |
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Composition; | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript; | ||
|
||
[Export(typeof(IVSTypeScriptDiagnosticService)), Shared] | ||
[method: ImportingConstructor] | ||
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
internal sealed class VSTypeScriptDiagnosticService(IDiagnosticService service) : IVSTypeScriptDiagnosticService | ||
internal sealed class VSTypeScriptDiagnosticService() : IVSTypeScriptDiagnosticService | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the only place that actually takes the events from IDiagnosticService and forwards them along. But it's only for "push style" diagnostics, which we've moved off of, and which TS also definitely does not want. @MariaSolOs for awareness. this should go nicely with yoru move to LSP pull diags. |
||
{ | ||
private readonly IDiagnosticService _service = service; | ||
|
||
public Task<ImmutableArray<VSTypeScriptDiagnosticData>> GetPushDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) | ||
{ | ||
// This type is only for push diagnostics, which is now no longer how any of our diagnostic systems work. So | ||
|
@@ -31,41 +27,15 @@ public Task<ImmutableArray<VSTypeScriptDiagnosticData>> GetPushDiagnosticsAsync( | |
|
||
[Obsolete] | ||
public IDisposable RegisterDiagnosticsUpdatedEventHandler(Action<VSTypeScriptDiagnosticsUpdatedArgsWrapper> action) | ||
=> new EventHandlerWrapper(_service, action); | ||
=> new EventHandlerWrapper(); | ||
|
||
public IDisposable RegisterDiagnosticsUpdatedEventHandler(Action<ImmutableArray<VSTypeScriptDiagnosticsUpdatedArgsWrapper>> action) | ||
=> new EventHandlerWrapper(_service, action); | ||
=> new EventHandlerWrapper(); | ||
|
||
private sealed class EventHandlerWrapper : IDisposable | ||
{ | ||
private readonly IDiagnosticService _service; | ||
private readonly EventHandler<ImmutableArray<DiagnosticsUpdatedArgs>> _handler; | ||
|
||
[Obsolete] | ||
internal EventHandlerWrapper(IDiagnosticService service, Action<VSTypeScriptDiagnosticsUpdatedArgsWrapper> action) | ||
{ | ||
_service = service; | ||
_handler = (sender, argsCollection) => | ||
{ | ||
foreach (var args in argsCollection) | ||
action(new VSTypeScriptDiagnosticsUpdatedArgsWrapper(args)); | ||
}; | ||
_service.DiagnosticsUpdated += _handler; | ||
} | ||
|
||
internal EventHandlerWrapper(IDiagnosticService service, Action<ImmutableArray<VSTypeScriptDiagnosticsUpdatedArgsWrapper>> action) | ||
{ | ||
_service = service; | ||
_handler = (sender, argsCollection) => | ||
{ | ||
action(ImmutableArray.CreateRange(argsCollection, static args => new VSTypeScriptDiagnosticsUpdatedArgsWrapper(args))); | ||
}; | ||
_service.DiagnosticsUpdated += _handler; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_service.DiagnosticsUpdated -= _handler; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,7 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeFixes | |
[UseExportProvider] | ||
public class CodeFixServiceTests | ||
{ | ||
private static readonly TestComposition s_compositionWithMockDiagnosticUpdateSourceRegistrationService = EditorTestCompositions.EditorFeatures | ||
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService)) | ||
.AddParts(typeof(MockDiagnosticUpdateSourceRegistrationService)); | ||
private static readonly TestComposition s_compositionWithMockDiagnosticUpdateSourceRegistrationService = EditorTestCompositions.EditorFeatures; | ||
|
||
[Fact] | ||
public async Task TestGetFirstDiagnosticWithFixAsync() | ||
|
@@ -49,7 +47,6 @@ public async Task TestGetFirstDiagnosticWithFixAsync() | |
"; | ||
using var workspace = TestWorkspace.CreateCSharp(code, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService, openDocuments: true); | ||
|
||
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(workspace.GetService<IDiagnosticUpdateSourceRegistrationService>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tons of asserts taht tests were actually not even using actual product code... |
||
var diagnosticService = Assert.IsType<DiagnosticAnalyzerService>(workspace.GetService<IDiagnosticAnalyzerService>()); | ||
|
||
var analyzerReference = new TestAnalyzerReferenceByLanguage(DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap()); | ||
|
@@ -365,7 +362,6 @@ private static (EditorTestWorkspace workspace, DiagnosticAnalyzerService analyze | |
var analyzerReference = new TestAnalyzerReferenceByLanguage(DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap()); | ||
workspace.TryApplyChanges(workspace.CurrentSolution.WithAnalyzerReferences(new[] { analyzerReference })); | ||
|
||
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(workspace.GetService<IDiagnosticUpdateSourceRegistrationService>()); | ||
var diagnosticService = Assert.IsType<DiagnosticAnalyzerService>(workspace.GetService<IDiagnosticAnalyzerService>()); | ||
var logger = SpecializedCollections.SingletonEnumerable(new Lazy<IErrorLoggerService>(() => new TestErrorLogger())); | ||
var errorLogger = logger.First().Value; | ||
|
@@ -778,7 +774,6 @@ private static async Task<ImmutableArray<CodeFixCollection>> GetNuGetAndVsixCode | |
|
||
using var workspace = TestWorkspace.CreateCSharp(code, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService, openDocuments: true); | ||
|
||
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(workspace.GetService<IDiagnosticUpdateSourceRegistrationService>()); | ||
var diagnosticService = Assert.IsType<DiagnosticAnalyzerService>(workspace.GetService<IDiagnosticAnalyzerService>()); | ||
|
||
var logger = SpecializedCollections.SingletonEnumerable(new Lazy<IErrorLoggerService>(() => workspace.Services.GetRequiredService<IErrorLoggerService>())); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: the names of this compositions need to change.