|
14 | 14 | using Microsoft.Extensions.Logging;
|
15 | 15 | using Microsoft.PowerShell.EditorServices.Services.PowerShell;
|
16 | 16 | using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
|
| 17 | +using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host; |
17 | 18 |
|
18 | 19 | namespace Microsoft.PowerShell.EditorServices.Services.Symbols
|
19 | 20 | {
|
@@ -92,6 +93,34 @@ await executionService.ExecuteDelegateAsync(
|
92 | 93 | (pwsh, _) =>
|
93 | 94 | {
|
94 | 95 | stopwatch.Start();
|
| 96 | + |
| 97 | + // If the current runspace is not out of process, then we call TabExpansion2 so |
| 98 | + // that we have the ability to issue pipeline stop requests on cancellation. |
| 99 | + if (executionService is PsesInternalHost psesInternalHost |
| 100 | + && !psesInternalHost.Runspace.RunspaceIsRemote) |
| 101 | + { |
| 102 | + IReadOnlyList<CommandCompletion> completionResults = new SynchronousPowerShellTask<CommandCompletion>( |
| 103 | + logger, |
| 104 | + psesInternalHost, |
| 105 | + new PSCommand() |
| 106 | + .AddCommand("TabExpansion2") |
| 107 | + .AddParameter("ast", scriptAst) |
| 108 | + .AddParameter("tokens", currentTokens) |
| 109 | + .AddParameter("positionOfCursor", cursorPosition), |
| 110 | + executionOptions: null, |
| 111 | + cancellationToken) |
| 112 | + .ExecuteAndGetResult(cancellationToken); |
| 113 | + |
| 114 | + if (completionResults is { Count: > 0 }) |
| 115 | + { |
| 116 | + commandCompletion = completionResults[0]; |
| 117 | + } |
| 118 | + |
| 119 | + return; |
| 120 | + } |
| 121 | + |
| 122 | + // If the current runspace is out of process, we can't call TabExpansion2 |
| 123 | + // because the output will be serialized. |
95 | 124 | commandCompletion = CommandCompletion.CompleteInput(
|
96 | 125 | scriptAst,
|
97 | 126 | currentTokens,
|
|
0 commit comments