OpenCode can start Symfony Language Tools as a custom language server and make Symfony-aware diagnostics and navigation available to its coding agent. Install the standalone server, then configure it in the Symfony project.
Use the standalone guide to download a release and make symfony-lsp
available on PATH.
The OpenCode integration is supported on Linux and macOS.
For a project whose code you trust, create opencode.json in the project
root:
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"symfony": {
"command": ["symfony-lsp"],
"extensions": [
".php",
".twig",
".yaml",
".yml",
".xml",
".json",
".js",
".mjs",
".ts",
".env",
".env.local"
],
"initialization": {
"workspaceTrust": true
}
}
}
}Use an absolute executable path in command when symfony-lsp isn't on
PATH. OpenCode starts the server when it accesses a file matching one of
the configured extensions. Add other project-specific dotenv suffixes, such as
.env.dev, when the agent needs to initiate requests from those files.
Keep OpenCode's general PHP language server enabled. Symfony Language Tools adds Symfony-specific information alongside it.
OpenCode doesn't display the interactive workspace trust request sent by the
language server, so configure workspaceTrust explicitly. Set it to true
only after reviewing and trusting the project because runtime indexing executes
application code.
Set workspaceTrust to false to keep the project in static-only mode.
Source-based navigation and diagnostics remain available, but features that
need information from the running application are unavailable.
OpenCode can consume Symfony-aware diagnostics and use hover, go-to-definition and find-references requests while its agent works on PHP, Twig, configuration and frontend files.
Changes made with OpenCode are picked up without restarting it. Files changed outside OpenCode are refreshed the next time OpenCode accesses them.
Put shared settings in .symfony-lsp.json; see the project configuration.
Use the initialization object for trust, tracing or an OpenCode-only
override:
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"symfony": {
"command": ["symfony-lsp"],
"extensions": [".php", ".twig", ".yaml", ".yml", ".xml"],
"initialization": {
"workspaceTrust": true,
"environment": "test",
"trace": "off"
},
"env": {
"SYMFONY_LSP_MEMORY_LIMIT": "4G"
}
}
}
}Use the same setting names as .symfony-lsp.json for OpenCode-only
overrides. See Docker support when the PHP command runs in a container. The
env object configures environment variables for the server process.
Inspect the resolved OpenCode configuration first:
$ opencode debug config
Confirm that OpenCode can start the server and receive diagnostics for a file:
$ opencode debug lsp diagnostics src/Controller/HomeController.php
If runtime information is unavailable, verify that the project has Composer
dependencies installed, workspaceTrust is true and phpCommand can
run the application. Set trace to messages or verbose temporarily
for redacted protocol logging, then restore it to off.
See the OpenCode LSP documentation for its custom language server settings and debugging commands.