Open ghostoy opened 6 years ago
I use phpfmt
for that demands. It can sort use
statements by the length of line, clear unused imports and transform long array()
into short []
.
i use PHP Namespace Resolver for auto import and auto sort , also it cleans unnecessary imports
and thank @bmewburn your nice plugin 😄
+1 for having this added to Intelephense
+1
+1 for sorting/cleaning use
statements, and a short array conversion option would be so handy
Would be really useful to do this "on-save"
+1, PHPStorm has it, hope vscode-intelephense also offer this functionality
Just a question here, when you talk about sorting. Are there multiple different approaches to sorting imports? I saw "length of line" above, other methods could be "alphabetically".
For e.g. Java, I saw the sorting puts builtin imports first, then a newline, then user created classes etc.
What is the common approach for PHP?
I think alphabetical makes most sense to me.
+1 to alphabetical order.
I think there should be at least three options in the settings:
And on top of that, it worth to have the corresponding command in the command palette, so we can bind it to some keyboard shortcut.
Thanks in advance!
Have you tried running CS PHP Fixer on save with config 'ordered_imports' => ['sort_algorithm' => 'alpha'],
? I think that could be a simple solution as well.
Yes, I know we can achieve it with phpcs
, of course. But for some reasons it is not always convenient... For some projects it is quite enough to simply use intelephense
and this is really great, but in this case it lacks the kind of features this topic suggests.
I think there should be at least three options in the settings:
- sort strategy
- sort on save
- clean on save
And on top of that, it is worth having the corresponding command in the command palette, so we can bind it to some keyboard shortcut.
Thanks in advance!
Note: This is just food for thought. Please, DO NOT try to implement such behaviour, if it will delay the arrival of the Clean&Sort update.
Another one, which I definitely won't use, but probably some would like to, is an option to group imports.
Ie. converting
use App\Services\BbisWrapper\BbisWrapperClient;
use App\Services\BbisWrapper\CustomerAddress;
use App\Services\Dokumenti\DocumentTree;
use App\Services\Pim\PimCachingClient;
use App\Services\BbisWrapper\Customer;
use App\Events\OrderDocumentReceived;
use App\Enums\FinancialDocumentType;
use App\Jobs\StartShopOrderProcess;
use App\Models\FinancialDocument;
use App\Enums\Bbis\DeliveryType;
use App\Events\ShipmentUpdated;
use App\Services\Nop\NopClient;
use Illuminate\Support\Carbon;
use App\Services\Pim\Product;
use App\Models\OrderShipment;
use App\Dtos\ReceiptDocument;
use App\Enums\ShippingMethod;
use App\Enums\PaymentMethod;
use App\Enums\OrderLineType;
use Psr\Log\LoggerInterface;
use App\Dtos\OrderDocument;
use App\Models\OrderAction;
use App\Enums\OrderSource;
use App\Models\OrderLine;
use App\Dtos\Document;
use App\Models\Order;
use App\Dtos\Line;
to
use App\Services\Dokumenti\DocumentTree;
use App\Jobs\StartShopOrderProcess;
use App\Enums\Bbis\DeliveryType;
use App\Services\Nop\NopClient;
use Illuminate\Support\Carbon;
use App\Services\BbisWrapper\{
BbisWrapperClient,
CustomerAddress,
Customer,
};
use Psr\Log\LoggerInterface;
use App\Services\Pim\{
PimCachingClient,
Product,
};
use App\Events\{
OrderDocumentReceived,
ShipmentUpdated,
};
use App\Models\{
FinancialDocument,
OrderShipment,
OrderAction,
OrderLine,
Order,
};
use App\Enums\{
FinancialDocumentType,
ShippingMethod,
PaymentMethod,
OrderLineType,
OrderSource,
};
use App\Dtos\{
ReceiptDocument,
OrderDocument,
Document,
Line,
};
+1
+1
+1
That would be so cool to have. Support as well.
Usually after code refactor, some imports are not necessary and should be removed and re-sorted. Hope Intelephense can support this feature.
BTW, this plugin is the best PHP plugin on VSCode. Fast and stable.