Skip to content

Commit 09534d9

Browse files
authored
Merge pull request PowerShell#509 from PowerShell/rkeithhill/is503-cancel-dbg-on-invalid-file-type
Fix PowerShell#503 cancel debug on invalid file types.
2 parents 1243be6 + ff22234 commit 09534d9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: src/features/DebugSession.ts

+19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ export class DebugSessionFeature implements IFeature {
3636
if (config.request === 'launch') {
3737
// Make sure there's a usable working directory if possible
3838
config.cwd = config.cwd || vscode.workspace.rootPath || config.script;
39+
40+
// For launch of "current script", don't start the debugger if the current file
41+
// is not a file that can be debugged by PowerShell
42+
if (config.script === "${file}") {
43+
let filename = vscode.window.activeTextEditor.document.fileName;
44+
let ext = filename.substr(filename.lastIndexOf('.') + 1);
45+
let langId = vscode.window.activeTextEditor.document.languageId;
46+
if ((langId !== 'powershell') || (ext !== "ps1" && ext !== "psm1")) {
47+
let path = filename;
48+
let workspaceRootPath = vscode.workspace.rootPath;
49+
if (filename.startsWith(workspaceRootPath)) {
50+
path = filename.substring(vscode.workspace.rootPath.length + 1);
51+
}
52+
53+
let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger.";
54+
vscode.window.showErrorMessage(msg);
55+
return;
56+
}
57+
}
3958
}
4059

4160
vscode.commands.executeCommand('vscode.startDebug', config);

0 commit comments

Comments
 (0)