Skip to content

[DX] Add links to open the editor to the names of processed files and the names of rules applied #6272

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

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

carlos-granados
Copy link
Contributor

@carlos-granados carlos-granados commented Sep 1, 2024

Adds a new config option which provides capabilities similar to the editorUrl option in PHStan, see https://phpstan.org/user-guide/output-format#opening-file-in-an-editor

You use it by calling the withEditorURL() function with a URL template that when clicked will open a file in your editor, for example:

    ->withEditorUrl('phpstorm://open?file=%file%&line=%line%')

The editor URL allows the following template variables:

  • %file%: the absolute path to the file
  • %relFile% the relative path to the file
  • %line% the line number

This matches the template variables used by PHPStan

If this configuration is set, Rector will add editor links in the file name at the top of each file diff. When clicked this will open that file and line in your editor. This allows you to check any change that has been made or which has been suggested by Rector

You need to be using a terminal which understands these links to get this to work. If you are using a terminal which does not understand these links, these texts will be displayed as normal texts just like before.

See the attached video to see how it works.

Screen.Recording.2024-09-01.at.17.mp4

$this->symfonyStyle->listing($fileDiff->getRectorShortClasses());
$appliedRules = [];
foreach ($fileDiff->getRectorClasses() as $rectorClass) {
$appliedRuleName = (string) Strings::after($rectorClass, '\\', -1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the rules applied, we need to get the absolute URL of the corresponding rule file, we can do that using reflection. Then we can use the ParentDirectoryRelativePathHelper tool from PHPStan to get the relative URL

@carlos-granados
Copy link
Contributor Author

@TomasVotruba have you been able to take a look at this? I just rebased it, please let me know if there is any interest in this change so that I can keep it up to date. Thanks!!

@TomasVotruba
Copy link
Member

Looks good, thank you 👍

@TomasVotruba TomasVotruba merged commit e37a659 into rectorphp:main Oct 11, 2024
36 checks passed
@carlos-granados carlos-granados deleted the add-editor-url branch November 6, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy