adalessa / laravel.nvim

Plugin for Nvim to work with laravel projects.
MIT License
280 stars 15 forks source link

Failed to run healthcheck for "laravel" plugin - attempt to call method 'executable' (a nil value) #81

Closed FrostiiZ closed 6 months ago

FrostiiZ commented 6 months ago

Hello !

First of all thank you for your work on laravel nvim, I'm trying to move away from PHPStorm + Laravel Idea to Nvim + your plugin and it seems like a great integration, but I'm having difficulties running it.

For some context, I firstly tried to install your plugin on a fresh install of nvchad. It was not running great, as switching to any .php file would throw me errors about mappings.lua from nvchad or PHP access refused errors. Your plugin was not able to recognize my .env file configuration (NVIM_LARAVEL_ENV and APP_SERVICE), thus forcing the use of the local configuration, but I'm using docker compose. I have my docker-compose.yml containing my dev stack at a top level, and then my laravel app in a subfolder. Not being successful, I though nvchad is the issue and conflicts with your plugin. :verbose Dotenv was showing me an empty list, unless I manually open the .env file, which then would populate :verbose Dotenv with my configuration, but your plugin was still using the local environment instead of docker because it booted with local. I also had to configure NvimTree to show gitignored files, as my .env file was gitignored, else Dotenv wasn't reading my config even after opening the file manually.

Now I tried to start over from a fresh install of nvim with kickstart.nvim, I have Lazy working and I added your plugin into it. It installed but now I'm having an error as soon as I open my laravel project with nvim and your plugin enabled.

Here's the lazy.nvim error I'm getting when opening my project : image There are no errors when opening nvim from somewhere else than a Laravel project.

And here's the error I'm getting when running :healthcheck image

When looking at :Lazy, it looks like all dependencies are loaded : image

I tried editing a Controller by calling a Model method like updateOrCreate but no autocomplete was showing, indicating me it was not working either.

Doing :Artisan routes or any other Laravel command to test would give me the same error : image

I have noticed that now doing :verbose Dotenv works right away, indicating me my .env is indeed read at startup. It was not behaving the same with nvchad.

At this point I'm not really sure what to do, I'll be happy to help you figure out if there's any true errors, or just user's fault. Thank you for your help and have a very great day !

FrostiiZ commented 6 months ago

For clarification, here is the default config I used for lazy and laravel.nvim :

return {
        "adalessa/laravel.nvim",
        dependencies = {
                "tpope/vim-dotenv",
                "MunifTanjim/nui.nvim",
                "nvimtools/none-ls.nvim",
        },
        cmd = { "Sail", "Artisan", "Composer", "Npm", "Yarn", "Laravel" },
        keys = {
                { "<leader>la", ":Laravel artisan<cr>" },
                { "<leader>lr", ":Laravel routes<cr>" },
                { "<leader>lm", ":Laravel related<cr>" },
        },
        event = { "VeryLazy" },
        config = true,
}

Here are the two .env variables I set :

NVIM_LARAVEL_ENV=docker-compose
APP_SERVICE=myLaravelContainerName

When using nvchad, :healthcheck was working with your laravel plugin and was reporting me that dependencies were working. I just had php errors because of the fact that the plugin wasn't able to use the docker-compose configuration, thus tried to make actions with my system's php binary and it is not how my environment works. My docker container have its own file permissions and all actions are performed within the container. Any action with my system's php would result in a permission error.

With PHPStorm, I have configured Docker in it so it uses my docker socket, and my php interpreter is set as the container, so all php artisan actions or everything else are performed from the container. Laravel Idea is also configured to use my container, making all actions seamless for creating controllers or models or migrations or...

I know this should be working too with your plugin's docker-compose environment, but I saw it looks for a docker-compose.yml file in the project's root folder. As my docker-compose.yml file is somewhere else at a top level directory, it shouldn't work out of the box. When I did touch docker-compose.yml in my project's folder to test, your plugin with nvchad was switching to sail mode, because sail is present in my project's files, but I'm not using it. With vanilla nvim + kickstart, the plugin does the errors I gave you earlier and cannot go any further.

I hope I gave you enough information to have a great understanding of the situation, please let me know if you have any other questions and I'll happily forward everything you need here.

adalessa commented 6 months ago

Hey thanks for the report. I was informed about this but in the branch 2.1 and I forgot the update the main branch. I have done that. Now should resolve the environment property. from main, or from new version release 2.0.3 Please update and let me know if that resolve the issue.

FrostiiZ commented 6 months ago

Hello ! Thank you for your answer, I've installed a fresh nvim with kickstart.vim again and installed your plugin, version 2.0.3. It indeed fixed the startup errors I was having when booting nvim with my Laravel project.

I did :checkhealth and everything is green but your laravel plugin uses the local environment even tho my :verbose Dotenv is indeed populated with my .env configuration; this local configuration results in throwing Permission denied PHP errors when opening a file.

I have NVIM_LARAVEL_ENV set to docker-compose and APP_SERVICE set to my container's name. As said in my previous message, my docker-compose.yml file is in a top-level directory (2 directories above), and if I recall, your plugin expects the docker-compose.yml file to be present at the project's root directory, but that is not how my environment is setup.

Regardless, the main issue pointed by this thread is indeed fixed. Thank you for your quick reaction and have a very great day !

adalessa commented 6 months ago

I see, I have been comment that use case. I pushed a change to the branch 2.1 still in development, but before merging into the main, where the check for when the environment variable is set, does not run the check, since is defined as wanted by the user. Please let me know. I am worry that the default commands for docker compose does not work given the file is not there. but I don't have it one for test. so the help is appreciated. If you are using lazy you can set the branch in the configuration.

FrostiiZ commented 6 months ago

Sincere thanks to you, you're doing an amazing work, it is always a joy to experience such reactivity onto an open-source project. I have changed my lazy.vim config to use laravel.nvim branch 2.1 and it now works like a charm.

:checkhealth laravel does confirm the docker-compose environment is in use.

I am able to perform all my artisan commands through nvim thanks to your plugin and I didn't needed to create a dummy docker-compose.yml file at the root directory of my laravel project. :Laravel and :Artisan without arguments also shows me a window to select what action I'm willing to do, which comes very handy if I can later add my own artisan command shortcuts into this list.

Regarding your docker-compose integration, I tried :Laravel and chosed the docker-compose and then ps option and it showed me the containers I'm running, like I would expect if doing docker-compose ps from my project's directory. I believe docker-compose does watch itself for the docker-compose.yml file at top-level directories until it finds one and it also works within nvim with your plugin.

You have resolved both my issues in one day and I feel like I finally can comfortably switch to nvim for my laravel project. I just need to resolve my LSP issues, I use phpactor with phpstan and ide-helper but it seems like it is having a hard time getting right all the magic methods of Laravel. It also struggles to recognize MyModel::firstWhere and methods that are inherited from the Model class, but those issues are unrelated to your plugin.

I'm marking this issue as resolved, thank you once more for your amazing help and have a very great day ! 🤝

adalessa commented 6 months ago

Thanks for the appreciation. Regarding your issues, yes I experience the same, for I have currently 2 solutions. Once is use the query method that is part of the model. in your case will be MyModel::query()->firstWhere() this in my experience with php actor gives better result, but have the problem of not being the standar that most of the developers in laravel follows. If it's just your project is ok but not for share codebase which doesn't like it. Another option it's with ide helper to use the eloquent action which modifies the vendor directory to add a mixing which will indicate the support for that. It's temporary since you have to remember every time.