From 928d9d89117aeac8e61badbd0808b3665e52bfed Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 1 Apr 2017 15:26:23 -0600 Subject: [PATCH 1/4] Fix detection of valid PS ext for debugging. Was previously only allowing lower case ps1 and psm1. I'm assuming that on *nix file systems, that PowerShell allows all variations of ps1,PS1,pS1,Ps1 as valid script extensions. Fix #641 --- src/features/DebugSession.ts | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index dcf1c7621e..78a2da527b 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -42,25 +42,30 @@ export class DebugSessionFeature implements IFeature { // is not a file that can be debugged by PowerShell if (config.script === "${file}") { 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 (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) { + if (currentDocument.isUntitled) { config.script = currentDocument.uri.toString(); } + else { + let isValidExtension = false; + let extIndex = currentDocument.fileName.lastIndexOf('.'); + if (extIndex !== -1) { + let ext = currentDocument.fileName.substr(extIndex + 1).toUpperCase(); + isValidExtension = (ext === "PS1" || ext === "PSM1"); + } + + if ((currentDocument.languageId !== 'powershell') || !isValidExtension) { + let path = currentDocument.fileName; + let workspaceRootPath = vscode.workspace.rootPath; + 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; + } + } } } From 49d6214e4afcb931793895bf4a9e63ed06a8c822 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 1 Apr 2017 18:51:31 -0600 Subject: [PATCH 2/4] Fix issue with debugging unsaved file. --- src/features/DebugSession.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 78a2da527b..f62c95ea07 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -44,7 +44,15 @@ export class DebugSessionFeature implements IFeature { let currentDocument = vscode.window.activeTextEditor.document; if (currentDocument.isUntitled) { - config.script = currentDocument.uri.toString(); + if (currentDocument.languageId === 'powershell') { + config.script = currentDocument.uri.toString(); + } + else { + let msg = "In order to debug '" + currentDocument.fileName + + "', set the document's language mode to PowerShell or save the file with a PowerShell extension."; + vscode.window.showErrorMessage(msg); + return; + } } else { let isValidExtension = false; From 94d20b5c52844c3e7e355351352f2a277f7961d9 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 1 Apr 2017 18:52:55 -0600 Subject: [PATCH 3/4] Use same term used in the command palette. --- src/features/DebugSession.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index f62c95ea07..9248966654 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -49,7 +49,7 @@ export class DebugSessionFeature implements IFeature { } else { let msg = "In order to debug '" + currentDocument.fileName + - "', set the document's language mode to PowerShell or save the file with a PowerShell extension."; + "', change the document's language mode to PowerShell or save the file with a PowerShell extension."; vscode.window.showErrorMessage(msg); return; } From 855f69a4d3e33a5b8aaec5ee4695b5fbe3fc2c8c Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 1 Apr 2017 20:20:43 -0600 Subject: [PATCH 4/4] Shorten error message based on juneb feedback. --- src/features/DebugSession.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 9248966654..f827607f67 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -48,7 +48,7 @@ export class DebugSessionFeature implements IFeature { config.script = currentDocument.uri.toString(); } else { - let msg = "In order to debug '" + currentDocument.fileName + + let msg = "To debug '" + currentDocument.fileName + "', change the document's language mode to PowerShell or save the file with a PowerShell extension."; vscode.window.showErrorMessage(msg); return;