Skip to content

Commit 2ca0565

Browse files
committed
Add terminalQuoteCharacter as an option
1 parent bfb9323 commit 2ca0565

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ source .venv/bin/activate
1919
Install then setup with nox.
2020
```
2121
python3 -m pip install nox
22-
nox --session setup_repo
22+
nox
2323
```
2424

2525
## Reporting Issues

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@
256256
"description": "Enable logging of debugger events to a log file. This file can be found in the debugpy extension install folder.",
257257
"type": "boolean"
258258
},
259+
"terminalQuoteCharacter": {
260+
"default": null,
261+
"description": "The quoting character to be used by the debugger when quoting terminal commands.",
262+
"type": [
263+
"string",
264+
"null"
265+
],
266+
"enum": [
267+
"\"",
268+
"'",
269+
"`"
270+
],
271+
"enumDescriptions": [
272+
"Double quote (\")",
273+
"Single quote (')",
274+
"Backtick (`)"
275+
]
276+
},
259277
"pathMappings": {
260278
"default": [],
261279
"items": {
@@ -452,6 +470,24 @@
452470
"description": "Enable logging of debugger events to a log file. This file can be found in the debugpy extension install folder.",
453471
"type": "boolean"
454472
},
473+
"terminalQuoteCharacter": {
474+
"default": null,
475+
"description": "The quoting character to be used by the debugger when quoting terminal commands.",
476+
"type": [
477+
"string",
478+
"null"
479+
],
480+
"enum": [
481+
"\"",
482+
"'",
483+
"`"
484+
],
485+
"enumDescriptions": [
486+
"Double quote (\")",
487+
"Single quote (')",
488+
"Backtick (`)"
489+
]
490+
},
455491
"module": {
456492
"default": "",
457493
"description": "Name of the module to be debugged.",

src/extension/debugger/configuration/resolvers/launch.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
'use strict';
55

6-
import { CancellationToken, Uri, WorkspaceFolder } from 'vscode';
6+
import { CancellationToken, Uri, WorkspaceFolder, workspace } from 'vscode';
77
import { getOSType, OSType } from '../../../common/platform';
88
import { getEnvFile } from '../../../common/settings';
99
import { DebuggerTypeName } from '../../../constants';
@@ -13,6 +13,7 @@ import { BaseConfigurationResolver } from './base';
1313
import { getDebugEnvironmentVariables, getProgram } from './helper';
1414
import { getConfiguration } from '../../../common/vscodeapi';
1515
import { traceLog } from '../../../common/log/logging';
16+
import { debug } from 'console';
1617

1718
export class LaunchConfigurationResolver extends BaseConfigurationResolver<LaunchRequestArguments> {
1819
public async resolveDebugConfiguration(
@@ -105,6 +106,13 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
105106
if (debugConfiguration.console !== 'internalConsole' && !debugConfiguration.internalConsoleOptions) {
106107
debugConfiguration.internalConsoleOptions = 'neverOpen';
107108
}
109+
110+
// Compute the terminal quoting character.
111+
if (!debugConfiguration.terminalQuoteCharacter || debugConfiguration.terminalQuoteCharacter.length !== 1) {
112+
const quoteChar = this._computeTerminalQuoteCharacter();
113+
debugConfiguration.terminalQuoteCharacter = quoteChar;
114+
}
115+
108116
if (!Array.isArray(debugConfiguration.debugOptions)) {
109117
debugConfiguration.debugOptions = [];
110118
}
@@ -182,4 +190,46 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
182190
: 'launch';
183191
LaunchConfigurationResolver.sendTelemetry(trigger, debugConfiguration);
184192
}
193+
194+
private _computeTerminalQuoteCharacter(): string {
195+
const platform = process.platform; // 'win32', 'linux', 'darwin'
196+
const config = workspace.getConfiguration('terminal');
197+
198+
let defaultProfile: string | undefined;
199+
let profiles: any;
200+
201+
if (platform === 'win32') {
202+
defaultProfile = config.get<string>('integrated.defaultProfile.windows');
203+
profiles = config.get<any>('integrated.profiles.windows');
204+
} else if (platform === 'linux') {
205+
defaultProfile = config.get<string>('integrated.defaultProfile.linux');
206+
profiles = config.get<any>('integrated.profiles.linux');
207+
} else if (platform === 'darwin') {
208+
defaultProfile = config.get<string>('integrated.defaultProfile.osx');
209+
profiles = config.get<any>('integrated.profiles.osx');
210+
}
211+
212+
if (!defaultProfile || !profiles) {
213+
if (platform === 'win32') {
214+
return "'"; // Default is powershell
215+
} else {
216+
return '"'; // Default is bash/zsh
217+
}
218+
}
219+
220+
const profile = defaultProfile ? profiles[defaultProfile] : profiles[0];
221+
const shellPath = profile?.path || '';
222+
223+
if (/powershell/i.test(shellPath)) {
224+
return "'";
225+
}
226+
if (/cmd\.exe$/i.test(shellPath)) {
227+
return '"';
228+
}
229+
if (/bash|zsh|fish/i.test(shellPath)) {
230+
return '"';
231+
}
232+
233+
return '"';
234+
}
185235
}

0 commit comments

Comments
 (0)