Haehnchen / idea-php-laravel-plugin

Laravel Framework Plugin for PhpStorm / IntelliJ IDEA
MIT License
572 stars 109 forks source link

Does not find partial namespaced controllers #95

Open webmake opened 7 years ago

webmake commented 7 years ago

Hi, using laravel modules via bundle or defining custom controllers (not in \\App\\Http\\Controllers\\ path) doesn't work neither autocomplete, neither navigation (when defining namespace and after that controller). It still autocompletes with fully namespaced controller:

Expected:
Route::group(['middleware' => 'web', 'prefix' => 'cool', 'namespace' => 'Modules\Dummy\Http\Controllers'], function()
{
    Route::get('/', 'DummyController@index');
});

Works navigation only with this, but wrongly, because actual controller Class Modules\Cool\Http\Controllers\Modules\Cool\Http\Controllers\CoolController does not exist:
Route::group(['middleware' => 'web', 'prefix' => 'cool', 'namespace' => 'Modules\Dummy\Http\Controllers'], function()
{
    Route::get('/', 'Modules\Dummy\Http\Controllers\DummyController@index');
});

I see it is hardcoded now https://github.com/Haehnchen/idea-php-laravel-plugin/blob/93285fad392c7fe221eafb2b482cd7d6b15ee3c9/src/de/espend/idea/laravel/controller/ControllerCollector.java#L28

Wouldn't it be possible at least add controllers manually in phpstorm plugin configs? Or maybe there is way bypass this?

adelf commented 7 years ago

@webmake it searches all subclasses from \Illuminate\Routing\Controller class, base laravel class for controllers. Why your bundle controllers isn't inherited from it? Do they have any common parent?

webmake commented 7 years ago

Oh sorry for desinformation a little bit,

Yes, I am extending that abstract class, and tested that works good if in group is defined namespace, but I simplified problem wrongly.

I forgot to mention that my case is that I use my own RouteServiceProvider

<?php

namespace Modules\Dummy\Providers;

use Illuminate\Routing\Router;

class RouteServiceProvider extends \Illuminate\Foundation\Support\Providers\RouteServiceProvider
{
    protected $namespace = 'Modules\Dummy\Http\Controllers';

    public function map(Router $router)
    {
        $this->mapWebRoutes($router);
    }

    protected function mapWebRoutes(Router $router)
    {
        $router->group([
            'namespace' => $this->namespace,
            'middleware' => 'web',
        ], function () {
            require __DIR__ . '/../Http/routes.php';
        });
    }
}

My controller

<?php

namespace Modules\Dummy\Http\Controllers;

class DummyController extends \Illuminate\Routing\Controller
{
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        return view('index');
    }
}

So namespace in route provider is invisible for routes.php file. autocomplete

adelf commented 7 years ago

Do you have another RouteServiceProvider in this project?

webmake commented 7 years ago

Yes, multiple, as much as modules are I guess, plus laravel installer generated default provider (app/Providers/RouteServiceProvider.php)

adelf commented 7 years ago

Ok, thanks. Multiple default controllers namespaces. It can be fixed, I think. I'll try to do it a bit later.