Skip to content

Commit 5038d4d

Browse files
Copilotrchiodo
andauthored
fix: apply no-config terminal env vars via shell integration
Agent-Logs-Url: https://github.com/microsoft/vscode-python-debugger/sessions/17a3239c-44e7-4528-b313-a9af892cf887 Co-authored-by: rchiodo <19672699+rchiodo@users.noreply.github.com>
1 parent e703bd8 commit 5038d4d

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/extension/noConfigDebugInit.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as crypto from 'crypto';
77
import {
88
DebugSessionOptions,
99
Disposable,
10+
EnvironmentVariableMutatorOptions,
1011
GlobalEnvironmentVariableCollection,
1112
env,
1213
l10n,
@@ -37,6 +38,9 @@ export async function registerNoConfigDebug(
3738
extPath: string,
3839
): Promise<Disposable> {
3940
const collection = envVarCollection;
41+
const shellIntegrationMutatorOptions: EnvironmentVariableMutatorOptions = {
42+
applyAtShellIntegration: true,
43+
};
4044

4145
// create a temp directory for the noConfigDebugAdapterEndpoints
4246
// file path format: extPath/.noConfigDebugAdapterEndpoints/endpoint-<sessionId>.txt
@@ -60,19 +64,19 @@ export async function registerNoConfigDebug(
6064
collection.clear();
6165

6266
// Add env var for PYDEVD_DISABLE_FILE_VALIDATION to disable extra output in terminal when starting the debug session.
63-
collection.replace('PYDEVD_DISABLE_FILE_VALIDATION', '1');
67+
collection.replace('PYDEVD_DISABLE_FILE_VALIDATION', '1', shellIntegrationMutatorOptions);
6468

6569
// Add env vars for VSCODE_DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH
66-
collection.replace('VSCODE_DEBUGPY_ADAPTER_ENDPOINTS', tempFilePath);
70+
collection.replace('VSCODE_DEBUGPY_ADAPTER_ENDPOINTS', tempFilePath, shellIntegrationMutatorOptions);
6771

6872
const noConfigScriptsDir = path.join(extPath, 'bundled', 'scripts', 'noConfigScripts');
6973
const pathSeparator = process.platform === 'win32' ? ';' : ':';
7074

7175
// Always prepend separator when appending to PATH since append() concatenates to existing value
72-
collection.append('PATH', `${pathSeparator}${noConfigScriptsDir}`);
76+
collection.append('PATH', `${pathSeparator}${noConfigScriptsDir}`, shellIntegrationMutatorOptions);
7377

7478
const bundledDebugPath = path.join(extPath, 'bundled', 'libs', 'debugpy');
75-
collection.replace('BUNDLED_DEBUGPY_PATH', bundledDebugPath);
79+
collection.replace('BUNDLED_DEBUGPY_PATH', bundledDebugPath, shellIntegrationMutatorOptions);
7680

7781
envVarCollection.description = l10n.t(
7882
'Enables use of [no-config debugging](https://github.com/microsoft/vscode-python-debugger/wiki/No%E2%80%90Config-Debugging), `debugpy <script.py>`, in the terminal.',

src/test/unittest/noConfigDebugInit.unit.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,27 @@ suite('setup for no-config debug scenario', function () {
5858
// set up the environment variable collection mock including asserts for the key, value pairs
5959
environmentVariableCollectionMock
6060
.setup((x) => x.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
61-
.callback((key, value) => {
61+
.callback((key, value, options) => {
6262
if (key === DEBUGPY_ADAPTER_ENDPOINTS) {
6363
assert(value.includes('endpoint-'));
6464
} else if (key === BUNDLED_DEBUGPY_PATH) {
6565
assert(value === bundledDebugPath);
6666
} else if (key === 'PYDEVD_DISABLE_FILE_VALIDATION') {
6767
assert(value === '1');
6868
}
69+
assert(options?.applyAtShellIntegration === true);
70+
assert(options?.applyAtProcessCreation !== true);
6971
})
7072
.returns(envVarCollectionReplaceStub);
7173
environmentVariableCollectionMock
7274
.setup((x) => x.append(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
73-
.callback((key, value) => {
75+
.callback((key, value, options) => {
7476
if (key === 'PATH') {
7577
const pathSeparator = process.platform === 'win32' ? ';' : ':';
7678
assert(value === `${pathSeparator}${noConfigScriptsDir}`);
7779
}
80+
assert(options?.applyAtShellIntegration === true);
81+
assert(options?.applyAtProcessCreation !== true);
7882
})
7983
.returns(envVarCollectionAppendStub);
8084

0 commit comments

Comments
 (0)