Skip to content

Commit 760d13b

Browse files
committed
Small suggested cleanups while browsing
1 parent 3845d5f commit 760d13b

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
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

0 commit comments

Comments
 (0)