@@ -42,25 +42,30 @@ export class DebugSessionFeature implements IFeature {
42
42
// is not a file that can be debugged by PowerShell
43
43
if ( config . script === "${file}" ) {
44
44
let currentDocument = vscode . window . activeTextEditor . document ;
45
- let ext =
46
- currentDocument . fileName . substr (
47
- currentDocument . fileName . lastIndexOf ( '.' ) + 1 ) ;
48
-
49
- if ( ( currentDocument . languageId !== 'powershell' ) ||
50
- ( ! currentDocument . isUntitled ) && ( ext !== "ps1" && ext !== "psm1" ) ) {
51
- let path = currentDocument . fileName ;
52
- let workspaceRootPath = vscode . workspace . rootPath ;
53
- if ( currentDocument . fileName . startsWith ( workspaceRootPath ) ) {
54
- path = currentDocument . fileName . substring ( vscode . workspace . rootPath . length + 1 ) ;
55
- }
56
45
57
- let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger." ;
58
- vscode . window . showErrorMessage ( msg ) ;
59
- return ;
60
- }
61
- else if ( currentDocument . isUntitled ) {
46
+ if ( currentDocument . isUntitled ) {
62
47
config . script = currentDocument . uri . toString ( ) ;
63
48
}
49
+ else {
50
+ let isValidExtension = false ;
51
+ let extIndex = currentDocument . fileName . lastIndexOf ( '.' ) ;
52
+ if ( extIndex !== - 1 ) {
53
+ let ext = currentDocument . fileName . substr ( extIndex + 1 ) . toUpperCase ( ) ;
54
+ isValidExtension = ( ext === "PS1" || ext === "PSM1" ) ;
55
+ }
56
+
57
+ if ( ( currentDocument . languageId !== 'powershell' ) || ! isValidExtension ) {
58
+ let path = currentDocument . fileName ;
59
+ let workspaceRootPath = vscode . workspace . rootPath ;
60
+ if ( currentDocument . fileName . startsWith ( workspaceRootPath ) ) {
61
+ path = currentDocument . fileName . substring ( vscode . workspace . rootPath . length + 1 ) ;
62
+ }
63
+
64
+ let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger." ;
65
+ vscode . window . showErrorMessage ( msg ) ;
66
+ return ;
67
+ }
68
+ }
64
69
}
65
70
}
66
71
0 commit comments