Skip to content

fix: Improve Windows startup #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 19 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(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<void>((resolve, reject) => {
const startServer = new Promise<number>((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',
},
}
)
Expand All @@ -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(
Expand All @@ -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 = <StreamInfo>{
Expand Down