feat: enable Shift+F6 rename inside Qiq injected fragments#14
Merged
Conversation
Pressing Shift+F6 on a PHP identifier inside a Qiq template (e.g. the
property name in `{{h $article->title }}` or any identifier in an inline
`<?php ... ?>` host) did not open the rename dialog. Local variable
rename happened to work via the default handler, but property and
method accesses silently failed because CommonDataKeys.PSI_ELEMENT
resolves to the outer Qiq host (an unnamed wrapper) and the default
PsiElementRenameHandler.canRename rejects it.
Add QiqInjectedRenameHandler, registered via <renameHandler>:
- It scopes itself by checking that the top-level (host) file is Qiq,
using InjectedLanguageManager.getTopLevelFile. The platform pre-
narrows PSI_FILE in the data context to the most specific file at
the caret — sometimes the injected PHP file, sometimes the outer
Qiq file — so the scope check normalizes both shapes.
- It resolves the rename target by descending into the injected
fragment via InjectedLanguageManager.findInjectedElementAt, walking
parents, and asking each PSI element (or its references) to resolve
to a PsiNameIdentifierOwner. This handles variables, properties,
methods and class references uniformly through PHP's own resolution.
- It then hands the resolved target off to PsiElementRenameHandler's
standard pipeline, which in turn uses the host's ElementManipulator
(added in the previous PR) to rewrite the Qiq host text.
Combined with the existing PHP→Qiq propagation, rename refactoring now
flows bidirectionally between Qiq templates and PHP classes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a custom RenameHandler so that Shift+F6 on PHP identifiers inside Qiq injection hosts (e.g. {{h $article->title }} or inline <?php ... ?>) opens the rename dialog. Complements PR #13, which already wired the rewrite step via ElementManipulators.
Changes:
- New
QiqInjectedRenameHandlerthat descends into the injected PHP fragment, resolves the target via PHP references /PsiNameIdentifierOwner, and delegates toPsiElementRenameHandler. - Scope is restricted to files whose top-level language is
QiqTemplateLanguage, to avoid competing with PHP's default handler in plain.phpfiles. - Registers the handler in
plugin.xml.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/main/resources/META-INF/plugin.xml | Registers the new renameHandler extension. |
| src/main/kotlin/io/github/jingu/idea_qiq_plugin/navigation/QiqInjectedRenameHandler.kt | Implements the injected-fragment-aware rename handler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pressing Shift+F6 on a PHP identifier inside a Qiq template — for example the property name in
{{h \$article->title }}or any identifier inside an inline<?php ... ?>host — did not open the rename dialog. Local variable rename happened to work, but property and method accesses silently failed.Closes the follow-up tracked in PR #13.
Root cause
The platform's default
PsiElementRenameHandlerreadsCommonDataKeys.PSI_ELEMENTfrom the data context, which resolves to the outer Qiq host (an unnamed wrapper). The host satisfies neitherPsiNamedElementnorcanRename, so the action is disabled. The previous PR'sElementManipulatorwork was correct for the rewrite step, but the dispatch step (recognizing the caret position as renameable) was missing —<lang.elementManipulator>only matters once a rename pipeline has already chosen a target.Confirmed empirically by adding a temporary
Logger.warnto a draft handler and readingidea.log: the leaf returned byfile.findElementAt(offset)inside an injected fragment was always a PHP leaf with noQiqCodeHost/QiqPhpHostancestor, becausePSI_FILEin the data context was the injected PHP file itself.Implementation
Single new class
QiqInjectedRenameHandler, registered via<renameHandler>:InjectedLanguageManager.getTopLevelFile(file).language is QiqTemplateLanguage. This normalizes both cases the platform may give us (PSI_FILE = injected PHP file vs. outer Qiq file) and prevents competing with PHP's own handlers in plain.phpfiles.InjectedLanguageManager.findInjectedElementAt, then walks parents. At each step it asks PHP's own references to resolve themselves (PsiReference.resolve()directly when the element implements it, and viaelement.referencesotherwise), falling back to the element itself when it is aPsiNameIdentifierOwner. This handles variables, properties, methods and class references uniformly through PHP's resolution, which already has the injected context wired by ourMultiHostInjector.PsiElementRenameHandler's standard pipeline, which then uses the host'sElementManipulator(added in PR feat: propagate refactorings into Qiq host text #13) to rewrite the Qiq host text.Bidirectional rename, end-to-end
With this PR merged together with #13:
.phpfile)$variableinside{{h \$foo->bar }}{{h \$foo->bar }}<?php ... ?>hostTests
Action-layer tests for
RenameHandlerwould require aLightJavaCodeInsightFixtureTestCasewith PHP plugin fixtures and a full injected setup, which is significantly heavier than the rest of this project's test surface. Verified manually in PhpStorm 2026.1 instead:{{h \$article->title }}opens the dialog, renames the class field, and propagates back to all template references.<?php ... ?>blocks inside templates works for properties..phpfiles (outside any Qiq template) is unaffected — the scope check excludes them so this handler does not compete with PHP's own.Risks
truefromisAvailableOnDataContextonly when the caret resolves to aPsiNamedElementreachable from a Qiq host. In Qiq files where the default handler would otherwise also fire (e.g. on$articleitself, where the default works), the registry will list both. The current observation is that variable rename works as before with no chooser, but if a chooser surfaces in some corner case, a follow-up can returnfalsewhen the resolved target is something PHP's handler would already handle directly.Test plan
./gradlew test— existing tests green./gradlew buildPlugin— produces a valid distribution{{h ... }}opens the rename dialog and propagates correctly to both the PHP class and all template references🤖 Generated with Claude Code