Hylark settings

This commit is contained in:
Chris
2025-11-12 09:21:21 +00:00
parent f16cb91875
commit 344623eaf6
2 changed files with 51 additions and 31 deletions

View File

@@ -41,12 +41,11 @@ local PROJECTS = {
-- end, { desc = 'Open the dump-server window' }) -- end, { desc = 'Open the dump-server window' })
map( map(
'<leader>psl', '<leader>pl',
':cexpr system("cd server && vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>', ':cexpr system("cd server && vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>',
{ desc = 'Run lint' } { desc = 'Run lint' }
) )
map('<leader>pcl', ':cexpr system("cd client && tsc --allowJs --removeComments --noEmit") <CR>', { desc = 'Run lint' }) map('<leader>pd', function()
map('<leader>db', function()
helpers.open_term { cmd = 'lazysql mysql://root@localhost:3306/runcats' } helpers.open_term { cmd = 'lazysql mysql://root@localhost:3306/runcats' }
end, { desc = 'Open database manager' }) end, { desc = 'Open database manager' })
map('<leader>E', ':e .env<CR>', { desc = 'Edit .env file' }) map('<leader>E', ':e .env<CR>', { desc = 'Edit .env file' })
@@ -58,7 +57,6 @@ local PROJECTS = {
map('cmp ', '!cd server && composer ', { desc = 'Run composer script' }, 'c') map('cmp ', '!cd server && composer ', { desc = 'Run composer script' }, 'c')
map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c') map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c')
map('ts ', '!cd server && php artisan typescript:transform --format', { desc = 'Compile typescript' }, 'c') map('ts ', '!cd server && php artisan typescript:transform --format', { desc = 'Compile typescript' }, 'c')
map('<C-S-F', ':vimgrep', { desc = 'Grep everywhere' })
require('conform').formatters.pint = { require('conform').formatters.pint = {
append_args = { append_args = {
'--config=' .. dir .. '/server/pint.json', '--config=' .. dir .. '/server/pint.json',
@@ -66,6 +64,19 @@ local PROJECTS = {
} }
end, end,
['hylark'] = function(dir)
map('<leader>pl', ':cexpr system("vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>', { desc = 'Run lint' })
map('<leader>pd', function()
helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' }
end, { desc = 'Open database manager' })
map('<leader>E', ':e .env', { desc = 'Edit .env file' })
map('s ', '!vendor/bin/sail ', { desc = 'Run sail command' }, 'c')
map('art ', '!php artisan ', { desc = 'Run artisan command' }, 'c')
map('sart ', '!vendor/bin/sail artisan ', { desc = 'Run artisan command with sail' }, 'c')
map('cmp ', '!composer ', { desc = 'Run composer script' }, 'c')
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
end,
default = function() end, default = function() end,
} }

View File

@@ -4,34 +4,43 @@ local t = ls.text_node
local i = ls.insert_node local i = ls.insert_node
local f = ls.function_node local f = ls.function_node
local function get_psr4_root(path) local function psr_namespace(_, snip)
-- local dir = vim.fs.dirname(path) local path = snip.env.TM_FILENAME_FULL or ''
-- while dir ~= '/' and dir ~= nil do -- Get the directory of the path
-- local composer_json_path = dir .. '/composer.json' local dir = vim.fs.dirname(path)
-- if vim.fn.filereadable(composer_json_path) == 1 then -- Loop through parent directories to find composer.json
-- break while dir ~= '/' and dir ~= nil do
-- end local composer_json_path = dir .. '/composer.json'
-- dir = vim.fs.dirname(dir) if vim.fn.filereadable(composer_json_path) == 1 then
-- end break
local handle = io.popen [[php -r "echo array_keys(json_decode(file_get_contents('composer.json'), true)['autoload']['psr-4'])[0];"]]
local ns_root = handle and handle:read '*a' or ''
if handle then
handle:close()
end end
ns_root = ns_root:gsub('\\$', '') -- Remove trailing backslash dir = vim.fs.dirname(dir)
return ns_root end
-- If no composer.json found, return empty string
if dir == '/' or dir == nil then
return ''
end end
local function psr_namespace(args, snip) -- Decode composer.json and get PSR-4 autoload mappings
local path = snip.env.TM_FILENAME_FULL or '' local composer = vim.json.decode(vim.iter(vim.fn.readfile(dir .. '/composer.json')):join '')
local composer_root = get_psr4_root() local psr4 = composer['autoload'] and composer['autoload']['psr-4']
-- Find the directory mapped by composer.json
local root_dir = composer_root:gsub('\\', '/') -- If no PSR-4 mappings, return empty string
local ns = path:match(root_dir .. '/(.*)/[^/]+%.php$') if not psr4 then
if ns then return ''
return composer_root .. '\\' .. ns:gsub('/', '\\') end
else
return composer_root ~= '' and composer_root or 'App' -- Get the relative path from the composer.json directory
local relative_path = path:sub(#dir + 2)
-- Loop through PSR-4 mappings
for namespace, map in pairs(psr4) do
-- Check if the relative path matches the mapping
if relative_path:match('^' .. map:gsub('/', '%%/')) then
-- Extract the suffix of the path after the mapping, removing the filename
local suffix = relative_path:sub(#map + 2):match('^(.*)/[^/]+%.php$') or ''
local trimmed = namespace:gsub('\\$', '')
return trimmed .. (suffix ~= '' and ('\\' .. suffix:gsub('/', '\\')) or '')
end
end end
end end