Skip to content

Add cwd property to settings #1323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ public async Task StartAsync()
break;
}
}

// Set the working directory of the PowerShell session to the workspace path
if (workspaceService.WorkspacePath != null
&& Directory.Exists(workspaceService.WorkspacePath))
{
await serviceProvider.GetService<PowerShellContextService>().SetWorkingDirectoryAsync(
workspaceService.WorkspacePath,
isPathAlreadyEscaped: false).ConfigureAwait(false);
}
});
}).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
using System.IO;

namespace Microsoft.PowerShell.EditorServices.Handlers
{
Expand All @@ -26,6 +27,7 @@ internal class PsesConfigurationHandler : IDidChangeConfigurationHandler
private DidChangeConfigurationCapability _capability;
private bool _profilesLoaded;
private bool _consoleReplStarted;
private bool _cwdSet;

public PsesConfigurationHandler(
ILoggerFactory factory,
Expand Down Expand Up @@ -66,6 +68,26 @@ public async Task<Unit> Handle(DidChangeConfigurationParams request, Cancellatio
_workspaceService.WorkspacePath,
_logger);

if (!this._cwdSet)
{
if (!String.IsNullOrEmpty(_configurationService.CurrentSettings.Cwd)
&& Directory.Exists(_configurationService.CurrentSettings.Cwd))
{
await _powerShellContextService.SetWorkingDirectoryAsync(
_configurationService.CurrentSettings.Cwd,
isPathAlreadyEscaped: false).ConfigureAwait(false);

} else if (_workspaceService.WorkspacePath != null
&& Directory.Exists(_workspaceService.WorkspacePath))
{
await _powerShellContextService.SetWorkingDirectoryAsync(
_workspaceService.WorkspacePath,
isPathAlreadyEscaped: false).ConfigureAwait(false);
}

this._cwdSet = true;
}

if (!this._profilesLoaded &&
_configurationService.CurrentSettings.EnableProfileLoading &&
oldLoadProfiles != _configurationService.CurrentSettings.EnableProfileLoading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal class LanguageServerSettings

public PesterSettings Pester { get; set; }

public string Cwd { get; set; }

public LanguageServerSettings()
{
this.ScriptAnalysis = new ScriptAnalysisSettings();
Expand All @@ -56,6 +58,7 @@ public void Update(
this.CodeFormatting = new CodeFormattingSettings(settings.CodeFormatting);
this.CodeFolding.Update(settings.CodeFolding, logger);
this.Pester = new PesterSettings(settings.Pester);
this.Cwd = settings.Cwd;
}
}
}
Expand Down