Skip to content

Commit

Permalink
Merge pull request #72660 from CyrusNajmabadi/removeDiagService
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Mar 24, 2024
2 parents 2fa323c + cb55e77 commit e510ed1
Show file tree
Hide file tree
Showing 46 changed files with 43 additions and 786 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ protected override ImmutableArray<CodeAction> MassageActions(ImmutableArray<Code

// TODO: Requires WPF due to IInlineRenameService dependency (https://github.com/dotnet/roslyn/issues/46153)
protected override TestComposition GetComposition()
=> EditorTestCompositions.EditorFeaturesWpf
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(typeof(MockDiagnosticUpdateSourceRegistrationService));
=> EditorTestCompositions.EditorFeaturesWpf;

#region Generate Class

Expand Down
2 changes: 0 additions & 2 deletions src/EditorFeatures/CSharpTest/CodeActions/PreviewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings
public partial class PreviewTests : AbstractCSharpCodeActionTest
{
private static readonly TestComposition s_composition = EditorTestCompositions.EditorFeaturesWpf
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(
typeof(MockDiagnosticUpdateSourceRegistrationService),
typeof(MockPreviewPaneService));

private const string AddedDocumentName = "AddedDocument";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.UserDiagnos
[UseExportProvider]
public class DiagnosticAnalyzerDriverTests
{
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 DiagnosticAnalyzerDriverAllInOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MoveToNamespace
public class MoveToNamespaceTests : AbstractMoveToNamespaceTests
{
private static readonly TestComposition s_compositionWithoutOptions = FeaturesTestCompositions.Features
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(
typeof(MockDiagnosticUpdateSourceRegistrationService),
typeof(TestSymbolRenamedCodeActionOperationFactoryWorkspaceService));

private static readonly TestComposition s_composition = s_compositionWithoutOptions.AddParts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
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
Expand All @@ -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
Expand Up @@ -155,9 +155,7 @@ private protected virtual IDocumentServiceProvider GetDocumentServiceProvider()
=> null;

protected virtual TestComposition GetComposition()
=> EditorTestCompositions.EditorFeatures
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(typeof(MockDiagnosticUpdateSourceRegistrationService));
=> EditorTestCompositions.EditorFeatures;

protected virtual void InitializeWorkspace(EditorTestWorkspace workspace, TestParameters parameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public abstract partial class AbstractUserDiagnosticTest
{
// TODO: IInlineRenameService requires WPF (https://github.com/dotnet/roslyn/issues/46153)
private static readonly TestComposition s_composition = EditorTestCompositions.EditorFeaturesWpf
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(
typeof(MockDiagnosticUpdateSourceRegistrationService),
typeof(TestGenerateTypeOptionsService),
typeof(TestProjectManagementService));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public abstract class AbstractMoveTypeTest : AbstractCodeActionTest

// TODO: Requires WPF due to IInlineRenameService dependency (https://github.com/dotnet/roslyn/issues/46153)
protected override TestComposition GetComposition()
=> EditorTestCompositions.EditorFeaturesWpf
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(typeof(MockDiagnosticUpdateSourceRegistrationService));
=> EditorTestCompositions.EditorFeaturesWpf;

protected override CodeRefactoringProvider CreateCodeRefactoringProvider(EditorTestWorkspace workspace, TestParameters parameters)
=> new MoveTypeCodeRefactoringProvider();
Expand Down
7 changes: 1 addition & 6 deletions src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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>());
var diagnosticService = Assert.IsType<DiagnosticAnalyzerService>(workspace.GetService<IDiagnosticAnalyzerService>());

var analyzerReference = new TestAnalyzerReferenceByLanguage(DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
public class DiagnosticAnalyzerServiceTests
{
private static readonly TestComposition s_featuresCompositionWithMockDiagnosticUpdateSourceRegistrationService = EditorTestCompositions.EditorFeatures
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(typeof(MockDiagnosticUpdateSourceRegistrationService))
.AddParts(typeof(TestDocumentTrackingService));

private static readonly TestComposition s_editorFeaturesCompositionWithMockDiagnosticUpdateSourceRegistrationService = EditorTestCompositions.EditorFeatures
.AddExcludedPartTypes(typeof(IDiagnosticUpdateSourceRegistrationService))
.AddParts(typeof(MockDiagnosticUpdateSourceRegistrationService));
private static readonly TestComposition s_editorFeaturesCompositionWithMockDiagnosticUpdateSourceRegistrationService = EditorTestCompositions.EditorFeatures;

private static AdhocWorkspace CreateWorkspace(Type[] additionalParts = null)
{
Expand Down Expand Up @@ -78,7 +74,6 @@ public async Task TestHasSuccessfullyLoadedBeingFalse()
var document = GetDocumentFromIncompleteProject(workspace);

var exportProvider = workspace.Services.SolutionServices.ExportProvider;
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());
var analyzer = service.CreateIncrementalAnalyzer(workspace);
var globalOptions = exportProvider.GetExportedValue<IGlobalOptionService>();
Expand Down Expand Up @@ -202,7 +197,6 @@ public async Task TestDisabledByDefaultAnalyzerEnabledWithEditorConfig(bool enab
Assert.True(applied);

var exportProvider = workspace.Services.SolutionServices.ExportProvider;
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());
var analyzer = service.CreateIncrementalAnalyzer(workspace);

Expand Down Expand Up @@ -254,7 +248,6 @@ private static async Task TestAnalyzerAsync(
{
var exportProvider = workspace.Services.SolutionServices.ExportProvider;

Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());
var globalOptions = exportProvider.GetExportedValue<IGlobalOptionService>();

Expand Down Expand Up @@ -304,7 +297,6 @@ public async Task TestOpenFileOnlyAnalyzerDiagnostics()

var document = workspace.AddDocument(project.Id, "Empty.cs", SourceText.From(""));

Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());
var analyzer = service.CreateIncrementalAnalyzer(workspace);

Expand Down Expand Up @@ -368,7 +360,6 @@ public async Task TestSynchronizeWithBuild()
filePath: filePath));

var exportProvider = workspace.Services.SolutionServices.ExportProvider;
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());
var analyzer = service.CreateIncrementalAnalyzer(workspace);
var globalOptions = exportProvider.GetExportedValue<IGlobalOptionService>();
Expand Down Expand Up @@ -442,7 +433,6 @@ public void TestHostAnalyzerOrdering()
"Dummy",
LanguageNames.CSharp));

Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());

var incrementalAnalyzer = service.CreateIncrementalAnalyzer(workspace);
Expand Down Expand Up @@ -493,7 +483,6 @@ public async Task TestHostAnalyzerErrorNotLeaking()
filePath: "test.cs")}));

var exportProvider = workspace.Services.SolutionServices.ExportProvider;
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());

var called = false;
Expand Down Expand Up @@ -600,7 +589,6 @@ private static AdhocWorkspace CreateWorkspaceWithProjectAndAnalyzer(DiagnosticAn
private static async Task TestFullSolutionAnalysisForProjectAsync(AdhocWorkspace workspace, Project project, bool expectAnalyzerExecuted)
{
var exportProvider = workspace.Services.SolutionServices.ExportProvider;
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());
var globalOptions = exportProvider.GetExportedValue<IGlobalOptionService>();

Expand Down Expand Up @@ -662,7 +650,6 @@ internal async Task TestAdditionalFileAnalyzer(bool registerFromInitialize, bool
Assert.True(applied);

var exportProvider = workspace.Services.SolutionServices.ExportProvider;
Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(exportProvider.GetExportedValue<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(exportProvider.GetExportedValue<IDiagnosticAnalyzerService>());

var diagnostics = new ConcurrentSet<DiagnosticData>();
Expand Down Expand Up @@ -738,7 +725,6 @@ internal async Task TestDiagnosticSuppressor(bool includeAnalyzer, bool includeS
var project = workspace.CurrentSolution.Projects.Single();
var document = project.Documents.Single();

Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(workspace.GetService<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(workspace.GetService<IDiagnosticAnalyzerService>());
var globalOptions = workspace.GetService<IGlobalOptionService>();

Expand Down Expand Up @@ -875,7 +861,6 @@ void M()
else
Assert.IsType<Document>(document);

Assert.IsType<MockDiagnosticUpdateSourceRegistrationService>(workspace.GetService<IDiagnosticUpdateSourceRegistrationService>());
var service = Assert.IsType<DiagnosticAnalyzerService>(workspace.GetService<IDiagnosticAnalyzerService>());

var diagnostics = ArrayBuilder<DiagnosticData>.GetInstance();
Expand Down
3 changes: 0 additions & 3 deletions src/EditorFeatures/Test/Diagnostics/DiagnosticDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

#nullable disable

using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
Expand Down
Loading

0 comments on commit e510ed1

Please sign in to comment.