From 953722cb2011c3d5b31adc53bf59e476ecc0f8be Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:09:57 -0800 Subject: [PATCH 01/11] Remove unused diagnostic methods --- .../Test/Diagnostics/MockDiagnosticService.cs | 11 ---------- .../Features/Diagnostics/DiagnosticService.cs | 22 ------------------- .../Diagnostics/IDiagnosticService.cs | 6 ----- 3 files changed, 39 deletions(-) diff --git a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs index b5c088acf2485..1dbeca5df1ad6 100644 --- a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs +++ b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs @@ -46,17 +46,6 @@ private ImmutableArray GetDiagnostics(Workspace workspace, Proje return _diagnosticData == null ? ImmutableArray.Empty : ImmutableArray.Create(_diagnosticData); } - public ImmutableArray GetDiagnosticBuckets( - Workspace workspace, ProjectId? projectId, DocumentId? documentId, CancellationToken cancellationToken) - { - Assert.Equal(projectId, GetProjectId(workspace)); - Assert.Equal(documentId, GetDocumentId(workspace)); - - return _diagnosticData == null - ? ImmutableArray.Empty - : ImmutableArray.Create(new DiagnosticBucket(this, workspace, GetProjectId(workspace), GetDocumentId(workspace))); - } - internal void CreateDiagnosticAndFireEvents(Workspace workspace, MockDiagnosticAnalyzerService analyzerService, Location location, DiagnosticKind diagnosticKind, bool isSuppressed) { var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs index 6a787d72747f1..f27c7a5446818 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs @@ -281,28 +281,6 @@ private async ValueTask> GetDiagnosticsAsync( return result.ToImmutable(); } - public ImmutableArray GetDiagnosticBuckets( - Workspace workspace, - ProjectId? projectId, - DocumentId? documentId, - CancellationToken cancellationToken) - { - using var _1 = ArrayBuilder.GetInstance(out var result); - using var _2 = ArrayBuilder.GetInstance(out var buffer); - - foreach (var source in _updateSources) - { - buffer.Clear(); - cancellationToken.ThrowIfCancellationRequested(); - - AppendMatchingData(source, workspace, projectId, documentId, id: null, buffer); - foreach (var data in buffer) - result.Add(new DiagnosticBucket(data.Id, data.Workspace, data.ProjectId, data.DocumentId)); - } - - return result.ToImmutable(); - } - private void AppendMatchingData( IDiagnosticUpdateSource source, Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, ArrayBuilder list) { diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs index 5dc18b498f1c0..57b968d800c04 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs @@ -27,11 +27,5 @@ internal interface IDiagnosticService /// ValueTask> GetDiagnosticsAsync( Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken); - - /// - /// Get current buckets storing our grouped diagnostics. - /// - ImmutableArray GetDiagnosticBuckets( - Workspace workspace, ProjectId? projectId, DocumentId? documentId, CancellationToken cancellationToken); } } From 8a7a3bda20447eaf3af22442a20204b799f9944b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:18:04 -0800 Subject: [PATCH 02/11] Remove unused diagnostic methods --- .../Diagnostics/DiagnosticServiceTests.cs | 90 +---------- .../Test/Diagnostics/MockDiagnosticService.cs | 19 --- .../Features/Diagnostics/DiagnosticService.cs | 143 ------------------ .../Diagnostics/IDiagnosticService.cs | 8 - .../AnalyzerReferenceTests.vb | 30 ---- 5 files changed, 2 insertions(+), 288 deletions(-) diff --git a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs index 4c0f88db15801..b7c3ab927e086 100644 --- a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs +++ b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs @@ -26,86 +26,7 @@ private static DiagnosticService GetDiagnosticService(TestWorkspace workspace) } [Fact] - public async Task TestGetDiagnostics1() - { - using var workspace = new TestWorkspace(composition: EditorTestCompositions.EditorFeatures); - var mutex = new ManualResetEvent(false); - var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", string.Empty); - - var source = new TestDiagnosticUpdateSource(false, null); - var diagnosticService = GetDiagnosticService(workspace); - diagnosticService.Register(source); - - diagnosticService.DiagnosticsUpdated += (s, o) => - { - foreach (var _ in o) - mutex.Set(); - }; - - var id = Tuple.Create(workspace, document); - var diagnostic = RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, document.Id, id); - - var data1 = await diagnosticService.GetDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(diagnostic, data1.Single()); - - var data2 = await diagnosticService.GetDiagnosticsAsync(workspace, document.Project.Id, null, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(diagnostic, data2.Single()); - - var data3 = await diagnosticService.GetDiagnosticsAsync(workspace, document.Project.Id, document.Id, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(diagnostic, data3.Single()); - - var data4 = await diagnosticService.GetDiagnosticsAsync(workspace, document.Project.Id, document.Id, id, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(diagnostic, data4.Single()); - } - - [Fact] - public async Task TestGetDiagnostics2() - { - using var workspace = new TestWorkspace(composition: EditorTestCompositions.EditorFeatures); - var mutex = new ManualResetEvent(false); - var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", string.Empty); - var document2 = document.Project.AddDocument("TestDocument2", string.Empty); - - var source = new TestDiagnosticUpdateSource(false, null); - var diagnosticService = GetDiagnosticService(workspace); - diagnosticService.Register(source); - - diagnosticService.DiagnosticsUpdated += (s, o) => - { - foreach (var _ in o) - mutex.Set(); - }; - - var id = Tuple.Create(workspace, document); - RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, document.Id, id); - - var id2 = Tuple.Create(workspace, document.Project, document); - RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, document.Id, id2); - - RaiseDiagnosticEvent(mutex, source, workspace, document2.Project.Id, document2.Id, Tuple.Create(workspace, document2)); - - var id3 = Tuple.Create(workspace, document.Project); - RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, null, id3); - RaiseDiagnosticEvent(mutex, source, workspace, null, null, Tuple.Create(workspace)); - - var data1 = await diagnosticService.GetDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(5, data1.Count()); - - var data2 = await diagnosticService.GetDiagnosticsAsync(workspace, document.Project.Id, null, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(4, data2.Count()); - - var data3 = await diagnosticService.GetDiagnosticsAsync(workspace, document.Project.Id, null, id3, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(1, data3.Count()); - - var data4 = await diagnosticService.GetDiagnosticsAsync(workspace, document.Project.Id, document.Id, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(2, data4.Count()); - - var data5 = await diagnosticService.GetDiagnosticsAsync(workspace, document.Project.Id, document.Id, id, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(1, data5.Count()); - } - - [Fact] - public async Task TestCleared() + public void TestCleared() { using var workspace = new TestWorkspace(composition: EditorTestCompositions.EditorFeatures); var mutex = new ManualResetEvent(false); @@ -130,10 +51,6 @@ public async Task TestCleared() RaiseDiagnosticEvent(mutex, source2, workspace, document.Project.Id, null, Tuple.Create(workspace, document.Project)); RaiseDiagnosticEvent(mutex, source2, workspace, null, null, Tuple.Create(workspace)); - // confirm data is there. - var data1 = await diagnosticService.GetDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(5, data1.Count()); - diagnosticService.DiagnosticsUpdated -= MarkSet; // confirm clear for a source @@ -144,10 +61,7 @@ public async Task TestCleared() source1.RaiseDiagnosticsClearedEvent(); mutex.WaitOne(); - - // confirm there are 2 data left - var data2 = await diagnosticService.GetDiagnosticsAsync(workspace, null, null, null, includeSuppressedDiagnostics: false, CancellationToken.None); - Assert.Equal(2, data2.Count()); + return; void MarkCalled(object sender, ImmutableArray args) { diff --git a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs index 1dbeca5df1ad6..770707cfb028d 100644 --- a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs +++ b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs @@ -6,13 +6,8 @@ using System.Collections.Immutable; using System.Composition; using System.Linq; -using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.EditAndContinue.UnitTests; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics @@ -32,20 +27,6 @@ public MockDiagnosticService() { } - public ValueTask> GetDiagnosticsAsync( - Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) - { - return new ValueTask>(GetDiagnostics(workspace, projectId, documentId)); - } - - private ImmutableArray GetDiagnostics(Workspace workspace, ProjectId? projectId, DocumentId? documentId) - { - Assert.Equal(projectId, GetProjectId(workspace)); - Assert.Equal(documentId, GetDocumentId(workspace)); - - return _diagnosticData == null ? ImmutableArray.Empty : ImmutableArray.Create(_diagnosticData); - } - internal void CreateDiagnosticAndFireEvents(Workspace workspace, MockDiagnosticAnalyzerService analyzerService, Location location, DiagnosticKind diagnosticKind, bool isSuppressed) { var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs index f27c7a5446818..569709876c2b7 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs @@ -7,13 +7,11 @@ using System.Collections.Immutable; using System.Composition; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Common; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.Shared.TestHooks; using Roslyn.Utilities; @@ -197,147 +195,6 @@ private void OnCleared(object? sender, EventArgs e) RaiseDiagnosticsCleared((IDiagnosticUpdateSource)sender!); } - public ValueTask> GetDiagnosticsAsync( - Workspace workspace, - ProjectId? projectId, - DocumentId? documentId, - object? id, - bool includeSuppressedDiagnostics, - CancellationToken cancellationToken) - { - if (id != null) - { - // get specific one - return GetSpecificDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, cancellationToken); - } - - // get aggregated ones - return GetDiagnosticsAsync(workspace, projectId, documentId, includeSuppressedDiagnostics, cancellationToken); - } - - private async ValueTask> GetSpecificDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) - { - using var _ = ArrayBuilder.GetInstance(out var buffer); - - foreach (var source in _updateSources) - { - cancellationToken.ThrowIfCancellationRequested(); - - buffer.Clear(); - if (source.SupportGetDiagnostics) - { - var diagnostics = await source.GetDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false); - if (diagnostics.Length > 0) - return diagnostics; - } - else - { - AppendMatchingData(source, workspace, projectId, documentId, id, buffer); - Debug.Assert(buffer.Count is 0 or 1); - - if (buffer.Count == 1) - { - var diagnostics = buffer[0].Diagnostics; - return includeSuppressedDiagnostics - ? diagnostics - : diagnostics.NullToEmpty().WhereAsArray(d => !d.IsSuppressed); - } - } - } - - return []; - } - - private async ValueTask> GetDiagnosticsAsync( - Workspace workspace, ProjectId? projectId, DocumentId? documentId, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) - { - using var _1 = ArrayBuilder.GetInstance(out var result); - using var _2 = ArrayBuilder.GetInstance(out var buffer); - foreach (var source in _updateSources) - { - cancellationToken.ThrowIfCancellationRequested(); - - buffer.Clear(); - if (source.SupportGetDiagnostics) - { - result.AddRange(await source.GetDiagnosticsAsync(workspace, projectId, documentId, id: null, includeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false)); - } - else - { - AppendMatchingData(source, workspace, projectId, documentId, id: null, buffer); - - foreach (var data in buffer) - { - foreach (var diagnostic in data.Diagnostics) - { - AssertIfNull(diagnostic); - if (includeSuppressedDiagnostics || !diagnostic.IsSuppressed) - result.Add(diagnostic); - } - } - } - } - - return result.ToImmutable(); - } - - private void AppendMatchingData( - IDiagnosticUpdateSource source, Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, ArrayBuilder list) - { - Contract.ThrowIfNull(workspace); - - lock (_gate) - { - if (!_map.TryGetValue(source, out var workspaceMap) || - !workspaceMap.TryGetValue(workspace, out var current)) - { - return; - } - - if (id != null) - { - if (current.TryGetValue(id, out var data)) - { - list.Add(data); - } - - return; - } - - foreach (var data in current.Values) - { - if (TryAddData(workspace, documentId, data, d => d.DocumentId, list) || - TryAddData(workspace, projectId, data, d => d.ProjectId, list) || - TryAddData(workspace, workspace, data, d => d.Workspace, list)) - { - continue; - } - } - } - } - - private static bool TryAddData(Workspace workspace, [NotNullWhen(true)] T? key, Data data, Func keyGetter, ArrayBuilder result) - where T : class - { - if (key == null) - { - return false; - } - - // make sure data is from same workspace. project/documentId can be shared between 2 different workspace - if (workspace != data.Workspace) - { - return false; - } - - if (key == keyGetter(data)) - { - result.Add(data); - } - - return true; - } - [Conditional("DEBUG")] private static void AssertIfNull(ImmutableArray diagnostics) { diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs index 57b968d800c04..43521b1561ee9 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/IDiagnosticService.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Immutable; -using System.Threading; -using System.Threading.Tasks; namespace Microsoft.CodeAnalysis.Diagnostics { @@ -21,11 +19,5 @@ internal interface IDiagnosticService /// However, individual event notifications may occur on any thread. /// event EventHandler> DiagnosticsUpdated; - - /// - /// Get current diagnostics stored in IDiagnosticUpdateSource. - /// - ValueTask> GetDiagnosticsAsync( - Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken); } } diff --git a/src/VisualStudio/Core/Test/ProjectSystemShim/VisualStudioProjectTests/AnalyzerReferenceTests.vb b/src/VisualStudio/Core/Test/ProjectSystemShim/VisualStudioProjectTests/AnalyzerReferenceTests.vb index 4568133c70930..47a8b12842377 100644 --- a/src/VisualStudio/Core/Test/ProjectSystemShim/VisualStudioProjectTests/AnalyzerReferenceTests.vb +++ b/src/VisualStudio/Core/Test/ProjectSystemShim/VisualStudioProjectTests/AnalyzerReferenceTests.vb @@ -52,13 +52,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim Dim analyzers = environment.Workspace.CurrentSolution.Projects.Single().AnalyzerReferences.Single().GetAnalyzers(LanguageNames.CSharp) Assert.Empty(analyzers) - Assert.Single(Await GetDiagnostics(environment), Function(d) d.Id = DocumentAnalysisExecutor.WRN_UnableToLoadAnalyzerIdCS) - Using If(removeInBatch, project.CreateBatchScope(), Nothing) project.RemoveAnalyzerReference(analyzerPath) End Using - - Assert.Empty(Await GetDiagnostics(environment)) End Using End Function @@ -75,13 +71,10 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim ' Force there to be errors trying to load the missing DLL Dim analyzers = environment.Workspace.CurrentSolution.Projects.Single().AnalyzerReferences.Single().GetAnalyzers(LanguageNames.CSharp) Assert.Empty(analyzers) - Assert.Single(Await GetDiagnostics(environment), Function(d) d.Id = DocumentAnalysisExecutor.WRN_UnableToLoadAnalyzerIdCS) Using If(removeInBatch, project.CreateBatchScope(), Nothing) project.RemoveFromWorkspace() End Using - - Assert.Empty(Await GetDiagnostics(environment)) End Using End Function @@ -97,17 +90,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim ' Force there to be errors trying to load the missing DLL Dim analyzers = environment.Workspace.CurrentSolution.Projects.Single().AnalyzerReferences.Single().GetAnalyzers(LanguageNames.CSharp) Assert.Empty(analyzers) - Assert.Single(Await GetDiagnostics(environment), Function(d) d.Id = DocumentAnalysisExecutor.WRN_UnableToLoadAnalyzerIdCS) Using project.CreateBatchScope() project.RemoveAnalyzerReference(analyzerPath) project.AddAnalyzerReference(analyzerPath) End Using - - ' We should still have a diagnostic; the real point of this assertion isn't that - ' we keep it around immediately, but we don't accidentally screw up the batching and - ' lose the diagnostic permanently. - Assert.Single(Await GetDiagnostics(environment), Function(d) d.Id = DocumentAnalysisExecutor.WRN_UnableToLoadAnalyzerIdCS) End Using End Function @@ -215,24 +202,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim project.AddAnalyzerReference(path2) AssertEx.Equal({path1, path2}, environment.Workspace.CurrentSolution.Projects.Single().AnalyzerReferences.Select(Function(r) r.FullPath)) - End Using End Function - - Private Shared Async Function GetDiagnostics(environment As TestEnvironment) As Task(Of ImmutableArray(Of DiagnosticData)) - ' Wait for diagnostics to be updated asynchronously - Dim waiter = environment.ExportProvider.GetExportedValue(Of AsynchronousOperationListenerProvider).GetWaiter(FeatureAttribute.DiagnosticService) - Await waiter.ExpeditedWaitAsync() - - Dim diagnosticService = environment.ExportProvider.GetExportedValue(Of IDiagnosticService) - Dim diagnostics = Await diagnosticService.GetDiagnosticsAsync( - environment.Workspace, - projectId:=Nothing, - documentId:=Nothing, - id:=Nothing, - includeSuppressedDiagnostics:=True, - CancellationToken.None) - Return diagnostics - End Function End Class End Namespace From 974993db4bf0a112c59903d57bd753e4509d1604 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:23:55 -0800 Subject: [PATCH 03/11] remove more --- .../Test/Diagnostics/MockDiagnosticService.cs | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs index 770707cfb028d..25986eecb1d9a 100644 --- a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs +++ b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs @@ -17,8 +17,6 @@ internal class MockDiagnosticService : IDiagnosticService { public const string DiagnosticId = "MockId"; - private DiagnosticData? _diagnosticData; - public event EventHandler>? DiagnosticsUpdated; [ImportingConstructor] @@ -26,25 +24,5 @@ internal class MockDiagnosticService : IDiagnosticService public MockDiagnosticService() { } - - internal void CreateDiagnosticAndFireEvents(Workspace workspace, MockDiagnosticAnalyzerService analyzerService, Location location, DiagnosticKind diagnosticKind, bool isSuppressed) - { - var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); - _diagnosticData = DiagnosticData.Create(Diagnostic.Create(DiagnosticId, "MockCategory", "MockMessage", DiagnosticSeverity.Error, DiagnosticSeverity.Error, isEnabledByDefault: true, warningLevel: 0, isSuppressed: isSuppressed, - location: location), - document); - - analyzerService.AddDiagnostic(_diagnosticData, diagnosticKind); - DiagnosticsUpdated?.Invoke(this, ImmutableArray.Create(DiagnosticsUpdatedArgs.DiagnosticsCreated( - this, workspace, workspace.CurrentSolution, - GetProjectId(workspace), GetDocumentId(workspace), - ImmutableArray.Create(_diagnosticData)))); - } - - private static DocumentId GetDocumentId(Workspace workspace) - => workspace.CurrentSolution.Projects.Single().Documents.Single().Id; - - private static ProjectId GetProjectId(Workspace workspace) - => workspace.CurrentSolution.Projects.Single().Id; } } From 6148e15d0584ac8ec2fa428a57100c65c654910f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:32:37 -0800 Subject: [PATCH 04/11] lint --- src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs index 25986eecb1d9a..571b269b2cf55 100644 --- a/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs +++ b/src/EditorFeatures/Test/Diagnostics/MockDiagnosticService.cs @@ -17,7 +17,7 @@ internal class MockDiagnosticService : IDiagnosticService { public const string DiagnosticId = "MockId"; - public event EventHandler>? DiagnosticsUpdated; + public event EventHandler> DiagnosticsUpdated { add { } remove { } } [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] From 41ab2d9422324558d8c2054d57da5d99c8ef7fae Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:35:29 -0800 Subject: [PATCH 05/11] Remove type --- .../Portable/Diagnostics/DiagnosticBucket.cs | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 src/Features/Core/Portable/Diagnostics/DiagnosticBucket.cs diff --git a/src/Features/Core/Portable/Diagnostics/DiagnosticBucket.cs b/src/Features/Core/Portable/Diagnostics/DiagnosticBucket.cs deleted file mode 100644 index 64d9a1ea57e5f..0000000000000 --- a/src/Features/Core/Portable/Diagnostics/DiagnosticBucket.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. - -namespace Microsoft.CodeAnalysis.Diagnostics; - -internal readonly struct DiagnosticBucket(object id, Workspace workspace, ProjectId? projectId, DocumentId? documentId) -{ - /// - /// The identity of bucket group. - /// - public readonly object Id = id; - - /// - /// this bucket is associated with. - /// - public readonly Workspace Workspace = workspace; - - /// - /// this bucket is associated with, or . - /// - public readonly ProjectId? ProjectId = projectId; - - /// - /// this bucket is associated with, or . - /// - public readonly DocumentId? DocumentId = documentId; -} From 6b98b29bcd418befb06587a21b8615159a630f32 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:41:35 -0800 Subject: [PATCH 06/11] Remove more code only called by tests --- .../Test/Diagnostics/DiagnosticServiceTests.cs | 3 --- .../Squiggles/TestDiagnosticTagProducer.cs | 3 --- .../Diagnostics/AbstractHostDiagnosticUpdateSource.cs | 3 --- .../Portable/Diagnostics/IDiagnosticUpdateSource.cs | 9 ++------- .../EditAndContinueDiagnosticUpdateSource.cs | 3 --- .../DiagnosticAnalyzerService_UpdateSource.cs | 10 ---------- .../TaskList/ExternalErrorDiagnosticUpdateSource.cs | 8 -------- .../Diagnostics/ExternalDiagnosticUpdateSourceTests.vb | 8 -------- 8 files changed, 2 insertions(+), 45 deletions(-) diff --git a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs index b7c3ab927e086..26d78404a272e 100644 --- a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs +++ b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs @@ -127,9 +127,6 @@ public TestDiagnosticUpdateSource(bool support, DiagnosticData[]? diagnosticData public event EventHandler>? DiagnosticsUpdated; public event EventHandler? DiagnosticsCleared; - public ValueTask> GetDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default) - => new(_support ? _diagnosticData : ImmutableArray.Empty); - public void RaiseDiagnosticsUpdatedEvent(ImmutableArray args) => DiagnosticsUpdated?.Invoke(this, args); diff --git a/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs b/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs index c78608a989456..51c6aa2b26612 100644 --- a/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs +++ b/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs @@ -88,9 +88,6 @@ public void RaiseDiagnosticsUpdated(ImmutableArray args) public event EventHandler DiagnosticsCleared { add { } remove { } } public bool SupportGetDiagnostics => false; - - public ValueTask> GetDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default) - => new(includeSuppressedDiagnostics ? _diagnostics : _diagnostics.WhereAsArray(d => !d.IsSuppressed)); } } } diff --git a/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs b/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs index aad8ee4d6f6b5..b458dbe22abce 100644 --- a/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs +++ b/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs @@ -26,9 +26,6 @@ internal abstract class AbstractHostDiagnosticUpdateSource : IDiagnosticUpdateSo public bool SupportGetDiagnostics => false; - public ValueTask> GetDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) - => new([]); - public event EventHandler>? DiagnosticsUpdated; public event EventHandler DiagnosticsCleared { add { } remove { } } diff --git a/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs b/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs index 9fa64d6182530..4665e2dd994a0 100644 --- a/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs +++ b/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs @@ -25,13 +25,8 @@ internal interface IDiagnosticUpdateSource event EventHandler DiagnosticsCleared; /// - /// Return if the source supports API otherwise, return - /// so that the engine can cache data from in memory. + /// Return if the source supports GetDiagnosticsAsync API otherwise, return so that the engine can cache data from in memory. /// bool SupportGetDiagnostics { get; } - - /// - /// Get diagnostics stored in the source. - /// - ValueTask> GetDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken); } diff --git a/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs b/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs index ca77fa41c5173..8431d9dd9d5d0 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs @@ -49,9 +49,6 @@ internal EditAndContinueDiagnosticUpdateSource() /// public bool SupportGetDiagnostics => false; - public ValueTask> GetDiagnosticsAsync(Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default) - => new([]); - /// /// Clears all diagnostics reported thru this source. /// We do not track the particular reported diagnostics here since we can just clear all of them at once. diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs index b4f35d656d3aa..e62905e15cea4 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs @@ -101,15 +101,5 @@ void raiseEvents(ImmutableArray args) } bool IDiagnosticUpdateSource.SupportGetDiagnostics => true; - - ValueTask> IDiagnosticUpdateSource.GetDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) - { - if (id != null) - { - return new ValueTask>(GetSpecificCachedDiagnosticsAsync(workspace, id, includeSuppressedDiagnostics, includeNonLocalDocumentDiagnostics: true, cancellationToken)); - } - - return new ValueTask>(GetCachedDiagnosticsAsync(workspace, projectId, documentId, includeSuppressedDiagnostics, includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: true, cancellationToken)); - } } } diff --git a/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs b/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs index 5b115f5944d1e..6aec2a632d684 100644 --- a/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs +++ b/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs @@ -629,16 +629,8 @@ private void ProcessAndRaiseDiagnosticsUpdated(ImmutableArray BuildProgressChanged?.Invoke(this, progress); - #region not supported public bool SupportGetDiagnostics { get { return false; } } - public ValueTask> GetDiagnosticsAsync( - Workspace workspace, ProjectId? projectId, DocumentId? documentId, object? id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default) - { - return new ValueTask>(ImmutableArray.Empty); - } - #endregion - internal TestAccessor GetTestAccessor() => new(this); diff --git a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb index 2a221c24b0061..0b1acf78ef3bc 100644 --- a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb +++ b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb @@ -667,10 +667,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Public Event DiagnosticsUpdated As EventHandler(Of ImmutableArray(Of DiagnosticsUpdatedArgs)) Implements IDiagnosticUpdateSource.DiagnosticsUpdated Public Event DiagnosticsCleared As EventHandler Implements IDiagnosticUpdateSource.DiagnosticsCleared - Public Function GetDiagnosticsAsync(workspace As Workspace, projectId As ProjectId, documentId As DocumentId, id As Object, includeSuppressedDiagnostics As Boolean, cancellationToken As CancellationToken) As ValueTask(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticUpdateSource.GetDiagnosticsAsync - Return New ValueTask(Of ImmutableArray(Of DiagnosticData))(If(includeSuppressedDiagnostics, _data, _data.WhereAsArray(Function(d) Not d.IsSuppressed))) - End Function - Public Sub Reanalyze(workspace As Workspace, projectIds As IEnumerable(Of ProjectId), documentIds As IEnumerable(Of DocumentId), highPriority As Boolean) Implements IDiagnosticAnalyzerService.Reanalyze End Sub @@ -686,10 +682,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() End Function - Public Function GetDiagnosticsAsync(solution As Solution, projectId As ProjectId, documentId As DocumentId, includeSuppressedDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetDiagnosticsAsync - Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() - End Function - Public Function GetDiagnosticsForIdsAsync(solution As Solution, projectId As ProjectId, documentId As DocumentId, diagnosticIds As ImmutableHashSet(Of String), shouldIncludeAnalyzer As Func(Of DiagnosticAnalyzer, Boolean), includeSuppressedDiagnostics As Boolean, includeLocalDocumentDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetDiagnosticsForIdsAsync Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() End Function From 6dcb3bb68ba386ccf8bbc09160ac6541bc1691bb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:44:35 -0800 Subject: [PATCH 07/11] Remove more code only called by tests --- .../Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb index 0b1acf78ef3bc..9d57a8bc2e829 100644 --- a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb +++ b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb @@ -641,7 +641,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Private Class TestDiagnosticAnalyzerService Implements IDiagnosticAnalyzerService, IDiagnosticUpdateSource - Private ReadOnly _data As ImmutableArray(Of DiagnosticData) Private ReadOnly _analyzerInfoCache As DiagnosticAnalyzerInfoCache Public ReadOnly Property GlobalOptions As IGlobalOptionService Implements IDiagnosticAnalyzerService.GlobalOptions @@ -682,6 +681,10 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() End Function + Public Function GetDiagnosticsAsync(solution As Solution, projectId As ProjectId, documentId As DocumentId, includeSuppressedDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetDiagnosticsAsync + Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() + End Function + Public Function GetDiagnosticsForIdsAsync(solution As Solution, projectId As ProjectId, documentId As DocumentId, diagnosticIds As ImmutableHashSet(Of String), shouldIncludeAnalyzer As Func(Of DiagnosticAnalyzer, Boolean), includeSuppressedDiagnostics As Boolean, includeLocalDocumentDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetDiagnosticsForIdsAsync Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() End Function From fe41d7ee1a137f97f3c70541327a8b5349d3489f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:45:33 -0800 Subject: [PATCH 08/11] Remove more code only called by tests --- .../Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb | 1 - 1 file changed, 1 deletion(-) diff --git a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb index 9d57a8bc2e829..85dff7c7d61f3 100644 --- a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb +++ b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb @@ -646,7 +646,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Public ReadOnly Property GlobalOptions As IGlobalOptionService Implements IDiagnosticAnalyzerService.GlobalOptions Public Sub New(globalOptions As IGlobalOptionService, Optional data As ImmutableArray(Of DiagnosticData) = Nothing) - _data = data.NullToEmpty _analyzerInfoCache = New DiagnosticAnalyzerInfoCache() Me.GlobalOptions = globalOptions End Sub From b1c2160d4b400b2d43c015679312df592e5419d4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:49:12 -0800 Subject: [PATCH 09/11] Remove more code only called by tests --- .../Test/Diagnostics/DiagnosticServiceTests.cs | 3 --- .../TestUtilities/Squiggles/TestDiagnosticTagProducer.cs | 2 -- .../Diagnostics/AbstractHostDiagnosticUpdateSource.cs | 2 -- .../Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs | 6 ------ .../EditAndContinueDiagnosticUpdateSource.cs | 5 ----- .../Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs | 2 -- .../Protocol/Features/Diagnostics/DiagnosticService.cs | 3 +-- .../Diagnostics/ExternalDiagnosticUpdateSourceTests.vb | 8 -------- 8 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs index 26d78404a272e..239a1365e9875 100644 --- a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs +++ b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs @@ -115,15 +115,12 @@ private static DiagnosticData CreateDiagnosticData(ProjectId? projectId, Documen private class TestDiagnosticUpdateSource : IDiagnosticUpdateSource { private readonly bool _support; - private readonly ImmutableArray _diagnosticData; public TestDiagnosticUpdateSource(bool support, DiagnosticData[]? diagnosticData) { _support = support; - _diagnosticData = (diagnosticData ?? []).ToImmutableArray(); } - public bool SupportGetDiagnostics { get { return _support; } } public event EventHandler>? DiagnosticsUpdated; public event EventHandler? DiagnosticsCleared; diff --git a/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs b/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs index 51c6aa2b26612..a40639fb1579d 100644 --- a/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs +++ b/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs @@ -86,8 +86,6 @@ public void RaiseDiagnosticsUpdated(ImmutableArray args) public event EventHandler>? DiagnosticsUpdated; public event EventHandler DiagnosticsCleared { add { } remove { } } - - public bool SupportGetDiagnostics => false; } } } diff --git a/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs b/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs index b458dbe22abce..2e7cdd0704fde 100644 --- a/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs +++ b/src/Features/Core/Portable/Diagnostics/AbstractHostDiagnosticUpdateSource.cs @@ -24,8 +24,6 @@ internal abstract class AbstractHostDiagnosticUpdateSource : IDiagnosticUpdateSo public abstract Workspace Workspace { get; } - public bool SupportGetDiagnostics => false; - public event EventHandler>? DiagnosticsUpdated; public event EventHandler DiagnosticsCleared { add { } remove { } } diff --git a/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs b/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs index 4665e2dd994a0..eb75cb6bd063b 100644 --- a/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs +++ b/src/Features/Core/Portable/Diagnostics/IDiagnosticUpdateSource.cs @@ -23,10 +23,4 @@ internal interface IDiagnosticUpdateSource /// Raise this when all diagnostics reported from this update source has cleared /// event EventHandler DiagnosticsCleared; - - /// - /// Return if the source supports GetDiagnosticsAsync API otherwise, return so that the engine can cache data from in memory. - /// - bool SupportGetDiagnostics { get; } } diff --git a/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs b/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs index 8431d9dd9d5d0..12ef5a0b226ae 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditAndContinueDiagnosticUpdateSource.cs @@ -44,11 +44,6 @@ internal EditAndContinueDiagnosticUpdateSource() public event EventHandler>? DiagnosticsUpdated; public event EventHandler? DiagnosticsCleared; - /// - /// This implementation reports diagnostics via event. - /// - public bool SupportGetDiagnostics => false; - /// /// Clears all diagnostics reported thru this source. /// We do not track the particular reported diagnostics here since we can just clear all of them at once. diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs index e62905e15cea4..2d4a1d39db757 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_UpdateSource.cs @@ -99,7 +99,5 @@ void raiseEvents(ImmutableArray args) _eventQueue.ScheduleTask(nameof(RaiseDiagnosticsUpdated), () => eventActionAsync(raiseEvents), CancellationToken.None); } } - - bool IDiagnosticUpdateSource.SupportGetDiagnostics => true; } } diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs index 569709876c2b7..67355e053ee03 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticService.cs @@ -141,8 +141,7 @@ private ImmutableArray UpdateDataMap(IDiagnosticUpdateSo if (diagnostics.Length > 0) { - // save data only if there is a diagnostic - var data = source.SupportGetDiagnostics ? new Data(args) : new Data(args, diagnostics); + var data = new Data(args, diagnostics); diagnosticDataMap.Add(args.Id, data); } diff --git a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb index 85dff7c7d61f3..e0c0d0306f3d4 100644 --- a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb +++ b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb @@ -36,8 +36,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Dim service = New TestDiagnosticAnalyzerService(workspace.GlobalOptions) Using source = New ExternalErrorDiagnosticUpdateSource( workspace, service, workspace.GetService(Of IGlobalOperationNotificationService), waiter, CancellationToken.None) - - Assert.False(source.SupportGetDiagnostics) End Using End Using End Sub @@ -650,12 +648,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Me.GlobalOptions = globalOptions End Sub - Public ReadOnly Property SupportGetDiagnostics As Boolean Implements IDiagnosticUpdateSource.SupportGetDiagnostics - Get - Return True - End Get - End Property - Public ReadOnly Property AnalyzerInfoCache As DiagnosticAnalyzerInfoCache Implements IDiagnosticAnalyzerService.AnalyzerInfoCache Get Return _analyzerInfoCache From 036d47139c3843b68e3792da8bfc40b22b7b56f1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 14:57:17 -0800 Subject: [PATCH 10/11] lint --- .../Test/Diagnostics/DiagnosticServiceTests.cs | 11 ++--------- .../Squiggles/TestDiagnosticTagProducer.cs | 3 --- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs index 239a1365e9875..bd444dac906fd 100644 --- a/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs +++ b/src/EditorFeatures/Test/Diagnostics/DiagnosticServiceTests.cs @@ -35,10 +35,10 @@ public void TestCleared() var diagnosticService = GetDiagnosticService(workspace); - var source1 = new TestDiagnosticUpdateSource(support: false, diagnosticData: null); + var source1 = new TestDiagnosticUpdateSource(); diagnosticService.Register(source1); - var source2 = new TestDiagnosticUpdateSource(support: false, diagnosticData: null); + var source2 = new TestDiagnosticUpdateSource(); diagnosticService.Register(source2); diagnosticService.DiagnosticsUpdated += MarkSet; @@ -114,13 +114,6 @@ private static DiagnosticData CreateDiagnosticData(ProjectId? projectId, Documen private class TestDiagnosticUpdateSource : IDiagnosticUpdateSource { - private readonly bool _support; - - public TestDiagnosticUpdateSource(bool support, DiagnosticData[]? diagnosticData) - { - _support = support; - } - public event EventHandler>? DiagnosticsUpdated; public event EventHandler? DiagnosticsCleared; diff --git a/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs b/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs index a40639fb1579d..b3891e7d0d3a7 100644 --- a/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs +++ b/src/EditorFeatures/TestUtilities/Squiggles/TestDiagnosticTagProducer.cs @@ -76,11 +76,8 @@ internal static DiagnosticData CreateDiagnosticData(EditorTestHostDocument docum private class TestDiagnosticUpdateSource : IDiagnosticUpdateSource { - private ImmutableArray _diagnostics = ImmutableArray.Empty; - public void RaiseDiagnosticsUpdated(ImmutableArray args) { - _diagnostics = args.SelectManyAsArray(e => e.Diagnostics); DiagnosticsUpdated?.Invoke(this, args); } From 4e9734b3c4c44d68c8c0db80dfc288a8b1149ebd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 7 Mar 2024 15:00:40 -0800 Subject: [PATCH 11/11] Remove more code only called by tests --- .../MockDiagnosticAnalyzerService.cs | 3 --- .../Diagnostics/IDiagnosticAnalyzerService.cs | 18 ------------------ .../Diagnostics/DiagnosticAnalyzerService.cs | 10 ---------- ...nosticIncrementalAnalyzer_GetDiagnostics.cs | 11 ----------- .../ExternalDiagnosticUpdateSourceTests.vb | 4 ---- 5 files changed, 46 deletions(-) diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/MockDiagnosticAnalyzerService.cs b/src/EditorFeatures/TestUtilities/Diagnostics/MockDiagnosticAnalyzerService.cs index 37809c55ec382..cf0f9c741a49f 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/MockDiagnosticAnalyzerService.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/MockDiagnosticAnalyzerService.cs @@ -70,9 +70,6 @@ public Task> GetDiagnosticsForSpanAsync(TextDocum public Task> GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId? projectId, ImmutableHashSet? diagnosticIds, Func? shouldIncludeAnalyzer, bool includeSuppressedDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) => throw new NotImplementedException(); - public Task> GetSpecificCachedDiagnosticsAsync(Workspace workspace, object id, bool includeSuppressedDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) - => throw new NotImplementedException(); - public Task<(ImmutableArray diagnostics, bool upToDate)> TryGetDiagnosticsForSpanAsync(TextDocument document, TextSpan range, Func? shouldIncludeDiagnostic, bool includeSuppressedDiagnostics, ICodeActionRequestPriorityProvider priorityProvider, DiagnosticKind diagnosticKind, bool isExplicit, CancellationToken cancellationToken) => throw new NotImplementedException(); } diff --git a/src/Features/Core/Portable/Diagnostics/IDiagnosticAnalyzerService.cs b/src/Features/Core/Portable/Diagnostics/IDiagnosticAnalyzerService.cs index 25f722a88a18b..5c85d2e600442 100644 --- a/src/Features/Core/Portable/Diagnostics/IDiagnosticAnalyzerService.cs +++ b/src/Features/Core/Portable/Diagnostics/IDiagnosticAnalyzerService.cs @@ -30,24 +30,6 @@ internal interface IDiagnosticAnalyzerService /// void Reanalyze(Workspace workspace, IEnumerable? projectIds, IEnumerable? documentIds, bool highPriority); - /// - /// Get specific diagnostics currently stored in the source. returned diagnostic might be out-of-date if solution has changed but analyzer hasn't run for the new solution. - /// - /// Workspace to fetch the diagnostics for. - /// - /// Specific id to scope the returned diagnostics. This id must correspond to the - /// associated with event. - /// - /// Indicates if diagnostics suppressed in source via pragmas and SuppressMessageAttributes should be returned. - /// - /// Indicates if non-local document diagnostics must be returned. - /// Non-local diagnostics are the ones reported by analyzers either at compilation end callback OR - /// in a different file from which the callback was made. Entire project must be analyzed to get the - /// complete set of non-local document diagnostics. - /// - /// Cancellation token. - Task> GetSpecificCachedDiagnosticsAsync(Workspace workspace, object id, bool includeSuppressedDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken); - /// /// Get diagnostics currently stored in the source. returned diagnostic might be out-of-date if solution has changed but analyzer hasn't run for the new solution. /// diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs index fbc4d8d24f62b..70c6d2cad6047 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService.cs @@ -148,16 +148,6 @@ public Task> GetCachedDiagnosticsAsync(Workspace return SpecializedTasks.EmptyImmutableArray(); } - public Task> GetSpecificCachedDiagnosticsAsync(Workspace workspace, object id, bool includeSuppressedDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) - { - if (_map.TryGetValue(workspace, out var analyzer)) - { - return analyzer.GetSpecificCachedDiagnosticsAsync(workspace.CurrentSolution, id, includeSuppressedDiagnostics, includeNonLocalDocumentDiagnostics, cancellationToken); - } - - return SpecializedTasks.EmptyImmutableArray(); - } - public Task> GetDiagnosticsAsync(Solution solution, ProjectId? projectId, DocumentId? documentId, bool includeSuppressedDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) { if (_map.TryGetValue(solution.Workspace, out var analyzer)) diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs index a3c33efdbc890..7bf0a3fbb7bf0 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs @@ -15,17 +15,6 @@ namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2 { internal partial class DiagnosticIncrementalAnalyzer { - public Task> GetSpecificCachedDiagnosticsAsync(Solution solution, object id, bool includeSuppressedDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) - { - if (id is not LiveDiagnosticUpdateArgsId argsId) - { - return SpecializedTasks.EmptyImmutableArray(); - } - - var (documentId, projectId) = (argsId.ProjectOrDocumentId is DocumentId docId) ? (docId, docId.ProjectId) : (null, (ProjectId)argsId.ProjectOrDocumentId); - return new IdeCachedDiagnosticGetter(this, solution, projectId, documentId, includeSuppressedDiagnostics, includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics).GetSpecificDiagnosticsAsync(argsId.Analyzer, argsId.Kind, cancellationToken); - } - public Task> GetCachedDiagnosticsAsync(Solution solution, ProjectId? projectId, DocumentId? documentId, bool includeSuppressedDiagnostics, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) => new IdeCachedDiagnosticGetter(this, solution, projectId, documentId, includeSuppressedDiagnostics, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken); diff --git a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb index e0c0d0306f3d4..3c03a208a23a3 100644 --- a/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb +++ b/src/VisualStudio/Core/Test/Diagnostics/ExternalDiagnosticUpdateSourceTests.vb @@ -664,10 +664,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData) End Function - Public Function GetSpecificCachedDiagnosticsAsync(workspace As Workspace, id As Object, includeSuppressedDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetSpecificCachedDiagnosticsAsync - Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() - End Function - Public Function GetCachedDiagnosticsAsync(workspace As Workspace, projectId As ProjectId, documentId As DocumentId, includeSuppressedDiagnostics As Boolean, includeLocalDocumentDiagnostics As Boolean, includeNonLocalDocumentDiagnostics As Boolean, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetCachedDiagnosticsAsync Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)() End Function