Skip to content

Commit 5fa604f

Browse files
jwfxrjmholt
andauthored
Add cwd property to settings (#1323)
* Add cwd property to settings * Update src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs Co-authored-by: Robert Holt <[email protected]> Co-authored-by: Robert Holt <[email protected]>
1 parent fdb2095 commit 5fa604f

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

-9
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,6 @@ public async Task StartAsync()
113113
break;
114114
}
115115
}
116-
117-
// Set the working directory of the PowerShell session to the workspace path
118-
if (workspaceService.WorkspacePath != null
119-
&& Directory.Exists(workspaceService.WorkspacePath))
120-
{
121-
await serviceProvider.GetService<PowerShellContextService>().SetWorkingDirectoryAsync(
122-
workspaceService.WorkspacePath,
123-
isPathAlreadyEscaped: false).ConfigureAwait(false);
124-
}
125116
});
126117
}).ConfigureAwait(false);
127118

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

+22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1515
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
1616
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
17+
using System.IO;
1718

1819
namespace Microsoft.PowerShell.EditorServices.Handlers
1920
{
@@ -26,6 +27,7 @@ internal class PsesConfigurationHandler : IDidChangeConfigurationHandler
2627
private DidChangeConfigurationCapability _capability;
2728
private bool _profilesLoaded;
2829
private bool _consoleReplStarted;
30+
private bool _cwdSet;
2931

3032
public PsesConfigurationHandler(
3133
ILoggerFactory factory,
@@ -66,6 +68,26 @@ public async Task<Unit> Handle(DidChangeConfigurationParams request, Cancellatio
6668
_workspaceService.WorkspacePath,
6769
_logger);
6870

71+
if (!this._cwdSet)
72+
{
73+
if (!string.IsNullOrEmpty(_configurationService.CurrentSettings.Cwd)
74+
&& Directory.Exists(_configurationService.CurrentSettings.Cwd))
75+
{
76+
await _powerShellContextService.SetWorkingDirectoryAsync(
77+
_configurationService.CurrentSettings.Cwd,
78+
isPathAlreadyEscaped: false).ConfigureAwait(false);
79+
80+
} else if (_workspaceService.WorkspacePath != null
81+
&& Directory.Exists(_workspaceService.WorkspacePath))
82+
{
83+
await _powerShellContextService.SetWorkingDirectoryAsync(
84+
_workspaceService.WorkspacePath,
85+
isPathAlreadyEscaped: false).ConfigureAwait(false);
86+
}
87+
88+
this._cwdSet = true;
89+
}
90+
6991
if (!this._profilesLoaded &&
7092
_configurationService.CurrentSettings.EnableProfileLoading &&
7193
oldLoadProfiles != _configurationService.CurrentSettings.EnableProfileLoading)

src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ internal class LanguageServerSettings
3030

3131
public PesterSettings Pester { get; set; }
3232

33+
public string Cwd { get; set; }
34+
3335
public LanguageServerSettings()
3436
{
3537
this.ScriptAnalysis = new ScriptAnalysisSettings();
@@ -56,6 +58,7 @@ public void Update(
5658
this.CodeFormatting = new CodeFormattingSettings(settings.CodeFormatting);
5759
this.CodeFolding.Update(settings.CodeFolding, logger);
5860
this.Pester = new PesterSettings(settings.Pester);
61+
this.Cwd = settings.Cwd;
5962
}
6063
}
6164
}

0 commit comments

Comments
 (0)