@@ -41,20 +41,26 @@ export class DebugSessionFeature implements IFeature {
4141 // For launch of "current script", don't start the debugger if the current file
4242 // is not a file that can be debugged by PowerShell
4343 if ( config . script === "${file}" ) {
44- let filename = vscode . window . activeTextEditor . document . fileName ;
45- let ext = filename . substr ( filename . lastIndexOf ( '.' ) + 1 ) ;
46- let langId = vscode . window . activeTextEditor . document . languageId ;
47- if ( ( langId !== 'powershell' ) || ( ext !== "ps1" && ext !== "psm1" ) ) {
48- let path = filename ;
44+ let currentDocument = vscode . window . activeTextEditor . document ;
45+ let ext =
46+ currentDocument . fileName . substr (
47+ currentDocument . fileName . lastIndexOf ( '.' ) + 1 ) ;
48+
49+ if ( ( currentDocument . languageId !== 'powershell' ) ||
50+ ( ! currentDocument . isUntitled ) && ( ext !== "ps1" && ext !== "psm1" ) ) {
51+ let path = currentDocument . fileName ;
4952 let workspaceRootPath = vscode . workspace . rootPath ;
50- if ( filename . startsWith ( workspaceRootPath ) ) {
51- path = filename . substring ( vscode . workspace . rootPath . length + 1 ) ;
53+ if ( currentDocument . fileName . startsWith ( workspaceRootPath ) ) {
54+ path = currentDocument . fileName . substring ( vscode . workspace . rootPath . length + 1 ) ;
5255 }
5356
5457 let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger." ;
5558 vscode . window . showErrorMessage ( msg ) ;
5659 return ;
5760 }
61+ else if ( currentDocument . isUntitled ) {
62+ config . script = currentDocument . uri . toString ( ) ;
63+ }
5864 }
5965 }
6066
0 commit comments