composer.json discovery fails in VS Code remote
还没有人认领这个 Issue。
评估
调研方向
从 src/options.mjs 中 issue 所引用的 composer.json 搜索开始,然后追踪 src/parser.mjs 如何传递 PHP 文件上下文。复现 CLI 与 VS Code 远程环境之间的差异,并验证格式化 src/a.php 时能够发现 workspace 根目录中的 composer.json,同时保持现有的 CLI 行为不变。
由索引模型根据 Issue 内容生成。
描述
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?
- 主要语言
- PHP
- 星标
- 1.9k
- 派生
- 139
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
prettier/plugin-php 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 62/100
prettier/plugin-php#2416 · 2 条评论 · 6 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 64/100
prettier/plugin-php#2498 ·
-
难度 4/5 3-5 天 新手友好度 55/100
prettier/plugin-php#2495 ·
-
难度 3/5 1-2 天 新手友好度 55/100
prettier/plugin-php#2494 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 48/100
prettier/plugin-php#2490 ·
查看 prettier/plugin-php 的全部 Issue
相似的 Issue
-
Solved site promotion gate fails on runner PHP patch drift (expects 8.2.33, runner installs 8.2.34) 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
Automattic/blocks-engine#2161 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
Automattic/static-site-importer#1824 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
0. Needs triage bug
难度 2/5 1-3 小时 新手友好度 75/100
-
0. Needs triage 35-feedback bug
难度 2/5 1-3 小时 新手友好度 75/100