You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/todo.md
+157Lines changed: 157 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,133 @@ long-tail polish.
8
8
9
9
---
10
10
11
+
## Composer Environment Detection & Warnings
12
+
13
+
### 37. Warn when composer.json is missing or classmap is not optimized
14
+
15
+
PHPantom relies on Composer artifacts (`vendor/composer/autoload_classmap.php`,
16
+
`autoload_psr4.php`, `autoload_files.php`) for class discovery. When these
17
+
are missing or incomplete, completions silently degrade. The user should be
18
+
told what's wrong and offered help fixing it.
19
+
20
+
#### Detection (during `initialized`)
21
+
22
+
| Condition | Severity | Message |
23
+
|---|---|---|
24
+
| No `composer.json` in workspace root | Warning | "No composer.json found. Class completions will be limited to open files and stubs." |
25
+
26
+
For the no-composer.json case, offer to generate a minimal one via
27
+
`window/showMessageRequest`:
28
+
29
+
1.**"Generate composer.json"** — create a `composer.json` that maps
30
+
the entire project root as a classmap (`"autoload": {"classmap": ["./"]}`).
31
+
Then run `composer dump-autoload -o` to build the classmap. This
32
+
covers legacy projects and single-directory setups that don't follow
33
+
PSR-4 conventions.
34
+
2.**"Dismiss"** — do nothing.
35
+
36
+
|`composer.json` exists but `vendor/` directory is missing | Warning | "No vendor directory found. Run `composer install` to enable full completions." |
37
+
| PSR-4 prefixes exist but no user classes in classmap | Info | "Composer classmap does not contain your project classes. Run `composer dump-autoload -o` for full class completions." |
38
+
39
+
The third condition needs care. The classmap is rarely empty because
40
+
vendor packages like PHPUnit use `classmap` autoloading (not PSR-4), so
41
+
there will be vendor entries even without `-o`. The real signal is:
42
+
the project's `composer.json` declares PSR-4 prefixes (e.g. `App\`,
43
+
`Tests\`), but none of the classmap FQNs start with any of those
44
+
project prefixes. This means the user's own classes were not dumped
45
+
into the classmap, which is exactly what `-o` fixes.
46
+
47
+
Detection logic:
48
+
1. Collect non-vendor PSR-4 prefixes from `psr4_mappings` (already
49
+
tagged with `is_vendor`).
50
+
2. After loading the classmap, check whether any classmap FQN starts
51
+
with one of those prefixes.
52
+
3. If there are project PSR-4 prefixes but zero matching classmap
53
+
entries, the autoloader is not optimized.
54
+
55
+
#### Actions (via `window/showMessageRequest`)
56
+
57
+
For the non-optimized classmap case, offer action buttons:
58
+
59
+
1.**"Run composer dump-autoload -o"** — spawn the command in the
60
+
workspace root, reload the classmap on success, show a progress
61
+
notification.
62
+
2.**"Add to composer.json & run"** — add
63
+
`"config": {"optimize-autoloader": true}` to `composer.json` so
64
+
future `composer install` / `composer update` always produce an
65
+
optimized classmap, then run `composer dump-autoload`.
66
+
3.**"Dismiss"** — do nothing.
67
+
68
+
#### UX guidelines
69
+
70
+
- The no-composer.json and no-vendor warnings are safe to show via
71
+
`window/showMessage` (informational, no action taken).
72
+
- The classmap warning should use `window/showMessageRequest` with
73
+
action buttons so the user explicitly opts in before we touch files
74
+
or run commands.
75
+
- Only show once per session. Do not re-trigger on every `didOpen`.
76
+
- Never modify `composer.json` or run commands without explicit user
77
+
confirmation via an action button.
78
+
- If the spawned `composer` command fails (e.g. PHP not installed
79
+
locally, Docker-only setup), catch the error gracefully and show
80
+
"Composer command failed. You may need to run it manually."
81
+
- Log the detection result to the output panel regardless (already done
82
+
for the "Loaded N classmap entries" message, just add context when
83
+
zero user classes are found).
84
+
85
+
---
86
+
87
+
### 38. File system watching for vendor and project changes
0 commit comments