laravel-idea / plugin

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

[Feature Request]: Auto-detect custom view namespaces #1008

Open mortenscheel opened 3 months ago

mortenscheel commented 3 months ago

Feature Description

The plugin already provides completion for namespaced blade views and components from vendors. It would be nice if it could also detect custom view namespaces registered within the app itself.

If I'm using simple directory modules, a module might include a ServiceProvider that registers a custom namespace like this

$this->callAfterResolving(Factory::class, function(Factory $view) {
    $view->addNamespace('foo', __DIR__ . '/resources/views');
});
$this->callAfterResolving(BladeCompiler::class, function(BladeCompiler $blade) {
    $blade->componentNamespace('App\\Foo\\View\\Components', 'foo');
});

This works, but in order to get completions, I have to manually add the path and namespace to ide.json. It would be nice if this could happen automatically like if the module was a composer package.

Onepamopa commented 2 months ago

I came here looking for the same thing... the app I'm working with has various themes in public\themes\\ but shift-click on return view('theme::something'); goes nowhere ..... very inconvenient (frustrating).

View::addNamespace('theme', theme_views_path());

define('THEME_PATH', 'themes'); // multiple
define('SELLING_THEME_PATH', 'themes/_selling'); // only a single theme

function theme_views_path(string $theme = null): string
{
    return theme_path($theme) . '/views';
}

function theme_path(string $theme = null): string
{
    if ($theme == null) {
        $theme = active_theme();
    }

    $path = public_path(THEME_PATH . DIRECTORY_SEPARATOR . strtolower($theme));

    // If the theme doesn't exist
    if (! file_exists($path) && $theme != '*') {
        return public_path(THEME_PATH . DIRECTORY_SEPARATOR . 'default');
    }

    return $path;
}