PhpStorm 2022.1 Help

Auto Import

XML

Show auto-import tooltip

Automatically show an auto-import tooltip when typing the name of an unbound namespace. See importing unbound namespaces for details.

TypeScript/JavaScript

Add ES6 imports on code completion

  • If this checkbox is selected, PhpStorm automatically inserts an import statement in JavaScript code when you complete a symbol exported using ES6 exports in another project file:

    Add ES6 imports on code completion
  • When the checkbox is cleared, on pressing Alt+Enter PhpStorm shows a popup that suggests to import the symbol:

    Add ES6 imports on code completion disabled
  • Completion and auto-import also work for React components, including stateless components. PhpStorm properly detects them, provides code completion, and adds import statements automatically:

    Completion for imports in React stateless components

Add TypeScript imports automatically

Select this checkbox if you want PhpStorm to generate import statements in TypeScript code. Use the checkboxes below to choose when import generation will be invoked.

  • On code completion If this checkbox is selected, PhpStorm automatically inserts an import statement in TypeScript code when you complete a symbol exported in another project file.

  • With auto-import tooltip If this checkbox is selected, PhpStorm shows a tooltip with an import suggestion when you position the caret at an unresolved symbol that can be imported. When the checkbox is cleared, you can invoke import generation only be pressing Alt+Enter.

  • Unambiguous imports on the fly With this checkbox selected, PhpStorm adds import statements when you type your code or paste a fragment with a symbol that is not yet imported if there is only one source to import the symbol from.

When you are using ES6 modules in a browser that requires full file names, for example, in Chrome, it is important that the names of ES6 modules in import statements have the .js extensions.

  • To add the extension automatically in the JavaScript context, select the Use file extension checkbox on the Imports tab of the Code Style: JavaScript page.

  • To add the extension automatically in the TypeScript context, select the Use file extension checkbox on the Imports tab of the Code Style: TypeScript page.

Dart

Update imports on paste

Select how PhpStorm should process references to missing symbols in pasted blocks of Dart code:

  • All — PhpStorm will insert import statements automatically for all missing symbols in pasted code.

  • Ask — you will be prompted to select the symbol to import.

  • None — PhpStorm will not add any import statements automatically, you can invoke import generation by pressing Alt+Enter at the unresolved reference and choosing Import <symbol name> from the list.

PHP

Insert imports on paste

Select how PhpStorm should process references to missing classes and methods in pasted blocks of code:

  • All: import statements will be added automatically for all missing classes and methods found in pasted blocks of code.

  • Ask: PhpStorm will prompt you to select which classes and methods you want to import.

    If the pasted class is already referenced in the target code via an alias, PhpStorm will prompt you to reuse this alias instead of creating a new import statement.

    the Select Classes To Import dialog: reuse existing alias
  • None: no import statements will be added, you won't be asked about unresolved references.

Note that adding imports on paste is only possible if the copied element is properly resolved in code (that is, not highlighted by the Undefined class or Undefined method inspections), and project indexing is finished.

Enable auto-import in file scope

Select this checkbox to have PhpStorm automatically import PHP namespaces, add use statements, and complete short class names on the fly, when you are typing in a class or file that does not belong to any specific namespace. By default, the checkbox is cleared.

Enable auto-import in namespace scope

Select this checkbox to have PhpStorm automatically import PHP namespaces, add use statements, and complete short class names on the fly when you are typing in a class or file that belongs to a certain namespace. The checkbox is selected by default.

Treat symbols from the global space

In this area, configure auto-import from the global namespace separately for classes, functions, and constants.

  • Prefer FQN: If selected, PhpStorm automatically inserts the fully-qualified name of a symbol from the global namespace, prepended with a backslash, for example:

    namespace A; $myException = new \Exception(); $a = \strlen("Test"); echo \PHP_EOL;
  • Prefer Import: If selected, PhpStorm automatically adds use statements for symbols from the global namespace if this doesn’t result in a conflict, for example:

    namespace A; use Exception; use const PHP_EOL; use function strlen; $myException = new Exception(); $a = strlen("Test"); echo PHP_EOL;
  • Prefer Fallback: If selected, PhpStorm neither inserts a fully-qualified name of a function or a constant, nor imports them by means of the use statement. The fallback global functions or constants are preferred in this case, for example:

    namespace A; use Exception; $myException = new Exception(); $a = strlen("Test"); echo PHP_EOL;
Last modified: 14 March 2022