Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make PHPStorm auto-import namespaces in use statements?

Tags:

phpstorm

I have checked the box for "Enable auto-import in namespace scope" in preferences, however when I select a class from the autocomplete, the FQN remains rather than placing it in a use statement. What am I doing wrong and how can I force phpstorm to auto-import these?

like image 868
KinsDotNet Avatar asked Feb 25 '15 21:02

KinsDotNet


People also ask

How do I enable auto import dependencies in IntelliJ?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), click Editor | General | Auto Import. Select the Add unambiguous imports on the fly checkbox, and apply the changes.

How do I stop auto import in IntelliJ?

You can disable auto-import on completion and use quick-fixes instead: In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | General | Auto Import. On the Auto Import page that opens, use the checkboxes in the TypeScript/JavaScript area to enable or disable import generation on code completion.

Do not import exactly from?

The option “Do not import exactly from” allows you to tell the IDE that you don't want any imports that are from the specific path (e.g. @material-ui/core ) or path pattern (e.g. @material-ui/core/** ). The IDE will then use an alternative path if there is one.

How do I get import suggestions in IntelliJ?

In general, in IntelliJ IDEA, you can use Ctrl - Shift - A and press part of a command to find it and know the appropriate shortcut. Typing Ctrl - Shift - A (or if you're on a Mac ⌘ - Shift - A ) and then search for "import" allows finding this command easily.


1 Answers

Make sure that the file where you performing this is actually properly namespaced (as that is the requirement for Enable auto-import in namespace scope option).

If working in non-namepsaced file .. you should enable Enable auto-import in file scope option (it is not enabled by default for better compatibility with older existing code reasons).

like image 63
LazyOne Avatar answered Oct 21 '22 01:10

LazyOne