[FEATURE] Add "Go to Definition" for ViewHelpers - #11
Open
chrissonntag wants to merge 4 commits into
Open
Conversation
Resolves a ViewHelper in a Fluid template to the PHP class implementing it,
in tag as well as in inline syntax, and for project ViewHelpers just as well
as for built-in ones.
Resolution mirrors what Fluid does at runtime, without executing anything:
namespaces are collected from every package Configuration/Fluid/Namespaces.php,
from the legacy $GLOBALS registration in ext_localconf.php and from the xmlns
and {namespace} declarations of the template; the candidates of an alias are
tried in reverse order because Fluid resolves the last registered namespace
first; the tag name becomes a class name through ucfirst per dotted segment;
and the class is located through the Composer autoload map, vendor as well as
.Build/vendor. The resolved index is cached per workspace folder and dropped
when a namespace file, an ext_localconf.php or the autoload map changes.
Because no binary is involved, this also works in projects where live
template analysis is unavailable.
s2b
requested changes
Sep 1, 2026
s2b
left a comment
Contributor
There was a problem hiding this comment.
Ideally, we would move all php parts to the php side, especially since the required classes are already implemented, but let's start with using what's already available.
I've looked through the code, but didn't test it yet. As discussed, this would be a temporary solution, but it's certainly better than no solution. Thanks for the effort!
The candidate list of typo3 and fluid binaries was assembled inline twice, once for fluid:analyze and once for --version, so every further command had to repeat the same block. Both now come from a shared module, which also runs a command asynchronously and formats it for the log. The candidate order is unchanged: user defined binaries first, then ddev, then vendor/bin, bin and .Build/bin.
fluid.bin.useDdevIfAvailable was read as "useDdevIfAvailable" instead of "bin.useDdevIfAvailable", so the configured value never arrived and binaries were always run inside DDEV whenever a project had it set up. Turning the setting off had no effect.
Global namespaces now come from typo3 fluid:namespaces --json instead of being pattern matched out of Configuration/Fluid/Namespaces.php and ext_localconf.php. They are therefore exactly the namespaces Fluid resolves, in the order it resolves them, which decides whether an extension overrides a core ViewHelper; the previous directory walk could pick a different winner. Ignored and wildcard aliases are skipped, and classes are still located through the Composer autoload map. The command ships with TYPO3 v14.2 and is backported to v12 and v13 by EXT:fluid_companion. Without it the feature stays off and points at the companion, rather than guessing and resolving to a plausible but wrong class. --no-interaction is mandatory, because a missing command otherwise makes Symfony Console ask which command to run instead. The namespaces are read once per workspace folder, asynchronously and shared by concurrent lookups. The index is now also dropped when the system configuration, the Composer lock or the package artifact changes, and the new "Fluid: Reload ViewHelper Index" command covers namespaces registered by an event listener, which no watcher can see.
chrissonntag
force-pushed
the
feature/viewhelper-go-to-definition
branch
from
September 4, 2026 13:59
219b385 to
3bad19d
Compare
Author
|
Ok, changes are in. Feel free to test it yourself and see whether the feature works for you, or let me know what else we could improve. |
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.
This implements what I proposed in #10 : F12 or Ctrl+click on a ViewHelper opens the PHP class behind it — built-in, third-party and project ViewHelpers alike, in tag as well as in inline syntax.
Scope is deliberately narrow: a
DefinitionProviderforfluidandhtml-fluid, nothing else — hover, completion and diagnostics would overlap with the generatedhtml.customDataand the analyzer. It is enabled by default and can be switched off withfluid.features.viewHelperDefinitions.Global namespaces come from
typo3 fluid:namespaces --json, so this needs TYPO3 v14.2, or EXT:fluid_companion in v12 and v13. Without it the feature stays off and points at the companion — there is no fallback that could resolve to a wrong class. Classes are located through the Composer autoload map, and the template's ownxmlnsand{namespace}declarations are added on top.Fluid: Reload ViewHelper Indexre-reads the namespaces, for the case that they were registered by an event listener.Tested on TYPO3 12.4, 13.4 and 14.3 DDEV projects and on a single extension repo with a tea-style
.Buildlayout, which works without a database orsettings.php.npm run lintpasses.The branch also contains an unrelated one-line bugfix:
fluid.bin.useDdevIfAvailablewas read from the wrong configuration key, so turning it off had no effect.