@@ -192,7 +192,6 @@ public PowerShellContextService(
192
192
OmniSharp . Extensions . LanguageServer . Protocol . Server . ILanguageServerFacade languageServer ,
193
193
bool isPSReadLineEnabled )
194
194
{
195
- logger . LogTrace ( "Instantiating PowerShellContextService and adding event handlers" ) ;
196
195
_languageServer = languageServer ;
197
196
this . logger = logger ;
198
197
this . isPSReadLineEnabled = isPSReadLineEnabled ;
@@ -214,7 +213,7 @@ public static PowerShellContextService Create(
214
213
// Respect a user provided bundled module path.
215
214
if ( Directory . Exists ( hostStartupInfo . BundledModulePath ) )
216
215
{
217
- logger . LogTrace ( $ "Using new bundled module path: { hostStartupInfo . BundledModulePath } ") ;
216
+ logger . LogDebug ( $ "Using new bundled module path: { hostStartupInfo . BundledModulePath } ") ;
218
217
s_bundledModulePath = hostStartupInfo . BundledModulePath ;
219
218
}
220
219
@@ -238,7 +237,6 @@ public static PowerShellContextService Create(
238
237
hostUserInterface ,
239
238
logger ) ;
240
239
241
- logger . LogTrace ( "Creating initial PowerShell runspace" ) ;
242
240
Runspace initialRunspace = PowerShellContextService . CreateRunspace ( psHost , hostStartupInfo . InitialSessionState ) ;
243
241
powerShellContext . Initialize ( hostStartupInfo . ProfilePaths , initialRunspace , true , hostUserInterface ) ;
244
242
powerShellContext . ImportCommandsModuleAsync ( ) ;
@@ -327,7 +325,6 @@ public void Initialize(
327
325
IHostOutput consoleHost )
328
326
{
329
327
Validate . IsNotNull ( "initialRunspace" , initialRunspace ) ;
330
- this . logger . LogTrace ( $ "Initializing PowerShell context with runspace { initialRunspace . Name } ") ;
331
328
332
329
this . ownsInitialRunspace = ownsInitialRunspace ;
333
330
this . SessionState = PowerShellContextState . NotStarted ;
@@ -363,6 +360,7 @@ public void Initialize(
363
360
}
364
361
else
365
362
{
363
+ // TODO: Also throw for PowerShell 6
366
364
throw new NotSupportedException (
367
365
"This computer has an unsupported version of PowerShell installed: " +
368
366
powerShellVersion . ToString ( ) ) ;
@@ -577,10 +575,9 @@ public Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
577
575
cancellationToken ) ;
578
576
}
579
577
580
-
581
578
/// <summary>
582
579
/// Executes a PSCommand against the session's runspace and returns
583
- /// a collection of results of the expected type.
580
+ /// a collection of results of the expected type. This function needs help.
584
581
/// </summary>
585
582
/// <typeparam name="TResult">The expected result type.</typeparam>
586
583
/// <param name="psCommand">The PSCommand to be executed.</param>
@@ -601,8 +598,6 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
601
598
Validate . IsNotNull ( nameof ( psCommand ) , psCommand ) ;
602
599
Validate . IsNotNull ( nameof ( executionOptions ) , executionOptions ) ;
603
600
604
- this . logger . LogTrace ( $ "Attempting to execute command(s): { GetStringForPSCommand ( psCommand ) } ") ;
605
-
606
601
// Add history to PSReadLine before cancelling, otherwise it will be restored as the
607
602
// cancelled prompt when it's called again.
608
603
if ( executionOptions . AddToHistory )
@@ -636,8 +631,6 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
636
631
this . ShouldExecuteWithEventing ( executionOptions ) ||
637
632
( PromptNest . IsRemote && executionOptions . IsReadLine ) ) )
638
633
{
639
- this . logger . LogTrace ( "Passing command execution to pipeline thread" ) ;
640
-
641
634
if ( shouldCancelReadLine && PromptNest . IsReadLineBusy ( ) )
642
635
{
643
636
// If a ReadLine pipeline is running in the debugger then we'll stop responding here
@@ -715,6 +708,7 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
715
708
}
716
709
try
717
710
{
711
+ this . logger . LogTrace ( $ "Executing in debugger: { GetStringForPSCommand ( psCommand ) } ") ;
718
712
return this . ExecuteCommandInDebugger < TResult > (
719
713
psCommand ,
720
714
executionOptions . WriteOutputToHost ) ;
@@ -742,8 +736,6 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
742
736
AddToHistory = executionOptions . AddToHistory
743
737
} ;
744
738
745
- this . logger . LogTrace ( "Passing to PowerShell" ) ;
746
-
747
739
PowerShell shell = this . PromptNest . GetPowerShell ( executionOptions . IsReadLine ) ;
748
740
749
741
// Due to the following PowerShell bug, we can't just assign shell.Commands to psCommand
@@ -767,6 +759,8 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
767
759
: this . CurrentRunspace . Runspace ;
768
760
try
769
761
{
762
+ this . logger . LogDebug ( $ "Invoking: { GetStringForPSCommand ( psCommand ) } ") ;
763
+
770
764
// Nested PowerShell instances can't be invoked asynchronously. This occurs
771
765
// in nested prompts and pipeline requests from eventing.
772
766
if ( shell . IsNested )
@@ -830,15 +824,11 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
830
824
831
825
hadErrors = true ;
832
826
}
833
- else
834
- {
835
- this . logger . LogTrace ( "Execution completed successfully" ) ;
836
- }
837
827
}
838
828
}
839
829
catch ( PSRemotingDataStructureException e )
840
830
{
841
- this . logger . LogHandledException ( "Pipeline stopped while executing command" , e ) ;
831
+ this . logger . LogHandledException ( "PSRemotingDataStructure exception while executing command" , e ) ;
842
832
errorMessages ? . Append ( e . Message ) ;
843
833
}
844
834
catch ( PipelineStoppedException e )
@@ -1083,7 +1073,7 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n
1083
1073
. FirstOrDefault ( )
1084
1074
. ProviderPath ;
1085
1075
1086
- this . logger . LogTrace ( $ "Prepending working directory { workingDir } to script path { script } ") ;
1076
+ this . logger . LogDebug ( $ "Prepending working directory { workingDir } to script path { script } ") ;
1087
1077
script = Path . Combine ( workingDir , script ) ;
1088
1078
}
1089
1079
catch ( System . Management . Automation . DriveNotFoundException e )
@@ -1115,7 +1105,6 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n
1115
1105
strBld . Append ( ' ' ) . Append ( arguments ) ;
1116
1106
1117
1107
var launchedScript = strBld . ToString ( ) ;
1118
- this . logger . LogTrace ( $ "Launch script is: { launchedScript } ") ;
1119
1108
1120
1109
command . AddScript ( launchedScript , false ) ;
1121
1110
}
@@ -1257,15 +1246,15 @@ public void AbortExecution()
1257
1246
/// </param>
1258
1247
public void AbortExecution ( bool shouldAbortDebugSession )
1259
1248
{
1249
+ this . logger . LogTrace ( "Execution abort requested..." ) ;
1250
+
1260
1251
if ( this . SessionState == PowerShellContextState . Aborting
1261
1252
|| this . SessionState == PowerShellContextState . Disposed )
1262
1253
{
1263
1254
this . logger . LogTrace ( $ "Execution abort requested when already aborted (SessionState = { this . SessionState } )") ;
1264
1255
return ;
1265
1256
}
1266
1257
1267
- this . logger . LogTrace ( "Execution abort requested..." ) ;
1268
-
1269
1258
if ( shouldAbortDebugSession )
1270
1259
{
1271
1260
this . ExitAllNestedPrompts ( ) ;
@@ -1411,7 +1400,7 @@ private void ResumeDebugger(DebuggerResumeAction resumeAction, bool shouldWaitFo
1411
1400
/// </summary>
1412
1401
public void Close ( )
1413
1402
{
1414
- logger . LogDebug ( "Closing PowerShellContextService..." ) ;
1403
+ logger . LogTrace ( "Closing PowerShellContextService..." ) ;
1415
1404
this . PromptNest . Dispose ( ) ;
1416
1405
this . SessionState = PowerShellContextState . Disposed ;
1417
1406
@@ -1849,13 +1838,7 @@ private void OnSessionStateChanged(object sender, SessionStateChangedEventArgs e
1849
1838
{
1850
1839
if ( this . SessionState != PowerShellContextState . Disposed )
1851
1840
{
1852
- this . logger . LogTrace (
1853
- string . Format (
1854
- "Session state changed --\r \n \r \n Old state: {0}\r \n New state: {1}\r \n Result: {2}" ,
1855
- this . SessionState . ToString ( ) ,
1856
- e . NewSessionState . ToString ( ) ,
1857
- e . ExecutionResult ) ) ;
1858
-
1841
+ this . logger . LogTrace ( $ "Session state was: { SessionState } , is now: { e . NewSessionState } , result: { e . ExecutionResult } ") ;
1859
1842
this . SessionState = e . NewSessionState ;
1860
1843
this . SessionStateChanged ? . Invoke ( sender , e ) ;
1861
1844
}
@@ -1901,8 +1884,6 @@ private void OnExecutionStatusChanged(
1901
1884
/// </remarks>
1902
1885
private void PowerShellContext_RunspaceChangedAsync ( object sender , RunspaceChangedEventArgs e )
1903
1886
{
1904
- this . logger . LogTrace ( "Sending runspaceChanged notification" ) ;
1905
-
1906
1887
_languageServer ? . SendNotification (
1907
1888
"powerShell/runspaceChanged" ,
1908
1889
new MinifiedRunspaceDetails ( e . NewRunspace ) ) ;
@@ -1947,8 +1928,6 @@ public MinifiedRunspaceDetails(RunspaceDetails eventArgs)
1947
1928
/// <param name="e">details of the execution status change</param>
1948
1929
private void PowerShellContext_ExecutionStatusChangedAsync ( object sender , ExecutionStatusChangedEventArgs e )
1949
1930
{
1950
- this . logger . LogTrace ( "Sending executionStatusChanged notification" ) ;
1951
-
1952
1931
// The cancelling of the prompt (PSReadLine) causes an ExecutionStatus.Aborted to be sent after every
1953
1932
// actual execution (ExecutionStatus.Running) on the pipeline. We ignore that event since it's counterintuitive to
1954
1933
// the goal of this method which is to send updates when the pipeline is actually running something.
@@ -1968,8 +1947,6 @@ private void PowerShellContext_ExecutionStatusChangedAsync(object sender, Execut
1968
1947
1969
1948
private IEnumerable < TResult > ExecuteCommandInDebugger < TResult > ( PSCommand psCommand , bool sendOutputToHost )
1970
1949
{
1971
- this . logger . LogTrace ( $ "Attempting to execute command(s) in the debugger: { GetStringForPSCommand ( psCommand ) } ") ;
1972
-
1973
1950
IEnumerable < TResult > output =
1974
1951
this . versionSpecificOperations . ExecuteCommandInDebugger < TResult > (
1975
1952
this ,
0 commit comments