Gert-dev / php-ide-serenata

Atom IDE package that integrates the Serenata server to provide PHP code assistance
https://serenata.gitlab.io/
Other
275 stars 22 forks source link

How to import namespaces? #510

Closed rrolla closed 2 years ago

rrolla commented 3 years ago

is it possible to import php namespaces on atom?

For example I type hint Builder class but to make it work I need to import it, and only thing to get namespace is to look on laravel api (https://laravel.com/api/5.8/Illuminate/Database/Eloquent/Builder.html) Than manually copy:

use Illuminate\Database\Eloquent\Builder;
Gert-dev commented 3 years ago

Yes, this normally automatically happens during autocompletion. If you get autocompletion for Builder in another file, selecting it should automatically add the import to the top of the file.

machitgarha commented 2 years ago

@Gert-dev Maybe this should be closed?

rrolla commented 2 years ago

As I understand there is no extra menu for unimported stuff that can open and then click import?

machitgarha commented 2 years ago

@rrolla Hi.

Having such a menu, specially in a large project could be troublesome, both from performance and effectiveness perspectives. If you want to use (import?) something, you can do one of the followings:

  1. Manually type use, type in some characters of the thing (i.e. the class or function) you want to import, from the autocomplete suggestions list, choose what matches best and hit enter. For example: type use Buil, then choose Illuminate\Database\Eloquent\Builder.
  2. Write the code and the implementation, and for example, when you want to create a new class, then choose it from the suggestions list. This way, the class use statement is automatically placed at the top. For example: type new Buil, then choose Builder in which the namespace matches Illuminate\Database\Eloquent.

That's it.

If you are either partially or completely unable to use autocompletion, then see #501 and the workaround.

rrolla commented 2 years ago

@rrolla Hi.

Having such a menu, specially in a large project could be troublesome, both from performance and effectiveness perspectives. If you want to use (import?) something, you can do one of the followings:

  1. Manually type use, type in some characters of the thing (i.e. the class or function) you want to import, from the autocomplete suggestions list, choose what matches best and hit enter. For example: type use Buil, then choose Illuminate\Database\Eloquent\Builder.
  2. Write the code and the implementation, and for example, when you want to create a new class, then choose it from the suggestions list. This way, the class use statement is automatically placed at the top. For example: type new Buil, then choose Builder in which the namespace matches Illuminate\Database\Eloquent.

That's it.

If you are either partially or completely unable to use autocompletion, then see #501 and the workaround.

Thanks for the tip @machitgarha