qossmic / deptrac

Keep your architecture clean.
https://qossmic.github.io/deptrac
MIT License
2.62k stars 136 forks source link

DEPTRAC_INTERNAL\___PHPSTORM_HELPERS\object #1436

Open vudaltsov opened 1 week ago

vudaltsov commented 1 week ago

I have "qossmic/deptrac": "^2.0.1" in my dev requirements. Every time I use the object type, PhpStorm imports DEPTRAC_INTERNAL\___PHPSTORM_HELPERS\object first. This is extremely annoying.

I understand that autocomplete is a PhpStorm issue. However I want to ask, why are you including PhpStorm stubs into the package instead of requiring jetbrains/phpstorm-stubs via composer (PhpStorm automatically removes this package from autocompletion)? And why do you prepend a custom namespace for object?

patrickkusebauch commented 1 week ago

The reason is an attempt to make deptrac non-conflicting with other dev dependencies and project transitive dependencies. You can see now that deptrac installed via composer does not have any dependencies of its own. As part of the build process, deptrac pulls all dependencies it needs and then prepends them with the custom namespace to prevent conflicts.

Personally, I am not sure how necessary this is today with https://github.com/bamarni/composer-bin-plugin, which solves this issue on Composer level by creating custom namespaces/environments for dev dependencies.

But this approach is useful for other installation methods like Phar and Phive. @dbrumann thoughts?

jon-ht commented 2 days ago

If you don't want PHPStorm to suggest DEPTRAC_INTERNAL\___PHPSTORM_HELPERS\object, you can mark vendor/qossmic/deptrac/vendor as excluded

https://www.jetbrains.com/help/phpstorm/excluding-files-from-project.html

Maybe vendor/qossmic/deptrac/deptrac.phar should also be excluded, not sure about this one

vudaltsov commented 2 days ago

@jon-ht , I know this technique and I use use it for var directory in Symfony projects. However, you cannot exclude vendor/qossmic/deptrac/vendor, because PhpStorm already automatically excludes vendor packages (see, the whole deptrac directory is yellow):

image

Even if I manually exclude the qossmic directory (so that it's red now), the autocomplete remains. Probably because PhpStorm treats vendor directory differently. I also don't want to exclude the qossmic directory, because I need autocomplete for writing custom Deptrac collectors.

jon-ht commented 2 days ago

@vudaltsov Indeed, I didn't had your issue because I'm working on a mono-repo, so my path to deptrac was actually my-app/vendor/qossmic/deptrac/vendor. PHPStorm seems to only exclude root vendors by default

And what about https://www.jetbrains.com/help/phpstorm/excluding-files-from-project.html#exclude-libraries-from-indexing ? Is it what you mention with red color ?