Skip to content
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

emit warnings when xdebug is not used according to cli-flags #1878

Merged
merged 1 commit into from
Oct 20, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Oct 20, 2022

as discussed in phpstan/phpstan#8173

we don't have tests with/without xdebug. does this PR require tests?

I tested it manually

$ php bin/phpstan analyze test.php --debug  --level 9
Note: The xdebug php-extension is active, but "--xdebug" is not used.
      This may slow down performance and the process will not halt at breakpoints.
Note: Using configuration file C:\dvl\Workspace\phpstan-src-staabm\phpstan.neon.dist.
C:\dvl\Workspace\phpstan-src-staabm\test.php


$ php bin/phpstan analyze test.php --debug  --level 9   --xdebug
Note: You are running with "--xdebug" enabled, but the xdebug php-extension is not active.
      The process will not halt at breakpoints.
Note: Using configuration file C:\dvl\Workspace\phpstan-src-staabm\phpstan.neon.dist.
C:\dvl\Workspace\phpstan-src-staabm\test.php

@staabm staabm changed the title emit warnings when xdebug is not used according th cli-flags emit warnings when xdebug is not used according to cli-flags Oct 20, 2022
@staabm
Copy link
Contributor Author

staabm commented Oct 20, 2022

(sorry for the typo in the PR title)

@staabm staabm marked this pull request as ready for review October 20, 2022 09:21
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

$stdOutput = new SymfonyOutput($output, new SymfonyStyle(new ErrorsConsoleStyle($input, $output)));

/** @var Output $errorOutput */
$errorOutput = (static function () use ($input, $output): Output {
$symfonyErrorOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
return new SymfonyOutput($symfonyErrorOutput, new SymfonyStyle(new ErrorsConsoleStyle($input, $symfonyErrorOutput)));
})();

if ($allowXdebug && !XdebugHandler::isXdebugActive()) {
$errorOutput->writeLineFormatted(sprintf('Note: You are running with "--xdebug" enabled, but the xdebug php-extension is not active.' . "\n" . ' The process will not halt at breakpoints.'));
Copy link
Member

Choose a reason for hiding this comment

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

  1. Please use $errorOutput->getStyle()->note() instead.
  2. Correct capitalization of Xdebug please: https://xdebug.org/
  3. php-extension should be PHP extension

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed thanks.

screenshot of the cli error for preview

grafik

@ondrejmirtes
Copy link
Member

Purrrrfect!

@ondrejmirtes ondrejmirtes merged commit 7277d46 into phpstan:1.9.x Oct 20, 2022
@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the xdebug-warn branch October 20, 2022 09:43
@staabm
Copy link
Contributor Author

staabm commented Oct 20, 2022

off-topic: you may also notice, that my commits from the work pc, now also use the same git user as those from my personal computer

@ondrejmirtes
Copy link
Member

👏

@InvisibleSmiley
Copy link

The problem with the current warning message is that it can be interpreted as "please add the --xdebug flag to improve performance" which is wrong of course.

See for example https://youtrack.jetbrains.com/issue/WI-69996

Please improve the message to help people understand that:

  • if you want to improve performance, disable Xdebug altogether
  • debugging PHPStan itself, use --xdebug with Xdebug enabled
  • do not use --xdebug with Xdebug enabled for regular use since it really hurts performance

@staabm
Copy link
Contributor Author

staabm commented Dec 5, 2022

@InvisibleSmiley feel free to suggest a pull request with a concrete message.

@jorismak
Copy link

Shouldn't it be possible to disable this warning in the configuration file or something?

It now breaks integrations with phpstan because the warning is always displayed. Setting 'start_with_request' to trigger still doesn't quiet the warning.

So on a development machine where you want Xdebug to be available, you now always get this warning? Seems like it now breaks more than it helps? (The performance difference with XDEBUG_MODE=off vs XDEBUG_MODE=debug is very, very small).

@ondrejmirtes
Copy link
Member

What does it break? It's printed to stderr. And there have always been messages printed to stderr, even when combined with JSON error format for example.

@jorismak
Copy link

I get a popup in phpstorm and vscode every time it tries to run phpstan, that there is some error running the process (and then shows the xdebug warning).

@ondrejmirtes
Copy link
Member

  1. The same integration should fail if there's a note in the output about auto-discovered phpstan.neon or phpstan.neon.dist. Is that correct?
  2. Seems like you can disable this message with an environment variable XDEBUG_MODE=off. Is that correct?

@jorismak
Copy link

jorismak commented Dec 29, 2022 via email

@Balkoth
Copy link

Balkoth commented Feb 8, 2023

I guess this change breaks extensions like this?

@ondrejmirtes
Copy link
Member

Extension that gets broken when something meant for humans to read is printed to stderr needs to be fixed :)

@ondrejmirtes
Copy link
Member

Anyway, if you have any questions, please open new issues or discussions in phpstan/phpstan. Thank you.

@phpstan phpstan locked as resolved and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants