composer.json discovery fails in VS Code remote
まだ誰も着手していません。
評価
調査の方向性
issueで参照されているcomposer.jsonの検索箇所をsrc/options.mjsから確認し、次に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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
prettier/plugin-php のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
prettier/plugin-php#2416 · コメント 2 件 · リアクション 6 件 ·
-
難易度 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 件 ·
-
strange format issue オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
prettier/plugin-php#2490 ·
prettier/plugin-php の issue をすべて見る
似ている issue
-
jira-created
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
nunomaduro/phpinsights#745 ·
-
status/awaiting_triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
WordPress/plugin-check#1486 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
az-digital/az_quickstart#6019 ·