Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get fully-classified class name in PHPStorm's Code Completion?

I'm new to PHPStorm and want to ask how can I get fully-classified class name (absolute path to the class) using Code Completion (Command+Space)?

For example, I have a function in my code:

<?php

namespace A;
use C\D\Class;

/**
 * @return Class (what PHPStorm suggests)
 * @return \C\D\Class (what I need)
 */
function foo() {
  return new Class();
}
?>

This function returns an instance of \C\D\Class When generating docblock for this function, I use Command+Space to place class name after @return keyword. PHPStorm suggests Class in the expanded list but when I select necessary class it places only "Class" instead of "\C\D\Class".

How can I fix it?

Thanks in advance.

like image 858
NikitaObukhov Avatar asked Sep 23 '13 04:09

NikitaObukhov


People also ask

How do I get fully qualified class name in Intellij?

Press Ctrl + Alt + Shift + C (Edit | Copy Reference) on "Editor" in the code and you'll have the fully-qualified name in your clipboard.

Why Autocomplete is not working in Intellij?

I have tried the following according to this thread (Intellij IDEA CE 12 Android XML Code Completion not working): Go to File->Power Save Mode and disable it - it is off. Go to Preferences->Editor->Code Completion and check Autopopup code completion - this has been checked. Go to File->Invalidate Caches and restart.


1 Answers

I had the same issue too. Actually it is very simple, but I also did not find the option. It is well hidden.

Open the settings and go to:

IDE Settings -> Editor -> Auto Import

Settings dialog in PhpStorm

There you'll find the checkbox "Enable auto-import in namespace scope". Uncheck it, and namespaces will not be shorten anymore using the"use" keyword.

But now PhpStorm will tell you that it is unnecessary to use the complete namespace. To avoid that just disable the inspection "Unnecessary fully qualified name".

Inspections in settings dialog in PhpStorm

You are still able to tell PhpStorm to import the current class' namespace. For me it is just marking the class with the cursor and pressing ALT+ENTER. Then this dialog appears:

Import class dialog

When I confirm with ENTER the namespace of this class becomes imported and shorten: Shorten class name

like image 128
Armin Avatar answered Nov 01 '22 06:11

Armin