PHP Formatting Not Working
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
I've asked for help in other PHP related issues and code formatting issues I'm creating this specific because the language_server works with most files but it's not working with PHP since ZED moved PHP to an extension. But only the format on save is not working.... I had to move back to VSCODE because it stopped working and I have no idea why. Anybody?
Opening Zed, saving a PHP file... I get this in my LOG
2024-04-23T18:15:50+00:00 [INFO] ========== starting zed ==========
2024-04-23T18:15:50+00:00 [INFO] Opening main db
2024-04-23T18:15:50+00:00 [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git")
2024-04-23T18:15:50+00:00 [INFO] extensions updated. loading 3, reloading 0, unloading 0
2024-04-23T18:15:50+00:00 [ERROR] crates/zed/src/zed.rs:628: EOF while parsing a value at line 1 column 0
2024-04-23T18:15:50+00:00 [INFO] Opening main db
2024-04-23T18:15:51+00:00 [INFO] set status on client 0: Authenticating
2024-04-23T18:15:51+00:00 [INFO] set status on client 98447: Connecting
2024-04-23T18:15:51+00:00 [INFO] building git repository, .git path in the worktree: ".git"
2024-04-23T18:15:51+00:00 [INFO] Opening main db
2024-04-23T18:15:51+00:00 [INFO] Opening main db
2024-04-23T18:15:51+00:00 [INFO] set environment variables from shell:/bin/zsh, path:/Users/xcrap/.bun/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/curl/bin:/Users/xcrap/Library/Application Support/Herd/bin/:/Users/xcrap/miniconda3/bin:/Users/xcrap/miniconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/xcrap/.nvm/versions/node/v20.10.0/bin:/Applications/MAMP/bin/php/php8.2.4/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin://Applications/Topaz Photo AI.app/Contents/Resources/bin:/Users/xcrap/Library/Application Support/JetBrains/Toolbox/scripts
2024-04-23T18:15:51+00:00 [INFO] starting language server "tailwindcss-language-server", path: "/Users/xcrap/htdocs/hotelgaivota", id: 1
2024-04-23T18:15:51+00:00 [INFO] starting language server "intelephense", path: "/Users/xcrap/htdocs/hotelgaivota", id: 2
2024-04-23T18:15:51+00:00 [INFO] fetching latest version of language server "tailwindcss-language-server"
2024-04-23T18:15:51+00:00 [INFO] Node runtime install_if_needed
2024-04-23T18:15:51+00:00 [INFO] Node runtime install_if_needed
2024-04-23T18:15:51+00:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-04-23T18:15:51+00:00 [INFO] Node runtime install_if_needed
2024-04-23T18:15:52+00:00 [INFO] starting language server. binary path: "/Users/xcrap/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node", working directory: "/", args: ["/Users/xcrap/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-04-23T18:15:52+00:00 [INFO] add connection to peer
2024-04-23T18:15:52+00:00 [INFO] waiting for server hello
2024-04-23T18:15:52+00:00 [INFO] got server hello
2024-04-23T18:15:52+00:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 392, id: 4189661 })
2024-04-23T18:15:52+00:00 [INFO] set status on client 98447: Connected { peer_id: PeerId { owner_id: 392, id: 4189661 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-04-23T18:15:52+00:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
"level": 0,
"message": "[DEBUG] [agent] [2024-04-23T18:15:52.337Z] Agent service starting",
"metadataStr": "[DEBUG] [agent] [2024-04-23T18:15:52.337Z]",
"extra": [
"Agent service starting"
]
}
2024-04-23T18:15:52+00:00 [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
"registrations": [
{
"id": "e963ed01-14bc-4e67-8e49-e8e9395530d4",
"method": "workspace/didChangeWorkspaceFolders",
"registerOptions": {}
}
]
}
2024-04-23T18:15:52+00:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
"level": 0,
"message": "[DEBUG] [agent] [2024-04-23T18:15:52.867Z] Telemetry initialized",
"metadataStr": "[DEBUG] [agent] [2024-04-23T18:15:52.867Z]",
"extra": [
"Telemetry initialized"
]
}
2024-04-23T18:15:52+00:00 [INFO] Node runtime install_if_needed
2024-04-23T18:15:53+00:00 [INFO] starting language server. binary path: "/Users/xcrap/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node", working directory: "/Users/xcrap/htdocs/hotelgaivota", args: ["/Users/xcrap/Library/Application Support/Zed/extensions/work/php/node_modules/intelephense/lib/intelephense.js", "--stdio"]
2024-04-23T18:15:53+00:00 [INFO] Language server with id 2 sent unhandled notification window/logMessage:
{
"type": 3,
"message": "Initialising intelephense 1.10.4"
}
2024-04-23T18:15:53+00:00 [INFO] Language server with id 2 sent unhandled notification window/logMessage:
{
"type": 3,
"message": "Reading state from /var/folders/0j/629mw8tj5y7dkm056_1pthq40000gn/T/intelephense/44936fb5."
}
2024-04-23T18:15:53+00:00 [INFO] Language server with id 2 sent unhandled notification window/logMessage:
{
"type": 3,
"message": "Initialised in 78 ms"
}
2024-04-23T18:15:53+00:00 [INFO] downloading language server "tailwindcss-language-server"
2024-04-23T18:15:53+00:00 [INFO] Node runtime install_if_needed
2024-04-23T18:15:53+00:00 [INFO] Language server with id 2 sent unhandled notification indexingStarted:
[
null
]
2024-04-23T18:15:53+00:00 [INFO] starting language server. binary path: "/Users/xcrap/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node", working directory: "/Users/xcrap/htdocs/hotelgaivota", args: ["/Users/xcrap/Library/Application Support/Zed/languages/tailwindcss-language-server/node_modules/.bin/tailwindcss-language-server", "--stdio"]
2024-04-23T18:15:53+00:00 [INFO] Language server with id 2 sent unhandled notification indexingEnded:
[
null
]
2024-04-23T18:15:54+00:00 [INFO] Language server with id 1 sent unhandled notification @/tailwindCSS/projectInitialized:
[
null
]
Environment
Zed: v0.131.7 (Zed) OS: macOS 14.4.1 Memory: 16 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
No response
@xcrap Does formatting manually with editor: format work (and only doesn't work with format_on_save)?
Or is formatting broken for both editor: format and format_on_save?
@xcrap Does formatting manually with
editor: formatwork (and only doesn't work withformat_on_save)?Or is formatting broken for both
editor: formatandformat_on_save?
Both fails, also editor:format fails and with the same errors in the log. Any kind of formatting fails.
Also I closed all projects and try to edit a php from a clean folder for testing, why the hell he's downloading tailwindcss-language-server when there's no tailwind project o.O
Additional log errors...
2024-04-24T12:03:58+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:03:58+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:03:58+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:03:58+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:03:58+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:03:58+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:04+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:05+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:06+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:06+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:06+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:06+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:34+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition 2024-04-24T12:04:35+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition
@xcrap A fix for this will be going out in the Preview build later today: https://github.com/zed-industries/zed/pull/10939
So I've installed the nightly build and the formatter worked for PHP, but I had to specific in my settings:
"PHP": { "language_servers": [ "intelephense" ] }
I wonder what's the default and if the default language_server for php, I mean that should work without specify or ?
So I've installed the nightly build and the formatter worked for PHP, but I had to specific in my settings:
"PHP": { "language_servers": [ "intelephense" ] }
I wonder what's the default and if the default language_server for php, I mean that should work without specify or ?
Hmm, you shouldn't have to specify the language server.
The default is ["..."] which just means "any language server registered for the current language".
The bug that was fixed in https://github.com/zed-industries/zed/pull/10939 was that the order of those language servers changed after PHP was moved to an extension, which meant that the Tailwind language server would receive the formatting request.
If you remove that language_servers setting for PHP and then open a .php file, do you see any logs that say "starting language servers for PHP: ..."? That should show which language servers are being used, and in which order.
If I remove the language_servers I get this:
2024-04-25T18:17:03+00:00 [ERROR] Have not found plugin path for "@prettier/plugin-php" inside "/Users/xcrap/node_modules"
2024-04-25T18:17:03+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
2024-04-25T18:17:03+00:00 [INFO] starting language servers for JSON: json-language-server
2024-04-25T18:17:04+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
2024-04-25T18:17:04+00:00 [INFO] starting language servers for JSON: json-language-server
2024-04-25T18:17:07+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
2024-04-25T18:17:07+00:00 [INFO] starting language servers for JSON: json-language-server
2024-04-25T18:17:08+00:00 [ERROR] unexpected item event after pane was dropped
2024-04-25T18:17:08+00:00 [ERROR] crates/lsp/src/lsp.rs:768: oneshot canceled
2024-04-25T18:17:08+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
2024-04-25T18:17:08+00:00 [ERROR] crates/lsp/src/lsp.rs:768: oneshot canceled
2024-04-25T18:17:10+00:00 [ERROR] unexpected item event after pane was dropped
2024-04-25T18:17:11+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition
2024-04-25T18:17:11+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition
2024-04-25T18:17:11+00:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition
2024-04-25T18:17:16+00:00 [ERROR] crates/lsp/src/lsp.rs:768: oneshot canceled
2024-04-25T18:17:16+00:00 [ERROR] crates/lsp/src/lsp.rs:768: oneshot canceled
2024-04-25T18:17:16+00:00 [ERROR] crates/lsp/src/lsp.rs:768: oneshot canceled
2024-04-25T18:17:21+00:00 [INFO] ========== starting zed ==========
2024-04-25T18:17:21+00:00 [INFO] Opening main db
2024-04-25T18:17:21+00:00 [INFO] Using git binary path: Some("/Applications/Zed Preview.app/Contents/MacOS/git")
2024-04-25T18:17:21+00:00 [INFO] extensions updated. loading 4, reloading 0, unloading 0
2024-04-25T18:17:21+00:00 [ERROR] crates/zed/src/zed.rs:660: EOF while parsing a value at line 1 column 0
2024-04-25T18:17:21+00:00 [INFO] Opening main db
2024-04-25T18:17:21+00:00 [INFO] set status on client 0: Authenticating
2024-04-25T18:17:21+00:00 [INFO] set status on client 98447: Connecting
2024-04-25T18:17:21+00:00 [INFO] building git repository, .git path in the worktree: ".git"
2024-04-25T18:17:21+00:00 [INFO] set environment variables from shell:/bin/zsh, path:/Users/xcrap/.bun/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/curl/bin:/Users/xcrap/Library/Application Support/Herd/bin/:/Users/xcrap/miniconda3/bin:/Users/xcrap/miniconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/xcrap/.nvm/versions/node/v20.10.0/bin:/Applications/MAMP/bin/php/php8.2.4/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin://Applications/Topaz Photo AI.app/Contents/Resources/bin:/Users/xcrap/Library/Application Support/JetBrains/Toolbox/scripts
2024-04-25T18:17:21+00:00 [INFO] Opening main db
2024-04-25T18:17:21+00:00 [INFO] Node runtime install_if_needed
2024-04-25T18:17:21+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
2024-04-25T18:17:21+00:00 [INFO] starting language server "tailwindcss-language-server", path: "/Users/xcrap/htdocs/hotelgaivota", id: 1
2024-04-25T18:17:21+00:00 [INFO] starting language server "emmet-language-server", path: "/Users/xcrap/htdocs/hotelgaivota", id: 2
2024-04-25T18:17:21+00:00 [INFO] starting language server "intelephense", path: "/Users/xcrap/htdocs/hotelgaivota", id: 3
2024-04-25T18:17:21+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
2024-04-25T18:17:21+00:00 [INFO] fetching latest version of language server "tailwindcss-language-server"
2024-04-25T18:17:21+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
2024-04-25T18:17:22+00:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-04-25T18:17:22+00:00 [INFO] starting language server. binary path: "/Users/xcrap/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node", working directory: "/", args: ["/Users/xcrap/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-04-25T18:17:22+00:00 [INFO] Node runtime install_if_needed
2024-04-25T18:17:22+00:00 [INFO] Node runtime install_if_needed
2024-04-25T18:17:22+00:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
"level": 0,
"message": "[DEBUG] [agent] [2024-04-25T18:17:22.337Z] Agent service starting",
"metadataStr": "[DEBUG] [agent] [2024-04-25T18:17:22.337Z]",
"extra": [
"Agent service starting"
]
}
2024-04-25T18:17:22+00:00 [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
"registrations": [
{
"id": "b0797c75-6062-4f15-a30a-29cedb70bbaf",
"method": "workspace/didChangeWorkspaceFolders",
"registerOptions": {}
}
]
}
2024-04-25T18:17:22+00:00 [INFO] Node runtime install_if_needed
2024-04-25T18:17:22+00:00 [INFO] add connection to peer
2024-04-25T18:17:22+00:00 [INFO] add_connection;
2024-04-25T18:17:22+00:00 [INFO] waiting for server hello
2024-04-25T18:17:22+00:00 [INFO] got server hello
2024-04-25T18:17:22+00:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 395, id: 914011 })
2024-04-25T18:17:22+00:00 [INFO] set status on client 98447: Connected { peer_id: PeerId { owner_id: 395, id: 914011 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-04-25T18:17:22+00:00 [INFO] downloading language server "tailwindcss-language-server"
2024-04-25T18:17:22+00:00 [INFO] Node runtime install_if_needed
2024-04-25T18:17:22+00:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
"level": 0,
"message": "[DEBUG] [agent] [2024-04-25T18:17:22.888Z] Telemetry initialized",
"metadataStr": "[DEBUG] [agent] [2024-04-25T18:17:22.888Z]",
"extra": [
"Telemetry initialized"
]
}
2024-04-25T18:17:23+00:00 [INFO] starting language server. binary path: "/Users/xcrap/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node", working directory: "/Users/xcrap/htdocs/hotelgaivota", args: ["/Users/xcrap/Library/Application Support/Zed/languages/tailwindcss-language-server/node_modules/.bin/tailwindcss-language-server", "--stdio"]
2024-04-25T18:17:23+00:00 [INFO] Node runtime install_if_needed
2024-04-25T18:17:23+00:00 [INFO] starting language server. binary path: "/Users/xcrap/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node", working directory: "/Users/xcrap/htdocs/hotelgaivota", args: ["/Users/xcrap/Library/Application Support/Zed/extensions/work/emmet/node_modules/.bin/emmet-language-server", "--stdio"]
2024-04-25T18:17:23+00:00 [INFO] Node runtime install_if_needed
2024-04-25T18:17:23+00:00 [INFO] starting language server. binary path: "/Users/xcrap/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node", working directory: "/Users/xcrap/htdocs/hotelgaivota", args: ["/Users/xcrap/Library/Application Support/Zed/extensions/work/php/node_modules/intelephense/lib/intelephense.js", "--stdio"]
2024-04-25T18:17:24+00:00 [INFO] Language server with id 1 sent unhandled notification @/tailwindCSS/projectInitialized:
[
null
]
2024-04-25T18:17:24+00:00 [INFO] Language server with id 3 sent unhandled notification window/logMessage:
{
"type": 3,
"message": "Initialising intelephense 1.10.4"
}
2024-04-25T18:17:24+00:00 [INFO] Language server with id 3 sent unhandled notification window/logMessage:
{
"type": 3,
"message": "Reading state from /var/folders/0j/629mw8tj5y7dkm056_1pthq40000gn/T/intelephense/44936fb5."
}
2024-04-25T18:17:24+00:00 [INFO] Language server with id 3 sent unhandled notification window/logMessage:
{
"type": 3,
"message": "Initialised in 82 ms"
}
2024-04-25T18:17:24+00:00 [INFO] Language server with id 3 sent unhandled notification indexingStarted:
[
null
]
2024-04-25T18:17:24+00:00 [INFO] Language server with id 3 sent unhandled notification indexingEnded:
[
null
]
So the order is clearly not the best.
Also If I remove ""formatter": "language_server", (I believe it uses auto) it's even worse it tries to use prettier.
My point is that the PHP formatter should work out of the box without any specific option, which it did before the extensions, now it does not at least for me.
I can see here that Intelephense is indeed being loaded last.
2024-04-25T18:17:21+00:00 [INFO] starting language servers for PHP: tailwindcss-language-server, emmet-language-server, intelephense
Although I forgot that the fix made in https://github.com/zed-industries/zed/pull/10939 doesn't rely on the order listed there.
However, it does look like you have Emmet installed, which is being put before Intelephense.
Could you try uninstalling the Emmet extension to see if that fixes the issue?
If that does indeed fix the issue, then continuing to use this setting would be my recommendation to work around the problem, for now:
"languages": {
"PHP": {
"language_servers": ["intelephense", "..."]
}
}
Yes I can confirm that uninstalling emmet did solved the issue.
I'll have emmet uninstalled until you guys figure this out. Also keep in mind that if I remove "formatter": "language_server", everything stops working also.
Thanks for the quick answers.
Yes I can confirm that uninstalling emmet did solved the issue.
Same here. If I uninstall emmet and reinstall it the PHP formatting works fine.