deep-assoc-completion icon indicating copy to clipboard operation
deep-assoc-completion copied to clipboard

Customize completion

Open RobinRadic opened this issue 5 years ago • 8 comments

Not entirely sure if this belongs in / duplicates #106 so il just do it here.

It would be awesome if it was somehow possible to tweak the completion window stuff. Like custom icon, tail text, type text, etc.

An example: (by using PHP Toolbox plugin using this config)

image

RobinRadic avatar Dec 07 '19 06:12 RobinRadic

Hi. Do you only want to customize how it looks, or you want to add more options to the completion based on a config file (like "in such and such method provide completion based on that and that")?

If it's just about styling, in your link there are different icons for different keywoards, do you want to stylize each keywoard separately here as well?

Could you post an example of the hypothetical config file for deep-assoc to help me grasp how it is supposed to work? Will it be like "in the return value of method A for key B use such icon and such tail/type text"?

klesun avatar Dec 07 '19 10:12 klesun

Maby something like this? My idea would be to use comments on array keys to define the characteristics of the completion item.

Note: The exact syntax to use in this array key definition comment could/should be improved.. this is just an example.


class Examples
{
    public static function booleanCompletion()
    {           
        return [
            /** type_text:"string", tail_text:"checkbox|toggle|radio|switch", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'mode'          => '',
            /** type_text:"string", tail_text:"The label text", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'label'         => '',
            /** type_text:"string", tail_text:"The text on displayed when using toggle or switch", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'on_text'       => '',
            /** type_text:"string", tail_text:"success|info|primary|warning", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'on_color'      => 'success',
            /** type_text:"string", tail_text:"The text on displayed when using toggle or switch", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'off_text'      => '',
            /** type_text:"string", tail_text:"success|info|primary|warning", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'off_color'     => 'danger',
            /** type_text:"bool", tail_text:"true|false", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'default_value' => false,
            /** type:"App\\BooleanHandler", type_text:"BooleanHandler", tail_text:"true|false", icon:"com.jetbrains.php.PhpIcons.FUNCTION" */
            'handler' => Examples::class,
        ];
    }

    /**
     * @param array $options = static::booleanCompletion()
     */
    public function setBoolean(array $options)
    {
    }

    /**
     * @return array = static::booleanCompletion()
     */
    public function getBoolean()
    {

    }

    public function handleBoolean()
    {
        $this->setBoolean([
            '<CARET>'
        ]);
        $boolean = $this->getBoolean();
        $boolean[ '<CARET>' ];
    }
}

RobinRadic avatar Dec 07 '19 12:12 RobinRadic

Also, would something like this; return type based on the given parameter value, be possible? Sure we got the meta file stuff for that, but doing it inline would be kinda cool as well.


    public static function addonType()
    {
        return [
            /** tail_text:"field type", type:"Anomaly\\CheckboxFieldType\\CheckboxFieldType", type_text:"CheckboxFieldType", icon:"com.jetbrains.php.PhpIcons.CLASS" */
            'anomaly.field_type.checkbox',
            /** tail_text:"module", type:"Anomaly\\UsersModule\\UsersModule", type_text:"UsersModule", icon:"com.jetbrains.php.PhpIcons.CLASS" */
            'anomaly.module.users',
        ];
    }
    
    /**
     * @param string $namespace = static::addonType()
     *
     * @return mixed
     */
    public function getAddon($namespace)
    {

    }

    public function handleAddon()
    {
        $this->getAddon('<CARET>');
        $module = $this->getAddon('anomaly.module.users'); // returns type Anomaly\UsersModule\UsersModule
        $module->foo(); // resolves properly to Anomaly\UsersModule\UsersModule->foo()
    }

RobinRadic avatar Dec 07 '19 12:12 RobinRadic

Hm, meta info for display looks pretty easy to implement. Would you mind if it was actual json (or at least JSON5) in the comments? Less headache parsing it...

Like that:

public static function booleanCompletion()
{           
    return [
        /** {type_text:"string", tail_text:"checkbox|toggle|radio|switch", icon:"com.jetbrains.php.PhpIcons.FUNCTION"} */
        'mode'          => '',

klesun avatar Dec 07 '19 12:12 klesun

Awesome!

Using a JSON/JSON5 sounds good to me. You could also consider using a PHP array, for better consistency with other doc comments?

How about also implementing the target meta? info. It is used for CTRL+click/CTRL+b. Examples from PHP Toolbox:

  • file: "target": "file:///config/database.php",
  • file with line/col: "target": "file:///config/database.php:23:14",
  • class "target": "Anomaly\\AddonsModule\\AddonsModule"
  • method/prop "target": "Anomaly\\AddonsModule\\AddonsModule::getType()"

RobinRadic avatar Dec 07 '19 19:12 RobinRadic

php array it is then Released basic support in 2019.12.08.001 image

Don't have much time left now, will implement the target later (few weeks from now maybe).

klesun avatar Dec 08 '19 01:12 klesun

Regarding reusing the parameter type info in return, I just rolled out an update that allows referencing function arguments in the php doc expression - 2019.12.08.002

It does not reuse the new key metadata comment feature, but there are various other ways to specify the relation between the keyword string and the class.

image

Click to expand code
<?php
namespace Anomaly\CheckboxFieldType {
    class CheckboxFieldType {
        public $fieldId;
    }
}

namespace Anomaly\UsersModule {
    class UsersModule {
        public $userId;
        public function userFoo() {}
    }
}

namespace Ololo {
    class Main
    {
        public static function addonTypeFqns()
        {
            return [
                /** ['tail_text' => "field type", 'type_text' => "CheckboxFieldType", 'icon' => "com.jetbrains.php.PhpIcons.CLASS" */
                'anomaly.field_type.checkbox' => \Anomaly\CheckboxFieldType\CheckboxFieldType::class,
                'anomaly.module.users' => \Anomaly\UsersModule\UsersModule::class,
            ];
        }
        public static function addonType()
        {
            return array_keys(self::addonTypeFqns());
        }
        /**
         * @param string $namespace = static::addonType()[$any]
         *
         * @return object = new (self::addonTypeFqns()[$namespace])
         */
        public function getAddon($namespace) {}

        public function handleAddon()
        {
            $module = $this->getAddon('anomaly.module.users'); // returns type Anomaly\UsersModule\UsersModule
            $module->userFoo();
        }
    }
}

klesun avatar Dec 08 '19 04:12 klesun

Again i was happily coding, then saw the intellij popup with deep-assoc-completion update. Friggin awesome man.

RobinRadic avatar Dec 08 '19 05:12 RobinRadic