|
2 | 2 |
|
3 | 3 | This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
4 | 4 |
|
5 | | -## Project Overview |
| 5 | +### Project Overview |
6 | 6 |
|
7 | | -This is an IntelliJ IDEA/PhpStorm plugin that provides PHP annotation and PHP 8 Attribute support. The plugin extends the IDE to recognize annotation classes marked with `@Annotation`, provides code completion, navigation, inspections, and integrates with Doctrine ORM and Symfony frameworks. |
8 | | - |
9 | | -**Plugin ID**: `de.espend.idea.php.annotation` |
10 | | - |
11 | | -## Build Commands |
12 | | - |
13 | | -### Build the plugin |
14 | | -```bash |
15 | | -./gradlew buildPlugin |
16 | | -``` |
17 | | -The plugin ZIP will be in `build/distributions/`. |
18 | | - |
19 | | -### Run tests |
20 | | -```bash |
21 | | -./gradlew test |
22 | | -``` |
23 | | - |
24 | | -### Run a single test class |
25 | | -```bash |
26 | | -./gradlew test --tests "de.espend.idea.php.annotation.tests.AnnotationStubIndexTest" |
27 | | -``` |
28 | | - |
29 | | -### Run a single test method |
30 | | -```bash |
31 | | -./gradlew test --tests "de.espend.idea.php.annotation.tests.AnnotationStubIndexTest.testThatAnnotationClassIsInIndex" |
32 | | -``` |
33 | | - |
34 | | -### Run the plugin in a test IDE instance |
35 | | -```bash |
36 | | -./gradlew runIde |
37 | | -``` |
38 | | - |
39 | | -### Verify plugin compatibility |
40 | | -```bash |
41 | | -./gradlew verifyPlugin |
42 | | -``` |
43 | | - |
44 | | -### Clean build |
45 | | -```bash |
46 | | -./gradlew clean buildPlugin |
47 | | -``` |
48 | | - |
49 | | -## Architecture |
50 | | - |
51 | | -### Extension Point System |
52 | | - |
53 | | -The plugin's core architecture is based on extension points that allow both internal components and external plugins (like Symfony Support or PHP Toolbox) to extend functionality. |
54 | | - |
55 | | -**Key extension point interfaces** (in `src/main/java/de/espend/idea/php/annotation/extension/`): |
56 | | - |
57 | | -- **PhpAnnotationCompletionProvider**: Provides code completion for annotation property values |
58 | | -- **PhpAnnotationReferenceProvider**: Provides references and navigation for annotation elements |
59 | | -- **PhpAnnotationDocTagGotoHandler**: Handles "Go to Declaration" for annotation tags |
60 | | -- **PhpAnnotationDocTagAnnotator**: Provides custom highlighting/error annotations for doc tags |
61 | | -- **PhpAnnotationGlobalNamespacesLoader**: Loads global annotation namespace mappings |
62 | | -- **PhpAnnotationVirtualProperties**: Provides virtual properties for annotation classes |
63 | | -- **PhpAnnotationUseAlias**: Maps custom class aliases (e.g., "ORM" => "Doctrine\\ORM\\Mapping") |
64 | | - |
65 | | -Extension points are registered in `src/main/resources/META-INF/plugin.xml` and can be used by other plugins. |
66 | | - |
67 | | -### Indexing System |
68 | | - |
69 | | -The plugin uses two main file-based indices for fast lookup: |
70 | | - |
71 | | -- **AnnotationStubIndex**: Indexes all PHP classes marked with `@Annotation` in their doc block |
72 | | -- **AnnotationUsageIndex**: Indexes where annotations are used in the codebase |
73 | | - |
74 | | -These indices power the navigation features (find usages, line markers) and are updated automatically when files change. |
75 | | - |
76 | | -### Module Organization |
77 | | - |
78 | | -- **annotator/**: Provides inline error highlighting and warnings |
79 | | -- **completion/**: Code completion contributors and providers |
80 | | -- **dict/**: Data transfer objects and dictionary classes |
81 | | -- **doctrine/**: Doctrine ORM-specific features (property generators, repository class handling, column type support) |
82 | | -- **extension/**: Extension point interfaces and parameters |
83 | | -- **inspection/**: Code inspections (missing imports, deprecated usage, etc.) |
84 | | -- **navigation/**: Navigation handlers and line marker providers |
85 | | -- **pattern/**: PSI pattern matching for identifying annotation contexts |
86 | | -- **reference/**: Reference contributors for navigation and "Find Usages" |
87 | | -- **symfony/**: Symfony-specific annotation support |
88 | | -- **toolbox/**: PHP Toolbox integration |
89 | | -- **ui/**: Settings forms and configuration UI |
90 | | -- **util/**: Utility classes, particularly `AnnotationUtil` which contains core logic for annotation detection and processing |
91 | | - |
92 | | -### Dual Support: DocBlock Annotations and PHP 8 Attributes |
93 | | - |
94 | | -The plugin supports both: |
95 | | -- **DocBlock annotations**: `/** @Route("/path") */` |
96 | | -- **PHP 8 Attributes**: `#[Route('/path')]` |
97 | | - |
98 | | -Extension points work transparently with both formats, allowing feature implementations to support both simultaneously. |
99 | | - |
100 | | -## Key Concepts |
101 | | - |
102 | | -### Annotation Detection |
103 | | - |
104 | | -Classes are recognized as annotation classes if they have `@Annotation` in their doc block: |
105 | | -```php |
106 | | -/** |
107 | | - * @Annotation |
108 | | - * @Target("METHOD", "CLASS") |
109 | | - */ |
110 | | -class Route { |
111 | | - public $path; |
112 | | -} |
113 | | -``` |
114 | | - |
115 | | -### Target Filtering |
116 | | - |
117 | | -The `@Target` annotation restricts where annotations can be used (METHOD, CLASS, PROPERTY, ALL). The plugin uses this for completion filtering. |
118 | | - |
119 | | -### Property Type Detection |
120 | | - |
121 | | -Annotation properties support type hints via doc comments: |
122 | | -- Simple types: `@var string`, `@var bool` |
123 | | -- Arrays: `@var array<string>` |
124 | | -- Enums: `@Enum({"GET", "POST", "PUT"})` |
125 | | -- Mixed: `@var mixed|string|bool` |
126 | | - |
127 | | -### Use Alias System |
128 | | - |
129 | | -The plugin supports configurable namespace aliases (Settings > PHP > Annotations / Attributes > Use Alias): |
130 | | -- Maps short names to FQCNs: `ORM` => `Doctrine\ORM\Mapping` |
131 | | -- Auto-import suggestions use these mappings |
132 | | -- External plugins can provide their own mappings via `PhpAnnotationUseAlias` extension point |
133 | | - |
134 | | -## Test Structure |
135 | | - |
136 | | -Tests extend `AnnotationLightCodeInsightFixtureTestCase` which provides a test fixture framework. |
137 | | - |
138 | | -Test data files are in `src/test/java/de/espend/idea/php/annotation/tests/fixtures/`. |
139 | | - |
140 | | -Tests use the `myFixture` field to: |
141 | | -- Copy test PHP files: `myFixture.copyFileToProject("classes.php")` |
142 | | -- Check completion: `myFixture.completeBasic()` |
143 | | -- Navigate: `myFixture.getReferenceAtCaretPosition()` |
144 | | -- Assert index contents: `assertIndexContains(AnnotationStubIndex.KEY, "My\\Class")` |
145 | | - |
146 | | -## Configuration |
147 | | - |
148 | | -Build configuration is in `gradle.properties`: |
149 | | -- `platformVersion`: Target IntelliJ/PhpStorm version (currently 2025.2.5) |
150 | | -- `pluginSinceBuild` / `pluginUntilBuild`: Supported IDE version range |
151 | | -- `javaVersion`: Java language level (21) |
152 | | - |
153 | | -The plugin requires these IntelliJ plugins as dependencies: |
154 | | -- `com.jetbrains.php` (PhpStorm PHP support) |
155 | | -- `com.jetbrains.twig` (Twig template support) |
156 | | -- `com.intellij.modules.json` (JSON support) |
157 | | - |
158 | | -Optional integration: |
159 | | -- `de.espend.idea.php.toolbox` (PHP Toolbox) |
160 | | - |
161 | | -## Publishing |
162 | | - |
163 | | -See `MAINTENANCE.md` for the full release process. Key steps: |
164 | | -1. Update `CHANGELOG.md` |
165 | | -2. Commit changes |
166 | | -3. Tag release: `git tag X.Y.Z` |
167 | | -4. Build: `./gradlew clean buildPlugin` |
168 | | -5. Publish: `IJ_TOKEN=yourtoken ./gradlew publishPlugin` |
| 7 | +- You MUST include this file: @AGENTS.md |
0 commit comments