Cheatsheets and debuggin
This commit is contained in:
+51
-1
@@ -51,7 +51,57 @@ helpers.open_term = function(opts)
|
||||
end
|
||||
|
||||
helpers.has_copilot = function()
|
||||
return vim.fn.getenv('COPILOT_API_KEY') ~= vim.NIL
|
||||
return vim.fn.getenv 'COPILOT_API_KEY' ~= vim.NIL
|
||||
end
|
||||
|
||||
helpers.open_file_modal = function(path, title)
|
||||
local width = math.floor(vim.o.columns * 0.85)
|
||||
local height = math.floor(vim.o.lines * 0.85)
|
||||
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
|
||||
vim.api.nvim_open_win(buf, true, {
|
||||
relative = 'editor',
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = 'minimal',
|
||||
border = 'rounded',
|
||||
title = ' ' .. title .. ' ',
|
||||
title_pos = 'center',
|
||||
})
|
||||
|
||||
vim.api.nvim_buf_set_name(buf, path)
|
||||
|
||||
local lines = vim.fn.readfile(path)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
|
||||
vim.bo[buf].filetype = 'markdown'
|
||||
vim.bo[buf].buftype = 'nofile'
|
||||
vim.bo[buf].bufhidden = 'wipe'
|
||||
vim.bo[buf].swapfile = false
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.bo[buf].readonly = true
|
||||
|
||||
vim.wo.wrap = false
|
||||
vim.wo.number = false
|
||||
vim.wo.relativenumber = false
|
||||
vim.wo.cursorline = true
|
||||
|
||||
vim.keymap.set('n', 'q', '<cmd>close<CR>', {
|
||||
buffer = buf,
|
||||
silent = true,
|
||||
desc = 'Close cheatsheet',
|
||||
})
|
||||
vim.keymap.set('n', '<Esc>', '<cmd>close<CR>', {
|
||||
buffer = buf,
|
||||
silent = true,
|
||||
desc = 'Close cheatsheet',
|
||||
})
|
||||
end
|
||||
|
||||
return helpers
|
||||
|
||||
+109
-90
@@ -26,7 +26,7 @@ vim.keymap.set('v', 'p', '"zdP', { desc = 'Paste over selection without yanking
|
||||
-- or just use <C-\><C-n> to exit terminal mode
|
||||
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
|
||||
|
||||
vim.keymap.set('n', '<Leader>c', function()
|
||||
vim.keymap.set('n', '<Leader>z', function()
|
||||
vim.treesitter.inspect_tree()
|
||||
end, { desc = 'Treesitter' })
|
||||
|
||||
@@ -259,101 +259,110 @@ vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item i
|
||||
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
|
||||
vim.keymap.set('n', '<Leader>r', '<CMD>e!<CR>', { desc = 'Reload buffer' })
|
||||
|
||||
|
||||
local function open_test()
|
||||
require('neotest').summary.open()
|
||||
require('neotest').output_panel.open()
|
||||
end
|
||||
-- Testing
|
||||
-- local test_maps = {
|
||||
-- {
|
||||
-- keys = { '<F12>', '<Leader>tn' },
|
||||
-- action = function()
|
||||
-- require('neotest').run.run()
|
||||
-- open_test()
|
||||
-- end,
|
||||
-- desc = 'Run nearest test',
|
||||
-- },
|
||||
-- {
|
||||
-- keys = { '<F9>', '<Leader>ta' },
|
||||
-- action = function()
|
||||
-- require('neotest').run.run { suite = true }
|
||||
-- open_test()
|
||||
-- end,
|
||||
-- desc = 'Run all tests in the project',
|
||||
-- },
|
||||
-- {
|
||||
-- keys = { '<F11>', '<Leader>tp' },
|
||||
-- action = function()
|
||||
-- require('neotest').run.run_last()
|
||||
-- open_test()
|
||||
-- end,
|
||||
-- desc = 'Run previous test again',
|
||||
-- },
|
||||
-- {
|
||||
-- keys = { '<F10>', '<Leader>td' },
|
||||
-- action = function()
|
||||
-- local dap = require 'dap'
|
||||
-- if dap.session() == nil then
|
||||
-- dap.continue()
|
||||
-- end
|
||||
-- require('dapui').open()
|
||||
-- local neotest = require 'neotest'
|
||||
-- local bufnr = vim.api.nvim_get_current_buf()
|
||||
-- local row = vim.api.nvim_win_get_cursor(0)[1] - 1
|
||||
--
|
||||
-- local adapters = neotest.state.adapter_ids()
|
||||
-- local found = false
|
||||
--
|
||||
-- for _, adapter_id in ipairs(adapters) do
|
||||
-- local tree = neotest.state.positions(adapter_id, { buffer = bufnr })
|
||||
-- if tree then
|
||||
-- local nearest = require('neotest.lib.positions').nearest(tree, row)
|
||||
-- if nearest and nearest:data().type ~= 'file' then
|
||||
-- neotest.run.run()
|
||||
-- found = true
|
||||
-- break
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- if not found then
|
||||
-- neotest.run.run_last()
|
||||
-- end
|
||||
-- end,
|
||||
-- desc = 'Run last test with debugger',
|
||||
-- },
|
||||
-- }
|
||||
--
|
||||
-- for _, map_info in ipairs(test_maps) do
|
||||
-- for _, key in ipairs(map_info.keys) do
|
||||
-- vim.keymap.set('n', key, map_info.action, { desc = map_info.desc })
|
||||
-- end
|
||||
-- end
|
||||
-- vim.keymap.set('n', '<Leader>tf', function()
|
||||
-- require('neotest').run.run(vim.fn.expand '%')
|
||||
-- open_test()
|
||||
-- end, { desc = 'Run all tests in the current file' })
|
||||
-- vim.keymap.set('n', '<Leader>tc', function()
|
||||
-- require('neotest').summary.close()
|
||||
-- require('neotest').output_panel.close()
|
||||
-- end, { desc = 'Close test panels' })
|
||||
local test_maps = {
|
||||
{
|
||||
keys = { '<Leader>tc' },
|
||||
action = function()
|
||||
require('neotest').summary.close()
|
||||
require('neotest').output_panel.close()
|
||||
end,
|
||||
desc = 'Close [T]est panels',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>tn' },
|
||||
action = function()
|
||||
require('neotest').run.run()
|
||||
open_test()
|
||||
end,
|
||||
desc = 'Run nearest [T]est',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>ta' },
|
||||
action = function()
|
||||
require('neotest').run.run { suite = true }
|
||||
open_test()
|
||||
end,
|
||||
desc = 'Run all [T]ests in the project',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>tp' },
|
||||
action = function()
|
||||
require('neotest').run.run_last()
|
||||
open_test()
|
||||
end,
|
||||
desc = 'Run previous [T]est again',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>td' },
|
||||
action = function()
|
||||
local dap = require 'dap'
|
||||
if dap.session() == nil then
|
||||
dap.continue()
|
||||
end
|
||||
require('dapui').open()
|
||||
local neotest = require 'neotest'
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1] - 1
|
||||
|
||||
-- vim.keymap.set('i', '<Tab>', function()
|
||||
-- local copilot = require 'copilot.suggestion'
|
||||
-- local ls = require 'luasnip'
|
||||
-- if copilot.is_visible() then
|
||||
-- vim.api.nvim_echo({{'Accepting copilot suggestion'}}, false, {})
|
||||
-- copilot.accept()
|
||||
-- copilot.dismiss()
|
||||
-- elseif ls.jumpable(1) then
|
||||
-- vim.api.nvim_echo({{'Jumping in snippet'}}, false, {})
|
||||
-- ls.jump()
|
||||
-- else
|
||||
-- vim.api.nvim_echo({{'Inserting tab'}}, false, {})
|
||||
-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, true, true), 'n', true)
|
||||
-- end
|
||||
-- end, { desc = 'Luasnip accept copilot or jump forward' })
|
||||
local adapters = neotest.state.adapter_ids()
|
||||
local found = false
|
||||
|
||||
vim.g.neotest_debug = true
|
||||
for _, adapter_id in ipairs(adapters) do
|
||||
local tree = neotest.state.positions(adapter_id, { buffer = bufnr })
|
||||
if tree then
|
||||
local nearest = require('neotest.lib.positions').nearest(tree, row)
|
||||
if nearest and nearest:data().type ~= 'file' then
|
||||
neotest.run.run()
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
neotest.run.run_last()
|
||||
end
|
||||
vim.g.neotest_debug = nil
|
||||
end,
|
||||
desc = 'Run last [T]est with debugger',
|
||||
},
|
||||
}
|
||||
|
||||
for _, map_info in ipairs(test_maps) do
|
||||
for _, key in ipairs(map_info.keys) do
|
||||
vim.keymap.set('n', key, map_info.action, { desc = map_info.desc })
|
||||
end
|
||||
end
|
||||
vim.keymap.set('n', '<Leader>tf', function()
|
||||
require('neotest').run.run(vim.fn.expand '%')
|
||||
open_test()
|
||||
end, { desc = 'Run all tests in the current file' })
|
||||
vim.keymap.set('n', '<Leader>tc', function()
|
||||
require('neotest').summary.close()
|
||||
require('neotest').output_panel.close()
|
||||
end, { desc = 'Close test panels' })
|
||||
|
||||
vim.keymap.set('i', '<Tab>', function()
|
||||
local copilot = require 'copilot.suggestion'
|
||||
local ls = require 'luasnip'
|
||||
if copilot.is_visible() then
|
||||
vim.api.nvim_echo({ { 'Accepting copilot suggestion' } }, false, {})
|
||||
copilot.accept()
|
||||
copilot.dismiss()
|
||||
elseif ls.jumpable(1) then
|
||||
vim.api.nvim_echo({ { 'Jumping in snippet' } }, false, {})
|
||||
ls.jump()
|
||||
else
|
||||
vim.api.nvim_echo({ { 'Inserting tab' } }, false, {})
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, true, true), 'n', true)
|
||||
end
|
||||
end, { desc = 'Luasnip accept copilot or jump forward' })
|
||||
|
||||
-- Leaving this commented out, I will try the format command instead
|
||||
-- "A command to properly indent json code
|
||||
@@ -371,4 +380,14 @@ vim.keymap.set('n', '<Leader>es', function()
|
||||
vim.cmd('tabedit ' .. snippets_file)
|
||||
end, { desc = 'Edit snippets file' })
|
||||
|
||||
vim.keymap.set('n', '<Leader>cz', function()
|
||||
require('utils/cheatsheets').open 'zsh'
|
||||
end, { desc = 'Open zsh cheat sheet' })
|
||||
vim.keymap.set('n', '<Leader>cb', function()
|
||||
require('utils/cheatsheets').open 'bash'
|
||||
end, { desc = 'Open bash cheat sheet' })
|
||||
vim.keymap.set('n', '<Leader>cr', function()
|
||||
require('utils/cheatsheets').open 'regex'
|
||||
end, { desc = 'Open RegExp cheat sheet' })
|
||||
|
||||
require('helpers').edit_cf('k', '/lua/keymap.lua')
|
||||
|
||||
@@ -52,16 +52,16 @@ return {
|
||||
},
|
||||
|
||||
sources = {
|
||||
default = { 'lsp', 'path', 'snippets', 'lazydev', 'blade-nav' },
|
||||
default = { 'lsp', 'path', 'snippets', 'lazydev' },
|
||||
providers = {
|
||||
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
|
||||
-- avante = { module = 'blink-cmp-avante', name = 'Avante', opts = {} },
|
||||
['blade-nav'] = {
|
||||
module = 'blade-nav.blink',
|
||||
opts = {
|
||||
clost_tag_on_complete = false,
|
||||
},
|
||||
},
|
||||
-- ['blade-nav'] = {
|
||||
-- module = 'blade-nav.blink',
|
||||
-- opts = {
|
||||
-- clost_tag_on_complete = false,
|
||||
-- },
|
||||
-- },
|
||||
},
|
||||
per_filetype = {
|
||||
codecompanion = { 'codecompanion' },
|
||||
|
||||
@@ -180,40 +180,6 @@ return {
|
||||
vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl })
|
||||
end
|
||||
|
||||
local function get_php_ini_dir()
|
||||
local handle = io.popen 'php --ini 2>/dev/null'
|
||||
if not handle then
|
||||
return nil
|
||||
end
|
||||
local result = handle:read '*a'
|
||||
handle:close()
|
||||
local dir = result:match 'Scan for additional .ini files in:%s+([^\n]+)'
|
||||
if dir and dir:find '%(none%)' == nil then
|
||||
return vim.trim(dir)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function enable_xdebug()
|
||||
local ini_dir = get_php_ini_dir()
|
||||
if not ini_dir then
|
||||
return
|
||||
end
|
||||
os.execute(string.format('mv "%s/20-xdebug.ini.disabled" "%s/20-xdebug.ini" 2>/dev/null', ini_dir, ini_dir))
|
||||
end
|
||||
|
||||
local function disable_xdebug()
|
||||
local ini_dir = get_php_ini_dir()
|
||||
if not ini_dir then
|
||||
return
|
||||
end
|
||||
os.execute(string.format('mv "%s/20-xdebug.ini" "%s/20-xdebug.ini.disabled" 2>/dev/null', ini_dir, ini_dir))
|
||||
end
|
||||
|
||||
dap.listeners.after.event_initialized['xdebug_enable'] = enable_xdebug
|
||||
dap.listeners.before.event_terminated['xdebug_disable'] = disable_xdebug
|
||||
dap.listeners.before.event_exited['xdebug_disable'] = disable_xdebug
|
||||
|
||||
-- dap.listeners.after.event_output['neotest_display'] = function(_, body)
|
||||
-- require('neotest').output.open { enter = true, last = true }
|
||||
-- end
|
||||
|
||||
+14
-8
@@ -13,9 +13,10 @@ return {
|
||||
'saghen/blink.cmp',
|
||||
'folke/lazydev.nvim',
|
||||
},
|
||||
build = function()
|
||||
vim.fn.system 'composer global require jetbrains/phpstorm-stubs friendsofphp/php-cs-fixer'
|
||||
end,
|
||||
-- Might not be necessary for phpantom
|
||||
-- build = function()
|
||||
-- vim.fn.system 'composer global require jetbrains/phpstorm-stubs friendsofphp/php-cs-fixer'
|
||||
-- end,
|
||||
config = function()
|
||||
-- This function gets run when an LSP attaches to a particular buffer.
|
||||
-- That is to say, every time a new file is opened that is associated with
|
||||
@@ -115,10 +116,11 @@ return {
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.phpactor = {
|
||||
cmd = { 'phpactor', 'language-server' },
|
||||
filetypes = { 'php' },
|
||||
}
|
||||
-- vim.lsp.config['phpantom'] = {
|
||||
-- filetypes = { 'php' },
|
||||
-- cmd = { 'phpantom_lsp' },
|
||||
-- root_markers = { 'composer.json', '.git' },
|
||||
-- }
|
||||
|
||||
-- Enable the following language servers
|
||||
--
|
||||
@@ -144,7 +146,11 @@ return {
|
||||
},
|
||||
},
|
||||
},
|
||||
-- phpactor = {},
|
||||
phpantom_lsp = {
|
||||
filetypes = { 'php' },
|
||||
cmd = { 'phpantom_lsp' },
|
||||
root_markers = { 'composer.json', '.git' },
|
||||
},
|
||||
vtsls = {
|
||||
settings = {
|
||||
vtsls = {
|
||||
|
||||
@@ -5,6 +5,13 @@ return {
|
||||
-- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, -- if you prefer nvim-web-devicons
|
||||
---@module 'render-markdown'
|
||||
---@type render.md.UserConfig
|
||||
opts = {},
|
||||
ft = { 'markdown', 'codecompanion' },
|
||||
config = function()
|
||||
require('render-markdown').setup {
|
||||
latex = {
|
||||
enabled = true,
|
||||
render_modes = true,
|
||||
},
|
||||
}
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
require('helpers').edit_cf('pt', '/lua/plugins/test.lua')
|
||||
|
||||
return {
|
||||
'nvim-neotest/neotest',
|
||||
dependencies = {
|
||||
'V13Axel/neotest-pest',
|
||||
},
|
||||
config = function()
|
||||
require('neotest').setup {
|
||||
adapters = {
|
||||
require 'neotest-pest' {
|
||||
sail_enabled = function()
|
||||
return false
|
||||
end,
|
||||
parallel = 8,
|
||||
pest_cmd = function()
|
||||
local cmd = vim.g.neotest_pest_cmd or { 'vendor/bin/pest' }
|
||||
if vim.g.neotest_debug then
|
||||
cmd = { 'sh', '-c', 'XDEBUG_MODE=debug exec ' .. table.concat(cmd, ' ') .. ' "$@"' }
|
||||
end
|
||||
return cmd
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
end,
|
||||
}
|
||||
@@ -7,9 +7,11 @@ return {
|
||||
config = function()
|
||||
local langs = {
|
||||
'bash',
|
||||
'zsh',
|
||||
'c',
|
||||
'diff',
|
||||
'html',
|
||||
'latex',
|
||||
'lua',
|
||||
'luadoc',
|
||||
'markdown',
|
||||
|
||||
@@ -258,6 +258,31 @@ local PROJECTS = {
|
||||
end,
|
||||
})
|
||||
end,
|
||||
['server'] = 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' })
|
||||
laravel_keymaps()
|
||||
laravel_makes()
|
||||
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
|
||||
map('<Leader>pm', ':vendor/bin/sail composer migrate<CR>')
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
|
||||
pattern = { '*.php', '.env', '.graphql' },
|
||||
callback = function()
|
||||
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,
|
||||
})
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
@@ -378,7 +378,11 @@ return {
|
||||
{ i(1), i(0) }
|
||||
)
|
||||
),
|
||||
s(etr('nn ', 'Assert not null'), fmta('Assert::notNull(#~)', { i(0) })),
|
||||
s(etr('nn ', 'Assert not null'), fmta('Assert::notNull(#~);', { i(0) })),
|
||||
s(etr('ast ', 'Assert string'), fmta('Assert::string(#~);', { i(0) })),
|
||||
s(etr('ain ', 'Assert integer'), fmta('Assert::integer(#~);', { i(0) })),
|
||||
s(etr('aio ', 'Assert instance of'), fmta('Assert::isInstanceOf(#~);', { i(0) })),
|
||||
s(etr('at ', 'Assert true'), fmta('Assert::true(#~);', { i(0) })),
|
||||
-------------
|
||||
-- LARAVEL --
|
||||
-------------
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
local M = {}
|
||||
|
||||
function M.open(name)
|
||||
local titles = {
|
||||
zsh = 'ZSH Cheat Sheet',
|
||||
bash = 'Bash Cheat Sheet',
|
||||
regex = 'RegExp Cheat Sheet',
|
||||
}
|
||||
|
||||
local path = vim.fn.stdpath 'config' .. '/cheatsheets/' .. name .. '.md'
|
||||
print('Opening cheat sheet: ' .. path)
|
||||
|
||||
require('../helpers').open_file_modal(path, titles[name] or name)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user