diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index 09f866d6a..ced177b06 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -204,7 +204,7 @@ protected override void BeginProcessing() { // NOTE: Ignore the suggestion to use Environment.ProcessId as it doesn't work for // .NET 4.6.2 (for Windows PowerShell), and this won't be caught in CI. - Console.WriteLine($"Waiting for debugger to attach, PID: {Process.GetCurrentProcess().Id}"); + Console.WriteLine($"Waiting for debugger to attach, PID: {s_currentPID}"); while (!Debugger.IsAttached) { Thread.Sleep(1000); diff --git a/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs b/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs index f5cafc206..a9bbab38e 100644 --- a/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs +++ b/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Diagnostics; using System.IO; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -13,7 +14,6 @@ using Microsoft.PowerShell.EditorServices.Services.Extension; #if DEBUG -using System.Diagnostics; using Serilog.Debugging; #endif diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs index de4064853..700c154b9 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs @@ -87,7 +87,7 @@ internal record PsesAttachRequestArguments : AttachRequestArguments internal class LaunchAndAttachHandler : ILaunchHandler<PsesLaunchRequestArguments>, IAttachHandler<PsesAttachRequestArguments>, IOnDebugAdapterServerStarted { - private static readonly int currentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id; + private static readonly int s_currentPID = System.Diagnostics.Process.GetCurrentProcess().Id; private static readonly Version s_minVersionForCustomPipeName = new(6, 2); private readonly ILogger<LaunchAndAttachHandler> _logger; private readonly BreakpointService _breakpointService; @@ -275,7 +275,7 @@ void RunspaceChangedHandler(object s, RunspaceChangedEventArgs _) if (processIdIsSet) { - if (request.ProcessId == currentProcessId) + if (request.ProcessId == s_currentPID) { throw new RpcErrorException(0, null, $"Attaching to the Extension Terminal is not supported!"); } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Handlers/PSHostProcessAndRunspaceHandlers.cs b/src/PowerShellEditorServices/Services/PowerShell/Handlers/PSHostProcessAndRunspaceHandlers.cs index fb86e4950..c14e533cc 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Handlers/PSHostProcessAndRunspaceHandlers.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Handlers/PSHostProcessAndRunspaceHandlers.cs @@ -19,7 +19,7 @@ internal class PSHostProcessAndRunspaceHandlers : IGetPSHostProcessesHandler, IG private readonly ILogger<PSHostProcessAndRunspaceHandlers> _logger; private readonly IInternalPowerShellExecutionService _executionService; private readonly IRunspaceContext _runspaceContext; - private static readonly int currentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id; + private static readonly int s_currentPID = System.Diagnostics.Process.GetCurrentProcess().Id; public PSHostProcessAndRunspaceHandlers( ILoggerFactory factory, @@ -50,7 +50,7 @@ public async Task<PSHostProcessResponse[]> Handle(GetPSHostProcessesParams reque // NOTE: We do not currently support attaching to ourself in this manner, so we // exclude our process. When we maybe eventually do, we should name it. - if (response.ProcessId == currentProcessId) + if (response.ProcessId == s_currentPID) { continue; } @@ -63,7 +63,7 @@ public async Task<PSHostProcessResponse[]> Handle(GetPSHostProcessesParams reque public async Task<RunspaceResponse[]> Handle(GetRunspaceParams request, CancellationToken cancellationToken) { - if (request.ProcessId == currentProcessId) + if (request.ProcessId == s_currentPID) { throw new RpcErrorException(0, null, $"Attaching to the Extension Terminal is not supported!"); }