Skip to content

Commit fef3e22

Browse files
committed
fix: refresh env vars when auto attach settings change
Fixes microsoft/vscode-js-debug#731
1 parent d87a8cd commit fef3e22

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

extensions/debug-auto-launch/src/extension.ts

+36-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { createServer, Server } from 'net';
67
import * as vscode from 'vscode';
78
import * as nls from 'vscode-nls';
8-
import { createServer, Server } from 'net';
99

1010
const localize = nls.loadMessageBundle();
1111
const ON_TEXT = localize('status.text.auto.attach.on', 'Auto Attach: On');
@@ -15,10 +15,12 @@ const TOGGLE_COMMAND = 'extension.node-debug.toggleAutoAttach';
1515
const JS_DEBUG_SETTINGS = 'debug.javascript';
1616
const JS_DEBUG_USEPREVIEWAA = 'usePreviewAutoAttach';
1717
const JS_DEBUG_IPC_KEY = 'jsDebugIpcState';
18+
const JS_DEBUG_REFRESH_SETTINGS = ['autoAttachSmartPattern', 'autoAttachFilter']; // settings that, when changed, should cause us to refresh js-debug vars
1819
const NODE_DEBUG_SETTINGS = 'debug.node';
1920
const AUTO_ATTACH_SETTING = 'autoAttach';
2021
const LAST_STATE_STORAGE_KEY = 'lastState';
2122

23+
2224
type AUTO_ATTACH_VALUES = 'disabled' | 'on' | 'off';
2325

2426
const enum State {
@@ -45,10 +47,23 @@ export function activate(context: vscode.ExtensionContext): void {
4547
`${JS_DEBUG_SETTINGS}.${JS_DEBUG_USEPREVIEWAA}`,
4648
];
4749

50+
const refreshConfigurationSettings = JS_DEBUG_REFRESH_SETTINGS.map(s => `${JS_DEBUG_SETTINGS}.${s}`);
51+
4852
context.subscriptions.push(
4953
vscode.workspace.onDidChangeConfiguration((e) => {
5054
if (effectualConfigurationSettings.some(setting => e.affectsConfiguration(setting))) {
5155
updateAutoAttach();
56+
} else if (refreshConfigurationSettings.some(setting => e.affectsConfiguration(setting))) {
57+
currentState = currentState.then(async s => {
58+
if (s.state !== State.OnWithJsDebug) {
59+
return s;
60+
}
61+
62+
await transitions[State.OnWithJsDebug].exit?.(context, s.transitionData);
63+
await clearJsDebugAttachState(context);
64+
const transitionData = await transitions[State.OnWithJsDebug].enter?.(context);
65+
return { context, state: State.OnWithJsDebug, transitionData };
66+
});
5267
}
5368
})
5469
);
@@ -138,6 +153,7 @@ async function clearJsDebugAttachState(context: vscode.ExtensionContext) {
138153
interface CachedIpcState {
139154
ipcAddress: string;
140155
jsDebugPath: string;
156+
settingsValue: string;
141157
}
142158

143159
interface StateTransition<StateData> {
@@ -278,18 +294,34 @@ async function getIpcAddress(context: vscode.ExtensionContext) {
278294
const jsDebugPath = vscode.extensions.getExtension('ms-vscode.js-debug-nightly')?.extensionPath
279295
|| vscode.extensions.getExtension('ms-vscode.js-debug')?.extensionPath;
280296

281-
if (cachedIpc && cachedIpc.jsDebugPath === jsDebugPath) {
297+
const settingsValue = getJsDebugSettingKey();
298+
if (cachedIpc && cachedIpc.jsDebugPath === jsDebugPath && cachedIpc.settingsValue === settingsValue) {
282299
return cachedIpc.ipcAddress;
283300
}
284301

285302
const result = await vscode.commands.executeCommand<{ ipcAddress: string; }>(
286-
'extension.js-debug.setAutoAttachVariables'
303+
'extension.js-debug.setAutoAttachVariables',
304+
cachedIpc?.ipcAddress
287305
);
288306
if (!result) {
289307
return;
290308
}
291309

292310
const ipcAddress = result.ipcAddress;
293-
await context.workspaceState.update(JS_DEBUG_IPC_KEY, { ipcAddress, jsDebugPath });
311+
await context.workspaceState.update(
312+
JS_DEBUG_IPC_KEY,
313+
{ ipcAddress, jsDebugPath, settingsValue } as CachedIpcState,
314+
);
315+
294316
return ipcAddress;
295317
}
318+
319+
function getJsDebugSettingKey() {
320+
let o: { [key: string]: unknown } = {};
321+
const config = vscode.workspace.getConfiguration(JS_DEBUG_SETTINGS);
322+
for (const setting of JS_DEBUG_REFRESH_SETTINGS) {
323+
o[setting] = config.get(setting);
324+
}
325+
326+
return JSON.stringify(o);
327+
}

0 commit comments

Comments
 (0)