Skip to content

Catch OperationCanceledException in both command loops #1850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ protected override void EndProcessing()

using EditorServicesLoader psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, sessionFileWriter, _loggerUnsubscribers);
_logger.Log(PsesLogLevel.Verbose, "Loading EditorServices");
// Start editor services and wait here until it shuts down
// Synchronously start editor services and wait here until it shuts down.
#pragma warning disable VSTHRD002
psesLoader.LoadAndRunEditorServicesAsync().GetAwaiter().GetResult();
#pragma warning restore VSTHRD002
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,14 @@ private void RunExecutionLoop(bool isForDebug = false)
&& !cancellationScope.CancellationToken.IsCancellationRequested
&& _taskQueue.TryTake(out ISynchronousTask task))
{
task.ExecuteSynchronously(cancellationScope.CancellationToken);
try
{
task.ExecuteSynchronously(cancellationScope.CancellationToken);
}
catch (OperationCanceledException e)
{
_logger.LogDebug(e, "Task {Task} was canceled!", task);
}
}

if (_shouldExit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public ExtensionCommandTests()
serviceProvider: null,
editorOperations: null,
executionService: psesHost);
#pragma warning disable VSTHRD002
extensionService.InitializeAsync().Wait();
#pragma warning restore VSTHRD002
extensionCommandService = new(extensionService);
}

Expand Down Expand Up @@ -110,7 +112,8 @@ await psesHost.ExecutePSCommandAsync(
Assert.Equal(commandName, commandAdded.Name);
Assert.Equal(commandDisplayName, commandAdded.DisplayName);

// Invoke the command
// Invoke the command.
// TODO: What task was this cancelling?
await extensionCommandService.InvokeCommandAsync("test.scriptblock", editorContext).ConfigureAwait(true);

// Assert the expected value
Expand Down