提交 afbfe9dd 编写于 作者: C CyrusNajmabadi

Add option to disable OOP diagnostics during testing. They don't currently...

Add option to disable OOP diagnostics during testing.  They don't currently work with the CodeAction testing infrastructure.
上级 d190b8b8
......@@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.UnitTests;
......@@ -356,6 +357,10 @@ public TestParameters WithFixProviderData(object fixProviderData)
using (var workspace = CreateWorkspaceFromOptions(initialMarkup, parameters))
{
// Currently, OOP diagnostics don't work with code action tests.
workspace.Options = workspace.Options.WithChangedOption(
RemoteFeatureOptions.DiagnosticsEnabled, false);
var actions = await GetCodeActionsAsync(workspace, parameters);
await TestActionsAsync(
workspace, expected, index,
......
......@@ -8,7 +8,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.UnitTests.Diagnostics;
......@@ -63,6 +62,7 @@ internal virtual (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderA
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider))
{
var diagnostics = await testDriver.GetAllDiagnosticsAsync(provider, document, span);
AssertNoAnalyzerExceptionDiagnostics(diagnostics);
var fixer = providerAndFixer.Item2;
......
......@@ -14,7 +14,8 @@ namespace Microsoft.CodeAnalysis.Test.Utilities.RemoteHost
internal static class RemoteHostOptions
{
[ExportOption]
public static readonly Option<bool> RemoteHostTest = new Option<bool>(nameof(RemoteHostOptions), nameof(RemoteHostTest), defaultValue: false);
public static readonly Option<bool> RemoteHostTest = new Option<bool>(
nameof(RemoteHostOptions), nameof(RemoteHostTest), defaultValue: false);
}
[ExportWorkspaceService(typeof(IRemoteHostClientFactory)), Shared]
......
......@@ -58,34 +58,36 @@ public AnalyzerExecutor(AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateS
public async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeAsync(CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
{
var service = project.Solution.Workspace.Services.GetService<IRemoteHostClientService>();
if (service == null)
var workspace = project.Solution.Workspace;
if (workspace.Options.GetOption(RemoteFeatureOptions.DiagnosticsEnabled))
{
// host doesn't support RemoteHostService such as under unit test
return await AnalyzeInProcAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false);
}
var remoteHostClient = await service.TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
if (remoteHostClient == null)
{
// remote host is not running. this can happen if remote host is disabled.
return await AnalyzeInProcAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false);
var service = project.Solution.Workspace.Services.GetService<IRemoteHostClientService>();
if (service != null)
{
var remoteHostClient = await service.TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
if (remoteHostClient != null)
{
// due to OpenFileOnly analyzer, we need to run inproc as well for such analyzers
var inProcResultTask = AnalyzeInProcAsync(CreateAnalyzerDriver(analyzerDriver, a => a.IsOpenFileOnly(project.Solution.Workspace)), project, cancellationToken);
var outOfProcResultTask = AnalyzeOutOfProcAsync(remoteHostClient, analyzerDriver, project, cancellationToken);
// run them concurrently in vs and remote host
await Task.WhenAll(inProcResultTask, outOfProcResultTask).ConfigureAwait(false);
// make sure things are not cancelled
cancellationToken.ThrowIfCancellationRequested();
// merge 2 results
return DiagnosticAnalysisResultMap.Create(
inProcResultTask.Result.AnalysisResult.AddRange(outOfProcResultTask.Result.AnalysisResult),
inProcResultTask.Result.TelemetryInfo.AddRange(outOfProcResultTask.Result.TelemetryInfo));
}
}
}
// due to OpenFileOnly analyzer, we need to run inproc as well for such analyzers
var inProcResultTask = AnalyzeInProcAsync(CreateAnalyzerDriver(analyzerDriver, a => a.IsOpenFileOnly(project.Solution.Workspace)), project, cancellationToken);
var outOfProcResultTask = AnalyzeOutOfProcAsync(remoteHostClient, analyzerDriver, project, cancellationToken);
// run them concurrently in vs and remote host
await Task.WhenAll(inProcResultTask, outOfProcResultTask).ConfigureAwait(false);
// make sure things are not cancelled
cancellationToken.ThrowIfCancellationRequested();
// merge 2 results
return DiagnosticAnalysisResultMap.Create(
inProcResultTask.Result.AnalysisResult.AddRange(outOfProcResultTask.Result.AnalysisResult),
inProcResultTask.Result.TelemetryInfo.AddRange(outOfProcResultTask.Result.TelemetryInfo));
// host doesn't support RemoteHostService such as under unit test
// remote host is not running. this can happen if remote host is disabled.
return await AnalyzeInProcAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false);
}
private async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeInProcAsync(
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Remote;
namespace Microsoft.CodeAnalysis.NavigateTo
......
......@@ -44,6 +44,10 @@ internal static class RemoteFeatureOptions
nameof(RemoteFeatureOptions), nameof(SymbolFinderEnabled), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(SymbolFinderEnabled)));
public static readonly Option<bool> DiagnosticsEnabled = new Option<bool>(
nameof(RemoteFeatureOptions), nameof(DiagnosticsEnabled), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(DiagnosticsEnabled)));
private static ImmutableArray<Option<bool>> AllFeatureOptions { get; } =
ImmutableArray.Create(AddImportEnabled, DocumentHighlightingEnabled, NavigateToEnabled, SymbolSearchEnabled, SymbolFinderEnabled);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册