Skip to content

Commit 34836e8

Browse files
committed
Fix profiling loading logic in config handler
1 parent 94c1a30 commit 34836e8

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

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

+24-32
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1818
using OmniSharp.Extensions.LanguageServer.Protocol.Window;
1919
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
20-
using System.IO;
21-
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
2220
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
2321
using Microsoft.PowerShell.EditorServices.Services.Extension;
2422

@@ -81,14 +79,35 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
8179
_workspaceService.WorkspacePath,
8280
_logger);
8381

82+
// We need to load the profiles if:
83+
// - Profile loading is configured, AND
84+
// - Profiles haven't been loaded before, OR
85+
// - The profile loading configuration just changed
86+
bool loadProfiles = _configurationService.CurrentSettings.EnableProfileLoading
87+
&& (!_profilesLoaded || !profileLoadingPreviouslyEnabled);
88+
8489
if (!_psesHost.IsRunning)
8590
{
86-
await _psesHost.StartAsync(new HostStartOptions
91+
_logger.LogTrace("Starting command loop");
92+
93+
if (loadProfiles)
8794
{
88-
LoadProfiles = _configurationService.CurrentSettings.EnableProfileLoading,
89-
}, CancellationToken.None).ConfigureAwait(false);
95+
_logger.LogTrace("Loading profiles...");
96+
}
97+
98+
await _psesHost.StartAsync(new HostStartOptions(), CancellationToken.None).ConfigureAwait(false);
99+
100+
_consoleReplStarted = true;
101+
102+
if (loadProfiles)
103+
{
104+
_profilesLoaded = true;
105+
_logger.LogTrace("Loaded!");
106+
}
90107
}
91108

109+
// TODO: Load profiles when the host is already running
110+
92111
if (!this._cwdSet)
93112
{
94113
if (!string.IsNullOrEmpty(_configurationService.CurrentSettings.Cwd)
@@ -116,33 +135,6 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
116135
this._cwdSet = true;
117136
}
118137

119-
// We need to load the profiles if:
120-
// - Profile loading is configured, AND
121-
// - Profiles haven't been loaded before, OR
122-
// - The profile loading configuration just changed
123-
bool loadProfiles = _configurationService.CurrentSettings.EnableProfileLoading
124-
&& (!_profilesLoaded || !profileLoadingPreviouslyEnabled);
125-
126-
if (!_psesHost.IsRunning)
127-
{
128-
_logger.LogTrace("Starting command loop");
129-
130-
if (loadProfiles)
131-
{
132-
_logger.LogTrace("Loading profiles...");
133-
}
134-
135-
await _psesHost.StartAsync(new HostStartOptions
136-
{
137-
LoadProfiles = loadProfiles,
138-
}, CancellationToken.None).ConfigureAwait(false);
139-
140-
_consoleReplStarted = true;
141-
_profilesLoaded = loadProfiles;
142-
143-
_logger.LogTrace("Loaded!");
144-
}
145-
146138
if (!_extensionServiceInitialized)
147139
{
148140
await _extensionService.InitializeAsync();

0 commit comments

Comments
 (0)