@@ -12,15 +12,14 @@ import getPort = require('get-port');
12
12
import path = require( 'path' ) ;
13
13
import * as fs from 'fs' ;
14
14
import * as net from 'net' ;
15
- import { Logger , logVerbose , TimestampedLogger } from './goLogging' ;
16
15
import { DebugProtocol } from 'vscode-debugprotocol' ;
17
16
import { getWorkspaceFolderPath } from './util' ;
18
17
import { getEnvPath , getBinPathFromEnvVar } from './utils/pathUtils' ;
19
18
import { GoExtensionContext } from './context' ;
20
19
import { createRegisterCommand } from './commands' ;
21
20
22
21
export function activate ( ctx : vscode . ExtensionContext , goCtx : GoExtensionContext ) {
23
- const debugOutputChannel = vscode . window . createOutputChannel ( 'Go Debug' ) ;
22
+ const debugOutputChannel = vscode . window . createOutputChannel ( 'Go Debug' , { log : true } ) ;
24
23
ctx . subscriptions . push ( debugOutputChannel ) ;
25
24
26
25
const factory = new GoDebugAdapterDescriptorFactory ( debugOutputChannel ) ;
@@ -40,7 +39,7 @@ export function activate(ctx: vscode.ExtensionContext, goCtx: GoExtensionContext
40
39
}
41
40
42
41
class GoDebugAdapterDescriptorFactory implements vscode . DebugAdapterDescriptorFactory {
43
- constructor ( private outputChannel ? : vscode . OutputChannel ) { }
42
+ constructor ( private outputChannel : vscode . LogOutputChannel ) { }
44
43
45
44
public createDebugAdapterDescriptor (
46
45
session : vscode . DebugSession ,
@@ -59,11 +58,11 @@ class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFa
59
58
private async createDebugAdapterDescriptorDlvDap (
60
59
configuration : vscode . DebugConfiguration
61
60
) : Promise < vscode . ProviderResult < vscode . DebugAdapterDescriptor > > {
62
- const logger = new TimestampedLogger ( configuration . trace , this . outputChannel ) ;
63
- logger . debug ( `Config: ${ JSON . stringify ( configuration ) } \n ` ) ;
61
+ const logger = this . outputChannel ;
62
+ logger . debug ( `Config: ${ JSON . stringify ( configuration ) } ` ) ;
64
63
if ( configuration . port ) {
65
64
const host = configuration . host ?? '127.0.0.1' ;
66
- logger . info ( `Connecting to DAP server at ${ host } :${ configuration . port } \n ` ) ;
65
+ logger . info ( `Connecting to DAP server at ${ host } :${ configuration . port } ` ) ;
67
66
return new vscode . DebugAdapterServer ( configuration . port , host ) ;
68
67
}
69
68
const d = new DelveDAPOutputAdapter ( configuration , logger ) ;
@@ -72,28 +71,24 @@ class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFa
72
71
}
73
72
74
73
class GoDebugAdapterTrackerFactory implements vscode . DebugAdapterTrackerFactory {
75
- constructor ( private outputChannel : vscode . OutputChannel ) { }
74
+ constructor ( private outputChannel : vscode . LogOutputChannel ) { }
76
75
77
76
createDebugAdapterTracker ( session : vscode . DebugSession ) {
78
- const level = session . configuration ?. trace ;
79
- if ( ! level || level === 'off' ) {
80
- return null ;
81
- }
82
- const logger = new TimestampedLogger ( session . configuration ?. trace || 'off' , this . outputChannel ) ;
77
+ const logger = this . outputChannel ;
83
78
let requestsSent = 0 ;
84
79
let responsesReceived = 0 ;
85
80
return {
86
81
onWillStartSession : ( ) =>
87
- logger . debug ( `session ${ session . id } will start with ${ JSON . stringify ( session . configuration ) } \n ` ) ,
82
+ logger . debug ( `session ${ session . id } will start with ${ JSON . stringify ( session . configuration ) } ` ) ,
88
83
onWillReceiveMessage : ( message : any ) => {
89
- logger . trace ( `client -> ${ JSON . stringify ( message ) } \n ` ) ;
84
+ logger . trace ( `client -> ${ JSON . stringify ( message ) } ` ) ;
90
85
requestsSent ++ ;
91
86
} ,
92
87
onDidSendMessage : ( message : any ) => {
93
- logger . trace ( `client <- ${ JSON . stringify ( message ) } \n ` ) ;
88
+ logger . trace ( `client <- ${ JSON . stringify ( message ) } ` ) ;
94
89
responsesReceived ++ ;
95
90
} ,
96
- onError : ( error : Error ) => logger . error ( `error: ${ error } \n ` ) ,
91
+ onError : ( error : Error ) => logger . error ( `error: ${ error } ` ) ,
97
92
onWillStopSession : ( ) => {
98
93
if (
99
94
session . configuration . debugAdapter === 'dlv-dap' &&
@@ -109,7 +104,7 @@ class GoDebugAdapterTrackerFactory implements vscode.DebugAdapterTrackerFactory
109
104
logger . debug ( `session ${ session . id } will stop\n` ) ;
110
105
} ,
111
106
onExit : ( code : number | undefined , signal : string | undefined ) =>
112
- logger . info ( `debug adapter exited: (code: ${ code } , signal: ${ signal } )\n ` )
107
+ logger . info ( `debug adapter exited: (code: ${ code } , signal: ${ signal } )` )
113
108
} ;
114
109
}
115
110
@@ -118,6 +113,8 @@ class GoDebugAdapterTrackerFactory implements vscode.DebugAdapterTrackerFactory
118
113
119
114
const TWO_CRLF = '\r\n\r\n' ;
120
115
116
+ type ILogger = Pick < vscode . LogOutputChannel , 'error' | 'info' | 'debug' | 'trace' > ;
117
+
121
118
// Proxies DebugProtocolMessage exchanges between VSCode and a remote
122
119
// process or server connected through a duplex stream, after its
123
120
// start method is called.
@@ -126,10 +123,10 @@ export class ProxyDebugAdapter implements vscode.DebugAdapter {
126
123
// connection from/to server (= dlv dap)
127
124
private readable ?: stream . Readable ;
128
125
private writable ?: stream . Writable ;
129
- protected logger ?: Logger ;
126
+ protected logger : ILogger ;
130
127
private terminated = false ;
131
128
132
- constructor ( logger : Logger ) {
129
+ constructor ( logger : ILogger ) {
133
130
this . logger = logger ;
134
131
this . onDidSendMessage = this . messageEmitter . event ;
135
132
}
@@ -240,7 +237,7 @@ export class ProxyDebugAdapter implements vscode.DebugAdapter {
240
237
// VSCode and a dlv dap process spawned and managed by this adapter.
241
238
// It turns the process's stdout/stderrr into OutputEvent.
242
239
export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
243
- constructor ( private configuration : vscode . DebugConfiguration , logger : Logger ) {
240
+ constructor ( private configuration : vscode . DebugConfiguration , logger : ILogger ) {
244
241
super ( logger ) ;
245
242
}
246
243
@@ -252,7 +249,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
252
249
protected sendMessageToClient ( message : vscode . DebugProtocolMessage ) {
253
250
const m = message as any ;
254
251
if ( m . type === 'request' ) {
255
- logVerbose ( `do not forward reverse request: dropping ${ JSON . stringify ( m ) } ` ) ;
252
+ this . logger . debug ( `do not forward reverse request: dropping ${ JSON . stringify ( m ) } ` ) ;
256
253
return ;
257
254
}
258
255
@@ -262,7 +259,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
262
259
protected async sendMessageToServer ( message : vscode . DebugProtocolMessage ) : Promise < void > {
263
260
const m = message as any ;
264
261
if ( m . type === 'response' ) {
265
- logVerbose ( `do not forward reverse request response: dropping ${ JSON . stringify ( m ) } ` ) ;
262
+ this . logger . debug ( `do not forward reverse request response: dropping ${ JSON . stringify ( m ) } ` ) ;
266
263
return ;
267
264
}
268
265
@@ -353,7 +350,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
353
350
} catch ( err ) {
354
351
return { connected : false , reason : err } ;
355
352
}
356
- this . logger ?. debug ( `Running dlv dap server: pid=${ this . dlvDapServer ?. pid } \n ` ) ;
353
+ this . logger ?. debug ( `Running dlv dap server: pid=${ this . dlvDapServer ?. pid } ` ) ;
357
354
return { connected : true } ;
358
355
}
359
356
@@ -372,7 +369,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
372
369
// may not appear in the DEBUG CONSOLE. For easier debugging, log
373
370
// the messages through the logger that prints to Go Debug output
374
371
// channel.
375
- this . logger ?. info ( msg ) ;
372
+ this . logger ?. trace ( msg ) ;
376
373
} ;
377
374
378
375
// If a port has been specified, assume there is an already
@@ -437,7 +434,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
437
434
438
435
try {
439
436
const port = await getPort ( ) ;
440
- const rendezvousServerPromise = waitForDAPServer ( port , 30_000 ) ;
437
+ const rendezvousServerPromise = waitForDAPServer ( port , 30_000 , this . logger ) ;
441
438
442
439
dlvArgs . push ( `--client-addr=:${ port } ` ) ;
443
440
@@ -470,7 +467,7 @@ function getSudo(): string | null {
470
467
return sudoPath ;
471
468
}
472
469
473
- function waitForDAPServer ( port : number , timeoutMs : number ) : Promise < net . Socket > {
470
+ function waitForDAPServer ( port : number , timeoutMs : number , logger : ILogger ) : Promise < net . Socket > {
474
471
return new Promise ( ( resolve , reject ) => {
475
472
// eslint-disable-next-line prefer-const
476
473
let s : net . Server | undefined ;
@@ -482,7 +479,7 @@ function waitForDAPServer(port: number, timeoutMs: number): Promise<net.Socket>
482
479
} , timeoutMs ) ;
483
480
484
481
s = net . createServer ( { pauseOnConnect : true } , ( socket ) => {
485
- logVerbose (
482
+ logger . debug (
486
483
`connected: ${ port } (remote: ${ socket . remoteAddress } :${ socket . remotePort } local: ${ socket . localAddress } :${ socket . localPort } )`
487
484
) ;
488
485
clearTimeout ( timeoutToken ) ;
@@ -491,7 +488,7 @@ function waitForDAPServer(port: number, timeoutMs: number): Promise<net.Socket>
491
488
resolve ( socket ) ;
492
489
} ) ;
493
490
s . on ( 'error' , ( err ) => {
494
- logVerbose ( `connection error ${ err } ` ) ;
491
+ logger . error ( `connection error ${ err } ` ) ;
495
492
reject ( err ) ;
496
493
} ) ;
497
494
s . maxConnections = 1 ;
0 commit comments