@@ -68,20 +68,18 @@ import { statSync } from 'fs';
6868import { DiagnosticsService } from 'vs/platform/diagnostics/node/diagnosticsIpc' ;
6969import { IDiagnosticsService } from 'vs/platform/diagnostics/node/diagnosticsService' ;
7070import { ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc' ;
71+ import { ElectronExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/electron-main/extensionHostDebugIpc' ;
7172import { IElectronMainService , ElectronMainService } from 'vs/platform/electron/electron-main/electronMainService' ;
7273import { ISharedProcessMainService , SharedProcessMainService } from 'vs/platform/ipc/electron-main/sharedProcessMainService' ;
7374import { IDialogMainService , DialogMainService } from 'vs/platform/dialogs/electron-main/dialogs' ;
7475import { withNullAsUndefined } from 'vs/base/common/types' ;
75- import { parseArgs , OPTIONS } from 'vs/platform/environment/node/argv' ;
7676import { coalesce } from 'vs/base/common/arrays' ;
7777import { IStorageKeysSyncRegistryService } from 'vs/platform/userDataSync/common/storageKeys' ;
7878import { StorageKeysSyncRegistryChannel } from 'vs/platform/userDataSync/common/userDataSyncIpc' ;
7979import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService' ;
8080import { mnemonicButtonLabel , getPathLabel } from 'vs/base/common/labels' ;
8181import { WebviewMainService } from 'vs/platform/webview/electron-main/webviewMainService' ;
8282import { IWebviewManagerService } from 'vs/platform/webview/common/webviewManagerService' ;
83- import { createServer , AddressInfo } from 'net' ;
84- import { IOpenExtensionWindowResult } from 'vs/platform/debug/common/extensionHostDebug' ;
8583import { IFileService } from 'vs/platform/files/common/files' ;
8684import { stripComments } from 'vs/base/common/json' ;
8785import { generateUuid } from 'vs/base/common/uuid' ;
@@ -867,100 +865,3 @@ export class CodeApplication extends Disposable {
867865 } ) ;
868866 }
869867}
870-
871- class ElectronExtensionHostDebugBroadcastChannel < TContext > extends ExtensionHostDebugBroadcastChannel < TContext > {
872-
873- constructor ( private windowsMainService : IWindowsMainService ) {
874- super ( ) ;
875- }
876-
877- call ( ctx : TContext , command : string , arg ?: any ) : Promise < any > {
878- if ( command === 'openExtensionDevelopmentHostWindow' ) {
879- return this . openExtensionDevelopmentHostWindow ( arg [ 0 ] , arg [ 1 ] , arg [ 2 ] ) ;
880- } else {
881- return super . call ( ctx , command , arg ) ;
882- }
883- }
884-
885- private async openExtensionDevelopmentHostWindow ( args : string [ ] , env : IProcessEnvironment , debugRenderer : boolean ) : Promise < IOpenExtensionWindowResult > {
886- const pargs = parseArgs ( args , OPTIONS ) ;
887- const extDevPaths = pargs . extensionDevelopmentPath ;
888- if ( ! extDevPaths ) {
889- return { } ;
890- }
891-
892- const [ codeWindow ] = this . windowsMainService . openExtensionDevelopmentHostWindow ( extDevPaths , {
893- context : OpenContext . API ,
894- cli : pargs ,
895- userEnv : Object . keys ( env ) . length > 0 ? env : undefined
896- } ) ;
897-
898- if ( ! debugRenderer ) {
899- return { } ;
900- }
901-
902- const debug = codeWindow . win . webContents . debugger ;
903-
904- let listeners = debug . isAttached ( ) ? Infinity : 0 ;
905- const server = createServer ( listener => {
906- if ( listeners ++ === 0 ) {
907- debug . attach ( ) ;
908- }
909-
910- let closed = false ;
911- const writeMessage = ( message : object ) => {
912- if ( ! closed ) { // in case sendCommand promises settle after closed
913- listener . write ( JSON . stringify ( message ) + '\0' ) ; // null-delimited, CDP-compatible
914- }
915- } ;
916-
917- const onMessage = ( _event : Event , method : string , params : unknown , sessionId ?: string ) =>
918- writeMessage ( ( { method, params, sessionId } ) ) ;
919-
920- codeWindow . win . on ( 'close' , ( ) => {
921- debug . removeListener ( 'message' , onMessage ) ;
922- listener . end ( ) ;
923- closed = true ;
924- } ) ;
925-
926- debug . addListener ( 'message' , onMessage ) ;
927-
928- let buf = Buffer . alloc ( 0 ) ;
929- listener . on ( 'data' , data => {
930- buf = Buffer . concat ( [ buf , data ] ) ;
931- for ( let delimiter = buf . indexOf ( 0 ) ; delimiter !== - 1 ; delimiter = buf . indexOf ( 0 ) ) {
932- let data : { id : number ; sessionId : string ; params : { } } ;
933- try {
934- const contents = buf . slice ( 0 , delimiter ) . toString ( 'utf8' ) ;
935- buf = buf . slice ( delimiter + 1 ) ;
936- data = JSON . parse ( contents ) ;
937- } catch ( e ) {
938- console . error ( 'error reading cdp line' , e ) ;
939- }
940-
941- // depends on a new API for which electron.d.ts has not been updated:
942- // @ts -ignore
943- debug . sendCommand ( data . method , data . params , data . sessionId )
944- . then ( ( result : object ) => writeMessage ( { id : data . id , sessionId : data . sessionId , result } ) )
945- . catch ( ( error : Error ) => writeMessage ( { id : data . id , sessionId : data . sessionId , error : { code : 0 , message : error . message } } ) ) ;
946- }
947- } ) ;
948-
949- listener . on ( 'error' , err => {
950- console . error ( 'error on cdp pipe:' , err ) ;
951- } ) ;
952-
953- listener . on ( 'close' , ( ) => {
954- closed = true ;
955- if ( -- listeners === 0 ) {
956- debug . detach ( ) ;
957- }
958- } ) ;
959- } ) ;
960-
961- await new Promise ( r => server . listen ( 0 , r ) ) ;
962- codeWindow . win . on ( 'close' , ( ) => server . close ( ) ) ;
963-
964- return { rendererDebugPort : ( server . address ( ) as AddressInfo ) . port } ;
965- }
966- }
0 commit comments