diff --git a/init.lua b/init.lua index e5f265e..e1f38a1 100644 --- a/init.lua +++ b/init.lua @@ -63,3 +63,4 @@ TODO: Neovim configurations I want to add: -- " - To operate on multiple lines use to select the lines, to go to -- " insert mode, perform edit, press . -- " - Use the command :r to paste the output of a command to the buffer. + diff --git a/lua/helpers.lua b/lua/helpers.lua index 3c51fda..2622561 100644 --- a/lua/helpers.lua +++ b/lua/helpers.lua @@ -163,5 +163,11 @@ helpers.format_buffer = function(formatter, buf, cwd) vim.api.nvim_buf_set_lines(buf, 0, -1, false, vim.split(result.stdout, '\n', { plain = true })) end +helpers.create_bookmark = function(key, bookmark) + helpers.map('b' .. key, function() + vim.cmd('edit ' .. bookmark) + end, { desc = 'Navigate to ' .. bookmark }) +end + return helpers diff --git a/lua/keymap.lua b/lua/keymap.lua index a635e1c..484782e 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -239,6 +239,10 @@ end, { desc = 'Open scratchpad buffers' }) vim.keymap.set({ 'n', 'v', 'c', 'i', 't' }, '', function() require('snacks').terminal.toggle() end, { desc = 'Toggle terminal' }) +vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', '', { desc = 'Enter normal mode' }) +vim.keymap.set({ 't' }, '', '', { desc = 'Enter normal mode' }) +vim.keymap.set({ 't' }, '', '', { desc = 'Scroll up in terminal' }) +vim.keymap.set({ 't' }, '', '', { desc = 'Scroll down in terminal' }) -- Editing helpers vim.keymap.set('i', '', 'o', { desc = 'Add line below' }) diff --git a/lua/projects.lua b/lua/projects.lua index 9619e22..1e7d2b3 100644 --- a/lua/projects.lua +++ b/lua/projects.lua @@ -6,328 +6,48 @@ local M = {} local helpers = require 'helpers' local map = helpers.map +local function relevant_directory_from_cwd(cwd) + local basename = vim.fn.fnamemodify(cwd, ':t') + local nested_folder_names = { 'server', 'frontend', 'frontend2', 'client', 'backend' } + if vim.tbl_contains(nested_folder_names, basename) then + local parent = vim.fn.fnamemodify(cwd, ':h') + return relevant_directory_from_cwd(parent) + end + return cwd +end + -- Get the last folder name from a path -local function project_name_from_cwd(cwd) - return vim.fn.fnamemodify(cwd, ':t') +local function project_name_from_dir(dir) + return vim.fn.fnamemodify(dir, ':t') end -local function command_with_dir(dir, cmd) - if dir then - return '!cd ' .. dir .. ' && ' .. cmd - end - return '!' .. cmd -end - -local function make_laravel_file(dir, cmd) - local cwd = vim.fn.getcwd() - if dir then - vim.fn.chdir(dir) - end - vim.ui.input({ prompt = 'Make: ' .. cmd }, function(input) - if input == nil then - vim.fn.chdir(cwd) - return - end - - local output = vim.system({ 'vendor/bin/sail', 'artisan', 'make:' .. cmd, input }):wait().stdout - local new_file = output:match '%[([%w%./]+)%]' - if new_file ~= nil then - vim.cmd('edit ' .. new_file) - end - vim.fn.chdir(cwd) - end) -end - -local function get_scope_from_file(filename) - local ext = filename:match '%.(%w+)$' - local base_name = filename:match '^(%w+)%.?%w*$' - local extensionSuffixes = { - php = { 'Controller', 'Repository', 'StoreRequest', 'UpdateRequest', 'Request', 'Resource', 'Test', 'Observer', 'Policy', 'Seeder', 'Factory' }, - ['[jt]s'] = { 'Service' }, - } - for suffix_type, _ in pairs(extensionSuffixes) do - if ext:match(suffix_type) then - local suffixes = extensionSuffixes[suffix_type] - for _, suffix in ipairs(suffixes) do - local scope = base_name:match('^(%w+)' .. suffix .. '$') - if scope then - return scope - end - end - end - end - return base_name -end - -local function navigate_using_suffix(suffix) - local scope = get_scope_from_file(vim.fn.expand '%:t') - local file_name = scope .. suffix - local file_path = vim.system({ 'git', 'ls-files', file_name, '**/' .. file_name }):wait().stdout - if file_path ~= '' then - vim.cmd('edit ' .. file_path) - else - vim.notify('File ' .. file_name .. ' not found in git ls-files', vim.log.levels.ERROR) - end -end - -local function create_navigation_maps(maps) - for key, suffix_and_name in pairs(maps) do - map('n' .. key, function() - navigate_using_suffix(suffix_and_name[1]) - end, { desc = 'Navigate to relevant ' .. suffix_and_name[2] }) - end -end - -local function create_bookmark(key, bookmark) - map('b' .. key, function() - vim.cmd('edit ' .. bookmark) - end, { desc = 'Navigate to ' .. bookmark }) -end - -local function create_bookmark_maps(maps) - for key, bookmark in pairs(maps) do - create_bookmark(key, bookmark) - end -end - -local function laravel_bookmarks_with_dir(dir) - create_bookmark_maps { - ['e'] = dir .. '.env', - ['l'] = dir .. 'storage/logs/laravel.log', - ['w'] = dir .. 'routes/web.php', - ['a'] = dir .. 'routes/api.php', - ['m'] = dir .. 'database/migrations', - - ['dc'] = dir .. 'app/Core/', - ['dd'] = dir .. 'app/Data/', - ['dE'] = dir .. 'app/Enums/', - ['de'] = dir .. 'app/Events/', - ['dh'] = dir .. 'app/Http/', - ['dj'] = dir .. 'app/Jobs/', - ['dl'] = dir .. 'app/Listeners/', - ['dM'] = dir .. 'app/Mail/', - ['dm'] = dir .. 'app/Models/', - ['dn'] = dir .. 'app/Notifications/', - ['do'] = dir .. 'app/Observers/', - ['dp'] = dir .. 'app/Providers/', - - ['pa'] = dir .. 'app/Providers/AppServiceProvider.php', - ['pe'] = dir .. 'app/Providers/EventServiceProvider.php', - - ['cA'] = dir .. 'config/app.php', - ['ca'] = dir .. 'config/auth.php', - ['cb'] = dir .. 'config/broadcasting.php', - ['cd'] = dir .. 'config/database.php', - ['cf'] = dir .. 'config/filesystems.php', - ['ch'] = dir .. 'config/filesystems.php', - ['cl'] = dir .. 'config/logging.php', - ['cm'] = dir .. 'config/mail.php', - ['cq'] = dir .. 'config/queue.php', - ['cS'] = dir .. 'config/services.php', - ['cs'] = dir .. 'config/session.php', - } -end - -local function laravel_utils(dir) - map('D', function() - helpers.open_term { - cmd = dir .. 'vendor/bin/var-dump-server', - buf_opts = { - bufhidden = 'hide', - modifiable = false, - }, - } - end, { desc = 'Open dump-server window' }) -end - -local function laravel_keymaps(dir) - map('sl ', command_with_dir(dir, 'vendor/bin/sail '), { desc = 'Run sail command' }, 'c') - map('art ', command_with_dir(dir, 'php artisan '), { desc = 'Run artisan command' }, 'c') - map('sart ', command_with_dir(dir, 'vendor/bin/sail artisan '), { desc = 'Run artisan command with sail' }, 'c') - map('cmp ', command_with_dir(dir, 'composer '), { desc = 'Run composer script' }, 'c') - map('pm', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan migrate')) - map('pr', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan migrate:rollback')) - map('pM', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan make:')) - create_navigation_maps { - ['m'] = { '.php', 'model' }, - ['c'] = { 'Controller.php', 'controller' }, - ['p'] = { 'Policy.php', 'policy' }, - ['R'] = { 'Resource.php', 'resource' }, - ['r'] = { 'Request.php', 'request' }, - ['t'] = { 'Test.php', 'test file' }, - } - if dir == nil then - dir = '' - end - laravel_bookmarks_with_dir(dir) -end - -local function laravel_makes(dir) - for key, name in pairs { - c = 'controller', - d = 'data', - e = 'event', - f = 'factory', - j = 'job', - l = 'listener', - ma = 'mail', - mi = 'migration', - mo = 'model', - mw = 'middleware', - n = 'notification', - o = 'observer', - pi = 'model --pivot', - po = 'policy', - pr = 'provider', - t = 'test --pest', - v = 'view', - x = 'exception', - } do - map('m' .. key, function() - make_laravel_file(dir, name) - end, { desc = 'Make and navigate to relevant ' .. name }) - end -end - --- Define per-project configuration here. --- Keys are folder names (last segment of your cwd). -local PROJECTS = { - -- Example: a repo folder - ['runcats'] = function(dir) - -- local dump_buf = vim.api.nvim_create_buf(false, true) - -- vim.api.nvim_set_option_value('bufhidden', 'hide', { buf = dump_buf }) - -- vim.api.nvim_set_option_value('modifiable', false, { buf = dump_buf }) - -- - -- vim.fn.jobstart('cd server && sail artisan dump-server', { - -- term = true, - -- }) - - -- map('dd', function() - -- local height = math.ceil(vim.o.lines * 0.8) - -- local width = math.ceil(vim.o.columns * 0.8) - -- vim.api.nvim_open_win(dump_buf, true, { - -- style = 'minimal', - -- relative = 'editor', - -- width = width, - -- height = height, - -- row = math.ceil((vim.o.lines - height) / 2), - -- col = math.ceil((vim.o.columns - width) / 2), - -- border = 'single', - -- }) - -- - -- vim.cmd.startinsert() - -- end, { desc = 'Open the dump-server window' }) - - map( - 'pl', - ':cexpr system("cd server && vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") ', - { desc = 'Run lint' } - ) - map('T', function() - helpers.open_term { cmd = 'lazysql mysql://root@localhost:3306/runcats' } - end, { desc = 'Open database manager' }) - map('s ', '!cd server && ', { desc = 'Run command in server directory' }, 'c') - map('c ', '!cd client && ', { desc = 'Run command in client directory' }, 'c') - laravel_keymaps 'server/' - laravel_makes 'server/' - laravel_utils 'server/' - map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c') - map('pt', ':!cd server && php artisan typescript:transform --format', { desc = 'Compile typescript' }) - vim.api.nvim_create_autocmd({ 'BufWritePre' }, { - pattern = { '*.php' }, - callback = function(args) - require('helpers').format_buffer('pint', args.buf) - end, - }) - - vim.api.nvim_create_autocmd({ 'BufWritePre' }, { - pattern = { '*.js', '*.ts', '*.vue' }, - callback = function(args) - require('helpers').format_buffer('eslint_d', args.buf) - end, - }) - - create_bookmark('E', dir .. '/client/src/types/api/endpointMap.d.ts') - create_bookmark('q', dir .. '/client/quasar.config.ts') - create_bookmark('db', dir .. '/client/src/boot') - create_bookmark('ds', dir .. '/client/src/stores') - create_bookmark('dS', dir .. '/client/src/services') - end, - - ['hylark'] = function(dir) - map('pl', ':cexpr system("vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") ', { desc = 'Run lint' }) - map('T', function() - helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' } - end, { desc = 'Open database manager' }) - laravel_keymaps() - laravel_makes() - laravel_utils 'server/' - map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c') - map('pm', ':vendor/bin/sail composer migrate') - - 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 - vim.fn.jobstart('php artisan typescript:transform', { cwd = dir .. '/server', stdout_buffered = true }) - 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, - }) - end, - - default = function() end, -} - local last_applied = nil function M.apply(cwd) - local dir = cwd or vim.fn.getcwd() - local name = project_name_from_cwd(dir) + local dir = relevant_directory_from_cwd(cwd or vim.fn.getcwd()) + local name = project_name_from_dir(dir) if last_applied == name then return end last_applied = name - local setup = PROJECTS[name] - if type(setup) == 'function' then + -- Check if project lua file exists in nvim config path + if vim.fn.filereadable(vim.fn.stdpath 'config' .. '/lua/projects/' .. name .. '.lua') == 1 then + local setup = require('projects.' .. name) + helpers.edit_cf('w', '/lua/projects/' .. name .. '.lua') setup(dir) vim.notify(('Project config loaded: %s'):format(name), vim.log.levels.INFO, { title = 'projects.lua' }) - else - PROJECTS.default(dir) + + -- Source the project file to apply any new settings + vim.api.nvim_create_autocmd({ 'BufWritePost' }, { + pattern = { vim.fn.stdpath 'config' .. '/lua/projects/' .. name .. '.lua' }, + callback = function() + package.loaded['projects.' .. name] = nil + local setup = require('projects.' .. name) + setup(dir) + vim.notify(('Project config reloaded: %s'):format(name), vim.log.levels.INFO, { title = 'projects.lua' }) + end, + }) end end @@ -357,6 +77,3 @@ vim.api.nvim_create_user_command('ProjectReload', function() M.apply() end, {}) --- Keep your helper line -require('helpers').edit_cf('w', '/lua/projects.lua') - diff --git a/lua/projects/framework_utils/laravel.lua b/lua/projects/framework_utils/laravel.lua new file mode 100644 index 0000000..fd721c2 --- /dev/null +++ b/lua/projects/framework_utils/laravel.lua @@ -0,0 +1,184 @@ +local helpers = require 'helpers' +local map = helpers.map + +local M = {} + +local function command_with_dir(dir, cmd) + if dir then + return '!cd ' .. dir .. ' && ' .. cmd + end + return '!' .. cmd +end + +local function make_laravel_file(dir, cmd) + local cwd = vim.fn.getcwd() + if dir then + vim.fn.chdir(dir) + end + vim.ui.input({ prompt = 'Make: ' .. cmd }, function(input) + if input == nil then + vim.fn.chdir(cwd) + return + end + + local output = vim.system({ 'vendor/bin/sail', 'artisan', 'make:' .. cmd, input }):wait().stdout + local new_file = output:match '%[([%w%./]+)%]' + if new_file ~= nil then + vim.cmd('edit ' .. new_file) + end + vim.fn.chdir(cwd) + end) +end + +local function get_scope_from_file(filename) + local ext = filename:match '%.(%w+)$' + local base_name = filename:match '^(%w+)%.?%w*$' + local extensionSuffixes = { + php = { 'Controller', 'Repository', 'StoreRequest', 'UpdateRequest', 'Request', 'Resource', 'Test', 'Observer', 'Policy', 'Seeder', 'Factory' }, + ['[jt]s'] = { 'Service' }, + } + for suffix_type, _ in pairs(extensionSuffixes) do + if ext:match(suffix_type) then + local suffixes = extensionSuffixes[suffix_type] + for _, suffix in ipairs(suffixes) do + local scope = base_name:match('^(%w+)' .. suffix .. '$') + if scope then + return scope + end + end + end + end + return base_name +end + +local function navigate_using_suffix(suffix) + local scope = get_scope_from_file(vim.fn.expand '%:t') + local file_name = scope .. suffix + local file_path = vim.system({ 'git', 'ls-files', file_name, '**/' .. file_name }):wait().stdout + if file_path ~= '' then + vim.cmd('edit ' .. file_path) + else + vim.notify('File ' .. file_name .. ' not found in git ls-files', vim.log.levels.ERROR) + end +end + +local function create_navigation_maps(maps) + for key, suffix_and_name in pairs(maps) do + map('n' .. key, function() + navigate_using_suffix(suffix_and_name[1]) + end, { desc = 'Navigate to relevant ' .. suffix_and_name[2] }) + end +end + +local function create_bookmark_maps(maps) + for key, bookmark in pairs(maps) do + helpers.create_bookmark(key, bookmark) + end +end + +local function laravel_bookmarks_with_dir(dir) + create_bookmark_maps { + ['e'] = dir .. '.env', + ['l'] = dir .. 'storage/logs/laravel.log', + ['w'] = dir .. 'routes/web.php', + ['a'] = dir .. 'routes/api.php', + ['m'] = dir .. 'database/migrations', + + ['dc'] = dir .. 'app/Core/', + ['dd'] = dir .. 'app/Data/', + ['dE'] = dir .. 'app/Enums/', + ['de'] = dir .. 'app/Events/', + ['dh'] = dir .. 'app/Http/', + ['dj'] = dir .. 'app/Jobs/', + ['dl'] = dir .. 'app/Listeners/', + ['dM'] = dir .. 'app/Mail/', + ['dm'] = dir .. 'app/Models/', + ['dn'] = dir .. 'app/Notifications/', + ['do'] = dir .. 'app/Observers/', + ['dp'] = dir .. 'app/Providers/', + + ['pa'] = dir .. 'app/Providers/AppServiceProvider.php', + ['pe'] = dir .. 'app/Providers/EventServiceProvider.php', + + ['cA'] = dir .. 'config/app.php', + ['ca'] = dir .. 'config/auth.php', + ['cb'] = dir .. 'config/broadcasting.php', + ['cd'] = dir .. 'config/database.php', + ['cf'] = dir .. 'config/filesystems.php', + ['ch'] = dir .. 'config/filesystems.php', + ['cl'] = dir .. 'config/logging.php', + ['cm'] = dir .. 'config/mail.php', + ['cq'] = dir .. 'config/queue.php', + ['cS'] = dir .. 'config/services.php', + ['cs'] = dir .. 'config/session.php', + } +end + +local function laravel_utils(dir) + map('D', function() + helpers.open_term { + cmd = dir .. 'vendor/bin/var-dump-server', + buf_opts = { + bufhidden = 'hide', + modifiable = false, + }, + } + end, { desc = 'Open dump-server window' }) +end + +local function laravel_keymaps(dir) + map('sl ', command_with_dir(dir, 'vendor/bin/sail '), { desc = 'Run sail command' }, 'c') + map('art ', command_with_dir(dir, 'php artisan '), { desc = 'Run artisan command' }, 'c') + map('sart ', command_with_dir(dir, 'vendor/bin/sail artisan '), { desc = 'Run artisan command with sail' }, 'c') + map('cmp ', command_with_dir(dir, 'composer '), { desc = 'Run composer script' }, 'c') + map('pm', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan migrate')) + map('pr', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan migrate:rollback')) + map('pM', ':' .. command_with_dir(dir, 'vendor/bin/sail artisan make:')) + create_navigation_maps { + ['m'] = { '.php', 'model' }, + ['c'] = { 'Controller.php', 'controller' }, + ['p'] = { 'Policy.php', 'policy' }, + ['R'] = { 'Resource.php', 'resource' }, + ['r'] = { 'Request.php', 'request' }, + ['t'] = { 'Test.php', 'test file' }, + } + if dir == nil then + dir = '' + end + laravel_bookmarks_with_dir(dir) +end + +local function laravel_makes(dir) + for key, name in pairs { + c = 'controller', + d = 'data', + e = 'event', + f = 'factory', + j = 'job', + l = 'listener', + ma = 'mail', + mi = 'migration', + mo = 'model', + mw = 'middleware', + n = 'notification', + o = 'observer', + pi = 'model --pivot', + po = 'policy', + pr = 'provider', + t = 'test --pest', + v = 'view', + x = 'exception', + } do + map('m' .. key, function() + make_laravel_file(dir, name) + end, { desc = 'Make and navigate to relevant ' .. name }) + end +end + +M.laravel_keymaps = laravel_keymaps +M.laravel_makes = laravel_makes +M.laravel_utils = laravel_utils +M.laravel_bookmarks = laravel_bookmarks_with_dir + +return M + diff --git a/lua/projects/hylark.lua b/lua/projects/hylark.lua new file mode 100644 index 0000000..dba19fe --- /dev/null +++ b/lua/projects/hylark.lua @@ -0,0 +1,100 @@ +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 + + map('pl', ':cexpr system("vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") ', { desc = 'Run lint' }) + map('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('pm', ':vendor/bin/sail composer migrate') + map('pcs', switch_to_server, { desc = 'Change working directory to server' }) + map('pcf', switch_to_frontend, { desc = 'Change working directory to frontend2' }) + map('pcr', switch_to_root, { desc = 'Change working directory to root' }) + + 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 + vim.fn.jobstart('php artisan typescript:transform', { cwd = dir .. '/server', stdout_buffered = true }) + 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 'server/' + + create_bookmark('s', dir .. '/frontend2/src/types/api/server-types.d.ts') +end + diff --git a/lua/projects/runcats.lua b/lua/projects/runcats.lua new file mode 100644 index 0000000..cfbcb0f --- /dev/null +++ b/lua/projects/runcats.lua @@ -0,0 +1,44 @@ +local laravel_utils = require 'projects.framework_utils.laravel' +local helpers = require 'helpers' +local map = helpers.map +local create_bookmark = helpers.create_bookmark + +return function(dir) + map( + 'pl', + ':cexpr system("cd server && vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") ', + { desc = 'Run lint' } + ) + map('T', function() + helpers.open_term { cmd = 'lazysql mysql://root@localhost:3306/runcats' } + end, { desc = 'Open database manager' }) + map('s ', '!cd server && ', { desc = 'Run command in server directory' }, 'c') + map('c ', '!cd client && ', { desc = 'Run command in client directory' }, 'c') + map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c') + map('pt', ':!cd server && php artisan typescript:transform --format', { desc = 'Compile typescript' }) + vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + pattern = { '*.php' }, + callback = function(args) + helpers.format_buffer('pint', args.buf) + end, + }) + + vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + pattern = { '*.js', '*.ts', '*.vue' }, + callback = function(args) + helpers.format_buffer('eslint_d', args.buf) + end, + }) + + laravel_utils.laravel_keymaps 'server/' + laravel_utils.laravel_makes 'server/' + laravel_utils.laravel_utils 'server/' + laravel_utils.laravel_bookmarks 'server/' + + create_bookmark('E', dir .. '/client/src/types/api/endpointMap.d.ts') + create_bookmark('q', dir .. '/client/quasar.config.ts') + create_bookmark('db', dir .. '/client/src/boot') + create_bookmark('ds', dir .. '/client/src/stores') + create_bookmark('dS', dir .. '/client/src/services') +end +