@@ -191,26 +191,26 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
191191 }
192192 } ) ,
193193
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" ) ; } ) ,
196196
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" ) ; } ) ,
199199
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" ) ; } ) ,
202202
203- vscode . commands . registerCommand ( ' PowerShell.Debug.Start' ,
203+ vscode . commands . registerCommand ( " PowerShell.Debug.Start" ,
204204 async ( ) => {
205205 // TODO: Use a named debug configuration.
206206 await vscode . debug . startDebugging ( undefined , {
207207 name : "PowerShell: Launch Current File" ,
208208 type : "PowerShell" ,
209209 request : "launch" ,
210210 script : "${file}" ,
211- } )
211+ } ) ;
212212 } )
213- ]
213+ ] ;
214214 }
215215
216216 public override setLanguageClient ( languageclient : LanguageClient ) {
@@ -431,72 +431,72 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
431431
432432 let newFileAbsolutePath : string ;
433433 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+ }
440440
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 ( ) ;
448446 }
447+ return EditorOperationResponse . Completed ;
448+ }
449449
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+ }
458468
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." ) ;
466477 return EditorOperationResponse . Completed ;
467478 }
468479
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. " +
486486 "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 ;
490488 }
491- break ;
489+ newFileAbsolutePath = path . join ( workspaceRootUri . fsPath , saveFileDetails . newPath ) ;
490+ }
491+ break ;
492492
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 } ' ` +
498498 `is currently unsupported. Message: '${ msg } '` ) ;
499- return EditorOperationResponse . Completed ;
499+ return EditorOperationResponse . Completed ;
500500 }
501501
502502 await this . saveDocumentContentToAbsolutePath ( currentFileUri , newFileAbsolutePath ) ;
0 commit comments