Files
nvim/lua/projects/hylark.lua
T
2026-07-11 13:16:12 +01:00

107 lines
3.9 KiB
Lua

local laravel_utils = require 'projects.framework_utils.laravel'
local helpers = require 'helpers'
local map = helpers.map
local create_bookmark = helpers.create_bookmark
local function switch_to(dir)
if vim.fn.getcwd() == dir then
return
end
vim.fn.chdir(dir)
vim.notify('Changed working directory to ' .. dir, vim.log.levels.INFO, { title = 'hylark.lua' })
end
return function(dir)
local function switch_to_server()
switch_to(dir .. '/server')
end
local function switch_to_frontend()
switch_to(dir .. '/frontend2')
end
local function switch_to_root()
switch_to(dir)
end
local function compile_typescript()
vim.fn.jobstart('php artisan typescript:transform', { cwd = dir .. '/server', stdout_buffered = true })
vim.notify('Compiling typescript types', vim.log.levels.INFO, { title = 'hylark.lua' })
end
map('<leader>pl', ':cexpr system("vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>', { desc = 'Run lint' })
map('<leader>T', function()
helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' }
end, { desc = 'Open database manager' })
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
map('<Leader>pm', ':vendor/bin/sail composer migrate<CR>')
map('<Leader>pcs', switch_to_server, { desc = 'Change working directory to server' })
map('<Leader>pcf', switch_to_frontend, { desc = 'Change working directory to frontend2' })
map('<Leader>pcr', switch_to_root, { desc = 'Change working directory to root' })
map('<Leader>pt', compile_typescript, { desc = 'Compile typescript' })
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
pattern = { '*.php', '.env', '.graphql' },
callback = function()
if not vim.fn.expand('%:p'):match(dir .. '/server/') then
vim.fn.jobstart('vendor/bin/sail artisan octane:reload', { stdout_buffered = true })
vim.fn.jobstart('vendor/bin/sail artisan horizon:terminate', { stdout_buffered = true })
end
if vim.fn.search '#\\[TypeScript\\]' ~= 0 then
compile_typescript()
end
end,
})
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
pattern = { '*.js', '*.ts', '*.vue' },
callback = function(args)
vim.env.ESLINT_D_PPID = vim.fn.getpid()
local cwd = vim.fn.getcwd()
if vim.fn.expand('%:p'):match(dir .. '/frontend2/') then
cwd = dir .. '/frontend2/'
end
require('helpers').format_buffer('eslint_d', args.buf, cwd)
end,
})
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
pattern = { '*.php' },
callback = function(args)
local cwd = vim.fn.getcwd()
if vim.fn.expand('%:p'):match(dir .. '/server/') then
cwd = dir .. '/server/'
end
require('helpers').format_buffer('pint', args.buf, cwd)
end,
})
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
pattern = { '.graphql' },
callback = function()
vim.fn.jobstart('vendor/bin/sail artisan lighthouse:clear-cache', { stdout_buffered = true })
end,
})
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
pattern = { dir .. '**' },
callback = function()
if vim.fn.expand('%:p'):match(dir .. '/server/') then
switch_to_server()
elseif vim.fn.expand('%:p'):match(dir .. '/frontend2/') then
switch_to_frontend()
else
switch_to_root()
end
end,
})
laravel_utils.laravel_keymaps 'server/'
laravel_utils.laravel_makes 'server/'
laravel_utils.laravel_utils 'server/'
laravel_utils.laravel_bookmarks(dir .. '/server/')
create_bookmark('s', dir .. '/frontend2/src/types/api/server-types.d.ts')
end