Skip to content

Commit b222d0e

Browse files
committed
Small suggested cleanups while browsing
1 parent ca83e0e commit b222d0e

File tree

6 files changed

+15
-31
lines changed

6 files changed

+15
-31
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
using System.Globalization;
1414

1515
#if DEBUG
16-
using System.Diagnostics;
1716
using System.Threading;
18-
1917
using Debugger = System.Diagnostics.Debugger;
2018
#endif
2119

@@ -197,9 +195,9 @@ protected override void BeginProcessing()
197195
#if DEBUG
198196
if (WaitForDebugger)
199197
{
198+
Console.WriteLine($"Waiting for debugger to attach, PID: {Environment.ProcessId}");
200199
while (!Debugger.IsAttached)
201200
{
202-
Console.WriteLine($"PID: {Process.GetCurrentProcess().Id}");
203201
Thread.Sleep(1000);
204202
}
205203
}

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -98,16 +98,11 @@ public VariableDetails(string name, object value)
9898
/// If this variable instance is expandable, this method returns the
9999
/// details of its children. Otherwise it returns an empty array.
100100
/// </summary>
101-
/// <returns></returns>
102101
public override VariableDetailsBase[] GetChildren(ILogger logger)
103102
{
104103
if (IsExpandable)
105104
{
106-
if (cachedChildren == null)
107-
{
108-
cachedChildren = GetChildren(ValueObject, logger);
109-
}
110-
105+
cachedChildren ??= GetChildren(ValueObject, logger);
111106
return cachedChildren;
112107
}
113108

@@ -131,9 +126,7 @@ private static bool GetIsExpandable(object valueObject)
131126
valueObject = psobject.BaseObject;
132127
}
133128

134-
Type valueType =
135-
valueObject?.GetType();
136-
129+
Type valueType = valueObject?.GetType();
137130
TypeInfo valueTypeInfo = valueType.GetTypeInfo();
138131

139132
return
@@ -379,7 +372,7 @@ protected static void AddDotNetProperties(object obj, List<VariableDetails> chil
379372

380373
#endregion
381374

382-
private struct UnableToRetrievePropertyMessage
375+
private readonly struct UnableToRetrievePropertyMessage
383376
{
384377
public UnableToRetrievePropertyMessage(string message) => Message = message;
385378

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetailsBase.cs

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ internal abstract class VariableDetailsBase
5151
/// If this variable instance is expandable, this method returns the
5252
/// details of its children. Otherwise it returns an empty array.
5353
/// </summary>
54-
/// <returns></returns>
5554
public abstract VariableDetailsBase[] GetChildren(ILogger logger);
5655
}
5756
}

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -64,21 +64,15 @@ await _executionService.ExecutePSCommandAsync(
6464
result = _debugService.GetVariableFromExpression(request.Expression);
6565

6666
// If the expression is not a naked variable reference, then evaluate the expression.
67-
if (result == null)
68-
{
69-
result =
70-
await _debugService.EvaluateExpressionAsync(
71-
request.Expression,
72-
isFromRepl).ConfigureAwait(false);
73-
}
67+
result ??= await _debugService.EvaluateExpressionAsync(
68+
request.Expression,
69+
isFromRepl).ConfigureAwait(false);
7470
}
7571

7672
if (result != null)
7773
{
7874
valueString = result.ValueString;
79-
variableId =
80-
result.IsExpandable ?
81-
result.Id : 0;
75+
variableId = result.IsExpandable ? result.Id : 0;
8276
}
8377
}
8478

src/PowerShellEditorServices/Services/PowerShell/Debugging/PowerShellDebugContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void SetDebugResuming(DebuggerResumeAction debuggerResumeAction)
146146
// TODO: We need to assign cancellation tokens to each frame, because the current
147147
// logic results in a deadlock here when we try to cancel the scopes...which
148148
// includes ourself (hence running it in a separate thread).
149-
_ = Task.Run(() => _psesHost.UnwindCallStack());
149+
_ = Task.Run(_psesHost.UnwindCallStack);
150150
return;
151151
}
152152

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public async Task DebuggerBreaksWhenRequested()
496496
Assert.Equal(0, confirmedBreakpoints.Count);
497497
Task _ = ExecuteDebugFileAsync();
498498
// NOTE: This must be run on a separate thread so the async event handlers can fire.
499-
await Task.Run(() => debugService.Break()).ConfigureAwait(true);
499+
await Task.Run(debugService.Break).ConfigureAwait(true);
500500
AssertDebuggerPaused();
501501
}
502502

@@ -505,7 +505,7 @@ public async Task DebuggerRunsCommandsWhileStopped()
505505
{
506506
Task _ = ExecuteDebugFileAsync();
507507
// NOTE: This must be run on a separate thread so the async event handlers can fire.
508-
await Task.Run(() => debugService.Break()).ConfigureAwait(true);
508+
await Task.Run(debugService.Break).ConfigureAwait(true);
509509
AssertDebuggerPaused();
510510

511511
// Try running a command from outside the pipeline thread
@@ -723,7 +723,7 @@ await debugService.SetLineBreakpointsAsync(
723723

724724
// The above just tests that the debug service returns the correct new value string.
725725
// Let's step the debugger and make sure the values got set to the new values.
726-
await Task.Run(() => debugService.StepOver()).ConfigureAwait(true);
726+
await Task.Run(debugService.StepOver).ConfigureAwait(true);
727727
AssertDebuggerStopped(variableScriptFile.FilePath);
728728

729729
// Test set of a local string variable (not strongly typed)
@@ -779,7 +779,7 @@ await debugService.SetLineBreakpointsAsync(
779779

780780
// The above just tests that the debug service returns the correct new value string.
781781
// Let's step the debugger and make sure the values got set to the new values.
782-
await Task.Run(() => debugService.StepOver()).ConfigureAwait(true);
782+
await Task.Run(debugService.StepOver).ConfigureAwait(true);
783783
AssertDebuggerStopped(variableScriptFile.FilePath);
784784

785785
// Test set of a local string variable (not strongly typed but force conversion)

0 commit comments

Comments
 (0)