bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.6k stars 93 forks source link

Sort and clean imports #254

Open ghostoy opened 6 years ago

ghostoy commented 6 years ago

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.

banqhsia commented 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 [].

oommgg commented 5 years ago

i use PHP Namespace Resolver for auto import and auto sort , also it cleans unnecessary imports

and thank @bmewburn your nice plugin 😄

chrislentz commented 4 years ago

+1 for having this added to Intelephense

andrefelipe commented 4 years ago

+1

richmilns commented 3 years ago

+1 for sorting/cleaning use statements, and a short array conversion option would be so handy

HomelessCoder commented 3 years ago

Would be really useful to do this "on-save"

slyang-git commented 2 years ago

+1, PHPStorm has it, hope vscode-intelephense also offer this functionality

PythooonUser commented 2 years ago

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?

richmilns commented 2 years ago

I think alphabetical makes most sense to me.

HomelessCoder commented 2 years ago

+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!

PythooonUser commented 2 years ago

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.

HomelessCoder commented 2 years ago

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.

mathmul commented 2 years ago

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,
};
GabrieleOlmi commented 1 year ago

+1

berniedurfee-renaissance commented 1 year ago

+1

3elDU commented 10 months ago

+1

Tamas-hi commented 6 months ago

That would be so cool to have. Support as well.