Skip to content

Commit 162a7e9

Browse files
authored
fix: Improve Windows startup (#196)
* Run phpactor with verbose output to find TCP port. Remove PHPACTOR_ALLOW_XDEBUG * Improve vscode debug/build setup. * Changelog
1 parent 7434488 commit 162a7e9

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

.vscode/launch.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"runtimeExecutable": "${execPath}",
1212
"args": ["--extensionDevelopmentPath=${workspaceFolder}", "--Xdisable-extensions"],
1313
"outFiles": ["${workspaceFolder}/out/**/*.js"],
14-
"sourceMaps": true
14+
"sourceMaps": true,
15+
"preLaunchTask": "npm: watch"
1516
},
1617
{
1718
"name": "Listen for Xdebug",

.vscode/tasks.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"kind": "build",
99
"isDefault": true
1010
},
11-
"problemMatcher": [],
11+
"problemMatcher": ["$tsc-watch"],
1212
"label": "npm: watch",
13-
"detail": "tsc -watch -p ./"
13+
"detail": "tsc -watch -p ./",
14+
"isBackground": true
1415
},
1516
{
1617
"type": "npm",

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## [1.7.2] - 2025-04-20
4+
5+
- Improve phpactor start on Windows
6+
- Do not allow phpactor to run with Xdebug
7+
38
## [1.7.1] - 2025-04-17
49

510
- Bundle phpactor [2025.04.17.0](https://github.com/phpactor/phpactor/releases/tag/2025.04.17.0) to fix broken installation

src/extension.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,23 @@ function getServerOptions(config: PhpactorConfig): ServerOptions {
141141
function 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(/Listening on 127\.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

Comments
 (0)