File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
src/PowerShellEditorServices.Protocol/Server Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -74,10 +74,23 @@ protected async Task HandleLaunchRequest(
74
74
LaunchRequestArguments launchParams ,
75
75
RequestContext < object > requestContext )
76
76
{
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 ) ;
77
+ // Set the working directory for the PowerShell runspace to the cwd passed in via launch.json.
78
+ // In case that is null, use the the folder of the script to be executed. If the resulting
79
+ // working dir path is a file path then extract the directory and use that.
80
+ string workingDir = launchParams . Cwd ?? launchParams . Program ;
81
+ try
82
+ {
83
+ if ( ( File . GetAttributes ( workingDir ) & FileAttributes . Directory ) != FileAttributes . Directory )
84
+ {
85
+ workingDir = Path . GetDirectoryName ( workingDir ) ;
86
+ }
87
+ }
88
+ catch ( Exception ex )
89
+ {
90
+ Logger . Write ( LogLevel . Error , "cwd path is bad: " + ex . Message ) ;
91
+ workingDir = Environment . CurrentDirectory ;
92
+ }
93
+
81
94
var setWorkingDirCommand = new PSCommand ( ) ;
82
95
setWorkingDirCommand . AddCommand ( @"Microsoft.PowerShell.Management\Set-Location" )
83
96
. AddParameter ( "LiteralPath" , workingDir ) ;
You can’t perform that action at this time.
0 commit comments