@@ -141,27 +141,23 @@ function getServerOptions(config: PhpactorConfig): ServerOptions {
141
141
function getWindowsServerOptions ( config : PhpactorConfig ) : ServerOptions {
142
142
// Find a free port, start PHPActor and connect to it
143
143
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 ) => {
156
145
const childProcess = spawn (
157
146
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
+ ] ,
160
156
{
161
157
env : {
162
158
...process . env ,
163
- XDEBUG_MODE : 'debug' ,
164
- PHPACTOR_ALLOW_XDEBUG : '1' ,
159
+ // XDEBUG_MODE: 'debug',
160
+ // PHPACTOR_ALLOW_XDEBUG: '1',
165
161
} ,
166
162
}
167
163
)
@@ -171,7 +167,11 @@ function getWindowsServerOptions(config: PhpactorConfig): ServerOptions {
171
167
languageClient . outputChannel . appendLine ( str )
172
168
173
169
// 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
+ }
175
175
} )
176
176
childProcess . on ( 'exit' , ( code , signal ) => {
177
177
languageClient . outputChannel . appendLine (
@@ -185,11 +185,11 @@ function getWindowsServerOptions(config: PhpactorConfig): ServerOptions {
185
185
} )
186
186
} )
187
187
188
- await startServer
188
+ const lspPort = await startServer
189
189
190
190
const socket = net . connect ( {
191
191
host : '127.0.0.1' ,
192
- port : freePort ,
192
+ port : lspPort ,
193
193
} )
194
194
195
195
const result = < StreamInfo > {
0 commit comments