@@ -191,26 +191,26 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
191
191
}
192
192
} ) ,
193
193
194
- vscode . commands . registerCommand ( ' PowerShell.ClosePanel' ,
195
- async ( ) => { await vscode . commands . executeCommand ( ' workbench.action.closePanel' ) ; } ) ,
194
+ vscode . commands . registerCommand ( " PowerShell.ClosePanel" ,
195
+ async ( ) => { await vscode . commands . executeCommand ( " workbench.action.closePanel" ) ; } ) ,
196
196
197
- vscode . commands . registerCommand ( ' PowerShell.PositionPanelLeft' ,
198
- async ( ) => { await vscode . commands . executeCommand ( ' workbench.action.positionPanelLeft' ) ; } ) ,
197
+ vscode . commands . registerCommand ( " PowerShell.PositionPanelLeft" ,
198
+ async ( ) => { await vscode . commands . executeCommand ( " workbench.action.positionPanelLeft" ) ; } ) ,
199
199
200
- vscode . commands . registerCommand ( ' PowerShell.PositionPanelBottom' ,
201
- async ( ) => { await vscode . commands . executeCommand ( ' workbench.action.positionPanelBottom' ) ; } ) ,
200
+ vscode . commands . registerCommand ( " PowerShell.PositionPanelBottom" ,
201
+ async ( ) => { await vscode . commands . executeCommand ( " workbench.action.positionPanelBottom" ) ; } ) ,
202
202
203
- vscode . commands . registerCommand ( ' PowerShell.Debug.Start' ,
203
+ vscode . commands . registerCommand ( " PowerShell.Debug.Start" ,
204
204
async ( ) => {
205
205
// TODO: Use a named debug configuration.
206
206
await vscode . debug . startDebugging ( undefined , {
207
207
name : "PowerShell: Launch Current File" ,
208
208
type : "PowerShell" ,
209
209
request : "launch" ,
210
210
script : "${file}" ,
211
- } )
211
+ } ) ;
212
212
} )
213
- ]
213
+ ] ;
214
214
}
215
215
216
216
public override setLanguageClient ( languageclient : LanguageClient ) {
@@ -431,72 +431,72 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
431
431
432
432
let newFileAbsolutePath : string ;
433
433
switch ( currentFileUri . scheme ) {
434
- case "file" :
435
- // If the file to save can't be found, just complete the request
436
- if ( ! this . findTextDocument ( this . normalizeFilePath ( currentFileUri . fsPath ) ) ) {
437
- await this . log . writeAndShowError ( `File to save not found: ${ currentFileUri . fsPath } .` ) ;
438
- return EditorOperationResponse . Completed ;
439
- }
434
+ case "file" :
435
+ // If the file to save can't be found, just complete the request
436
+ if ( ! this . findTextDocument ( this . normalizeFilePath ( currentFileUri . fsPath ) ) ) {
437
+ await this . log . writeAndShowError ( `File to save not found: ${ currentFileUri . fsPath } .` ) ;
438
+ return EditorOperationResponse . Completed ;
439
+ }
440
440
441
- // If no newFile is given, just save the current file
442
- if ( ! saveFileDetails . newPath ) {
443
- const doc = await vscode . workspace . openTextDocument ( currentFileUri . fsPath ) ;
444
- if ( doc . isDirty ) {
445
- await doc . save ( ) ;
446
- }
447
- return EditorOperationResponse . Completed ;
441
+ // If no newFile is given, just save the current file
442
+ if ( ! saveFileDetails . newPath ) {
443
+ const doc = await vscode . workspace . openTextDocument ( currentFileUri . fsPath ) ;
444
+ if ( doc . isDirty ) {
445
+ await doc . save ( ) ;
448
446
}
447
+ return EditorOperationResponse . Completed ;
448
+ }
449
449
450
- // Make sure we have an absolute path
451
- if ( path . isAbsolute ( saveFileDetails . newPath ) ) {
452
- newFileAbsolutePath = saveFileDetails . newPath ;
453
- } else {
454
- // If not, interpret the path as relative to the current file
455
- newFileAbsolutePath = path . join ( path . dirname ( currentFileUri . fsPath ) , saveFileDetails . newPath ) ;
456
- }
457
- break ;
450
+ // Make sure we have an absolute path
451
+ if ( path . isAbsolute ( saveFileDetails . newPath ) ) {
452
+ newFileAbsolutePath = saveFileDetails . newPath ;
453
+ } else {
454
+ // If not, interpret the path as relative to the current file
455
+ newFileAbsolutePath = path . join ( path . dirname ( currentFileUri . fsPath ) , saveFileDetails . newPath ) ;
456
+ }
457
+ break ;
458
+
459
+ case "untitled" :
460
+ // We need a new name to save an untitled file
461
+ if ( ! saveFileDetails . newPath ) {
462
+ // TODO: Create a class handle vscode warnings and errors so we can warn easily
463
+ // without logging
464
+ this . log . writeAndShowWarning (
465
+ "Cannot save untitled file. Try SaveAs(\"path/to/file.ps1\") instead." ) ;
466
+ return EditorOperationResponse . Completed ;
467
+ }
458
468
459
- case "untitled" :
460
- // We need a new name to save an untitled file
461
- if ( ! saveFileDetails . newPath ) {
462
- // TODO: Create a class handle vscode warnings and errors so we can warn easily
463
- // without logging
464
- this . log . writeAndShowWarning (
465
- "Cannot save untitled file. Try SaveAs(\"path/to/file.ps1\") instead." ) ;
469
+ // Make sure we have an absolute path
470
+ if ( path . isAbsolute ( saveFileDetails . newPath ) ) {
471
+ newFileAbsolutePath = saveFileDetails . newPath ;
472
+ } else {
473
+ // In fresh contexts, workspaceFolders is not defined...
474
+ if ( ! vscode . workspace . workspaceFolders || vscode . workspace . workspaceFolders . length === 0 ) {
475
+ this . log . writeAndShowWarning ( "Cannot save file to relative path: no workspaces are open. " +
476
+ "Try saving to an absolute path, or open a workspace." ) ;
466
477
return EditorOperationResponse . Completed ;
467
478
}
468
479
469
- // Make sure we have an absolute path
470
- if ( path . isAbsolute ( saveFileDetails . newPath ) ) {
471
- newFileAbsolutePath = saveFileDetails . newPath ;
472
- } else {
473
- // In fresh contexts, workspaceFolders is not defined...
474
- if ( ! vscode . workspace . workspaceFolders || vscode . workspace . workspaceFolders . length === 0 ) {
475
- this . log . writeAndShowWarning ( "Cannot save file to relative path: no workspaces are open. " +
476
- "Try saving to an absolute path, or open a workspace." ) ;
477
- return EditorOperationResponse . Completed ;
478
- }
479
-
480
- // If not, interpret the path as relative to the workspace root
481
- const workspaceRootUri = vscode . workspace . workspaceFolders [ 0 ] . uri ;
482
- // We don't support saving to a non-file URI-schemed workspace
483
- if ( workspaceRootUri . scheme !== "file" ) {
484
- this . log . writeAndShowWarning (
485
- "Cannot save untitled file to a relative path in an untitled workspace. " +
480
+ // If not, interpret the path as relative to the workspace root
481
+ const workspaceRootUri = vscode . workspace . workspaceFolders [ 0 ] . uri ;
482
+ // We don't support saving to a non-file URI-schemed workspace
483
+ if ( workspaceRootUri . scheme !== "file" ) {
484
+ this . log . writeAndShowWarning (
485
+ "Cannot save untitled file to a relative path in an untitled workspace. " +
486
486
"Try saving to an absolute path or opening a workspace folder." ) ;
487
- return EditorOperationResponse . Completed ;
488
- }
489
- newFileAbsolutePath = path . join ( workspaceRootUri . fsPath , saveFileDetails . newPath ) ;
487
+ return EditorOperationResponse . Completed ;
490
488
}
491
- break ;
489
+ newFileAbsolutePath = path . join ( workspaceRootUri . fsPath , saveFileDetails . newPath ) ;
490
+ }
491
+ break ;
492
492
493
- default :
494
- // Other URI schemes are not supported
495
- const msg = JSON . stringify ( saveFileDetails ) ;
496
- this . log . writeVerbose (
497
- `<${ ExtensionCommandsFeature . name } >: Saving a document with scheme '${ currentFileUri . scheme } ' ` +
493
+ default :
494
+ // Other URI schemes are not supported
495
+ const msg = JSON . stringify ( saveFileDetails ) ;
496
+ this . log . writeVerbose (
497
+ `<${ ExtensionCommandsFeature . name } >: Saving a document with scheme '${ currentFileUri . scheme } ' ` +
498
498
`is currently unsupported. Message: '${ msg } '` ) ;
499
- return EditorOperationResponse . Completed ;
499
+ return EditorOperationResponse . Completed ;
500
500
}
501
501
502
502
await this . saveDocumentContentToAbsolutePath ( currentFileUri , newFileAbsolutePath ) ;
0 commit comments