Skip to content

Commit

Permalink
Fix analyzer test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Apr 17, 2022
1 parent 2f88954 commit 1340c24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICodeActionProvider> providers,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -157,7 +168,7 @@ void decrementDocumentCountRemaining()

_workQueue.WorkComplete(workType);

await Task.Delay(50);
await Task.Delay(WorkerWait);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -219,7 +230,7 @@ public async Task<IEnumerable<Diagnostic>> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"));

Expand Down

0 comments on commit 1340c24

Please sign in to comment.