5
5
6
6
import { promises as fs } from 'fs' ;
7
7
import { createServer , Server } from 'net' ;
8
+ import { dirname } from 'path' ;
8
9
import * as vscode from 'vscode' ;
9
10
10
11
const enum State {
@@ -72,8 +73,7 @@ export function activate(context: vscode.ExtensionContext): void {
72
73
e . affectsConfiguration ( `${ SETTING_SECTION } .${ SETTING_STATE } ` ) ||
73
74
[ ...SETTINGS_CAUSE_REFRESH ] . some ( setting => e . affectsConfiguration ( setting ) )
74
75
) {
75
- updateAutoAttach ( State . Disabled ) ;
76
- updateAutoAttach ( readCurrentState ( ) ) ;
76
+ refreshAutoAttachVars ( ) ;
77
77
}
78
78
} ) ,
79
79
) ;
@@ -85,6 +85,11 @@ export async function deactivate(): Promise<void> {
85
85
await destroyAttachServer ( ) ;
86
86
}
87
87
88
+ function refreshAutoAttachVars ( ) {
89
+ updateAutoAttach ( State . Disabled ) ;
90
+ updateAutoAttach ( readCurrentState ( ) ) ;
91
+ }
92
+
88
93
function getDefaultScope ( info : ReturnType < vscode . WorkspaceConfiguration [ 'inspect' ] > ) {
89
94
if ( ! info ) {
90
95
return vscode . ConfigurationTarget . Global ;
@@ -204,8 +209,22 @@ async function createAttachServer(context: vscode.ExtensionContext) {
204
209
return undefined ;
205
210
}
206
211
207
- server = createServerInner ( ipcAddress ) . catch ( err => {
208
- console . error ( err ) ;
212
+ server = createServerInner ( ipcAddress ) . catch ( async err => {
213
+ console . error ( '[debug-auto-launch] Error creating auto attach server: ' , err ) ;
214
+
215
+ if ( process . platform !== 'win32' ) {
216
+ // On macOS, and perhaps some Linux distros, the temporary directory can
217
+ // sometimes change. If it looks like that's the cause of a listener
218
+ // error, automatically refresh the auto attach vars.
219
+ try {
220
+ await fs . access ( dirname ( ipcAddress ) ) ;
221
+ } catch {
222
+ console . error ( '[debug-auto-launch] Refreshing variables from error' ) ;
223
+ refreshAutoAttachVars ( ) ;
224
+ return undefined ;
225
+ }
226
+ }
227
+
209
228
return undefined ;
210
229
} ) ;
211
230
0 commit comments