@@ -141,27 +141,23 @@ function getServerOptions(config: PhpactorConfig): ServerOptions {
141141function getWindowsServerOptions ( config : PhpactorConfig ) : ServerOptions {
142142 // Find a free port, start PHPActor and connect to it
143143 const serverOptions = async ( ) => {
144- const findPort = new Promise < number > ( resolve => {
145- const server = net . createServer ( )
146- server . listen ( 0 , '127.0.0.1' , ( ) => {
147- const freePort = ( server . address ( ) ! as net . AddressInfo ) . port
148- server . close ( )
149- resolve ( freePort )
150- } )
151- } )
152-
153- const freePort = await findPort
154-
155- const startServer = new Promise < void > ( ( resolve , reject ) => {
144+ const startServer = new Promise < number > ( ( resolve , reject ) => {
156145 const childProcess = spawn (
157146 config . executablePath ,
158- [ config . path , 'language-server' , `--address=127.0.0.1:${ freePort } ` , ...config . launchServerArgs ] ,
159-
147+ [
148+ config . path ,
149+ 'language-server' ,
150+ '--address=127.0.0.1:0' ,
151+ '--no-ansi' ,
152+ '-n' ,
153+ '-v' ,
154+ ...config . launchServerArgs ,
155+ ] ,
160156 {
161157 env : {
162158 ...process . env ,
163- XDEBUG_MODE : 'debug' ,
164- PHPACTOR_ALLOW_XDEBUG : '1' ,
159+ // XDEBUG_MODE: 'debug',
160+ // PHPACTOR_ALLOW_XDEBUG: '1',
165161 } ,
166162 }
167163 )
@@ -171,7 +167,11 @@ function getWindowsServerOptions(config: PhpactorConfig): ServerOptions {
171167 languageClient . outputChannel . appendLine ( str )
172168
173169 // when we get the first line, the server is running
174- resolve ( )
170+ const match = str . match ( / L i s t e n i n g o n 1 2 7 \. 0 \. 0 \. 1 : ( \d + ) \n / )
171+ if ( match ) {
172+ const port = parseInt ( match [ 1 ] , 10 )
173+ resolve ( port )
174+ }
175175 } )
176176 childProcess . on ( 'exit' , ( code , signal ) => {
177177 languageClient . outputChannel . appendLine (
@@ -185,11 +185,11 @@ function getWindowsServerOptions(config: PhpactorConfig): ServerOptions {
185185 } )
186186 } )
187187
188- await startServer
188+ const lspPort = await startServer
189189
190190 const socket = net . connect ( {
191191 host : '127.0.0.1' ,
192- port : freePort ,
192+ port : lspPort ,
193193 } )
194194
195195 const result = < StreamInfo > {
0 commit comments