Skip to content

Commit a0ee401

Browse files
authored
Merge pull request #83 from adalessa/2.1
2.1
2 parents ef57e6a + 876823d commit a0ee401

Some content is hidden

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

43 files changed

+1353
-369
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ You can run `shell` as tinker will open a new terminal
135135

136136
## Plugin specific
137137
`Laravel cache:clear` purge the cache clears the cache for commands.
138-
`Laravel commands` shows the list of artisan commands and executes it.
138+
`Laravel artisan` shows the list of artisan commands and executes it.
139139
`Laravel routes` show the list of routes and goes to the implementation.
140140
`Laravel related` show the list of model related classes, includes observers, policy and relations and goes to the implementation.
141141
`Laravel test:watch` runs the application tests and keep monitoring the changes
@@ -144,6 +144,13 @@ You can run `shell` as tinker will open a new terminal
144144
`Laravel recipes` There are some recipes like installing ide helper and running the model and eloquent command. and to install doctrine dbal
145145
`Laravel health` trigger the neovim command `:checkhealth laravel`
146146

147+
## User commands
148+
Is normal that you may want to define custom commands for example you don't want
149+
to always have to add the flag `--seed` to migrate but don't want to overwrite the default artisan command
150+
for that you can define custom commands for the different executables and have them list for you
151+
check [config](./lua/laravel/config/user_commands.lua) to see an example you can acces them from the command `:LaravelMyCommands` or from `:Laravel commands`
152+
153+
147154
## Lua API
148155
### Telescope
149156
One of the things you may want to change are actions or styles or something related to telescope

lua/laravel/api/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function M.is_composer_package_install(package)
5454
return M.sync("composer", { "info", package }):successful()
5555
end
5656

57-
function M.php_execute(code)
57+
function M.tinker_execute(code)
5858
return M.sync("artisan", { "tinker", "--execute", "echo " .. code })
5959
end
6060

lua/laravel/app/config.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local api = require "laravel.api"
2+
3+
local cache = {}
4+
5+
local M = {}
6+
7+
--- Get value from app config
8+
---@param name string
9+
function M.get(name)
10+
if cache[name] then
11+
return cache[name]
12+
end
13+
14+
local response = api.tinker_execute(string.format('json_encode(config("%s"))', name))
15+
if response:failed() then
16+
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
17+
return nil
18+
end
19+
20+
local conf = vim.fn.json_decode(response:first())
21+
22+
cache[name] = conf
23+
24+
return conf
25+
end
26+
27+
return M

lua/laravel/config/default.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
---@class NullLsFeature
2+
---@field enable boolean
3+
4+
---@class RouteInfoFeature
5+
---@field enable boolean
6+
---@field position string
7+
8+
---@class LaravelFeatures
9+
---@field null_ls NullLsFeature
10+
---@field route_info RouteInfoFeature
11+
12+
---@class LaravelOptions
13+
---@field lsp_server string
14+
---@field register_user_commands boolean
15+
---@field features LaravelFeatures
16+
---@field ui LaravelOptionsUI
17+
---@field commands_options table
18+
---@field environments LaravelOptionsEnvironments
19+
---@field user_commands table
20+
---@field resources table
121
return {
222
lsp_server = "phpactor",
323
register_user_commands = true,
@@ -13,5 +33,6 @@ return {
1333
ui = require "laravel.config.ui",
1434
commands_options = require "laravel.config.command_options",
1535
environments = require "laravel.config.environments",
36+
user_commands = require "laravel.config.user_commands",
1637
resources = require "laravel.config.resources",
1738
}

lua/laravel/config/environments.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
---@class EnvironmentCondition
2+
---@field file_exists string[]|nil
3+
---@field executable string[]|nil
4+
5+
---@class LaravelEnvironmentConfig
6+
---@field name string
7+
---@field condition EnvironmentCondition
8+
---@field commands table|nil
9+
10+
---@class LaravelOptionsEnvironments
11+
---@field env_variable string
12+
---@field auto_dicover boolean
13+
---@field default string
14+
---@field definitions LaravelEnvironmentConfig[]
115
return {
216
env_variable = "NVIM_LARAVEL_ENV",
317
auto_dicover = true,

lua/laravel/config/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
22

3-
---@class LaravelOptions
3+
---@type LaravelOptions
44
M.defaults = require "laravel.config.default"
55

66
--- @type LaravelOptions

lua/laravel/config/resources.lua

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
1-
-- each element represent a command that after execution should open a file
2-
-- if the return is a string is use as directory to search file.
3-
-- if the return is a function will call and expects the result to be an string
41
return {
5-
["make:cast"] = "app/Casts",
6-
["make:channel"] = "app/Broadcasting",
7-
["make:command"] = "app/Console/Commands",
8-
["make:component"] = "app/View/Components",
9-
["make:controller"] = "app/Http/Controllers",
10-
["make:event"] = "app/Events",
11-
["make:exception"] = "app/Exceptions",
12-
["make:factory"] = function(name)
13-
return string.format("database/factories/%sFactory.php", name)
14-
end,
15-
["make:job"] = "app/Jobs",
16-
["make:listener"] = "app/Listeners",
17-
["make:mail"] = "app/Mail",
18-
["make:middleware"] = "app/Http/Middleware",
19-
["make:migration"] = function(name)
20-
return vim.fn.systemlist(string.format("fd %s.php", name))[1]
21-
end,
22-
["make:model"] = "app/Models",
23-
["make:notification"] = "app/Notifications",
24-
["make:observer"] = "app/Observers",
25-
["make:policy"] = "app/Policies",
26-
["make:provider"] = "app/Providers",
27-
["make:request"] = "app/Http/Requests",
28-
["make:resource"] = "app/Http/Resources",
29-
["make:rule"] = "app/Rules",
30-
["make:scope"] = "app/Models/Scopes",
31-
["make:seeder"] = "database/seeders",
32-
["make:test"] = "tests/Feature",
33-
["make:view"] = function(name)
34-
return "resources/views/" .. name:gsub("%.", "/") .. ".blade.php"
35-
end,
2+
["Controllers"] = "app/Http/Controllers",
3+
["Livewire"] = "app/Livewire",
4+
["Models"] = "app/Models",
5+
["Views"] = "resources/views",
6+
["Migrations"] = "database/migrations",
7+
["Providers"] = "app/Providers",
8+
["Components"] = "app/View/Components",
9+
["Routes"] = "routes",
10+
["Factories"] = "database/factories",
11+
["Seeders"] = "database/seeders",
12+
["Configs"] = "config",
13+
["FeatureTest"] = "tests/Feature",
14+
["UnitTest"] = "tests/Unit",
15+
["Requests"] = "app/Http/Requests",
3616
}

lua/laravel/config/ui.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
---@class NuiOptions
2+
---@field enter boolean
3+
---@field relative string
4+
---@field position string|table
5+
---@field size string|table
6+
---@field buf_options table
7+
---@field win_options table
8+
9+
---@class LaravelOptionsUINui
10+
---@field split NuiOptions
11+
---@field popup NuiOptions
12+
13+
---@class LaravelOptionsUI
14+
---@field default string
15+
---@field nui_opts LaravelOptionsUINui
116
return {
217
default = "split",
318
nui_opts = {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
return {
2+
artisan = {
3+
["db:fresh"] = {
4+
cmd = { "migrate:fresh", "--seed" },
5+
desc = "Re-creates the db and seed's it",
6+
},
7+
},
8+
npm = {
9+
build = {
10+
cmd = { "run", "build" },
11+
desc = "Builds the javascript assets",
12+
},
13+
dev = {
14+
cmd = { "run", "dev" },
15+
desc = "Builds the javascript assets",
16+
},
17+
},
18+
composer = {
19+
autoload = {
20+
cmd = { "dump-autoload" },
21+
desc = "Dumps the composer autoload",
22+
},
23+
},
24+
}

lua/laravel/environment/init.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ local function resolve()
3030
if opts.env_variable then
3131
local env_opts = find_env_by_name(get_env(opts.env_variable), opts.definitions)
3232
if env_opts then
33-
local env = Environment:new(env_opts)
34-
if env:check() then
35-
return env
36-
end
33+
return Environment:new(env_opts)
3734
end
3835
end
3936

@@ -71,6 +68,7 @@ function M.setup()
7168
return
7269
end
7370

71+
require("laravel.treesitter").setup()
7472
user_commands.setup()
7573

7674
if config.options.features.route_info.enable then
@@ -80,6 +78,8 @@ function M.setup()
8078
if config.options.features.null_ls.enable then
8179
require("laravel.null_ls").setup()
8280
end
81+
82+
require("laravel.luasnip").setup()
8383
end
8484

8585
---@param name string

0 commit comments

Comments
 (0)