Skip to content

Commit 826e1d2

Browse files
committed
PowerShell is the default shell on Windows
1 parent 161627d commit 826e1d2

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Extension/src/Debugger/runWithoutDebuggingAdapter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from 'path';
99
import * as vscode from 'vscode';
1010
import * as nls from 'vscode-nls';
1111
import { buildShellCommandLine, sessionIsWsl } from '../common';
12+
import { isWindows } from '../constants';
1213

1314
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
1415
const localize = nls.loadMessageBundle();
@@ -116,15 +117,15 @@ export class RunWithoutDebuggingAdapter implements vscode.DebugAdapter {
116117
? this.terminal.creationOptions.shellPath?.toLowerCase()
117118
: undefined;
118119
const terminalShell: string | undefined = this.terminal.state.shell?.toLowerCase();
119-
const defaultTerminalProfile: string | undefined = os.platform() === 'win32'
120+
const defaultTerminalProfile: string | undefined = isWindows
120121
? vscode.workspace.getConfiguration('terminal.integrated').get<string>('defaultProfile.windows')?.toLowerCase()
121122
: undefined;
122123
const isPowerShell: boolean | undefined =
123124
shellPath?.endsWith('pwsh.exe') || shellPath?.endsWith('powershell.exe') || shellPath?.endsWith('pwsh') ||
124125
terminalShell?.includes('powershell') || terminalShell?.includes('pwsh') ||
125126
defaultTerminalProfile?.includes('powershell') || defaultTerminalProfile?.includes('pwsh');
126127

127-
if (isPowerShell) {
128+
if (isPowerShell || (isWindows && isPowerShell === undefined)) { // PowerShell is the default on Windows if we can't determine the shell.
128129
executable = '&';
129130
executableArgs = [program, ...args];
130131
} else {

Extension/test/scenarios/RunWithoutDebugging/tests/runWithoutDebugging.terminals.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ function disposeTerminals(programs: string[]): void {
5858
}
5959
}
6060

61+
/**
62+
* Sets or clears the setting for the default Windows terminal profile.
63+
* @param profile The terminal profile to set as the default, or undefined to clear the setting.
64+
*/
6165
async function setWindowsDefaultTerminalProfile(profile?: WindowsTerminalProfile): Promise<void> {
6266
if (!isWindows) {
6367
return;
@@ -136,11 +140,11 @@ suite('Run Without Debugging Terminal and Arguments Test', function (this: Mocha
136140
}
137141
});
138142

139-
const consoleCases: { label: string; consoleMode: ConsoleMode; windowsProfiles?: WindowsTerminalProfile[] }[] = [
143+
const consoleCases: { label: string; consoleMode: ConsoleMode; windowsProfiles?: (WindowsTerminalProfile | undefined)[] }[] = [
140144
{
141145
label: 'integrated terminal',
142146
consoleMode: 'integratedTerminal',
143-
windowsProfiles: ['Command Prompt', 'PowerShell']
147+
windowsProfiles: [undefined, 'Command Prompt', 'PowerShell']
144148
},
145149
{
146150
label: 'external terminal',
@@ -164,11 +168,9 @@ suite('Run Without Debugging Terminal and Arguments Test', function (this: Mocha
164168
const profiles: (WindowsTerminalProfile | undefined)[] = isWindows && consoleCase.consoleMode === 'integratedTerminal' ? consoleCase.windowsProfiles ?? [undefined] : [undefined];
165169

166170
for (const profile of profiles) {
167-
const profileSuffix = profile ? ` with ${profile} as the default terminal` : '';
171+
const profileSuffix = profile ? ` with ${profile} as the default terminal` : consoleCase.consoleMode === 'integratedTerminal' ? ' with default terminal' : '';
168172
test(`No-debug launch via ${consoleCase.label} handles ${programCase.label}${profileSuffix}`, async () => {
169-
if (profile) {
170-
await setWindowsDefaultTerminalProfile(profile);
171-
}
173+
await setWindowsDefaultTerminalProfile(profile);
172174

173175
disposeTerminals(executablePaths);
174176
const sessionName = `Run Without Debugging Args (${consoleCase.consoleMode}, ${path.basename(programCase.programPath)}${profile ? `, ${profile}` : ''})`;

0 commit comments

Comments
 (0)