From 63f5c0d30fd917e6a0df4be257320acbfb801dd0 Mon Sep 17 00:00:00 2001 From: jwfx Date: Tue, 7 Jul 2020 18:05:58 +0200 Subject: [PATCH 1/2] Add cwd property to settings --- .../Server/PsesLanguageServer.cs | 9 -------- .../Handlers/ConfigurationHandler.cs | 22 +++++++++++++++++++ .../Workspace/LanguageServerSettings.cs | 3 +++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/PowerShellEditorServices/Server/PsesLanguageServer.cs b/src/PowerShellEditorServices/Server/PsesLanguageServer.cs index e6480adac..82abc2b72 100644 --- a/src/PowerShellEditorServices/Server/PsesLanguageServer.cs +++ b/src/PowerShellEditorServices/Server/PsesLanguageServer.cs @@ -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().SetWorkingDirectoryAsync( - workspaceService.WorkspacePath, - isPathAlreadyEscaped: false).ConfigureAwait(false); - } }); }).ConfigureAwait(false); diff --git a/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs b/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs index bf39a1f3f..fe74d1400 100644 --- a/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs +++ b/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs @@ -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 { @@ -26,6 +27,7 @@ internal class PsesConfigurationHandler : IDidChangeConfigurationHandler private DidChangeConfigurationCapability _capability; private bool _profilesLoaded; private bool _consoleReplStarted; + private bool _cwdSet; public PsesConfigurationHandler( ILoggerFactory factory, @@ -66,6 +68,26 @@ public async Task 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) diff --git a/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs b/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs index 705c79866..2e2441619 100644 --- a/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs +++ b/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs @@ -30,6 +30,8 @@ internal class LanguageServerSettings public PesterSettings Pester { get; set; } + public string Cwd { get; set; } + public LanguageServerSettings() { this.ScriptAnalysis = new ScriptAnalysisSettings(); @@ -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; } } } From 4e4552aafd0ce7264e6000b2b74f0e13f2096123 Mon Sep 17 00:00:00 2001 From: jw <39484381+jwfx@users.noreply.github.com> Date: Tue, 7 Jul 2020 22:24:01 +0200 Subject: [PATCH 2/2] Update src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs Co-authored-by: Robert Holt --- .../Services/Workspace/Handlers/ConfigurationHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs b/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs index fe74d1400..8d94f1a7b 100644 --- a/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs +++ b/src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs @@ -70,7 +70,7 @@ public async Task Handle(DidChangeConfigurationParams request, Cancellatio if (!this._cwdSet) { - if (!String.IsNullOrEmpty(_configurationService.CurrentSettings.Cwd) + if (!string.IsNullOrEmpty(_configurationService.CurrentSettings.Cwd) && Directory.Exists(_configurationService.CurrentSettings.Cwd)) { await _powerShellContextService.SetWorkingDirectoryAsync( @@ -78,7 +78,7 @@ await _powerShellContextService.SetWorkingDirectoryAsync( isPathAlreadyEscaped: false).ConfigureAwait(false); } else if (_workspaceService.WorkspacePath != null - && Directory.Exists(_workspaceService.WorkspacePath)) + && Directory.Exists(_workspaceService.WorkspacePath)) { await _powerShellContextService.SetWorkingDirectoryAsync( _workspaceService.WorkspacePath,