From 47b4c5fd396391ea6ebcc4dd0298f4b270006207 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 30 Mar 2017 17:28:28 -0700 Subject: [PATCH 1/2] Enable debugging of untitled script files This change enables untitled files to be debugged when they are set to the 'powershell' language mode. Fixes #555. --- src/features/DebugSession.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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(); + } } } From 7096fe2ed491120bd884dfa3c197e86211c24418 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 30 Mar 2017 17:30:26 -0700 Subject: [PATCH 2/2] Set default language to 'powershell' in examples\settings.json. --- examples/.vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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