8000 Improve how the `ide-twig.json` file is generated by m-vo · Pull Request #8200 · contao/contao · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve how the ide-twig.json file is generated #8200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: 5.x
Choose a base branch
from

Conversation

m-vo
Copy link
Member
@m-vo m-vo commented Mar 14, 2025

Implements #8051

This PR improves the way the ide-twig.json IDE helper file is generated. Currently we are only creating the file during cache warmup in the dev environment in an optional cache warmer. This is unfortunate because you typically do not explicitly warm the dev cache. We also dumped the file to var/cache which is semantically wrong.

Now the file gets dumped to var/contao-twig in a mandatory cache warmer (still only in dev). In order to 8000 use it you can un-exclude the above directory in your IDE.

I also added a new command contao:dump-twig-ide-file that dumps the file to a given location in your project dir. This way it will be included by default and can be checked in to version control. In this case, you own the file, so in order to update it, you must manually re-run the command.

/cc @bytehead

@m-vo m-vo added the feature label Mar 14, 2025
@m-vo m-vo added this to the 5.6 milestone Mar 14, 2025
@m-vo m-vo self-assigned this Mar 14, 2025
@m-vo m-vo requested a review from leofeyer as a code owner March 14, 2025 11:07
@leofeyer leofeyer linked an issue Mar 14, 2025 that may be closed by this pull request
@leofeyer
Copy link
Member
leofeyer commented Mar 14, 2025

I'm not sure about the implementation, I'm afraid 😞

For example, I don't like that we use a cache warmer to generate the file, but the generated file eventually does not become part of the cache. If the file changes upon rebuilding the cache, it should be stored in var/cache/… so removing the cache also removes the file. And if it does not, we should not use the cache warmer to generate it.

  • If the file changes upon cache:warmup → store it under var/cache/….
  • Use a subfolder like var/cache/…/contao-twig that can be unexcluded in the IDE.
  • Optionally generate the file in the prod cache as well, although the Symfony plugin also requires the dev cache to work:

Or, if the file is independent from the Symfony cache, add the contao:dump-twig-ide-file command to the contao:setup command an store the file in var/contao-twig (or var/contao-ide or var/contao-generated).

@m-vo
Copy link
Member Author
m-vo commented Mar 14, 2025

For example, I don't like that we use a cache warmer to generate the file, but the generated file eventually does not become part of the cache.

I think a mandatory cache warmer is probably still the best "injection point": a kernel event listener would run too often (every request, waste of resources) and the contao:setup command - although it would fit the "point in time" - is only a thing in the managed edition…

There is probably never any difference between prod and dev and the file is not used as a cached resource, so that's why I would not like to have it in var/cache/[dev|prod] anymore. Also I find it much easier to find if its in var/contao-twig.

@m-vo
Copy link
Member Author
m-vo commented Mar 14, 2025

If the file changes upon cache:warmup → store it under var/cache/….

Btw., it's a mandatory cache warmer, so it won't run at cache:warmup but cache:clear (or application boot with a not-yet-built cache).

@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly calls. label Mar 14, 2025
@leofeyer
Copy link
Member

IMHO we should do it like Symfony and store the file in var/cache/dev/contao-twig (or …/contao-ide or …/contao-generated).

@m-vo
Copy link
Member Author
m-vo commented Mar 14, 2025

The only autogenerated non-cache files of Symfony (I know of) are the Symfony/Config classes. Strictly speaking, they are not inside the kernel.cache_dir but the kernel.build_dir (which by default is still configured to be under var/cache). So, this might be an alternative for us.

@bytehead
Copy link
Member

A custom command to generate the file in var/cache/dev is fine for me 👍🏼

@leofeyer leofeyer removed the up for discussion Issues and PRs which will be discussed in our monthly calls. label Apr 3, 2025
@m-vo
Copy link
Member Author
m-vo commented Apr 3, 2025

As discussed we want to stick with a CacheWarmer to write the file and write it to %kernel.build_dir%/contao-ide.

Copy link
Member
@leofeyer leofeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in Slack, the IDE namespace and the DumpTwigIDEFileCommand and DumpTwigIDEFileCommandTest classes should be in camel case:

  • Contao\CoreBundle\Twig\Ide\…
  • DumpTwigIdeFileCommand
  • DumpTwigIdeFileCommandTest

@leofeyer leofeyer marked this pull request as draft June 11, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change how the ide-twig.json file is generated
3 participants
0