Skip to content

Commit 74b8145

Browse files
authored
Merge pull request #108 from adalessa/development
3.0 Version Merge
2 parents aabe7c5 + 9afecad commit 74b8145

File tree

169 files changed

+4860
-3200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+4860
-3200
lines changed

.neoconf.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"library": {
44
"plugins": [
55
"telescope.nvim",
6-
"plenary.nvim"
6+
"plenary.nvim",
7+
"cmp.nvim",
8+
"promise-async"
79
]
810
}
911
},

README.md

Lines changed: 4 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,13 @@
1+
# Breaking Changes
2+
I have re-written most of the plugin so in case you need to stay in an old version use the tagged version `v2.2.1` and not master.
3+
14
# Laravel.nvim
25
Plugin for Neovim to enhance the development experience of Laravel projects
36

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

7-
## Preview
8-
![](./images/telescope_commands.png)
9-
![](./images/telescope_routes.png)
10-
![](./images/route_info.png)
11-
12-
## Requirements
13-
Treesitter, LSP Server (I use and recommend [phpactor](https://github.com/phpactor/phpactor))
14-
`fd` to look for files as migrations when are created
15-
`rg` ripgrep to look usage of views
16-
17-
## Installation
18-
Lazy
19-
```lua
20-
return {
21-
"adalessa/laravel.nvim",
22-
dependencies = {
23-
"nvim-telescope/telescope.nvim",
24-
"tpope/vim-dotenv",
25-
"MunifTanjim/nui.nvim",
26-
"nvimtools/none-ls.nvim",
27-
},
28-
cmd = { "Sail", "Artisan", "Composer", "Npm", "Yarn", "Laravel" },
29-
keys = {
30-
{ "<leader>la", ":Laravel artisan<cr>" },
31-
{ "<leader>lr", ":Laravel routes<cr>" },
32-
{ "<leader>lm", ":Laravel related<cr>" },
33-
},
34-
event = { "VeryLazy" },
35-
opts = {
36-
features = {
37-
null_ls = {
38-
enable = true,
39-
},
40-
route_info = {
41-
enable = true, --- to enable the laravel.nvim virtual text
42-
position = 'right', --- where to show the info (available options 'right', 'top')
43-
middlewares = true, --- wheather to show the middlewares section in the info
44-
method = true, --- wheather to show the method section in the info
45-
uri = true --- wheather to show the uri section in the info
46-
},
47-
},
48-
},
49-
config = true,
50-
}
51-
```
52-
Dotenv is use to read environment variables from the `.env` file
53-
54-
For nicer notifications I recommend `rcarriga/nvim-notify`
55-
56-
My lazy configuration for notify is
57-
```lua
58-
return {
59-
"rcarriga/nvim-notify",
60-
config = function()
61-
local notify = require("notify")
62-
-- this for transparency
63-
notify.setup({ background_colour = "#000000" })
64-
-- this overwrites the vim notify function
65-
vim.notify = notify.notify
66-
end
67-
}
68-
```
69-
70-
## Config
71-
72-
Default [config](./lua/laravel/config/default.lua), this can be set on the `setup` function
73-
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.
74-
Currently support `phpactor` and `intelephense` as far as I know there are no other php lsp sever.
75-
76-
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
77-
`register_user_commands` and set it as `false`.
78-
79-
80-
## Features
81-
In adition to the selector for the commands, routes and api, you can use some extras features *Route Info* *Views Completion* *Routes Completion*
82-
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
83-
add a diagnostic error which indicate which method is missing.
84-
![](./images/route_info.png)
85-
This also will show error if a route is defined but the method is not defined
86-
![](./images/missing_method.png)
87-
88-
> 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
89-
90-
The completions uses `none-ls` which was previusly know as `null-ls`.
91-
In case you don't want it in your config disable the feature
92-
```lua
93-
{
94-
features = {
95-
null_ls = {
96-
enable = false,
97-
}
98-
}
99-
}
100-
```
101-
Views and Routes completion works as providing the list of the respective in the php files for the function `view` and `route`.
102-
103-
## UI
104-
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
105-
You can customize from the size and options. examples can be seen in the default [here](./lua/laravel/config/ui.lua)
106-
107-
## Command Options
108-
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`.
109-
Can also set `nui_opts` to define how the ui should display.
110-
Also can define options this is usefull for example for `make:model` you may want to always use the flags `-mf`
111-
```lua
112-
["make:model"] = { options = { "-mf" } },
113-
```
114-
115-
## Resources
116-
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
117-
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
118-
you use [resources](./lua/laravel/config/resources.lua)
119-
120-
121-
122-
# Environments
123-
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
124-
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.
125-
In order to support this there is this [configuration](./lua/laravel/config/environments.lua)
126-
127-
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.
128-
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.
129-
In case no configuration matches will try to use the default one.
130-
131-
For the docker compose one also you can use an env variable to define which container will be use to run the commands.
132-
133-
## Artisan
134-
To run Artisan commands you can use `:Artisan` which will autocomplete with the available
135-
artisan command as the terminal
136-
137-
Not sending any arguments will run the Telescope prompt
138-
139-
`:Artisan tinker` will open the terminal inside of Neovim, with tinker
140-
141-
Any other command will just run and output the result on a new split
142-
143-
## Sail
144-
You can run `shell` as tinker will open a new terminal
145-
`up`, `down`, `restart` will notify when starting and result will show as notification
146-
147-
## Composer
148-
`install`, `update`, `require` and `remove` from the `:Composer` command
149-
150-
## Plugin specific
151-
`Laravel cache:clear` purge the cache clears the cache for commands.
152-
`Laravel artisan` shows the list of artisan commands and executes it.
153-
`Laravel routes` show the list of routes and goes to the implementation.
154-
`Laravel related` show the list of model related classes, includes observers, policy and relations and goes to the implementation.
155-
`Laravel test:watch` runs the application tests and keep monitoring the changes
156-
`Laravel history` each command is recorded in case you want to run the same again
157-
`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
158-
`Laravel recipes` There are some recipes like installing ide helper and running the model and eloquent command. and to install doctrine dbal
159-
`Laravel health` trigger the neovim command `:checkhealth laravel`
160-
161-
## User commands
162-
Is normal that you may want to define custom commands for example you don't want
163-
to always have to add the flag `--seed` to migrate but don't want to overwrite the default artisan command
164-
for that you can define custom commands for the different executables and have them list for you
165-
check [config](./lua/laravel/config/user_commands.lua) to see an example you can acces them from the command `:LaravelMyCommands` or from `:Laravel commands`
166-
167-
168-
## Lua API
169-
### Telescope
170-
One of the things you may want to change are actions or styles or something related to telescope
171-
The picker is `require("telescope").extensions.laravel.routes` so you can call it and pass the arguments as usual for telescope
172-
the same for `commands`, `related` and `history`
173-
174-
### Run commands
175-
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
176-
```lua
177-
local run = require "laravel.run"
178-
run("artisan", {"my-command"}, {})
179-
```
180-
181-
This will be run in the nui, but you may want to do more plugins like and do something with the output
182-
for that you can call the `api`
183-
184-
```lua
185-
local api = require "laravel.api"
186-
```
187-
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.
188-
have in consideration that to avoid hanging the editor there is the default timeout from plenary
189-
The response and the value for callback is [ApiResponse](./lua/laravel/api/response.lua)
190-
If you will use them I recommend peek into the code sync I use them a lot as building block for the plugin.
191-
10+
Check the Oficial Docs [Doc](https://adalessa.github.io/laravel-nvim-docs/)
19211

19312
# Self promotion
19413
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](https://youtube.com/@Alpha_Dev) 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.

doc/laravel.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ Author: Ariel D'Alessandro
44
Repo: https://github.com/adalessa/laravel.nvim
55
License: Same terms as Vim itself (see |license|)
66

7-
Usage *laravel* *:Artisan*
7+
Usage *laravel* *:Laravel*
88

99
vim:tw=78:et:ft=help:norl:

ftplugin/blade.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--- Here set things for blade
2+
vim.keymap.set({ "n" }, "fg", function()
3+
vim.print("Here needs to find the view if in extends or how")
4+
5+
vim.cmd("normal! fg")
6+
end, { buffer = 0 })

ftplugin/php.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--- Here set things for php buffers
2+
3+
vim.keymap.set({ "n" }, "fg", function()
4+
vim.print("checks if is in a view if not trigger the old fg")
5+
6+
vim.cmd("normal! fg")
7+
end, { buffer = 0 })

images/missing_method.png

-89.7 KB
Binary file not shown.

images/route_info.png

-384 KB
Binary file not shown.

images/telescope_commands.png

-195 KB
Binary file not shown.

images/telescope_routes.png

-184 KB
Binary file not shown.

lua/laravel/_lsp/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local phpactor = require "laravel._lsp.phpactor"
22
local intelephense = require "laravel._lsp.intelephense"
3-
local config = require "laravel.config"
3+
local app = require "laravel".app
44

55
local servers = {
66
phpactor = phpactor,
@@ -16,7 +16,7 @@ local get_client = function(server_name)
1616

1717
if not client then
1818
local server = require("lspconfig")[server_name]
19-
local client_id = vim.lsp.start(server.make_config(vim.fn.getcwd()))
19+
local client_id = vim.lsp.start(server.make_config(vim.loop.cwd()))
2020
if not client_id then
2121
error "Could not start lsp client"
2222
end
@@ -30,7 +30,7 @@ end
3030
---@param full_class string
3131
---@param method string
3232
local go_to = function(full_class, method)
33-
local server_name = config.options.lsp_server
33+
local server_name = app('options'):get().lsp_server
3434

3535
local server = servers[server_name]
3636
if server == nil then

0 commit comments

Comments
 (0)