@@ -16,7 +16,7 @@ import * as platform from 'vs/base/common/platform';
1616import { URI } from 'vs/base/common/uri' ;
1717import { IRemoteConsoleLog , log } from 'vs/base/common/console' ;
1818import { logRemoteEntry } from 'vs/workbench/services/extensions/common/remoteConsoleUtil' ;
19- import { findFreePort , randomPort } from 'vs/base/node/ports' ;
19+ import { findFreePort } from 'vs/base/node/ports' ;
2020import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc' ;
2121import { PersistentProtocol } from 'vs/base/parts/ipc/common/ipc.net' ;
2222import { generateRandomPipeName , NodeSocket } from 'vs/base/parts/ipc/node/ipc.net' ;
@@ -129,10 +129,10 @@ export class ExtensionHostProcessWorker implements IExtensionHostStarter {
129129 if ( ! this . _messageProtocol ) {
130130 this . _messageProtocol = Promise . all ( [
131131 this . _tryListenOnPipe ( ) ,
132- ! this . _environmentService . args [ 'disable-inspect' ] ? this . _tryFindDebugPort ( ) : Promise . resolve ( null )
132+ ! this . _environmentService . args [ 'disable-inspect' ] ? this . _tryFindDebugPort ( ) : 0
133133 ] ) . then ( data => {
134134 const pipeName = data [ 0 ] ;
135- const portData = data [ 1 ] ;
135+ const portNumber = data [ 1 ] ;
136136
137137 const opts = {
138138 env : objects . mixin ( objects . deepClone ( process . env ) , {
@@ -153,16 +153,11 @@ export class ExtensionHostProcessWorker implements IExtensionHostStarter {
153153 silent : true
154154 } ;
155155
156- if ( portData && portData . actual ) {
156+ if ( portNumber !== 0 ) {
157157 opts . execArgv = [
158158 '--nolazy' ,
159- ( this . _isExtensionDevDebugBrk ? '--inspect-brk=' : '--inspect=' ) + portData . actual
159+ ( this . _isExtensionDevDebugBrk ? '--inspect-brk=' : '--inspect=' ) + portNumber
160160 ] ;
161- if ( ! portData . expected ) {
162- // No one asked for 'inspect' or 'inspect-brk', only us. We add another
163- // option such that the extension host can manipulate the execArgv array
164- opts . env . VSCODE_PREVENT_FOREIGN_INSPECT = true ;
165- }
166161 }
167162
168163 const crashReporterOptions = undefined ; // TODO@electron pass this in as options to the extension host after verifying this actually works
@@ -221,11 +216,11 @@ export class ExtensionHostProcessWorker implements IExtensionHostStarter {
221216 this . _extensionHostProcess . on ( 'exit' , ( code : number , signal : string ) => this . _onExtHostProcessExit ( code , signal ) ) ;
222217
223218 // Notify debugger that we are ready to attach to the process if we run a development extension
224- if ( portData ) {
225- if ( this . _isExtensionDevHost && portData . actual && this . _isExtensionDevDebug && this . _environmentService . debugExtensionHost . debugId ) {
226- this . _extensionHostDebugService . attachSession ( this . _environmentService . debugExtensionHost . debugId , portData . actual ) ;
219+ if ( portNumber ) {
220+ if ( this . _isExtensionDevHost && portNumber && this . _isExtensionDevDebug && this . _environmentService . debugExtensionHost . debugId ) {
221+ this . _extensionHostDebugService . attachSession ( this . _environmentService . debugExtensionHost . debugId , portNumber ) ;
227222 }
228- this . _inspectPort = portData . actual ;
223+ this . _inspectPort = portNumber ;
229224 this . _onDidSetInspectPort . fire ( ) ;
230225 }
231226
@@ -279,29 +274,31 @@ export class ExtensionHostProcessWorker implements IExtensionHostStarter {
279274 /**
280275 * Find a free port if extension host debugging is enabled.
281276 */
282- private _tryFindDebugPort ( ) : Promise < { expected : number ; actual : number } > {
283- let expected : number ;
284- let startPort = randomPort ( ) ;
285- if ( typeof this . _environmentService . debugExtensionHost . port === 'number' ) {
286- startPort = expected = this . _environmentService . debugExtensionHost . port ;
277+ private async _tryFindDebugPort ( ) : Promise < number > {
278+
279+ if ( typeof this . _environmentService . debugExtensionHost . port !== 'number' ) {
280+ return 0 ;
287281 }
288- return new Promise ( resolve => {
289- return findFreePort ( startPort , 10 /* try 10 ports */ , 5000 /* try up to 5 seconds */ ) . then ( port => {
290- if ( ! port ) {
291- console . warn ( '%c[Extension Host] %cCould not find a free port for debugging' , 'color: blue' , 'color:' ) ;
292- } else {
293- if ( expected && port !== expected ) {
294- console . warn ( `%c[Extension Host] %cProvided debugging port ${ expected } is not free, using ${ port } instead.` , 'color: blue' , 'color:' ) ;
295- }
296- if ( this . _isExtensionDevDebugBrk ) {
297- console . warn ( `%c[Extension Host] %cSTOPPED on first line for debugging on port ${ port } ` , 'color: blue' , 'color:' ) ;
298- } else {
299- console . info ( `%c[Extension Host] %cdebugger listening on port ${ port } ` , 'color: blue' , 'color:' ) ;
300- }
301- }
302- return resolve ( { expected, actual : port } ) ;
303- } ) ;
304- } ) ;
282+
283+ const expected = this . _environmentService . debugExtensionHost . port ;
284+ const port = await findFreePort ( expected , 10 /* try 10 ports */ , 5000 /* try up to 5 seconds */ ) ;
285+
286+ if ( ! port ) {
287+ console . warn ( '%c[Extension Host] %cCould not find a free port for debugging' , 'color: blue' , 'color:' ) ;
288+ return 0 ;
289+ }
290+
291+ if ( port !== expected ) {
292+ console . warn ( `%c[Extension Host] %cProvided debugging port ${ expected } is not free, using ${ port } instead.` , 'color: blue' , 'color:' ) ;
293+ }
294+ if ( this . _isExtensionDevDebugBrk ) {
295+ console . warn ( `%c[Extension Host] %cSTOPPED on first line for debugging on port ${ port } ` , 'color: blue' , 'color:' ) ;
296+ } else {
297+ console . info ( `%c[Extension Host] %cdebugger listening on port ${ port } ` , 'color: blue' , 'color:' ) ;
298+ }
299+ return port ;
300+
301+
305302 }
306303
307304 private _tryExtHostHandshake ( ) : Promise < PersistentProtocol > {
0 commit comments