King2500 / idea-php-advanced-autocomplete

Plugin for PhpStorm IDE. Adds auto-completion support for various built-in PHP functions, where parameter is a string literal.
https://plugins.jetbrains.com/phpstorm/plugin/7276-php-advanced-autocomplete
MIT License
61 stars 7 forks source link

Add advanced completion for custom methods/functions via meta php #26

Open King2500 opened 4 years ago

King2500 commented 4 years ago

.phpstorm.meta.php:

<?php
namespace PHPSTORM_META {
    xAdvancedCompletion(\My\Stuff\Example::formatDate(), 1, 'date_format');
}

User code:

$x = new Example();
$x->formatDate($val, '<caret>');

Plugin's built-in .phpstorm.meta.php:

<?php
namespace PHPSTORM_META {
    function xAdvancedCompletion($functionReference, $argumentIndex, $completionList) {
        return "xAdvancedCompletion " . $functionReference . " at " . $argumentIndex . ": " . $completionList;
    }

    registerArgumentsSet('x_advanced_completion_lists', 'date_format', 'strftime_format' /*...*/);
    expectedArguments(\PHPSTORM_META\xAdvancedCompletion(), 2, argumentsSet('x_advanced_completion_lists');
}

Solves #19

King2500 commented 2 years ago

It's been in beta test for a while...

Should also allow for Attribute arguments (i.e. __construct calls).

King2500 commented 2 years ago

Add 'http_statuscode' Completion list:

xAdvancedCompletion(\My\Class::method(), 1, 'http_statuscode');
King2500 commented 2 years ago

Also add:

namespace PHPSTORM_META {
    function xAdvancedCompletionWithArg($functionReference, $matchArgumentIndex, $matchArgumentValue, $completionArgumentIndex, $completionList, $ignoreCase = false) {
        $matchArgumentValue = \json_encode($matchArgumentValue);
        return "xAdvancedCompletionWithArg $functionReference [with $matchArgumentValue at $matchArgumentIndex] at $completionArgumentIndex: $completionList";
    }

    function xAdvancedCompletionWithPrefix($functionReference, $argumentIndex, $prefix, $completionList, $ignoreCase = false) {
        return "xAdvancedCompletionWithPrefix $functionReference [with prefix '$prefix'] at $argumentIndex: $completionList";
    }
}

Examples:

xAdvancedCompletionWithArg(\Symfony\Component\HttpFoundation\ResponseHeaderBag::set(), 0, 'Content-Type', 1, 'mime_type', /*ignoreCase:*/ true);
xAdvancedCompletionWithPrefix(\header(), 0, 'Content-Type: ', 'mime_type', /*ignoreCase:*/ true);