Skip to content

Commit 32a7dea

Browse files
committed
Address static analyser compiler errors
1 parent 5331817 commit 32a7dea

File tree

11 files changed

+35
-51
lines changed

11 files changed

+35
-51
lines changed

src/PowerShellEditorServices/Server/PsesDebugServer.cs

-11
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ namespace Microsoft.PowerShell.EditorServices.Server
2525
/// </summary>
2626
internal class PsesDebugServer : IDisposable
2727
{
28-
/// <summary>
29-
/// This is a bool but must be an int, since Interlocked.Exchange can't handle a bool
30-
/// </summary>
31-
private static readonly IdempotentLatch s_psrlCtorLatch = new();
32-
33-
private static readonly Lazy<CmdletInfo> s_lazyInvokeReadLineConstructorCmdletInfo = new Lazy<CmdletInfo>(() =>
34-
{
35-
var type = Type.GetType("Microsoft.PowerShell.EditorServices.Commands.InvokeReadLineConstructorCommand, Microsoft.PowerShell.EditorServices.Hosting");
36-
return new CmdletInfo("__Invoke-ReadLineConstructor", type);
37-
});
38-
3928
private readonly Stream _inputStream;
4029
private readonly Stream _outputStream;
4130
private readonly bool _useTempSession;

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ internal class DebugService
3131
private const string PsesGlobalVariableNamePrefix = "__psEditorServices_";
3232
private const string TemporaryScriptFileName = "Script Listing.ps1";
3333

34-
private readonly BreakpointDetails[] s_emptyBreakpointDetailsArray = Array.Empty<BreakpointDetails>();
35-
3634
private readonly ILogger _logger;
3735
private readonly IInternalPowerShellExecutionService _executionService;
3836
private readonly BreakpointService _breakpointService;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ await _executionService
149149
_debugAdapterServer.SendNotification(EventNames.Terminated);
150150
}
151151

152-
private PSCommand BuildPSCommandFromArguments(string command, IReadOnlyList<string> arguments)
152+
private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyList<string> arguments)
153153
{
154154
if (arguments is null or { Count: 0 })
155155
{
@@ -179,7 +179,7 @@ private PSCommand BuildPSCommandFromArguments(string command, IReadOnlyList<stri
179179
return new PSCommand().AddScript(sb.ToString());
180180
}
181181

182-
private bool ArgumentNeedsEscaping(string argument)
182+
private static bool ArgumentNeedsEscaping(string argument)
183183
{
184184
foreach (char c in argument)
185185
{

src/PowerShellEditorServices/Services/PowerShell/Console/ConsoleReadLine.cs

+19-19
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
270270
if (completion != null)
271271
{
272272
currentCursorIndex =
273-
this.InsertInput(
273+
InsertInput(
274274
inputLine,
275275
promptStartCol,
276276
promptStartRow,
@@ -288,7 +288,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
288288
if (currentCursorIndex > 0)
289289
{
290290
currentCursorIndex =
291-
this.MoveCursorToIndex(
291+
MoveCursorToIndex(
292292
promptStartCol,
293293
promptStartRow,
294294
consoleWidth,
@@ -300,7 +300,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
300300
currentCompletion = null;
301301

302302
currentCursorIndex =
303-
this.MoveCursorToIndex(
303+
MoveCursorToIndex(
304304
promptStartCol,
305305
promptStartRow,
306306
consoleWidth,
@@ -313,7 +313,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
313313
if (currentCursorIndex < inputLine.Length)
314314
{
315315
currentCursorIndex =
316-
this.MoveCursorToIndex(
316+
MoveCursorToIndex(
317317
promptStartCol,
318318
promptStartRow,
319319
consoleWidth,
@@ -325,7 +325,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
325325
currentCompletion = null;
326326

327327
currentCursorIndex =
328-
this.MoveCursorToIndex(
328+
MoveCursorToIndex(
329329
promptStartCol,
330330
promptStartRow,
331331
consoleWidth,
@@ -359,7 +359,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
359359
historyIndex--;
360360

361361
currentCursorIndex =
362-
this.InsertInput(
362+
InsertInput(
363363
inputLine,
364364
promptStartCol,
365365
promptStartRow,
@@ -384,7 +384,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
384384
if (historyIndex < currentHistory.Count)
385385
{
386386
currentCursorIndex =
387-
this.InsertInput(
387+
InsertInput(
388388
inputLine,
389389
promptStartCol,
390390
promptStartRow,
@@ -396,7 +396,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
396396
else if (historyIndex == currentHistory.Count)
397397
{
398398
currentCursorIndex =
399-
this.InsertInput(
399+
InsertInput(
400400
inputLine,
401401
promptStartCol,
402402
promptStartRow,
@@ -413,7 +413,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
413413
historyIndex = currentHistory != null ? currentHistory.Count : -1;
414414

415415
currentCursorIndex =
416-
this.InsertInput(
416+
InsertInput(
417417
inputLine,
418418
promptStartCol,
419419
promptStartRow,
@@ -429,7 +429,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
429429
if (currentCursorIndex > 0)
430430
{
431431
currentCursorIndex =
432-
this.InsertInput(
432+
InsertInput(
433433
inputLine,
434434
promptStartCol,
435435
promptStartRow,
@@ -447,7 +447,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
447447
if (currentCursorIndex < inputLine.Length)
448448
{
449449
currentCursorIndex =
450-
this.InsertInput(
450+
InsertInput(
451451
inputLine,
452452
promptStartCol,
453453
promptStartRow,
@@ -488,7 +488,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
488488
currentCompletion = null;
489489

490490
currentCursorIndex =
491-
this.InsertInput(
491+
InsertInput(
492492
inputLine,
493493
promptStartCol,
494494
promptStartRow,
@@ -507,7 +507,7 @@ internal string InvokeLegacyReadLine(bool isCommandLine, CancellationToken cance
507507
}
508508

509509
// TODO: Is this used?
510-
private int CalculateIndexFromCursor(
510+
private static int CalculateIndexFromCursor(
511511
int promptStartCol,
512512
int promptStartRow,
513513
int consoleWidth)
@@ -517,7 +517,7 @@ private int CalculateIndexFromCursor(
517517
ConsoleProxy.GetCursorLeft() - promptStartCol;
518518
}
519519

520-
private void CalculateCursorFromIndex(
520+
private static void CalculateCursorFromIndex(
521521
int promptStartCol,
522522
int promptStartRow,
523523
int consoleWidth,
@@ -530,7 +530,7 @@ private void CalculateCursorFromIndex(
530530
cursorCol = cursorCol % consoleWidth;
531531
}
532532

533-
private int InsertInput(
533+
private static int InsertInput(
534534
StringBuilder inputLine,
535535
int promptStartCol,
536536
int promptStartRow,
@@ -549,7 +549,7 @@ private int InsertInput(
549549
}
550550

551551
// Move the cursor to the new insertion point
552-
this.MoveCursorToIndex(
552+
MoveCursorToIndex(
553553
promptStartCol,
554554
promptStartRow,
555555
consoleWidth,
@@ -598,7 +598,7 @@ private int InsertInput(
598598
{
599599
// Move the cursor to the final position
600600
return
601-
this.MoveCursorToIndex(
601+
MoveCursorToIndex(
602602
promptStartCol,
603603
promptStartRow,
604604
consoleWidth,
@@ -610,13 +610,13 @@ private int InsertInput(
610610
}
611611
}
612612

613-
private int MoveCursorToIndex(
613+
private static int MoveCursorToIndex(
614614
int promptStartCol,
615615
int promptStartRow,
616616
int consoleWidth,
617617
int newCursorIndex)
618618
{
619-
this.CalculateCursorFromIndex(
619+
CalculateCursorFromIndex(
620620
promptStartCol,
621621
promptStartRow,
622622
consoleWidth,

src/PowerShellEditorServices/Services/PowerShell/Console/PSReadLineProxy.cs

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ internal class PSReadLineProxy
3737

3838
private const string VirtualTerminalTypeName = "Microsoft.PowerShell.Internal.VirtualTerminal";
3939

40-
private const string ForcePSEventHandlingMethodName = "ForcePSEventHandling";
41-
4240
private static readonly Type[] s_setKeyHandlerTypes =
4341
{
4442
typeof(string[]),

src/PowerShellEditorServices/Services/PowerShell/Console/UnixConsoleOperations.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private async Task<bool> ShortWaitForKeyAsync(CancellationToken cancellationToke
245245
return false;
246246
}
247247

248-
private bool SpinUntilKeyAvailable(int millisecondsTimeout, CancellationToken cancellationToken)
248+
private static bool SpinUntilKeyAvailable(int millisecondsTimeout, CancellationToken cancellationToken)
249249
{
250250
return SpinWait.SpinUntil(
251251
() =>
@@ -256,7 +256,7 @@ private bool SpinUntilKeyAvailable(int millisecondsTimeout, CancellationToken ca
256256
millisecondsTimeout);
257257
}
258258

259-
private Task<bool> SpinUntilKeyAvailableAsync(int millisecondsTimeout, CancellationToken cancellationToken)
259+
private static Task<bool> SpinUntilKeyAvailableAsync(int millisecondsTimeout, CancellationToken cancellationToken)
260260
{
261261
return Task<bool>.Factory.StartNew(
262262
() => SpinWait.SpinUntil(
@@ -266,10 +266,11 @@ private Task<bool> SpinUntilKeyAvailableAsync(int millisecondsTimeout, Cancellat
266266
s_waitHandle.Wait(ShortWaitForKeySpinUntilSleepTime, cancellationToken);
267267
return IsKeyAvailable(cancellationToken);
268268
},
269-
millisecondsTimeout));
269+
millisecondsTimeout),
270+
cancellationToken);
270271
}
271272

272-
private bool IsKeyAvailable(CancellationToken cancellationToken)
273+
private static bool IsKeyAvailable(CancellationToken cancellationToken)
273274
{
274275
s_stdInHandle.Wait(cancellationToken);
275276
try
@@ -282,7 +283,7 @@ private bool IsKeyAvailable(CancellationToken cancellationToken)
282283
}
283284
}
284285

285-
private async Task<bool> IsKeyAvailableAsync(CancellationToken cancellationToken)
286+
private static async Task<bool> IsKeyAvailableAsync(CancellationToken cancellationToken)
286287
{
287288
await s_stdInHandle.WaitAsync(cancellationToken).ConfigureAwait(false);
288289
try

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
6666

6767
await executionService.ExecutePSCommandAsync(
6868
dscCommand,
69-
CancellationToken.None);
69+
CancellationToken.None)
70+
.ConfigureAwait(false);
7071

7172
// Verify all the breakpoints and return them
7273
foreach (var breakpoint in breakpoints)

src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public override void WriteWarningLine(string message)
129129
_underlyingHostUI.WriteWarningLine(message);
130130
}
131131

132-
private PSHostUserInterface GetConsoleHostUI(PSHostUserInterface ui)
132+
private static PSHostUserInterface GetConsoleHostUI(PSHostUserInterface ui)
133133
{
134134
FieldInfo externalUIField = ui.GetType().GetField("_externalUI", BindingFlags.NonPublic | BindingFlags.Instance);
135135

@@ -141,7 +141,7 @@ private PSHostUserInterface GetConsoleHostUI(PSHostUserInterface ui)
141141
return (PSHostUserInterface)externalUIField.GetValue(ui);
142142
}
143143

144-
private void SetConsoleHostUIToInteractive(PSHostUserInterface ui)
144+
private static void SetConsoleHostUIToInteractive(PSHostUserInterface ui)
145145
{
146146
ui.GetType().GetProperty("ThrowOnReadAndPrompt", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(ui, false);
147147
}

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ private void RemoveRunspaceEventHandlers(Runspace runspace)
589589
runspace.StateChanged -= OnRunspaceStateChanged;
590590
}
591591

592-
private PowerShell CreateNestedPowerShell(RunspaceInfo currentRunspace)
592+
private static PowerShell CreateNestedPowerShell(RunspaceInfo currentRunspace)
593593
{
594594
if (currentRunspace.RunspaceOrigin != RunspaceOrigin.Local)
595595
{
@@ -604,7 +604,7 @@ private PowerShell CreateNestedPowerShell(RunspaceInfo currentRunspace)
604604
return pwsh;
605605
}
606606

607-
private PowerShell CreatePowerShellForRunspace(Runspace runspace)
607+
private static PowerShell CreatePowerShellForRunspace(Runspace runspace)
608608
{
609609
var pwsh = PowerShell.Create();
610610
pwsh.Runspace = runspace;

src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ await executionService.ExecuteDelegateAsync(
101101
options: null,
102102
powershell: pwsh);
103103
},
104-
cancellationToken);
104+
cancellationToken)
105+
.ConfigureAwait(false);
105106

106107
stopwatch.Stop();
107108
logger.LogTrace($"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ internal class PsesConfigurationHandler : DidChangeConfigurationHandlerBase
3131
private readonly ExtensionService _extensionService;
3232
private readonly PsesInternalHost _psesHost;
3333
private readonly ILanguageServerFacade _languageServer;
34-
private DidChangeConfigurationCapability _capability;
3534
private bool _profilesLoaded;
36-
private bool _consoleReplStarted;
3735
private bool _extensionServiceInitialized;
3836
private bool _cwdSet;
3937

@@ -97,8 +95,6 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
9795

9896
await _psesHost.StartAsync(new HostStartOptions(), CancellationToken.None).ConfigureAwait(false);
9997

100-
_consoleReplStarted = true;
101-
10298
if (loadProfiles)
10399
{
104100
_profilesLoaded = true;

0 commit comments

Comments
 (0)