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 a380137
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 81 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 = 500;

public CSharpDiagnosticWorkerWithAnalyzers(
OmniSharpWorkspace workspace,
[ImportMany] IEnumerable<ICodeActionProvider> providers,
Expand Down Expand Up @@ -114,6 +116,12 @@ private async Task Worker(AnalyzerWorkType workType)
.Where(x => x.projectId != null)
.ToImmutableArray();

if (documents.IsEmpty)
{
await Task.Delay(WorkerWait);
continue;
}

var documentCount = documents.Length;
var documentCountRemaining = documentCount;

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

_workQueue.WorkComplete(workType);

await Task.Delay(50);
await Task.Delay(WorkerWait);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -219,7 +227,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
19 changes: 15 additions & 4 deletions tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OmniSharp.Eventing;
using OmniSharp.MSBuild.Discovery;
using OmniSharp.Roslyn.Utilities;
using OmniSharp.Services;
Expand Down Expand Up @@ -43,12 +44,22 @@ public void Dispose()
(_msbuildLocator as IDisposable)?.Dispose();
}

protected OmniSharpTestHost CreateMSBuildTestHost(string path, IEnumerable<ExportDescriptorProvider> additionalExports = null,
IConfiguration configurationData = null)
protected OmniSharpTestHost CreateMSBuildTestHost(
string path,
IEnumerable<ExportDescriptorProvider> additionalExports = null,
IConfiguration configurationData = null,
IEventEmitter eventEmitter = null)
{
var environment = new OmniSharpEnvironment(path, logLevel: LogLevel.Trace);
var serviceProvider = TestServiceProvider.Create(this.TestOutput, environment, this.LoggerFactory, _assemblyLoader, _analyzerAssemblyLoader, _msbuildLocator,
configurationData);
var serviceProvider = TestServiceProvider.Create(
this.TestOutput,
environment,
this.LoggerFactory,
_assemblyLoader,
_analyzerAssemblyLoader,
_msbuildLocator,
configurationData,
eventEmitter: eventEmitter);

return OmniSharpTestHost.Create(serviceProvider, additionalExports);
}
Expand Down
Loading

0 comments on commit a380137

Please sign in to comment.