laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
173 stars 7 forks source link

[Feature Request]: Advance Directory Modules #487

Open moisish opened 2 years ago

moisish commented 2 years ago

Feature Description

Hello,

First of all, thank you for the great plugin.

On my project I have implemented my own modules structure which is similar to nwidart/laravel-modules but I have multiple levels under the \Modules namespace.

At the moment I am using the Simple Directory modules but that's not working very well for my case. image

My modules structure can be like bellow:

modules/{moduleNameDir}
modules/{groupOfModules}/{moduleNameDir}
├── modules
|   ├── PlatformSettings
|   |   ├── Emails
|   |   |   |   Module.php
|   |   |   |
|   |   |   ├── Providers
|   |   |   |   |   ServiceProvider.php
|   |   |
|   |   ├── Notifications
|   |   |   |   Module.php
|   |   |   |
|   |   |   ├── Providers
|   |   |   |   |   ServiceProvider.php
|   |
|   ├── PlatformUsers
|   |   |   Module.php
|   |   |
|   |   ├── Providers
|   |   |   |   ServiceProvider.php

Is there anything I can do about?

I don't get any routes autocompletion for the modules and I am not sure if that's the problem or not.

The routes of the modules are included by a ServiceProvider

Route::namespace($module->getNamespace().'\App\Http\Controllers')->group($module->getRoutes());
adelf commented 2 years ago

Hello, Moisis. Yes, the custom modules structure support is weak. We are working on it. Routing declared that dynamic way isn't possible to support.

If you want to have route completion for route files declared such way(I hope these files at least under the routes directory) you can read here: https://laravel-idea.com/docs/routing#route-files-recognition

moisish commented 2 years ago

Hey @adelf,

Thanks for your reply. Let me know if there is a way to help with the modules structure.

A few more observations:

  1. Views autocompletion does not work when used loadViewsFrom on a serviceprovider This is my current implementation

    $this->loadViewsFrom($module->getBasePath('resources'), $module->getViewsNamespace());

    I tried changing my implementation of $module->getBasePath() to not return the base_path so I can do

    $this->loadViewsFrom(base_path($module->getBasePath('resources')), $module->getViewsNamespace());

    but still no luck

  2. The routes autocompletion is not working because i am using a mixin and not because of the modules structure. If I removed the mixin the autocompletion on routes work without the phpDocs as per your documentation.

I changed temporarily the Route::engagements(function () {}); to

 Route::middleware(['web', 'auth'])
        ->prefix('engagements')
        ->group(function () {
});

and I can get suggestion on routes

  1. Not modules specific - Config autocompletion is not working for config files under a directory in the root config folder. For example a config file config/api/app.php will not be autocompleted config('api.app.version')
adelf commented 2 years ago

I don't run PHP code inside PhpStorm. So, it's very hard to find these paths. I can. for example, register this view call:

$this->loadViewsFrom(base_path('Modules/Module1/resources'), 'module1');

Because it's static. But I don't understand what $module is. So, can't support this. The same is about config files and routes. I'll add a possibility to register everything in the ide.json file soon.

moisish commented 2 years ago

Ok, unfortunately I can't "hardcode" the loadViewsFrom for all modules since I have a system in place where it loops through all the active modules and runs it.

Config files is unrelated to my modules structure. On the laravel root config directory I have subdirectories with more config files in them.

Routes Mixin again is unrelated to my modules structure. On the RouteServiceProvider boot method I have Route::mixin(new RoutesMixin(), false);