maker-bundle icon indicating copy to clipboard operation
maker-bundle copied to clipboard

[make:entity] Suggestion: Add link in output that opens the file directly in my IDE

Open ThomasLandauer opened this issue 4 years ago • 2 comments

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:

  1. How can I get the ide configuration value from inside MakeMigration?
  2. 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.

ThomasLandauer avatar Oct 30 '21 15:10 ThomasLandauer

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 :).

weaverryan avatar Nov 17 '21 00:11 weaverryan

Oops, we have a general problem here! There are two "standards" on how to display links in a console:

  1. 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.
  2. 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.

ThomasLandauer avatar Nov 17 '21 14:11 ThomasLandauer