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(
360360 new VariableContainerDetails ( this . nextVariableId ++ , "Scope: " + scope ) ;
361361 this . variables . Add ( scopeVariableContainer ) ;
362362
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 )
365365 {
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 )
371367 {
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+ }
373376 }
374377 }
375378
Original file line number Diff line number Diff line change @@ -208,13 +208,17 @@ public Task<RunspaceHandle> GetRunspaceHandle()
208208 /// <param name="sendOutputToHost">
209209 /// If true, causes any output written during command execution to be written to the host.
210210 /// </param>
211+ /// <param name="sendErrorToHost">
212+ /// If true, causes any errors encountered during command execution to be written to the host.
213+ /// </param>
211214 /// <returns>
212215 /// An awaitable Task which will provide results once the command
213216 /// execution completes.
214217 /// </returns>
215218 public async Task < IEnumerable < TResult > > ExecuteCommand < TResult > (
216219 PSCommand psCommand ,
217- bool sendOutputToHost = false )
220+ bool sendOutputToHost = false ,
221+ bool sendErrorToHost = true )
218222 {
219223 RunspaceHandle runspaceHandle = null ;
220224 IEnumerable < TResult > executionResult = null ;
@@ -324,8 +328,11 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
324328 LogLevel . Error ,
325329 "Runtime exception occurred while executing command:\r \n \r \n " + e . ToString ( ) ) ;
326330
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+ }
329336 }
330337 finally
331338 {
You can’t perform that action at this time.
0 commit comments