提交 883bde50 编写于 作者: T Tomas Matousek

Feedback

上级 d407343c
......@@ -143,8 +143,8 @@ private async Task SynchronizeGlobalAssetToRemoteHostIfNeededAsync(Workspace wor
_ = await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizeGlobalAssetsAsync),
workspace.CurrentSolution,
new[] { (object)checksums },
workspace.CurrentSolution,
callbackTarget: null,
CancellationToken.None).ConfigureAwait(false);
}
......
......@@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Packaging;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Utilities;
using Roslyn.Utilities;
......@@ -141,10 +142,7 @@ private partial class SymbolReferenceFinder
foreach (var reference in project.MetadataReferences)
{
cancellationToken.ThrowIfCancellationRequested();
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
// The project must support compilations since we only create compilation for the project that invoked AddImport feature.
RoslynDebug.Assert(compilation != null);
var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false);
var assemblySymbol = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol;
if (assemblySymbol?.Name == result.AssemblyName)
......
......@@ -110,6 +110,7 @@ private async Task FireAndForgetReportAnalyzerPerformanceAsync(Project project,
// +1 for project itself
project.DocumentIds.Count + 1
},
solution: null,
callbackTarget: null,
cancellationToken).ConfigureAwait(false);
}
......
......@@ -540,6 +540,7 @@ private async Task ReportAnalyzerPerformanceAsync(Document document, Compilation
WellKnownServiceHubServices.CodeAnalysisService,
nameof(IRemoteDiagnosticAnalyzerService.ReportAnalyzerPerformance),
new object[] { pooledObject.Object.ToAnalyzerPerformanceInfo(AnalyzerService), /* unit count */ 1 },
solution: null,
callbackTarget: null,
cancellationToken).ConfigureAwait(false);
}
......
......@@ -213,8 +213,8 @@ private async Task<RemoteHostClient> EnableAsync(CancellationToken cancellationT
var success = await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizeGlobalAssetsAsync),
_workspace.CurrentSolution,
new[] { (object)checksums },
_workspace.CurrentSolution,
callbackTarget: null,
cancellationToken).ConfigureAwait(false);
......
......@@ -187,6 +187,7 @@ private void PushTextChanges(Document oldDocument, Document newDocument)
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizeTextAsync),
new object[] { oldDocument.Id, state.Text, textChanges },
solution: null,
callbackTarget: null,
CancellationToken).ConfigureAwait(false);
......
......@@ -27,7 +27,7 @@ internal static class Connections
TimeSpan timeout,
CancellationToken cancellationToken)
{
const int RetryDelayInMS = 50;
var retryDelay = TimeSpan.FromMilliseconds(50);
using (var pooledStopwatch = SharedPools.Default<Stopwatch>().GetPooledObject())
{
......@@ -42,16 +42,16 @@ internal static class Connections
{
return await client.RequestServiceAsync(descriptor, cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException e) when (e.CancellationToken != cancellationToken)
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
{
// Retry on cancellation that is not sourced by our cancellation token.
// Since HubClient will throw when it can't connect to service hub service (e.g. timeout, disposal).
}
// wait before next try
await Task.Delay(RetryDelayInMS, cancellationToken).ConfigureAwait(false);
await Task.Delay(retryDelay, cancellationToken).ConfigureAwait(false);
// if we tried for more than 10 mins and still couldn't connect, report non-fatal Watson
// if we tried for too long and still couldn't connect, report non-fatal Watson
if (!s_timeoutReported && watch.Elapsed > s_reportTimeout)
{
s_timeoutReported = true;
......@@ -80,9 +80,9 @@ internal static class Connections
CancellationToken cancellationToken)
{
const int MaxRetryAttempts = 10;
const int RetryDelayInMS = 50;
var retryDelay = TimeSpan.FromMilliseconds(50);
RemoteInvocationException lastException = null;
Exception lastException = null;
var descriptor = new ServiceDescriptor(serviceName) { HostGroup = hostGroup };
......@@ -103,7 +103,7 @@ internal static class Connections
timeout,
cancellationToken).ConfigureAwait(false);
}
catch (RemoteInvocationException ex)
catch (Exception ex) when (!(ex is OperationCanceledException))
{
// save info only if it failed with different issue than before.
if (lastException?.Message != ex.Message)
......@@ -117,7 +117,7 @@ internal static class Connections
}
// wait before next try
await Task.Delay(RetryDelayInMS, cancellationToken).ConfigureAwait(false);
await Task.Delay(retryDelay, cancellationToken).ConfigureAwait(false);
}
RemoteHostCrashInfoBar.ShowInfoBar(workspace, lastException);
......
......@@ -118,8 +118,8 @@ private async Task UpdatePrimaryWorkspace(InProcRemoteHostClient client, Solutio
Assert.True(await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizePrimaryWorkspaceAsync),
solution,
new object[] { await solution.State.GetChecksumAsync(CancellationToken.None), _solutionVersion++ },
solution,
callbackTarget: null,
CancellationToken.None));
}
......
......@@ -106,6 +106,7 @@ public async Task TestRemoteHostTextSynchronize()
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizeTextAsync),
new object[] { oldDocument.Id, oldState.Text, newText.GetTextChanges(oldText) },
solution: null,
callbackTarget: null,
CancellationToken.None);
......@@ -178,8 +179,8 @@ public async Task TestRemoteHostSynchronizeGlobalAssets()
Assert.True(await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizeGlobalAssetsAsync),
workspace.CurrentSolution,
new object[] { new Checksum[0] { } },
workspace.CurrentSolution,
callbackTarget: null,
CancellationToken.None));
......@@ -379,8 +380,8 @@ private async Task UpdatePrimaryWorkspace(InProcRemoteHostClient client, Solutio
Assert.True(await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizePrimaryWorkspaceAsync),
solution,
new object[] { await solution.State.GetChecksumAsync(CancellationToken.None), _solutionVersion++ },
solution,
callbackTarget: null,
CancellationToken.None));
}
......
......@@ -177,8 +177,8 @@ void Method()
Assert.True(await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizeGlobalAssetsAsync),
workspace.CurrentSolution,
new[] { new Checksum[] { asset.Checksum } },
workspace.CurrentSolution,
callbackTarget: null,
CancellationToken.None));
......@@ -233,10 +233,10 @@ void Method()
Assert.True(await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizeGlobalAssetsAsync),
workspace.CurrentSolution,
new[] { new Checksum[] { asset.Checksum } },
workspace.CurrentSolution,
callbackTarget: null,
CancellationToken.None));
cancellationToken: CancellationToken.None));
// run analysis
var project = workspace.CurrentSolution.Projects.First().AddAnalyzerReference(analyzerReference);
......
......@@ -71,6 +71,7 @@ public static void SetLoggers(IGlobalOptionService optionService, IThreadingCont
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SetLoggingFunctionIds),
new object[] { loggerTypes, functionIds },
solution: null,
callbackTarget: null,
CancellationToken.None));
}
......
......@@ -30,8 +30,8 @@ public static partial class SymbolFinder
var success = await client.TryRunRemoteAsync(
WellKnownServiceHubServices.CodeAnalysisService,
nameof(IRemoteSymbolFinder.FindLiteralReferencesAsync),
solution,
new object[] { value, typeCode },
solution,
serverCallback,
cancellationToken).ConfigureAwait(false);
......
......@@ -42,13 +42,13 @@ public static partial class SymbolFinder
var success = await client.TryRunRemoteAsync(
WellKnownServiceHubServices.CodeAnalysisService,
nameof(IRemoteSymbolFinder.FindReferencesAsync),
solution,
new object[]
{
SerializableSymbolAndProjectId.Dehydrate(symbolAndProjectId),
documents?.Select(d => d.Id).ToArray(),
SerializableFindReferencesSearchOptions.Dehydrate(options),
},
solution,
serverCallback,
cancellationToken).ConfigureAwait(false);
......
......@@ -127,28 +127,31 @@ public static string CreateClientId(string prefix)
return new KeepAliveSession(this, connection, serviceName, callbackTarget);
}
public async Task<bool> TryRunRemoteAsync(string serviceName, string targetName, Solution solution,
IReadOnlyList<object> arguments, object? callbackTarget, CancellationToken cancellationToken)
public async Task<bool> TryRunRemoteAsync(string serviceName, string targetName, IReadOnlyList<object> arguments, Solution? solution, object? callbackTarget, CancellationToken cancellationToken)
{
using var session = await TryCreateSessionAsync(serviceName, solution, callbackTarget, cancellationToken).ConfigureAwait(false);
if (session == null)
{
return false;
}
// TODO: revisit solution handling - see https://github.com/dotnet/roslyn/issues/24836
await session.InvokeAsync(targetName, arguments, cancellationToken).ConfigureAwait(false);
return true;
}
if (solution == null)
{
using var connection = await TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);
if (connection == null)
{
return false;
}
public async Task<bool> TryRunRemoteAsync(string serviceName, string targetName, IReadOnlyList<object> arguments, object? callbackTarget, CancellationToken cancellationToken)
{
using var connection = await TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);
if (connection == null)
await connection.InvokeAsync(targetName, arguments, cancellationToken).ConfigureAwait(false);
}
else
{
return false;
using var session = await TryCreateSessionAsync(serviceName, solution, callbackTarget, cancellationToken).ConfigureAwait(false);
if (session == null)
{
return false;
}
await session.InvokeAsync(targetName, arguments, cancellationToken).ConfigureAwait(false);
}
await connection.InvokeAsync(targetName, arguments, cancellationToken).ConfigureAwait(false);
return true;
}
......
......@@ -34,8 +34,8 @@ public static async Task SynchronizePrimaryWorkspaceAsync(this Workspace workspa
_ = await client.TryRunRemoteAsync(
WellKnownRemoteHostServices.RemoteHostService,
nameof(IRemoteHostService.SynchronizePrimaryWorkspaceAsync),
solution,
new object[] { checksum, solution.WorkspaceVersion },
solution,
callbackTarget: null,
cancellationToken).ConfigureAwait(false);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册