diff --git a/.vscode/launch.json b/.vscode/launch.json index 93a320a..ae78d2f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,8 @@ "runtimeExecutable": "${execPath}", "args": ["--extensionDevelopmentPath=${workspaceFolder}", "--Xdisable-extensions"], "outFiles": ["${workspaceFolder}/out/**/*.js"], - "sourceMaps": true + "sourceMaps": true, + "preLaunchTask": "npm: watch" }, { "name": "Listen for Xdebug", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0bf8020..9f03553 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,9 +8,10 @@ "kind": "build", "isDefault": true }, - "problemMatcher": [], + "problemMatcher": ["$tsc-watch"], "label": "npm: watch", - "detail": "tsc -watch -p ./" + "detail": "tsc -watch -p ./", + "isBackground": true }, { "type": "npm", diff --git a/CHANGELOG.md b/CHANGELOG.md index bfdb5de..5ad0246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## [1.7.2] - 2025-04-20 + +- Improve phpactor start on Windows +- Do not allow phpactor to run with Xdebug + ## [1.7.1] - 2025-04-17 - Bundle phpactor [2025.04.17.0](https://github.com/phpactor/phpactor/releases/tag/2025.04.17.0) to fix broken installation diff --git a/src/extension.ts b/src/extension.ts index 8609c4f..f1bfac0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -141,27 +141,23 @@ function getServerOptions(config: PhpactorConfig): ServerOptions { function getWindowsServerOptions(config: PhpactorConfig): ServerOptions { // Find a free port, start PHPActor and connect to it const serverOptions = async () => { - const findPort = new Promise(resolve => { - const server = net.createServer() - server.listen(0, '127.0.0.1', () => { - const freePort = (server.address()! as net.AddressInfo).port - server.close() - resolve(freePort) - }) - }) - - const freePort = await findPort - - const startServer = new Promise((resolve, reject) => { + const startServer = new Promise((resolve, reject) => { const childProcess = spawn( config.executablePath, - [config.path, 'language-server', `--address=127.0.0.1:${freePort}`, ...config.launchServerArgs], - + [ + config.path, + 'language-server', + '--address=127.0.0.1:0', + '--no-ansi', + '-n', + '-v', + ...config.launchServerArgs, + ], { env: { ...process.env, - XDEBUG_MODE: 'debug', - PHPACTOR_ALLOW_XDEBUG: '1', + // XDEBUG_MODE: 'debug', + // PHPACTOR_ALLOW_XDEBUG: '1', }, } ) @@ -171,7 +167,11 @@ function getWindowsServerOptions(config: PhpactorConfig): ServerOptions { languageClient.outputChannel.appendLine(str) // when we get the first line, the server is running - resolve() + const match = str.match(/Listening on 127\.0\.0\.1:(\d+)\n/) + if (match) { + const port = parseInt(match[1], 10) + resolve(port) + } }) childProcess.on('exit', (code, signal) => { languageClient.outputChannel.appendLine( @@ -185,11 +185,11 @@ function getWindowsServerOptions(config: PhpactorConfig): ServerOptions { }) }) - await startServer + const lspPort = await startServer const socket = net.connect({ host: '127.0.0.1', - port: freePort, + port: lspPort, }) const result = {