prettier / prettier/plugin-php
composer.json discovery fails in VS Code remote
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- PHP
- Estrellas
- 1.9k
- Forks
- 139
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
In my (admittedly specific) use case the plugin is unable to find composer.json, which is plainly present in the root of the workspace.
Environment
Running VS Code with a devcontainer in Rancher Desktop. Prettier plugin is running inside the container.
prettier and @prettier/plugin-php are installed locally inside node_modules and the VS Code plugin uses the local installation.
Settings:
"phpVersion": "composer"
Filesystem layout:
- /workspaces/myproject/
- composer.json
- .prettierrc
- node_modules/
- src/
- a.php
Result
When run on src/a.php through VS Code, the plugin fails.
["ERROR" - 9:22:26 AM] Error formatting document.
["ERROR" - 9:22:26 AM] Could not determine PHP version from composer; Could not find composer.json
Error: Could not determine PHP version from composer; Could not find composer.json
at resolvePhpVersion (file:///workspaces/myproject/node_modules/@prettier/plugin-php/src/options.mjs:95:13)
at Object.parse (file:///workspaces/myproject/node_modules/@prettier/plugin-php/src/parser.mjs:11:3)
at parse5 (file:///workspaces/myproject/node_modules/prettier/index.mjs:16731:24)
at async coreFormat (file:///workspaces/myproject/node_modules/prettier/index.mjs:17287:25)
at async formatWithCursor (file:///workspaces/myproject/node_modules/prettier/index.mjs:17504:14)
at async Module.format2 (file:///workspaces/myproject/node_modules/prettier/index.mjs:19051:25)
When doing the same thing through the CLI, not the VS Code plugin, everything works as expected.
Cause
A little bit of digging turns up the root cause here: https://github.com/prettier/plugin-php/blob/0c883a49850281077218007322f6149f853b2015/src/options.mjs#L23
In my environment, prettier is run in this directory: /vscode/vscode-server/bin/linux-x64/360a4e4fd251bfce169a4ddf857c7d25d1ad40da
The recursive search for composer.json upwards from process.cwd() fails.
I don't feel qualified to suggest a solution but maybe search from the target file's location upwards, instead of the process' working dir?
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza por src/options.mjs, en la búsqueda de composer.json a la que se hace referencia en el issue, y luego sigue cómo src/parser.mjs pasa el contexto del archivo PHP. Reproduce la diferencia entre el entorno remoto de la CLI y el de VS Code, y verifica que formatear src/a.php pueda descubrir el composer.json de la raíz del workspace, preservando el comportamiento existente de la CLI.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- php, vscode
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 52/100