@@ -12,15 +12,14 @@ import getPort = require('get-port');
1212import path = require( 'path' ) ;
1313import * as fs from 'fs' ;
1414import * as net from 'net' ;
15- import { Logger , logVerbose , TimestampedLogger } from './goLogging' ;
1615import { DebugProtocol } from 'vscode-debugprotocol' ;
1716import { getWorkspaceFolderPath } from './util' ;
1817import { getEnvPath , getBinPathFromEnvVar } from './utils/pathUtils' ;
1918import { GoExtensionContext } from './context' ;
2019import { createRegisterCommand } from './commands' ;
2120
2221export 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 } ) ;
2423 ctx . subscriptions . push ( debugOutputChannel ) ;
2524
2625 const factory = new GoDebugAdapterDescriptorFactory ( debugOutputChannel ) ;
@@ -40,7 +39,7 @@ export function activate(ctx: vscode.ExtensionContext, goCtx: GoExtensionContext
4039}
4140
4241class GoDebugAdapterDescriptorFactory implements vscode . DebugAdapterDescriptorFactory {
43- constructor ( private outputChannel ? : vscode . OutputChannel ) { }
42+ constructor ( private outputChannel : vscode . LogOutputChannel ) { }
4443
4544 public createDebugAdapterDescriptor (
4645 session : vscode . DebugSession ,
@@ -59,11 +58,11 @@ class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFa
5958 private async createDebugAdapterDescriptorDlvDap (
6059 configuration : vscode . DebugConfiguration
6160 ) : 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 ) } ` ) ;
6463 if ( configuration . port ) {
6564 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 } ` ) ;
6766 return new vscode . DebugAdapterServer ( configuration . port , host ) ;
6867 }
6968 const d = new DelveDAPOutputAdapter ( configuration , logger ) ;
@@ -72,28 +71,24 @@ class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFa
7271}
7372
7473class GoDebugAdapterTrackerFactory implements vscode . DebugAdapterTrackerFactory {
75- constructor ( private outputChannel : vscode . OutputChannel ) { }
74+ constructor ( private outputChannel : vscode . LogOutputChannel ) { }
7675
7776 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 ;
8378 let requestsSent = 0 ;
8479 let responsesReceived = 0 ;
8580 return {
8681 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 ) } ` ) ,
8883 onWillReceiveMessage : ( message : any ) => {
89- logger . trace ( `client -> ${ JSON . stringify ( message ) } \n ` ) ;
84+ logger . trace ( `client -> ${ JSON . stringify ( message ) } ` ) ;
9085 requestsSent ++ ;
9186 } ,
9287 onDidSendMessage : ( message : any ) => {
93- logger . trace ( `client <- ${ JSON . stringify ( message ) } \n ` ) ;
88+ logger . trace ( `client <- ${ JSON . stringify ( message ) } ` ) ;
9489 responsesReceived ++ ;
9590 } ,
96- onError : ( error : Error ) => logger . error ( `error: ${ error } \n ` ) ,
91+ onError : ( error : Error ) => logger . error ( `error: ${ error } ` ) ,
9792 onWillStopSession : ( ) => {
9893 if (
9994 session . configuration . debugAdapter === 'dlv-dap' &&
@@ -109,7 +104,7 @@ class GoDebugAdapterTrackerFactory implements vscode.DebugAdapterTrackerFactory
109104 logger . debug ( `session ${ session . id } will stop\n` ) ;
110105 } ,
111106 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 } )` )
113108 } ;
114109 }
115110
@@ -118,6 +113,8 @@ class GoDebugAdapterTrackerFactory implements vscode.DebugAdapterTrackerFactory
118113
119114const TWO_CRLF = '\r\n\r\n' ;
120115
116+ type ILogger = Pick < vscode . LogOutputChannel , 'error' | 'info' | 'debug' | 'trace' > ;
117+
121118// Proxies DebugProtocolMessage exchanges between VSCode and a remote
122119// process or server connected through a duplex stream, after its
123120// start method is called.
@@ -126,10 +123,10 @@ export class ProxyDebugAdapter implements vscode.DebugAdapter {
126123 // connection from/to server (= dlv dap)
127124 private readable ?: stream . Readable ;
128125 private writable ?: stream . Writable ;
129- protected logger ?: Logger ;
126+ protected logger : ILogger ;
130127 private terminated = false ;
131128
132- constructor ( logger : Logger ) {
129+ constructor ( logger : ILogger ) {
133130 this . logger = logger ;
134131 this . onDidSendMessage = this . messageEmitter . event ;
135132 }
@@ -240,7 +237,7 @@ export class ProxyDebugAdapter implements vscode.DebugAdapter {
240237// VSCode and a dlv dap process spawned and managed by this adapter.
241238// It turns the process's stdout/stderrr into OutputEvent.
242239export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
243- constructor ( private configuration : vscode . DebugConfiguration , logger : Logger ) {
240+ constructor ( private configuration : vscode . DebugConfiguration , logger : ILogger ) {
244241 super ( logger ) ;
245242 }
246243
@@ -252,7 +249,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
252249 protected sendMessageToClient ( message : vscode . DebugProtocolMessage ) {
253250 const m = message as any ;
254251 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 ) } ` ) ;
256253 return ;
257254 }
258255
@@ -262,7 +259,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
262259 protected async sendMessageToServer ( message : vscode . DebugProtocolMessage ) : Promise < void > {
263260 const m = message as any ;
264261 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 ) } ` ) ;
266263 return ;
267264 }
268265
@@ -353,7 +350,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
353350 } catch ( err ) {
354351 return { connected : false , reason : err } ;
355352 }
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 } ` ) ;
357354 return { connected : true } ;
358355 }
359356
@@ -372,7 +369,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
372369 // may not appear in the DEBUG CONSOLE. For easier debugging, log
373370 // the messages through the logger that prints to Go Debug output
374371 // channel.
375- this . logger ?. info ( msg ) ;
372+ this . logger ?. trace ( msg ) ;
376373 } ;
377374
378375 // If a port has been specified, assume there is an already
@@ -437,7 +434,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
437434
438435 try {
439436 const port = await getPort ( ) ;
440- const rendezvousServerPromise = waitForDAPServer ( port , 30_000 ) ;
437+ const rendezvousServerPromise = waitForDAPServer ( port , 30_000 , this . logger ) ;
441438
442439 dlvArgs . push ( `--client-addr=:${ port } ` ) ;
443440
@@ -470,7 +467,7 @@ function getSudo(): string | null {
470467 return sudoPath ;
471468}
472469
473- function waitForDAPServer ( port : number , timeoutMs : number ) : Promise < net . Socket > {
470+ function waitForDAPServer ( port : number , timeoutMs : number , logger : ILogger ) : Promise < net . Socket > {
474471 return new Promise ( ( resolve , reject ) => {
475472 // eslint-disable-next-line prefer-const
476473 let s : net . Server | undefined ;
@@ -482,7 +479,7 @@ function waitForDAPServer(port: number, timeoutMs: number): Promise<net.Socket>
482479 } , timeoutMs ) ;
483480
484481 s = net . createServer ( { pauseOnConnect : true } , ( socket ) => {
485- logVerbose (
482+ logger . debug (
486483 `connected: ${ port } (remote: ${ socket . remoteAddress } :${ socket . remotePort } local: ${ socket . localAddress } :${ socket . localPort } )`
487484 ) ;
488485 clearTimeout ( timeoutToken ) ;
@@ -491,7 +488,7 @@ function waitForDAPServer(port: number, timeoutMs: number): Promise<net.Socket>
491488 resolve ( socket ) ;
492489 } ) ;
493490 s . on ( 'error' , ( err ) => {
494- logVerbose ( `connection error ${ err } ` ) ;
491+ logger . error ( `connection error ${ err } ` ) ;
495492 reject ( err ) ;
496493 } ) ;
497494 s . maxConnections = 1 ;
0 commit comments