提交 99230ec2 编写于 作者: C CyrusNajmabadi 提交者: Heejae Chang

Properly thread through cancellation through a bunch of our RPC services (#34065)

* Property thread through cancellation through a bunch of our RPC services.

* Tokens

* Fix

* Revert
上级 a1c89711
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// 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.Concurrent;
......@@ -59,9 +59,9 @@ internal partial class SymbolSearchUpdateEngine
private readonly IDatabaseFactoryService _databaseFactoryService;
private readonly Func<Exception, bool> _reportAndSwallowException;
private Task LogInfoAsync(string text) => _logService.LogInfoAsync(text);
private Task LogInfoAsync(string text) => _logService.LogInfoAsync(text, _updateCancellationToken);
private Task LogExceptionAsync(Exception e, string text) => _logService.LogExceptionAsync(e.ToString(), text);
private Task LogExceptionAsync(Exception e, string text) => _logService.LogExceptionAsync(e.ToString(), text, _updateCancellationToken);
public Task UpdateContinuouslyAsync(string source, string localSettingsDirectory)
{
......@@ -227,24 +227,24 @@ private async Task<TimeSpan> DownloadFullDatabaseAsync()
try
{
var title = string.Format(EditorFeaturesWpfResources.Downloading_IntelliSense_index_for_0, _source);
await _service._progressService.OnDownloadFullDatabaseStartedAsync(title).ConfigureAwait(false);
await _service._progressService.OnDownloadFullDatabaseStartedAsync(title, _service._updateCancellationToken).ConfigureAwait(false);
var (succeeded, delay) = await DownloadFullDatabaseWorkerAsync().ConfigureAwait(false);
if (succeeded)
{
await _service._progressService.OnDownloadFullDatabaseSucceededAsync().ConfigureAwait(false);
await _service._progressService.OnDownloadFullDatabaseSucceededAsync(_service._updateCancellationToken).ConfigureAwait(false);
}
else
{
await _service._progressService.OnDownloadFullDatabaseFailedAsync(
EditorFeaturesWpfResources.Downloading_index_failed).ConfigureAwait(false);
EditorFeaturesWpfResources.Downloading_index_failed, _service._updateCancellationToken).ConfigureAwait(false);
}
return delay;
}
catch (OperationCanceledException)
{
await _service._progressService.OnDownloadFullDatabaseCanceledAsync().ConfigureAwait(false);
await _service._progressService.OnDownloadFullDatabaseCanceledAsync(_service._updateCancellationToken).ConfigureAwait(false);
throw;
}
catch (Exception e)
......@@ -252,7 +252,7 @@ private async Task<TimeSpan> DownloadFullDatabaseAsync()
var message = string.Format(
EditorFeaturesWpfResources.Downloading_index_failed_0,
"\r\n" + e.ToString());
await _service._progressService.OnDownloadFullDatabaseFailedAsync(message).ConfigureAwait(false);
await _service._progressService.OnDownloadFullDatabaseFailedAsync(message, _service._updateCancellationToken).ConfigureAwait(false);
throw;
}
}
......
......@@ -102,23 +102,23 @@ public CallbackObject(ISymbolSearchLogService logService, ISymbolSearchProgressS
_progressService = progressService;
}
public Task LogExceptionAsync(string exception, string text)
=> _logService.LogExceptionAsync(exception, text);
public Task LogExceptionAsync(string exception, string text, CancellationToken cancellationToken)
=> _logService.LogExceptionAsync(exception, text, cancellationToken);
public Task LogInfoAsync(string text)
=> _logService.LogInfoAsync(text);
public Task LogInfoAsync(string text, CancellationToken cancellationToken)
=> _logService.LogInfoAsync(text, cancellationToken);
public Task OnDownloadFullDatabaseStartedAsync(string title)
=> _progressService.OnDownloadFullDatabaseStartedAsync(title);
public Task OnDownloadFullDatabaseStartedAsync(string title, CancellationToken cancellationToken)
=> _progressService.OnDownloadFullDatabaseStartedAsync(title, cancellationToken);
public Task OnDownloadFullDatabaseSucceededAsync()
=> _progressService.OnDownloadFullDatabaseSucceededAsync();
public Task OnDownloadFullDatabaseSucceededAsync(CancellationToken cancellation)
=> _progressService.OnDownloadFullDatabaseSucceededAsync(cancellation);
public Task OnDownloadFullDatabaseCanceledAsync()
=> _progressService.OnDownloadFullDatabaseCanceledAsync();
public Task OnDownloadFullDatabaseCanceledAsync(CancellationToken cancellationToken)
=> _progressService.OnDownloadFullDatabaseCanceledAsync(cancellationToken);
public Task OnDownloadFullDatabaseFailedAsync(string message)
=> _progressService.OnDownloadFullDatabaseFailedAsync(message);
public Task OnDownloadFullDatabaseFailedAsync(string message, CancellationToken cancellationToken)
=> _progressService.OnDownloadFullDatabaseFailedAsync(message, cancellationToken);
}
}
}
......@@ -3,6 +3,7 @@
using System;
using System.Composition;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host.Mef;
......@@ -28,18 +29,18 @@ public VisualStudioSymbolSearchProgressService(VSShell.SVsServiceProvider servic
(IVsTaskStatusCenterService)serviceProvider.GetService(typeof(SVsTaskStatusCenterService)));
}
public async Task OnDownloadFullDatabaseStartedAsync(string title)
public async Task OnDownloadFullDatabaseStartedAsync(string title, CancellationToken cancellationToken)
{
try
{
await OnDownloadFullDatabaseStartedWorkerAsync(title).ConfigureAwait(false);
await OnDownloadFullDatabaseStartedWorkerAsync(title, cancellationToken).ConfigureAwait(false);
}
catch (Exception e) when (FatalError.ReportWithoutCrashUnlessCanceled(e))
{
}
}
private Task OnDownloadFullDatabaseStartedWorkerAsync(string title)
private Task OnDownloadFullDatabaseStartedWorkerAsync(string title, CancellationToken cancellationToken)
{
var options = GetOptions(title);
var data = new TaskProgressData
......@@ -78,7 +79,7 @@ private static TaskHandlerOptions GetOptions(string title)
return options;
}
public Task OnDownloadFullDatabaseSucceededAsync()
public Task OnDownloadFullDatabaseSucceededAsync(CancellationToken cancellation)
{
lock (_gate)
{
......@@ -87,7 +88,7 @@ public Task OnDownloadFullDatabaseSucceededAsync()
}
}
public Task OnDownloadFullDatabaseCanceledAsync()
public Task OnDownloadFullDatabaseCanceledAsync(CancellationToken cancellationToken)
{
lock (_gate)
{
......@@ -96,7 +97,7 @@ public Task OnDownloadFullDatabaseCanceledAsync()
}
}
public Task OnDownloadFullDatabaseFailedAsync(string message)
public Task OnDownloadFullDatabaseFailedAsync(string message, CancellationToken cancellationToken)
{
lock (_gate)
{
......
// 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.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.SymbolSearch;
......@@ -23,12 +24,12 @@ public LogService(IThreadingContext threadingContext, IVsActivityLog activityLog
_activityLog = activityLog;
}
public Task LogInfoAsync(string text)
public Task LogInfoAsync(string text, CancellationToken cancellationToken)
{
return LogAsync(text, __ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION);
}
public Task LogExceptionAsync(string exception, string text)
public Task LogExceptionAsync(string exception, string text, CancellationToken cancellationToken)
{
return LogAsync(text + ". " + exception, __ACTIVITYLOG_ENTRYTYPE.ALE_ERROR);
}
......
......@@ -287,13 +287,13 @@ public Assembly LoadFromPath(string fullPath)
private class MockLogAndProgressService : ISymbolSearchLogService, ISymbolSearchProgressService
{
public Task LogExceptionAsync(string exception, string text) => Task.CompletedTask;
public Task LogInfoAsync(string text) => Task.CompletedTask;
public Task LogExceptionAsync(string exception, string text, CancellationToken cancellationToken) => Task.CompletedTask;
public Task LogInfoAsync(string text, CancellationToken cancellationToken) => Task.CompletedTask;
public Task OnDownloadFullDatabaseStartedAsync(string title) => Task.CompletedTask;
public Task OnDownloadFullDatabaseSucceededAsync() => Task.CompletedTask;
public Task OnDownloadFullDatabaseCanceledAsync() => Task.CompletedTask;
public Task OnDownloadFullDatabaseFailedAsync(string message) => Task.CompletedTask;
public Task OnDownloadFullDatabaseStartedAsync(string title, CancellationToken cancellationToken) => Task.CompletedTask;
public Task OnDownloadFullDatabaseSucceededAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public Task OnDownloadFullDatabaseCanceledAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public Task OnDownloadFullDatabaseFailedAsync(string message, CancellationToken cancellationToken) => Task.CompletedTask;
}
}
}
......@@ -751,11 +751,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SymbolSearch
Private Sub New()
End Sub
Public Function LogExceptionAsync(exception As String, text As String) As Task Implements ISymbolSearchLogService.LogExceptionAsync
Public Function LogExceptionAsync(exception As String, text As String, cancellationToken As CancellationToken) As Task Implements ISymbolSearchLogService.LogExceptionAsync
Return Task.CompletedTask
End Function
Public Function LogInfoAsync(text As String) As Task Implements ISymbolSearchLogService.LogInfoAsync
Public Function LogInfoAsync(text As String, cancellationToken As CancellationToken) As Task Implements ISymbolSearchLogService.LogInfoAsync
Return Task.CompletedTask
End Function
End Class
......@@ -768,19 +768,19 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SymbolSearch
Private Sub New()
End Sub
Public Function OnDownloadFullDatabaseStartedAsync(title As String) As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseStartedAsync
Public Function OnDownloadFullDatabaseStartedAsync(title As String, cancellationToken As CancellationToken) As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseStartedAsync
Return Task.CompletedTask
End Function
Public Function OnDownloadFullDatabaseSucceededAsync() As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseSucceededAsync
Public Function OnDownloadFullDatabaseSucceededAsync(cancellationToken As CancellationToken) As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseSucceededAsync
Return Task.CompletedTask
End Function
Public Function OnDownloadFullDatabaseCanceledAsync() As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseCanceledAsync
Public Function OnDownloadFullDatabaseCanceledAsync(cancellationToken As CancellationToken) As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseCanceledAsync
Return Task.CompletedTask
End Function
Public Function OnDownloadFullDatabaseFailedAsync(message As String) As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseFailedAsync
Public Function OnDownloadFullDatabaseFailedAsync(message As String, cancellationToken As CancellationToken) As Task Implements ISymbolSearchProgressService.OnDownloadFullDatabaseFailedAsync
Return Task.CompletedTask
End Function
End Class
......
// 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.Threading;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.SymbolSearch
......@@ -9,7 +10,7 @@ namespace Microsoft.CodeAnalysis.SymbolSearch
/// </summary>
internal interface ISymbolSearchLogService
{
Task LogExceptionAsync(string exception, string text);
Task LogInfoAsync(string text);
Task LogExceptionAsync(string exception, string text, CancellationToken cancellationToken);
Task LogInfoAsync(string text, CancellationToken cancellationToken);
}
}
......@@ -2,6 +2,7 @@
using System;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
......@@ -11,11 +12,11 @@ namespace Microsoft.CodeAnalysis.SymbolSearch
{
internal interface ISymbolSearchProgressService : IWorkspaceService
{
Task OnDownloadFullDatabaseStartedAsync(string title);
Task OnDownloadFullDatabaseStartedAsync(string title, CancellationToken cancellationToken);
Task OnDownloadFullDatabaseSucceededAsync();
Task OnDownloadFullDatabaseCanceledAsync();
Task OnDownloadFullDatabaseFailedAsync(string message);
Task OnDownloadFullDatabaseSucceededAsync(CancellationToken cancellationToken);
Task OnDownloadFullDatabaseCanceledAsync(CancellationToken cancellationToken);
Task OnDownloadFullDatabaseFailedAsync(string message, CancellationToken cancellationToken);
}
[ExportWorkspaceService(typeof(ISymbolSearchProgressService)), Shared]
......@@ -26,9 +27,9 @@ public DefaultSymbolSearchProgressService()
{
}
public Task OnDownloadFullDatabaseStartedAsync(string title) => Task.CompletedTask;
public Task OnDownloadFullDatabaseSucceededAsync() => Task.CompletedTask;
public Task OnDownloadFullDatabaseCanceledAsync() => Task.CompletedTask;
public Task OnDownloadFullDatabaseFailedAsync(string message) => Task.CompletedTask;
public Task OnDownloadFullDatabaseStartedAsync(string title, CancellationToken cancellationToken) => Task.CompletedTask;
public Task OnDownloadFullDatabaseSucceededAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public Task OnDownloadFullDatabaseCanceledAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public Task OnDownloadFullDatabaseFailedAsync(string message, CancellationToken cancellationToken) => Task.CompletedTask;
}
}
......@@ -163,7 +163,9 @@ private class FindLiteralReferencesProgressCallback : IStreamingFindLiteralRefer
private readonly CodeAnalysisService _service;
private readonly CancellationToken _cancellationToken;
public FindLiteralReferencesProgressCallback(CodeAnalysisService service, CancellationToken cancellationToken)
public FindLiteralReferencesProgressCallback(
CodeAnalysisService service,
CancellationToken cancellationToken)
{
_service = service;
_cancellationToken = cancellationToken;
......@@ -181,7 +183,8 @@ private class FindReferencesProgressCallback : IStreamingFindReferencesProgress
private readonly CodeAnalysisService _service;
private readonly CancellationToken _cancellationToken;
public FindReferencesProgressCallback(CodeAnalysisService service, CancellationToken cancellationToken)
public FindReferencesProgressCallback(
CodeAnalysisService service, CancellationToken cancellationToken)
{
_service = service;
_cancellationToken = cancellationToken;
......
......@@ -15,7 +15,8 @@ internal partial class RemoteSymbolSearchUpdateEngine :
{
private readonly SymbolSearchUpdateEngine _updateEngine;
public RemoteSymbolSearchUpdateEngine(Stream stream, IServiceProvider serviceProvider)
public RemoteSymbolSearchUpdateEngine(
Stream stream, IServiceProvider serviceProvider)
: base(serviceProvider, stream)
{
_updateEngine = new SymbolSearchUpdateEngine(
......@@ -67,23 +68,23 @@ public Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithT
#region Messages to forward from here to VS
public Task LogExceptionAsync(string exception, string text)
=> this.InvokeAsync(nameof(LogExceptionAsync), new object[] { exception, text }, CancellationToken.None);
public Task LogExceptionAsync(string exception, string text, CancellationToken cancellationToken)
=> this.InvokeAsync(nameof(LogExceptionAsync), new object[] { exception, text }, cancellationToken);
public Task LogInfoAsync(string text)
=> this.InvokeAsync(nameof(LogInfoAsync), new object[] { text }, CancellationToken.None);
public Task LogInfoAsync(string text, CancellationToken cancellationToken)
=> this.InvokeAsync(nameof(LogInfoAsync), new object[] { text }, cancellationToken);
public Task OnDownloadFullDatabaseStartedAsync(string title)
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseStartedAsync), new object[] { title }, CancellationToken.None);
public Task OnDownloadFullDatabaseStartedAsync(string title, CancellationToken cancellationToken)
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseStartedAsync), new object[] { title }, cancellationToken);
public Task OnDownloadFullDatabaseSucceededAsync()
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseSucceededAsync), CancellationToken.None);
public Task OnDownloadFullDatabaseSucceededAsync(CancellationToken cancellationToken)
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseSucceededAsync), cancellationToken);
public Task OnDownloadFullDatabaseCanceledAsync()
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseCanceledAsync), CancellationToken.None);
public Task OnDownloadFullDatabaseCanceledAsync(CancellationToken cancellationToken)
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseCanceledAsync), cancellationToken);
public Task OnDownloadFullDatabaseFailedAsync(string message)
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseFailedAsync), new object[] { message }, CancellationToken.None);
public Task OnDownloadFullDatabaseFailedAsync(string message, CancellationToken cancellationToken)
=> this.InvokeAsync(nameof(OnDownloadFullDatabaseFailedAsync), new object[] { message }, cancellationToken);
#endregion
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册