File tree Expand file tree Collapse file tree 2 files changed +21
-11
lines changed
src/PowerShellEditorServices Expand file tree Collapse file tree 2 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -360,16 +360,19 @@ private async Task<VariableContainerDetails> FetchVariableContainer(
360
360
new VariableContainerDetails ( this . nextVariableId ++ , "Scope: " + scope ) ;
361
361
this . variables . Add ( scopeVariableContainer ) ;
362
362
363
- var results = await this . powerShellContext . ExecuteCommand < PSVariable > ( psCommand ) ;
364
- foreach ( PSVariable psvariable in results )
363
+ var results = await this . powerShellContext . ExecuteCommand < PSVariable > ( psCommand , sendErrorToHost : false ) ;
364
+ if ( results != null )
365
365
{
366
- var variableDetails = new VariableDetails ( psvariable ) { Id = this . nextVariableId ++ } ;
367
- this . variables . Add ( variableDetails ) ;
368
- scopeVariableContainer . Children . Add ( variableDetails . Name , variableDetails ) ;
369
-
370
- if ( ( autoVariables != null ) && AddToAutoVariables ( psvariable , scope ) )
366
+ foreach ( PSVariable psvariable in results )
371
367
{
372
- autoVariables . Children . Add ( variableDetails . Name , variableDetails ) ;
368
+ var variableDetails = new VariableDetails ( psvariable ) { Id = this . nextVariableId ++ } ;
369
+ this . variables . Add ( variableDetails ) ;
370
+ scopeVariableContainer . Children . Add ( variableDetails . Name , variableDetails ) ;
371
+
372
+ if ( ( autoVariables != null ) && AddToAutoVariables ( psvariable , scope ) )
373
+ {
374
+ autoVariables . Children . Add ( variableDetails . Name , variableDetails ) ;
375
+ }
373
376
}
374
377
}
375
378
Original file line number Diff line number Diff line change @@ -208,13 +208,17 @@ public Task<RunspaceHandle> GetRunspaceHandle()
208
208
/// <param name="sendOutputToHost">
209
209
/// If true, causes any output written during command execution to be written to the host.
210
210
/// </param>
211
+ /// <param name="sendErrorToHost">
212
+ /// If true, causes any errors encountered during command execution to be written to the host.
213
+ /// </param>
211
214
/// <returns>
212
215
/// An awaitable Task which will provide results once the command
213
216
/// execution completes.
214
217
/// </returns>
215
218
public async Task < IEnumerable < TResult > > ExecuteCommand < TResult > (
216
219
PSCommand psCommand ,
217
- bool sendOutputToHost = false )
220
+ bool sendOutputToHost = false ,
221
+ bool sendErrorToHost = true )
218
222
{
219
223
RunspaceHandle runspaceHandle = null ;
220
224
IEnumerable < TResult > executionResult = null ;
@@ -324,8 +328,11 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
324
328
LogLevel . Error ,
325
329
"Runtime exception occurred while executing command:\r \n \r \n " + e . ToString ( ) ) ;
326
330
327
- // Write the error to the host
328
- this . WriteExceptionToHost ( e ) ;
331
+ if ( sendErrorToHost )
332
+ {
333
+ // Write the error to the host
334
+ this . WriteExceptionToHost ( e ) ;
335
+ }
329
336
}
330
337
finally
331
338
{
You can’t perform that action at this time.
0 commit comments