From 1340c24208494957b0a1464386ff0099d88425cd Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 17 Apr 2022 00:17:43 -0700 Subject: [PATCH] Fix analyzer test --- .../CSharpDiagnosticWorkerWithAnalyzers.cs | 15 +++++++++++++-- .../ProjectWithAnalyzersTests.cs | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorkerWithAnalyzers.cs b/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorkerWithAnalyzers.cs index 62590c5dee..1c9ddd91f2 100644 --- a/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorkerWithAnalyzers.cs +++ b/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorkerWithAnalyzers.cs @@ -33,6 +33,8 @@ public class CSharpDiagnosticWorkerWithAnalyzers : ICsDiagnosticWorker, IDisposa private readonly OmniSharpOptions _options; private readonly OmniSharpWorkspace _workspace; + private const int WorkerWait = 250; + public CSharpDiagnosticWorkerWithAnalyzers( OmniSharpWorkspace workspace, [ImportMany] IEnumerable providers, @@ -114,6 +116,15 @@ private async Task Worker(AnalyzerWorkType workType) .Where(x => x.projectId != null) .ToImmutableArray(); + if (documents.IsEmpty) + { + _workQueue.WorkComplete(workType); + + await Task.Delay(WorkerWait); + + continue; + } + var documentCount = documents.Length; var documentCountRemaining = documentCount; @@ -157,7 +168,7 @@ void decrementDocumentCountRemaining() _workQueue.WorkComplete(workType); - await Task.Delay(50); + await Task.Delay(WorkerWait); } catch (Exception ex) { @@ -219,7 +230,7 @@ public async Task> AnalyzeDocumentAsync(Document documen Project project = document.Project; var allAnalyzers = GetAnalyzersForProject(project); var compilation = await project.GetCompilationAsync(cancellationToken); - + cancellationToken.ThrowIfCancellationRequested(); return await AnalyzeDocument(project, allAnalyzers, compilation, CreateAnalyzerOptions(document.Project), document); } diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs index 1b3e0da07b..fbe0026754 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs @@ -286,7 +286,7 @@ public async Task WhenNewAnalyzerReferenceIsAdded_ThenAutomaticallyUseItWithoutR csprojFileXml => { var referencesGroup = csprojFileXml.Descendants("ItemGroup").FirstOrDefault(); - referencesGroup.Add(new XElement("PackageReference", new XAttribute("Include", "Roslynator.Analyzers"), new XAttribute("Version", "2.1.0"))); + referencesGroup.Add(new XElement("PackageReference", new XAttribute("Include", "Roslynator.Analyzers"), new XAttribute("Version", "4.1.0"), new XAttribute("PrivateAssets", "all"), new XAttribute("IncludeAssets", "runtime; build; native; contentfiles; analyzers"))); }); await NotifyFileChanged(host, csprojFile); @@ -295,7 +295,7 @@ public async Task WhenNewAnalyzerReferenceIsAdded_ThenAutomaticallyUseItWithoutR await host.RestoreProject(testProject); // Todo: This can be removed and replaced with wait for event (project analyzed eg.) once they are available. - await Task.Delay(2000); + await Task.Delay(5000); var diagnostics = await host.RequestCodeCheckAsync(Path.Combine(testProject.Directory, "Program.cs"));