RicardoRamirezR / blade-nav.nvim

Navigating Blade views within Laravel projects
MIT License
37 stars 4 forks source link

E447: Can't find file "x-component.name" in path with customs locations #24

Open gmnz opened 1 week ago

gmnz commented 1 week ago

Hi,

So basically the problem is described in the tittle. gf doesn't work for me at all, always gives me the error mentioned above. Any ideas why this could be? The views are in these dirs:

resources/views/{common components errors staremesto vendor}

Is there any way I can help the plugin find them?

RicardoRamirezR commented 1 week ago

Hi @gmnz, the locations are Laravel one's app/View/Components and resources/views/components as Laravel docs states

gmnz commented 1 week ago

OK, so if my Laravel app is using components stored inside resources/views/other_than_components_dir, then there's no way to make "gf" work for these components? It works only for components stored in resources/views/components and its subdirs?

RicardoRamirezR commented 1 week ago

Since I’m not aware how Laravel can handle your components in non standard location, nor have any case on my own, yes the standard ones locations. PR are welcome

gmnz commented 1 week ago

I searched through the project's code and consulted it with my colleague and the method to make Laravel work with custom view paths that's used in this case is this one:

https://stackoverflow.com/questions/27458439/how-to-set-view-file-path-in-laravel -> accepted answer -> Method 3

Any hints where to start if I wanted to add support for this? If it's not too complicated I may try.

RicardoRamirezR commented 1 week ago

How are you setting the view file path?

gmnz commented 6 days ago

I'm not really sure what you're asking for. Is this it?

    View::addLocation(resource_path('views/common'));

It's used inside app/Http/Controllers/Controller.php -> __construct

RicardoRamirezR commented 6 days ago

Yes, I'll take a look at it

datsudo commented 5 days ago

This also happens to me. I have the components placed in resources/views/components but still doesn't work.

But here's the catch: the gf works when the component that I want to navigate is the first one that I open before the file that uses it:

https://github.com/user-attachments/assets/5f00d7bd-5691-4037-892e-bcecbcf6cbff

RicardoRamirezR commented 5 days ago

Hi @datsudo, thank for sharing. Is not the same issue, @gmnz has a custom view location.

Can yo load the view and wait a bit and then gf to see if happens

tylerdak commented 5 days ago

Just here to say I would love to see support added for jumping to associated blade files in custom view directories if possible (i.e. ./views instead of ./resources/views). However, the standard paths seem to be hardcoded into much of the codebase, so that might be a big undertaking.

RicardoRamirezR commented 5 days ago

@gmnz and @tylerdak, the way I'll go is to make a Artisan command to obtain the view paths and use them instead of the hardcoded's one via config flag.

As soon as a free time window appears will work on it.

RicardoRamirezR commented 4 days ago

The Artisan command is not the way to go, as you can add locations dynamically that won't be available when the command is executed.

$finder = View::getFinder();
$locations = $finder->getPaths();
dd($locations);

May be enabling exrc and in a local file you can set the paths to be searched by blade-nav. Something like .nvim.lua:

vim.g.blade_nav = {
    components_paths = {
        "resources/views/components".
        "resources/views/common".
    }
}
tylerdak commented 4 days ago

Ah yeah Artisan caveat makes sense.

Is there a simpler route for specifying paths, though? My two initial thoughts are:

RicardoRamirezR commented 4 days ago

I like the second, the first one is to global in my opinion, not all project has the same.

The second one but using defaults on exrc sound better to me. if exrc is on, Neovim will pick it automatically, you can have other options there also.

tylerdak commented 4 days ago

Ah okay, yeah didn't realize exrc had other benefits. Fairly new to nvim and haven't seen it before. Sounds good!

RicardoRamirezR commented 3 days ago

@tylerdak, @gmnz take a look at main, you can use any exrc file supported since neovim will read it automatically. i.e. .nvim.lua

vim.g.blade_nav = {
  laravel_componets = {
    "resources/views/common",
  }
}

And let me know

tylerdak commented 3 days ago

That works for me!

For anyone else, if you haven't used exrc before, it needs to be enabled somewhere in your nvim config: vim.o.exrc = true

RicardoRamirezR commented 3 days ago

Lets wait one week to see if there is any issue, and then I'll make a release