Skip to content

Commit c790e07

Browse files
committed
no config debug: Fix error when multiple vscode windows are open
Should fix #916, but getting this installed locally seemed sufficiently complicated that I gave up. Fix is: 1. Only watch a specific endpoint file 2. Make sure this endpoint file is unique (I imagine the workspace file path can be non unique across vscode windows)
1 parent d7b9643 commit c790e07

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/extension/noConfigDebugInit.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DebugSessionOptions,
99
Disposable,
1010
GlobalEnvironmentVariableCollection,
11+
env,
1112
l10n,
1213
RelativePattern,
1314
workspace,
@@ -49,13 +50,15 @@ export async function registerNoConfigDebug(
4950
return Promise.resolve(new Disposable(() => {}));
5051
}
5152

52-
// create a stable hash for the workspace folder, reduce terminal variable churn
53+
// Create unique hash based on workspace and VS Code session ID
5354
const hash = crypto.createHash('sha256');
5455
hash.update(workspaceString.toString());
56+
hash.update(env.sessionId);
5557
const stableWorkspaceHash = hash.digest('hex').slice(0, 16);
5658

5759
const tempDirPath = path.join(extPath, '.noConfigDebugAdapterEndpoints');
58-
const tempFilePath = path.join(tempDirPath, `endpoint-${stableWorkspaceHash}.txt`);
60+
const endpointFilename = `endpoint-${stableWorkspaceHash}.txt`;
61+
const tempFilePath = path.join(tempDirPath, endpointFilename);
5962

6063
// create the temp directory if it doesn't exist
6164
if (!fs.existsSync(tempDirPath)) {
@@ -92,8 +95,8 @@ export async function registerNoConfigDebug(
9295
'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.',
9396
);
9497

95-
// create file system watcher for the debuggerAdapterEndpointFolder for when the communication port is written
96-
const fileSystemWatcher = createFileSystemWatcher(new RelativePattern(tempDirPath, '**/*.txt'));
98+
// create file system watcher for the debugger adapter endpoint for when the communication port is written
99+
const fileSystemWatcher = createFileSystemWatcher(new RelativePattern(tempDirPath, endpointFilename));
97100
const fileCreationEvent = fileSystemWatcher.onDidCreate(async (uri) => {
98101
sendTelemetryEvent(EventName.DEBUG_SESSION_START, undefined, {
99102
trigger: 'noConfig' as TriggerType,

0 commit comments

Comments
 (0)