|
| 1 | +# Shared analysis context — Spiral Framework plugin |
| 2 | + |
| 3 | +This file is shared context for per-file analysis subagents. |
| 4 | + |
| 5 | +## Project facts (from CLAUDE.md) |
| 6 | +- Language: Kotlin (JVM toolchain 21). IntelliJ Platform Gradle Plugin 2.x. |
| 7 | +- Plugin ID: `com.github.xepozz.spiral`. Mandatory deps: `com.intellij.modules.platform`, `com.jetbrains.php`. |
| 8 | +- Since-build: 251 (IDE 2025.1+). `platformType = IU`. PhpStorm-only APIs from `com.jetbrains.php` are available. |
| 9 | +- Tests: JUnit 4 + `BasePlatformTestCase`. |
| 10 | +- All Spiral FQNs MUST live in `SpiralFrameworkClasses.kt` with leading backslash (`\Spiral\...`). |
| 11 | +- All user-facing strings MUST go through `SpiralBundle.message(...)`. |
| 12 | +- Icons via `SpiralIcons` only. |
| 13 | +- No `println` in new code — use `com.intellij.openapi.diagnostic.Logger`. |
| 14 | +- Indexes extend `common/index/AbstractIndex.kt`, must bump `getVersion()` when output shape changes. |
| 15 | +- `ObjectStreamDataExternalizer` uses Java serialization — value classes must stay `Serializable`. |
| 16 | +- Configuration cache enabled — don't break it. |
| 17 | + |
| 18 | +## IntelliJ Platform best-practices checklist (use as a lens when reviewing) |
| 19 | + |
| 20 | +### Threading & locks |
| 21 | +- Long PSI traversal, VFS scans, index queries must NOT run on EDT. |
| 22 | +- Reading PSI/VFS requires a read action (or smart-mode read access). Writing requires a write action on EDT. |
| 23 | +- Re-validate PSI / VirtualFile (`isValid()`) when re-entering a read action after suspension. |
| 24 | +- `ProcessCanceledException` must NEVER be swallowed — always rethrow. Catch only specific exceptions. |
| 25 | +- Avoid `runReadAction` on EDT for heavy work — prefer `ReadAction.nonBlocking(...).submit(...)` or background actions. |
| 26 | + |
| 27 | +### Dumb mode & indexes |
| 28 | +- `FileBasedIndex.getInstance().getValues(...)` / `getAllKeys(...)` is forbidden in dumb mode — guard with `DumbService.isDumb` or `runReadActionInSmartMode`. |
| 29 | +- `LineMarkerProvider`, `ReferenceContributor`, `CompletionContributor` may be invoked during indexing — handle dumb mode. |
| 30 | +- Concrete `FileBasedIndexExtension` must bump `getVersion()` if the indexed shape changes (keys, value class, input filter, key descriptor). |
| 31 | +- `dependsOnFileContent()` defaults to true in `AbstractIndex` — fine for content indexes, but path-only indexes should override. |
| 32 | +- Value externalizer using `ObjectStreamDataExternalizer` (Java serialization) is fragile across IDE/plugin versions — prefer `DataExternalizer<T>` with explicit `save`/`read`. |
| 33 | + |
| 34 | +### PSI references |
| 35 | +- `PsiReference.resolve()` must be fast — cache where possible, use `CachedValuesManager` for repeated resolves. |
| 36 | +- `PsiReferenceContributor` patterns should be specific to avoid invocation on every PSI element. |
| 37 | +- `getRangeInElement()` must be relative to the host element (not absolute). |
| 38 | +- Multi-resolve references should implement `PsiPolyVariantReference`. |
| 39 | +- `getVariants()` returning many items: use `LookupElementBuilder` and consider `withIcon`, `withTypeText`, `withTailText` for UX. |
| 40 | + |
| 41 | +### Completion contributors |
| 42 | +- `addCompletions` must be fast; avoid blocking I/O. |
| 43 | +- Always check `result.isStopped`/`ProgressManager.checkCanceled()` in long loops. |
| 44 | +- `extend(...)` patterns should be as specific as possible (use `psiElement().withParent(...)`). |
| 45 | +- Don't call `result.stopHere()` unless intentionally suppressing other contributors. |
| 46 | + |
| 47 | +### LineMarkerProvider |
| 48 | +- `LineMarkerProvider.getLineMarkerInfo` is invoked on the leaf element (not the whole class/function) — anchor to identifier, not container. |
| 49 | +- `RelatedItemLineMarkerProvider` is the modern alternative. |
| 50 | +- Marker must be cheap — heavy resolution should be deferred via `NavigationGutterIconBuilder`. |
| 51 | + |
| 52 | +### Run configurations |
| 53 | +- `ConfigurationFactory.getId()` must be stable across versions — changing it breaks user-saved configs. |
| 54 | +- `RunConfiguration.checkConfiguration()` should throw `RuntimeConfigurationError` / `RuntimeConfigurationWarning`. |
| 55 | +- `RunProfileState.execute()` should not block EDT. |
| 56 | +- Read/write external state via `JDOMExternalizer` / explicit XML; `Element` content is persisted to workspace.xml. |
| 57 | + |
| 58 | +### Service lifecycle / Disposers |
| 59 | +- Never use `Application` or `Project` directly as a Disposable parent inside plugin code — use the plugin's service. |
| 60 | +- Listeners registered without a `Disposable` parent leak across dynamic-plugin reloads. |
| 61 | +- Project services should be `@Service(Service.Level.PROJECT)`; app services `@Service(Service.Level.APP)`. |
| 62 | + |
| 63 | +### Other quality concerns |
| 64 | +- Hard-coded user-visible strings (must be in `SpiralBundle`). |
| 65 | +- Hard-coded FQNs scattered around (must be in `SpiralFrameworkClasses`). |
| 66 | +- `println` / `System.out` — replace with `Logger.getInstance(...)`. |
| 67 | +- `!!` on platform-returned nullables — risky; use `?:` or graceful fallback. |
| 68 | +- Companion-object constants should be `const val` when possible. |
| 69 | +- Unused imports / unused parameters / dead code. |
| 70 | +- Public visibility on classes that should be `internal`. |
| 71 | +- `var` instead of `val` where mutation isn't needed. |
| 72 | + |
| 73 | +## Output format expected from each subagent |
| 74 | + |
| 75 | +Each subagent writes ONE markdown file at the absolute path it is given, with this structure: |
| 76 | + |
| 77 | +``` |
| 78 | +# Analysis: <relative source path> |
| 79 | +
|
| 80 | +## Summary |
| 81 | +1-3 sentences describing the file's responsibility. |
| 82 | +
|
| 83 | +## Issues |
| 84 | +For each issue: a numbered heading with severity tag. |
| 85 | +
|
| 86 | +### 1. [SEVERITY] Short title |
| 87 | +- Location: <relative path>:<line range> |
| 88 | +- Problem: <what's wrong> |
| 89 | +- Why it matters: <impact> |
| 90 | +- Suggested fix: <concrete remediation> |
| 91 | +
|
| 92 | +Severity tags: [BUG], [PERF], [API-MISUSE], [STYLE], [MAINTAINABILITY], [I18N], [THREAD], [DUMB-MODE], [INDEX], [LEAK]. |
| 93 | +
|
| 94 | +## No-issue note |
| 95 | +If nothing meaningful is found, write "No significant issues found." and stop. |
| 96 | +``` |
| 97 | + |
| 98 | +Keep findings concrete, with file:line references. Don't speculate about issues that aren't present. |
0 commit comments