Skip to content

Commit 243f2ea

Browse files
committed
Small suggested cleanups while browsing
1 parent 3845d5f commit 243f2ea

File tree

7 files changed

+20
-33
lines changed

7 files changed

+20
-33
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#if DEBUG
1616
using System.Diagnostics;
1717
using System.Threading;
18-
1918
using Debugger = System.Diagnostics.Debugger;
2019
#endif
2120

@@ -197,9 +196,11 @@ protected override void BeginProcessing()
197196
#if DEBUG
198197
if (WaitForDebugger)
199198
{
199+
// NOTE: Ignore the suggestion to use Environment.ProcessId as it doesn't work for
200+
// .NET 4.6.2 (for Windows PowerShell), and this won't be caught in CI.
201+
Console.WriteLine($"Waiting for debugger to attach, PID: {Process.GetCurrentProcess().Id}");
200202
while (!Debugger.IsAttached)
201203
{
202-
Console.WriteLine($"PID: {Process.GetCurrentProcess().Id}");
203204
Thread.Sleep(1000);
204205
}
205206
}

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)

test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public async Task CanRunOnIdleTask()
180180
new PSCommand().AddScript("$handled"),
181181
CancellationToken.None).ConfigureAwait(true);
182182

183-
Assert.Collection(handled, (p) => Assert.False(p));
183+
Assert.Collection(handled, Assert.False);
184184

185185
await psesHost.ExecuteDelegateAsync(
186186
nameof(psesHost.OnPowerShellIdle),
@@ -195,7 +195,7 @@ await psesHost.ExecuteDelegateAsync(
195195
new PSCommand().AddScript("$handled"),
196196
CancellationToken.None).ConfigureAwait(true);
197197

198-
Assert.Collection(handled, (p) => Assert.True(p));
198+
Assert.Collection(handled, Assert.True);
199199
}
200200

201201
[Fact]
@@ -301,7 +301,7 @@ await psesHost.ExecuteDelegateAsync(
301301
new PSCommand().AddScript("$handledInProfile"),
302302
CancellationToken.None).ConfigureAwait(true);
303303

304-
Assert.Collection(handled, (p) => Assert.True(p));
304+
Assert.Collection(handled, Assert.True);
305305
}
306306
}
307307
}

0 commit comments

Comments
 (0)