laravel-idea / plugin

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

[Bug]: Completion/navigation for `loadViewsFrom()` with multi path does not work #1071

Closed NickSdot closed 2 months ago

NickSdot commented 2 months ago

Bug description

Hi Adelf! 👋

Laravel allows an array to be passed to the view loader:

$this->loadViewsFrom(['path1', ''path1''], 'admin');

This allows to have multiple paths under one namespace. In our case is a kinda fallback-mechanism / override under the same namespace.

It seems Laravel Idea cannot handle this. Completion and navigation do not / no longer (?) work.

Would be awesome if you could have a look. Cheers & thanks in advance1

Plugin version

8.2.5.242

Operating system

MacOS

Steps to reproduce

final class ProvidesViews extends ServiceProvider
{
    /**
     * @var list<string>
     */
    protected array $viewPaths = [
        __DIR__ . '/views/',
        __DIR__ . '/Feature/views',
       // ...
    ];

    public function boot(): void
    {
        $this->loadViewsFrom($this->viewPaths, 'admin');
    }
}
image

Relevant log output

No response

adelf commented 2 months ago

Hello.

I can make this work:

$this->loadViewsFrom([
        __DIR__ . '/views/',
        __DIR__ . '/Feature/views',
       // ...
    ], 'admin');

Or you can add an ide.json file to your project with:

{
  "$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
  "view": {
    "paths": [
      {
        "path": "custom/views",
        "namespace": "admin"
      },
      {
        "path": "/resources/modules/foo",
        "namespace": "admin"
      }
    ]
  }
}
NickSdot commented 2 months ago

I can make this work:

You mean on your end it works in the current version; or that you could make it happen?

If the latter, I'd prefer and appreciate it. Always better to not maintain things in two places. 😃🙏

Edit: The Json approach works. It made me think if the following works, too. And it does. Even thouh I'd prefer to keep the array; this's good enough for the time being. So, no rush with making the arrray approach work.

$this->loadViewsFrom(__DIR__ . '/views', 'admin');
$this->loadViewsFrom(__DIR__ . '/Feature/views', 'admin');
adelf commented 2 months ago

I've implemented it. It will work in the next version. Thank you.

NickSdot commented 2 months ago

Hey Adelf! 👋

I just got my hands on the update, and would like to report back. 8.3.1.242 works as you described above. Thank you!


For others, the array must be passed in directly. Passing variables does not work.

// ✅
$this->loadViewsFrom([
    __DIR__ . '/views/',
    __DIR__ . '/Feature/views',
]; 'admin');

// ❌
$viewPaths = [
    __DIR__ . '/views/',
    __DIR__ . '/Feature/views',
];

$this->loadViewsFrom($viewPaths; 'admin');