Skip to content

Enable debugging of untitled script files #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since vscode-powershell is typescript project, should defaultLanguage be typescript?

}
20 changes: 13 additions & 7 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down