maker-bundle
maker-bundle copied to clipboard
[make:entity] Suggestion: Add link in output that opens the file directly in my IDE
I'm suggesting to change this line after php bin/console make:migration:
Next: Review the new migration "src/Migrations/Version20211030130836.php"
to
Next: Review the new migration phpstorm://open?file=/.../src/Migrations/Version20211030130836.php
... if Symfony's ide option is set: https://symfony.com/doc/current/reference/configuration/framework.html#ide
The line is generated at MakeMigration::generate().
If you (a) think that this is good idea, and (b) ask me to come up with a PR ;-) I have two questions:
- How can I get the
ideconfiguration value from insideMakeMigration? - How can I convert the relative filename (coming from
$this->getGeneratedMigrationFilename($migrationOutput);) to an absolute path? I think this comes down to: How can I get%kernel.project_dir%to prepend it?
I committed a similar feature to phpstan and Codeception.
And a related feature has already been added in https://github.com/symfony/maker-bundle/pull/559 - but I'm not sure what it does exactly.
I definitely like this idea :). Yes, the MakerLinkFormatter - https://github.com/symfony/maker-bundle/blob/main/src/Util/MakerFileLinkFormatter.php - already has the complex parts of this. We use it currently when we output that we "wrote" to a file - https://github.com/symfony/maker-bundle/blob/ca4d157527028afa46cb90a7cffd710b53c7b878/src/FileManager.php#L84
But, you could certainly use this for make:migration - that would be great (i constantly go an open these files right after I create them). The service id is maker.file_link_formatter. We may still need to connect a few pieces, but hopefully this is enough :).
Oops, we have a general problem here! There are two "standards" on how to display links in a console:
- Old-fashioned: Display this text verbatim:
phpstorm://open?file=/.../src/Migrations/Version20211030130836.php, and then rely on the terminal's auto-detection to make it clickable. This is (as far as I know) supported by every terminal. - Fancy (i.e. HTML-like): Add some special characters to allow displaying a different link text. This is supported by some terminals: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
What I suggested (and what I've added to PHPStan) is (1). What makeLinkedPath creates is (2).
I don't know how the adoption of (2) will progress. But for Konsole (=default in KDE) it doesn't look too good: https://bugs.kde.org/show_bug.cgi?id=379294 And (frankly) I'm also not sure if it's a good idea at all...
Anyway. In order to get this to work for everybody, I see two ways:
- Switch to (1) completely, i.e. modify OutputFormatterStyle
- Introduce a configuration parameter to let the user decide.