Giter Club home page Giter Club logo

laravel.nvim's Introduction

Laravel.nvim

Plugin for Neovim to enhance the development experience of Laravel projects

Quick executing of artisan commands, list and navigate to routes. Information about the routes. Robust API to allow you to run any command in the way that you need.

Preview

Requirements

Treesitter, LSP Server (I use and recommend phpactor) fd to look for files as migrations when are created rg ripgrep to look usage of views

Installation

Lazy

return {
  "adalessa/laravel.nvim",
  dependencies = {
    "nvim-telescope/telescope.nvim",
    "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,
}

Dotenv is use to read environment variables from the .env file

For nicer notifications I recommend rcarriga/nvim-notify

My lazy configuration for notify is

return {
    "rcarriga/nvim-notify",
    config = function()
        local notify = require("notify")
        -- this for transparency
        notify.setup({ background_colour = "#000000" })
        -- this overwrites the vim notify function
        vim.notify = notify.notify
    end
}

Config

Default config, this can be set on the setup function In this config there are several secitions, like lsp_server which is use to interact with neovim lsp client to look for classes by the name. Currently support phpactor and intelephense as far as I know there are no other php lsp sever.

By default the plugin register several commands like Artisan Composer Npm Sail DockerCompose Yarn and Bun if you don't want them you can use register_user_commands and set it as false.

Features

In adition to the selector for the commands, routes and api, you can use some extras features Route Info Views Completion Routes Completion Route info can be seen in the above screenshots, this allows to see in the controller the route associated to it, and in case that is missing will add a diagnostic error which indicate which method is missing. This also will show error if a route is defined but the method is not defined

Note: using lazy is likely that you will not see at first since the plugin will not load until you call one of the commands, after that it is just picked up

The completions uses none-ls which was previusly know as null-ls. In case you don't want it in your config disable the feature

{
    features = {
        null_ls = {
            enable = false,
        }
    }
}

Views and Routes completion works as providing the list of the respective in the php files for the function view and route.

UI

An important part of the plugin is how to show the results of the commands, for this I decide to use nui this allow to easily interact with split and popup You can customize from the size and options. examples can be seen in the default here

Command Options

Of course not all the commands want to be run in the same way. you can specify for example which ui to use, if should skip_args. Can also set nui_opts to define how the ui should display. Also can define options this is usefull for example for make:model you may want to always use the flags -mf

  ["make:model"] = { options = { "-mf" } },

Resources

A main part when creating resources like controllers, models, etc you most likely want to open it. Since the laravel commands does not return what was created I base on the type and and provided name to look for the file here is the list that can also be customize to add in case you have custom or from a plugin that you use resources

Environments

Running your laravel app has many forms, you can use something like Laravel Herd Laravel Sail Docker Compose or just the good php artisan serve this presents a challange, a fundamental aspect you want to run the command where it should with sail, with in your docker or simple the php native executable. In order to support this there is this configuration

Since you may not want the same configuration for all you projects you can use the env variable NVIM_LARAVEL_ENV define it in your .env file in your project. If you don't se it by default will use auto_discover this will go over each definition and test base on the conditions, if they are meant will use that. In case no configuration matches will try to use the default one.

For the docker compose one also you can use an env variable to define which container will be use to run the commands.

Artisan

To run Artisan commands you can use :Artisan which will autocomplete with the available artisan command as the terminal

Not sending any arguments will run the Telescope prompt

:Artisan tinker will open the terminal inside of Neovim, with tinker

Any other command will just run and output the result on a new split

Sail

You can run shell as tinker will open a new terminal up, down, restart will notify when starting and result will show as notification

Composer

install, update, require and remove from the :Composer command

Plugin specific

Laravel cache:clear purge the cache clears the cache for commands. Laravel commands shows the list of artisan commands and executes it. Laravel routes show the list of routes and goes to the implementation. Laravel related show the list of model related classes, includes observers, policy and relations and goes to the implementation. Laravel test:watch runs the application tests and keep monitoring the changes Laravel history each command is recorded in case you want to run the same again Laravel view-finder This will look for the views that are use in the file and if only one will go to it, in case of more will show a select, in the view will look for the class that uses it Laravel recipes There are some recipes like installing ide helper and running the model and eloquent command. and to install doctrine dbal Laravel health trigger the neovim command :checkhealth laravel

Lua API

Telescope

One of the things you may want to change are actions or styles or something related to telescope The picker is require("telescope").extensions.laravel.routes so you can call it and pass the arguments as usual for telescope the same for commands, related and history

Run commands

You may want to run commands of course you can use :Artisan my-command args but you may want to pass nui options and more for that you can use

local run = require "laravel.run"
run("artisan", {"my-command"}, {})

This will be run in the nui, but you may want to do more plugins like and do something with the output for that you can call the api

local api = require "laravel.api"

Here you can use the methods sync and async I recommend the use of async that will not block the editor but there are cases that you may want to use sync. have in consideration that to avoid hanging the editor there is the default timeout from plenary The response and the value for callback is ApiResponse If you will use them I recommend peek into the code sync I use them a lot as building block for the plugin.

Self promotion

I am Ariel I am a developer and also content creator (mostly in Spanish) if you would like to show some love leave a start into the plugin and subscribe to my Youtube if you want to show even more love you can support becoming a member on Youtube. But just leaving a like or letting me know that you like and enjoy the plugin is appreciated.

Collaboration

I am open to review pr if you have ideas or ways to improve the plugin would be great.

laravel.nvim's People

Contributors

adalessa avatar dorkster100 avatar paganuzzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel.nvim's Issues

Request for Packer Instructions in Addition to Lazy.nvim

I hope this message finds you well. I'm a user of adalessa/laravel.nvim, and I've been greatly enjoying the functionality it offers for Laravel development within Neovim. Firstly, thank you for developing such a useful plugin!

I wanted to bring up a suggestion for enhancing the user experience. Currently, the plugin includes instructions for integration with Lazy.nvim in the repository's README. However, I noticed that there are no instructions provided for users who prefer to use the Packer plugin manager. Packer is gaining popularity as a lightweight and efficient plugin manager, and having instructions for Packer integration would help users who opt for this manager.

I have attempted to integrate adalessa/laravel.nvim with Packer using the following configuration:

  use {
    "adalessa/laravel.nvim",
    requires = {
      "nvim-telescope/telescope.nvim",
      "tpope/vim-dotenv",
      "MunifTanjim/nui.nvim",
    },
    cmd = { "Sail", "Artisan", "Composer", "Npm", "Yarn", "Laravel" },
    keys = {
      { "<leader>la", ":Laravel artisan<cr>" },
      { "<leader>lr", ":Laravel routes<cr>" },
      {
        "<leader>lt",
        function()
          require("laravel.tinker").send_to_tinker()
        end,
        mode = "v",
        desc = "Laravel Application Routes",
      },
    },
    event = { "VeryLazy" },
    config = function()
      require("laravel").setup()
      require("telescope").load_extension "laravel"
    end,
  }

However, this configuration does not seem to work as expected. I've verified that my Packer installation is functional and have successfully integrated other plugins with it.
Thank you for your consideration.

Cannot get the plugin work.

I use docker-compose, not sail.

When neovim starts, the following error is printed:

[laravel] [ERROR 11:00:41] /Users/xxx/.vim/plugged/laravel.nvim/lua/laravel/dev.lua:33: 1683774039 app.routes(): stderr { 'service "" is not running container #1' }

I use vim-plug and the configuration is as follows:

Plug 'adalessa/laravel.nvim'

lua << EOF
require('laravel').setup({})
require('telescope').load_extension "laravel"
EOF

Running test:watch only on current method or current file

Would be nice to add watch only for one method or one file as it may be too much to run whole test suite every time. Probably a simple treesitter parse.

I can implement this, it seems to be simple considering the watch runner that is in the project.

Plugin is assuming docker is running, even with NVIM_LARAVEL_ENV=local

It seems that this plugin is checking if docker is running when calling a command like Laravel artisan or Laravel routes.

I am setting the .env var NVIM_LARAVEL_ENV=local to let the plugin know I am running everything locally

[laravel] [ERROR 09:08:57] .../.local/share/nvim/lazy/laravel.nvim/lua/laravel/dev.lua:33: 1684739291 app.routes(): stderr { 'time="2023-05-22T09:08:57+02:00" level=warning msg="network devspread_server: network.external.name is deprecated. Please set network.name with external: true"', "Cannot connect to the Docker daemon at unix:///[[REDACTED]].
Is the docker daemon running?" }

adding flags

Problem:
i dont think we can add flags while making *(model, controller, etc) using this plugin. for example if i try to add add --resource flag to the make:controller option selected telescope meny by entering the controller name and the flags in the Argument name field, as expected it just created a controller with name of "Name --flag". refer the image below
image

Potential solution:
instead of asking users for the name of the thing they make how about let the enter any that are supposed to be entered after make:*. For example,

instead of asking:
Argument name <require>: NewController --resource
and do:
...
class People --resource extends Controller
...

how about asking:
Name + flags <required>: NewController --resource
and do:
split the input by " "(space) and pass it to the command ( php artisan ...)

Docker compose not working anymore

The problem is that compose executable does not exist for me, is there a reason it is not docker-compose? Replacing compose with docker-compose in this file fixes this issue for me.

  create_user_command("DockerCompose", "compose", {
    up = function()
      api.async(
        "compose",
        { "up", "-d" },
        ---@param response ApiResponse
        function(response)
          if response:failed() then
            vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
          else
            vim.notify("Compose Up Completed", vim.log.levels.INFO)
            status.refresh()
          end
        end
      )
    end,

On another note, create_user_command for some reason does register DockerCompose every other time even with non existing executable compose, so there is also some issue with that.

Support `ViewController` in route open

When opening a route that was defined from Route::view is define with the controller ViewController this is not correct, in this case want to open the view directly. Problem is that can't get directly from the route:list command. For now show a warning

[Feature request] Model list and Model info

It would be great to be able to see the model structure right from NeoVim.

Laravel has this ./artisan model:show <ModelName>, i.e.:

[21:27:50] (000) ~/p/m/m/sandbox ❯❯❯ ./artisan model:show Group

  App\Models\Group ..................................................................  
  Database .................................................................... pgsql  
  Table ...................................................................... groups  

  Attributes ............................................................ type / cast  
  id increments, unique ................................................ bigint / int  
  name unique, fillable ................................................. string(255)  
  description nullable, fillable ............................................... text  
  service fillable .......................................................... boolean  

  Relations .........................................................................  

  Observers .........................................................................

Seeing that in Telescope as a model list with a previewer showing colored model info (as it is in the console) would be awesome.

Failed to run config for laravel.nvim - attempt to call method 'executable' (a nil value)

Upon entering a laravel project I now get the following error, though it worked before my vacation:

image

This is my configuration

local laravel = {
	"adalessa/laravel.nvim",
	dependencies = {
		"nvim-telescope/telescope.nvim",
		"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>" },
		{
			"<leader>lt",
			function()
				require("laravel.tinker").send_to_tinker()
			end,
			mode = "v",
			desc = "Laravel Application Routes",
		},
	},
	event = { "VeryLazy" },
	config = function()
		require("laravel").setup() -- Line 251
		require("telescope").load_extension("laravel")
	end,
}

And my .zshrc contains

export NVIM_LARAVEL_ENV=local

Selector base on the resources

A lot of time want to open just the controllers, or the models, etc, the easiest way could be base on the resouces configuration since already have the directory define. May need to re-structure a couple of them but will be an improvement

Terminal runner was still useful?

I may not fully understand, but doesn't the terminal runner have some things the buffer runner cannot do? For example after the completion of the task any button press closes the buffer, so i cannot copy the text from it or scroll.

Also when running tinker command it asks me to include something - which is kind of weird?

I may as well be ignorant, if you are using the buffer runner in some cool ways, let me know, I may not know how to use it properly.

Support docker-compose without Sail

The project I work on does not use Laravel Sail, but I do use docker-compose. It would be nice to make the plugin extendable and usable without Sail. Do I understand correctly that we only need to add a setting to replace /vendor/bin/sail and have /vendor/bin/sail as default?

Usage i have in mind is to use docker-compose exec app to replace /vendor/bin/sail

Companion Package.

In several issues has been requested different features that currently there is no a direct solution. Most of them can be solve using some php reflection, or inheritance check.

Here I have state my line of thoughts. #21 (comment)

The more I think I think having the companion package and install as a dev dependency makes more sense.

Taking for example the ide-helper package is not uncommon to have a utility for the editor as a dev dependency.

The companion package could be easily installed from the plugin it self (after confirmation of the user). Or that option be disable.

Some features, commands or scripts could have a dependency check to see if the plugin is installed or not.

This is an open discussion, I appreciate your feedback. Would you mind if the plugin ask and install a composer package in your project ?

Request for Argument when Opening Tinker

Request for Argument when Opening Tinker

When executing the command to open Tinker from Telescope, it prompts for an additional argument. If I enter anything, it generates an error, but if I press [Esc], it allows me to access Tinker normally.

image

Related files picker

Hey there!

Stumbled on your plugin by accident, will for sure give it a try.

One cool picker would be related files.

For example when you are on a Model :Laravel related could show:

  • Filament resource
  • Migrations
  • Policy
  • ...

This could be done based on the name of the model I guess?

New Action to open route in the browser

I want to be able to open the selector route in the browser.
Using something like vim.fn.system({"xdg-open", "http://localhost:8000/settings"})
Should check the os, or to see if the xdg-open is executable, if not the open for mac.

To get the base url should get it from the config of the project from app.url

[Bug] Laravel.nvim hits error when trying to run commands using other plugins

So there's this somewhat annoying error:

E5108: Error executing lua: vim/_editor.lua:0: nvim_exec2()..function <SNR>91_parse_flags[84]..<SNR>91_start[16]..<SNR>91_run[9]..<SNR>91_chdir_p
ush[3]..DirChanged Autocommands for "*": Vim(append):Error executing lua callback: .../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:10
6: vendor/bin/sail: Executable not found
stack traceback:
        .../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:106: in function 'new'
        ...are/nvim/lazy/laravel.nvim/lua/laravel/runners/async.lua:28: in function <...are/nvim/lazy/laravel.nvim/lua/laravel/runners/async.lua:
8>
        .../nvim/lazy/laravel.nvim/lua/laravel/application/init.lua:88: in function 'run'
        ...al/share/nvim/lazy/laravel.nvim/lua/laravel/commands.lua:37: in function 'load'
        .../nvim/lazy/laravel.nvim/lua/laravel/application/init.lua:68: in function 'warmup'
        ....local/share/nvim/lazy/laravel.nvim/lua/laravel/init.lua:23: in function 'setup'
        ...are/nvim/lazy/laravel.nvim/lua/laravel/_autocommands.lua:10: in function <...are/nvim/lazy/laravel.nvim/lua/laravel/_autocommands.lua:
9>
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        /home/naquad/.config/nvim/lua/plugins/nvimtree.lua:23: in function </home/naquad/.config/nvim/lua/plugins/nvimtree.lua:9>
stack traceback:
        [C]: in function 'error'
        .../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:106: in function 'new'
        ...are/nvim/lazy/laravel.nvim/lua/laravel/runners/async.lua:28: in function <...are/nvim/lazy/laravel.nvim/lua/laravel/runners/async.lua:
8>
        .../nvim/lazy/laravel.nvim/lua/laravel/application/init.lua:88: in function 'run'
        ...al/share/nvim/lazy/laravel.nvim/lua/laravel/commands.lua:37: in function 'load'
        .../nvim/lazy/laravel.nvim/lua/laravel/application/init.lua:68: in function 'warmup'
        ....local/share/nvim/lazy/laravel.nvim/lua/laravel/init.lua:23: in function 'setup'
        ...are/nvim/lazy/laravel.nvim/lua/laravel/_autocommands.lua:10: in function <...are/nvim/lazy/laravel.nvim/lua/laravel/_autocommands.lua:
9>
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        /home/naquad/.config/nvim/lua/plugins/nvimtree.lua:23: in function </home/naquad/.config/nvim/lua/plugins/nvimtree.lua:9>
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        /home/naquad/.config/nvim/lua/plugins/nvimtree.lua:23: in function </home/naquad/.config/nvim/lua/plugins/nvimtree.lua:9>

It happens when you switch to the NvimTree window and run some custom command there. I'm not sure if there's a fix from the NvimTree side but IMHO it shouldn't be there

Laravel.nvim should be playing nice with others and do a sanity check before running anything.

STR

  1. cd to a Laravel project
  2. Open some PHP file
  3. Open NvimTree
  4. Jump between NvimTree and the buffer (may take several switches, also you may have to change the NvimTree current directory)

Route infos get cut on small screens

I don't know if it's possible, but I really wish the route infos would wrap to the next line instead of disapearing at the end of the window like so
image

Some artisan commands do not take required input

When trying to run some of the artisan commands that require input the terminal is not letting pass any input.
For example when running php artisan enforce:query I am not able to write yes or even insert <cr>

Going to a route doesn't work when using intelephense

I get the following error when I try to go to a route through telescope (running :Laravel routes)

Even though it lists all the routes that I have, I only get this when I try to go to a route.

I switched to phpactor just to see if it works, and it works fine with phpactor. But I personally would love to keep intelephense as my lsp server.

Client 1 quit with exit code 1 and signal 0                                                                                                                                               
Error executing vim.schedule lua callback: ...ker/start/laravel.nvim/lua/laravel/_lsp/intelephense.lua:16: attempt to index local 'resp' (a nil value)
stack traceback:
        ...ker/start/laravel.nvim/lua/laravel/_lsp/intelephense.lua:16: in function 'go_to'
        ...te/pack/packer/start/laravel.nvim/lua/laravel/routes.lua:32: in function 'go_to'
        ...start/laravel.nvim/lua/telescope/_extensions/laravel.lua:206: in function <...start/laravel.nvim/lua/telescope/_extensions/laravel.lua:205>

Attempt to concatenate local 'env_name' (a nil value)

My config is as suggested:

  {
    "adalessa/laravel.nvim",
    dependencies = {
      "nvim-telescope/telescope.nvim",
      -- which-key integration
      {
        "folke/which-key.nvim",
        opts = {
          defaults = {
            ["<leader>cp"] = { name = "+php" },
          },
        },
      },
    },
    cmd = { "Sail", "Artisan", "Composer", "Npm", "Yarn", "Laravel" },
    keys = {
      { "<leader>cpa", ":Laravel artisan<cr>", desc = "Artisan" },
      { "<leader>cpr", ":Laravel routes<cr>", desc = "Routes" },
      {
        "<leader>cpt",
        function()
          require("laravel").app.sendToTinker()
        end,
        mode = "v",
        desc = "Laravel Application Routes",
      },
    },
    ft = { "blade", "php" },
    config = function()
      require("laravel").setup()
      require("telescope").load_extension("laravel")
    end,
  }

I am getting this error message:
image

Help needed laravel.environment.resolver

Hey everyone, i'm kinda new to the nvim, lazy, etc, so im having some troubles setting up laravel.environment.resolver .
I'm getting an error module laravel.environment.resolver not found.
Can someone guide me on how to set this up, where do i need to pass 'NVIM_LARAVEL_ENV' variable so that the plugin can read it.
Sorry if this is stupid question :D

image

Rename `php_execute`

The function in api implies that runs php but it's more, it's run the given php in tinker.

Add `fd` requirement

Currently fd is use for finding the migration but if is not install in the system breaks the code.
The migration is created but there is the ugly error and confusion to the user.

Also add it to the docs

ref: https://github.com/sharkdp/fd

Can you add options to artisan commands?

So i user :Laravel artisan command and i want to do for example make:test can i pass -p option for pest test somehow? I see in code that it should ask for Options in some cases, it does not for make:test?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.