diff --git a/examples/.vscode/settings.json b/examples/.vscode/settings.json index 28db732896..64ffb7dd42 100644 --- a/examples/.vscode/settings.json +++ b/examples/.vscode/settings.json @@ -1,5 +1,6 @@ { // Use a custom PowerShell Script Analyzer settings file for this workspace. // Relative paths for this setting are always relative to the workspace root dir. - "powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1" + "powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1", + "files.defaultLanguage": "powershell" } \ No newline at end of file diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 5dd183a254..dcf1c7621e 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -41,20 +41,26 @@ export class DebugSessionFeature implements IFeature { // For launch of "current script", don't start the debugger if the current file // is not a file that can be debugged by PowerShell if (config.script === "${file}") { - let filename = vscode.window.activeTextEditor.document.fileName; - let ext = filename.substr(filename.lastIndexOf('.') + 1); - let langId = vscode.window.activeTextEditor.document.languageId; - if ((langId !== 'powershell') || (ext !== "ps1" && ext !== "psm1")) { - let path = filename; + let currentDocument = vscode.window.activeTextEditor.document; + let ext = + currentDocument.fileName.substr( + currentDocument.fileName.lastIndexOf('.') + 1); + + if ((currentDocument.languageId !== 'powershell') || + (!currentDocument.isUntitled) && (ext !== "ps1" && ext !== "psm1")) { + let path = currentDocument.fileName; let workspaceRootPath = vscode.workspace.rootPath; - if (filename.startsWith(workspaceRootPath)) { - path = filename.substring(vscode.workspace.rootPath.length + 1); + if (currentDocument.fileName.startsWith(workspaceRootPath)) { + path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1); } let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger."; vscode.window.showErrorMessage(msg); return; } + else if (currentDocument.isUntitled) { + config.script = currentDocument.uri.toString(); + } } }