Skip to content

Commit 83aed94

Browse files
committed
Merge pull request #139 from rkeithhill/rkeithhill/is137-dbg-working-dir
Fixes #137 - working dir should be set to something reasonable.
2 parents 5c69c7d + dc1cf30 commit 83aed94

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ public class LaunchRequestArguments
2424
public bool StopOnEntry { get; set; }
2525

2626
// /** Optional arguments passed to the debuggee. */
27-
public string[] Arguments { get; set; }
27+
public string[] Args { get; set; }
2828

2929
// /** Launch the debuggee in this working directory (specified as an absolute path). If omitted the debuggee is lauched in its own directory. */
30-
public string WorkingDirectory { get; set; }
30+
public string Cwd { get; set; }
3131

3232
// /** Absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. */
3333
public string RuntimeExecutable { get; set; }
3434

3535
// /** Optional arguments passed to the runtime executable. */
36-
public string[] RuntimeArguments { get; set; }
36+
public string[] RuntimeArgs { get; set; }
3737

3838
// /** Optional environment variables to pass to the debuggee. The string valued properties of the 'environmentVariables' are used as key/value pairs. */
39-
public Dictionary<string, string> EnvironmentVariables { get; set; }
39+
public Dictionary<string, string> Env { get; set; }
4040
}
4141
}
4242

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
using Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
77
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
88
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
9-
using Microsoft.PowerShell.EditorServices.Protocol.Server;
109
using Microsoft.PowerShell.EditorServices.Utility;
1110
using System;
1211
using System.Collections.Generic;
12+
using System.IO;
1313
using System.Linq;
1414
using System.Management.Automation;
1515
using System.Threading.Tasks;
@@ -74,15 +74,26 @@ protected async Task HandleLaunchRequest(
7474
LaunchRequestArguments launchParams,
7575
RequestContext<object> requestContext)
7676
{
77+
// Set the working directory for the PowerShell runspace to something reasonable
78+
// such as the cwd passed in via launch.json. And in case that is null, use the
79+
// folder or the script to be executed.
80+
string workingDir = launchParams.Cwd ?? Path.GetDirectoryName(launchParams.Program);
81+
var setWorkingDirCommand = new PSCommand();
82+
setWorkingDirCommand.AddCommand(@"Microsoft.PowerShell.Management\Set-Location")
83+
.AddParameter("LiteralPath", workingDir);
84+
85+
await editorSession.PowerShellContext.ExecuteCommand(setWorkingDirCommand);
86+
87+
Logger.Write(LogLevel.Verbose, "Working dir set to '" + workingDir + "'");
88+
7789
// Execute the given PowerShell script and send the response.
7890
// Note that we aren't waiting for execution to complete here
7991
// because the debugger could stop while the script executes.
8092
Task executeTask =
8193
editorSession.PowerShellContext
8294
.ExecuteScriptAtPath(launchParams.Program)
8395
.ContinueWith(
84-
async (t) =>
85-
{
96+
async (t) => {
8697
Logger.Write(LogLevel.Verbose, "Execution completed, terminating...");
8798

8899
await requestContext.SendEvent(

0 commit comments

Comments
 (0)