plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Feature Request]: Auto-detect custom view namespaces

Open mortenscheel opened this issue 1 year ago • 2 comments

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.

mortenscheel avatar Jun 19 '24 11:06 mortenscheel

I came here looking for the same thing... the app I'm working with has various themes in public\themes<the-theme-names>\ 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;
}

Onepamopa avatar Jul 12 '24 20:07 Onepamopa

@mortenscheel, for some reason, in 2024, I decided that we don't support this. But Laravel Idea supports componentNamespace and addNamespace calls since 2022. It doesn't work in your case?

@Onepamopa, Laravel Idea doesn't run PHP. It tries to understand your code. If you write View::addNamespace('theme', __DIR__.'/some/path'); it will work.

adelf avatar Aug 21 '25 11:08 adelf