Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
913 stars 137 forks source link

[Twig] Inconsistent constant() autocompletion #2249

Open klkvsk opened 11 months ago

klkvsk commented 11 months ago

There is a number of previous issues regarding this (#327, #639, #1167, #2049, #872), but here are summarized results:

autocompletion = visible in dropdown, completed on ctrl+space
declaration = visible on ctrl+hover, goes to declaration on ctrl+click or ctrl+B

{% set c1 = constant('ROOT_CONST') %} -- ok, full autocompletion + declaration
{% set c2 = constant('RootEnum::FOO') %} -- nothing
{% set c3 = constant('RootClass::FOO') %} -- declaration, autocompletion only after ::
{% set c4 = constant('BugDemo\\NAMESPACED_CONST') %} -- nothing
{% set c5 = constant('\\BugDemo\\NAMESPACED_CONST') %} -- nothing
{% set c6 = constant('BugDemo\\NamespacedEnum::FOO') %} -- nothing
{% set c7 = constant('\\BugDemo\\NamespacedEnum::FOO') %} -- nothing
{% set c8 = constant('BugDemo\\NamespacedClass::FOO') %} -- declaration, autocompletion only after ::
{% set c9 = constant('\\BugDemo\\NamespacedClass::FOO') %} -- declaration, autocompletion only after ::

{# @var rootClass RootClass #}
{% set c10 = constant('FOO', rootClass) %} -- nothing
{# @var namespacedClass BugDemo\NamespacedClass #}
{% set c11 = constant('FOO', namespacedClass) %} -- nothing
namespace {
    const ROOT_CONST = 'const';
    class RootClass {
        const FOO = 'in class';
    }
    enum RootEnum: string {
        case FOO = 'enum case';
    }
}

namespace BugDemo {
    const NAMESPACED_CONST = 'const';
    class NamespacedClass {
        const FOO = 'in class';
    }
    enum NamespacedEnum: string {
        case FOO = 'enum case';
    }
}

Here's what needs to be done