pyro/ide-helper

Various PyroCMS code completion improvements for ide's

1.0.7 2022-04-25 20:41 UTC

This package is auto-updated.

Last update: 2024-03-19 11:49:00 UTC


README

The purpose of this package is to provide improved code-completion for PyroCMS/Streams Platform applications and to reduce time spend reading the documentation/other code. It also allows you to tap into the docblock generation process to add your own docblocks!

Although this package has various PHPStorm specific features, it's still able to provide quite a few extras for other ide's/editors.

Version 1.1 Will feature much easier ways to create customize various auto-completions.

Installation

  1. Install using composer

    composer require pyro/ide-helper:~1.0
  2. Register service provider, preferably only when APP_ENV=local

    \Pyro\IdeHelper\IdeHelperServiceProvider::class;
  3. Run generation

    ide-helper:generate
    ide-helper:streams
    ide-helper:meta
    idea:completion
    idea:meta
    idea:toolbox

    You could wrap this in a composer run script:

    {
        "scripts": {
             "ide": [
                 "@php artisan ide-helper:generate",
                 "@php artisan ide-helper:streams",
                 "@php artisan ide-helper:meta",
                 "@php artisan idea:completion",
                 "@php artisan idea:meta",
                 "@php artisan idea:toolbox"
             ]
        }
    }   

    and run it with composer ide

  4. Install PHPStorm/IntelliJ Idea Plugins:

    • deep-assoc-completion
    • PHP Toolbox

Custom Generators

Docblock Generators
  1. Create a handler class as shown below
  2. Add the classname it to the pyro.ide-helper.docblock.generators config array.
  3. The class will be included and generated when running php artisan ide-helper:streams

Check the src/DocBlocks classes for examples.

// this will make auth()->user()->hasPermission() etc resolve properly, check screenshot below
class MyDocBlocks {
    public function handle(\Laradic\Generators\Doc\DocRegistry $registry){
        $registry->getClass(\Illuminate\Contracts\Auth\Guard::class)
            ->getMethod('user')
            ->ensureReturn([\Illuminate\Contracts\Auth\Authenticatable::class, \Anomaly\UsersModule\User\Contract\UserInterface::class]);
    }
}

ide-helper-auth-user

Toolbox Generators
  1. Create a handler class as shown below
  2. Add the classname it to the pyro.ide-helper.toolbox.generators config array.
  3. The class will be included and generated when running php artisan ide-helper:streams

Check the GenerateViewsMeta class for a easily digested example.

Check the src/DocBlocks classes for more examples.

```php
class GenerateMyMeta extends \Laradic\Idea\Toolbox\AbstractMetaGenerator
{
    protected $directory = 'custom/my'; // used in: $this->path = path_join(config('laradic.idea.toolbox.path'), $this->directory, '.ide-toolbox.metadata.json');

    public function handle()
    {
        $this->metadata()
            ->push('providers', [
                'name'  => 'my_stuff',
                'items' => [
                    ['lookup_string' => 'A',],
                    ['lookup_string' => 'B',]
                ],
            ])
            ->push('registrar', [
                'provider'  => 'my_stuff',
                'language'  => 'php',
                'signature' => [ 'my_method', 'my_method:1' ],
            ])
            ->save();
    }
}

Examples

These are just a few examples, to screenshot everything would be a big undertaking.

Docblock based

Most methods and properties in stream based related classes will now resolve properly. This is done using the same way as ide-helper:models by generating DocBlock tags in the source files

Some examples:

/**
 * Class LinkCollection
 *
 * @link http://pyrocms.com/
 * @author PyroCMS, Inc. <support@pyrocms.com>
 * @author Ryan Thompson <ryan@pyrocms.com>
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface[] all()
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface find($key, $default=null)
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface findBy($key, $value)
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface first()
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface[] get($key, $default=null)
 * etc...
 */
class LinkCollection extends EntryCollection{}
/**
 * Class LinkRepository
 *
 * @link http://pyrocms.com/
 * @author PyroCMS, Inc. <support@pyrocms.com>
 * @author Ryan Thompson <ryan@pyrocms.com>
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface first($direction = 'asc')
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface find($id)
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface findBy($key, $value)
 * @method \Pyro\MenusModule\Link\LinkCollection|\Pyro\MenusModule\Link\Contract\LinkInterface[] findAllBy($key, $value)
 * @method \Pyro\MenusModule\Link\LinkCollection|\Pyro\MenusModule\Link\Contract\LinkInterface[] findAll(array $ids)
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface create(array $attributes)
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface getModel()
 * @method \Pyro\MenusModule\Link\Contract\LinkInterface newInstance(array $attributes = [])
 * etc...         
 */
class LinkRepository extends EntryRepository implements LinkRepositoryInterface{}
/** @mixin \Pyro\MenusModule\Link\LinkRepository */
interface LinkRepositoryInterface {}
/** @mixin \Pyro\MenusModule\Link\LinkModel */
class LinkPresenter extends EntryPresenter{}
/** @mixin \Pyro\MenusModule\Link\LinkModel */
interface LinkInterface {}
/** @mixin \Pyro\MenusModule\Link\LinkModel */
class LinkPresenter extends EntryPresenter{}
Addon collections

For AddonCollection, ModuleCollection, ThemeCollection etc.
CTRL+click / CTRL+b opens the addon class file.

Views

CTRL+click / CTRL+b opens the view file.

Config

CTRL+click / CTRL+b opens the config file.
PyroCMS addon config files can have up to 3 locations. Opening resolves to the correct file!

Streams

For Repository classes in all Streams

Model completion

screenshots todo...

AddonServiceProvider properties

Module properties

FormBuilder properties

TableBuilder properties
  • Provides the same button completion as FormBuilder screenshots todo...
Twig completion (tip)

This is just a tip for when you want better code-completion in Twig files. ide-helper-twig_2

To use this: Install & Enable the symfony plugin. symfony-settings

Progress

  • DONE Discover possibilities / limitations of various completion providers (IntelliJ plugins, docblocks, metafiles, php helper files)
  • ALMOST DONE Use the appropriate completion provider for each completion.
  • IN PROGRESS Revisit all code, improve/introduce logical structure to it, cleanup mess
  • IN PROGRESS Make it extendable and configurable
Todos
  • Streams Platform
    • Addons
      • Module
        • Properties
          • Sections
          • Shortcuts
        • Methods
          • setSections
          • getSections
          • addSection
          • setShortcuts
          • getShortcuts
          • addShortcut
      • AddonCollection
      • ModuleCollection
      • ExtensionCollection
      • ThemeCollection
      • PluginCollection
      • FieldTypeCollection
      • AddonServiceProvider
        • Routes
    • UI
      • Button
      • ControlPanel
        • Methods
          • setButtons
          • getButtons
          • addButton
          • setSections
          • getSections
          • addSection
          • setNavigation
          • getNavigation
          • addNavigation
      • Form
        • Properties
          • Action
          • Button
          • Field
          • Section
          • Options
        • Methods
          • setActions
          • getActions
          • addAction
          • setButtons
          • getButtons
          • addButton
          • setSections
          • getSections
          • addSection
          • setOption
          • hasOption
          • getOption
          • setOptions
          • getOptions
      • Table
        • Row
          • getButtons
          • getColumns
        • Column
          • getEntry
        • Properties
          • Action
          • Button
          • Column
          • Filter
          • Header
          • Row
          • View
        • Methods
          • setActions
          • getActions
          • addAction
          • setButtons
          • getButtons
          • addButton
          • setColumns
          • getColumns
          • addColumn
          • setFilters
          • getFilters
          • addFilter
          • setHeaders
          • getHeaders
          • addHeader
          • setRows
          • getRows
          • addRow
          • setViews
          • getViews
          • addView
          • setOption
          • hasOption
          • getOption
          • setOptions
          • getOptions
      • Tree
  • Streams
    • Collections
    • Criterias
    • Factories
    • Models
      • Translation fields
      • Fields, methods
      • Presenter,Collection,Router,Builder
    • QueryBuilders
    • Repositories
    • Router
    • Contract
      • Interface
      • RepositoryInterface
  • Other
    • Twig
    • Views
    • Config
    • ...