Cheatsheets and debuggin

This commit is contained in:
Chris
2026-06-16 16:26:28 +01:00
parent 5dd9b59b90
commit ecbc266165
14 changed files with 1297 additions and 142 deletions
+109 -90
View File
@@ -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')