From df27513f89a16c9a20d2c719fb8f0dcf9c5d129b Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:12:57 -0700 Subject: [PATCH] Run `SetInitialWorkingDirectoryAsync` before `LoadProfiles` So that if a user runs `Set-Location` in their profile, it's not later overridden. --- .../Services/PowerShell/Host/PsesInternalHost.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index e6f85ca78..d3ae833d5 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -301,6 +301,13 @@ public async Task TryStartAsync(HostStartOptions startOptions, Cancellatio _pipelineThread.Start(); + if (startOptions.InitialWorkingDirectory is not null) + { + _logger.LogDebug($"Setting InitialWorkingDirectory to {startOptions.InitialWorkingDirectory}..."); + await SetInitialWorkingDirectoryAsync(startOptions.InitialWorkingDirectory, cancellationToken).ConfigureAwait(false); + _logger.LogDebug("InitialWorkingDirectory set!"); + } + if (startOptions.LoadProfiles) { _logger.LogDebug("Loading profiles..."); @@ -320,13 +327,6 @@ public async Task TryStartAsync(HostStartOptions startOptions, Cancellatio _logger.LogDebug("Shell integration not enabled!"); } - if (startOptions.InitialWorkingDirectory is not null) - { - _logger.LogDebug($"Setting InitialWorkingDirectory to {startOptions.InitialWorkingDirectory}..."); - await SetInitialWorkingDirectoryAsync(startOptions.InitialWorkingDirectory, cancellationToken).ConfigureAwait(false); - _logger.LogDebug("InitialWorkingDirectory set!"); - } - await _started.Task.ConfigureAwait(false); return true; }