Trying stuff

This commit is contained in:
2025-12-09 22:10:16 +00:00
parent 282301e206
commit aded597ffe

View File

@@ -27,13 +27,67 @@ vim.keymap.set('v', 'p', '"zdP', { desc = 'Paste over selection without yanking
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
vim.keymap.set('n', '<Leader>c', function()
local node = require('nvim-treesitter.ts_utils').get_node_at_cursor()
if node then
print(node:type())
vim.treesitter.inspect_tree()
end, { desc = 'Treesitter' })
vim.keymap.set('n', '<C-S-D>', function()
local node = vim.treesitter.get_node {}
local range = { vim.treesitter.get_node_range(node) }
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
vim.cmd.normal 'v`x'
end, { desc = 'Select surrounding treesitter node' })
function get_node_around(node, start_pos, end_pos)
local range = { vim.treesitter.get_node_range(node) }
if
(range[1] == start_pos[1] and range[2] > start_pos[2])
or (range[3] == end_pos[1] and range[4] < end_pos[2])
or (range[1] > start_pos[1])
or (range[3] < end_pos[1])
then
get_node_around(node:parent(), start_pos, end_pos)
elseif range[3] == end_pos[2] and range[4] < end_pos[3] then
get_node_around(node:parent(), start_pos, end_pos)
else
print 'No node found at cursor'
return node
end
end, { desc = 'Log node' })
end
vim.keymap.set('v', '<C-S-D>', function()
local start_pos = vim.api.nvim_win_get_cursor(0)
local end_pos = vim.fn.getpos "'>"
end_pos = { end_pos[2], end_pos[3] }
local node = vim.treesitter.get_node()
local parent = get_node_around(node:parent(), start_pos, end_pos)
if not parent then
return
end
local range = { vim.treesitter.get_node_range(parent) }
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
vim.cmd.normal 'i'
vim.cmd.normal 'v`x'
end, { desc = 'Select surrounding treesitter node' })
vim.keymap.set({ 'n' }, '<C-S-h>', function()
local node = vim.treesitter.get_node()
local prev_node = node:prev_sibling()
if prev_node == nil then
return
end
require('nvim-treesitter.ts_utils').swap_nodes(node, prev_node)
end, { desc = 'Swap with node to the left' })
vim.keymap.set({ 'n' }, '<C-S-l>', function()
local node = vim.treesitter.get_node()
local next_node = node:next_sibling()
if next_node == nil then
return
end
require('nvim-treesitter.ts_utils').swap_nodes(node, next_node)
end, { desc = 'Swap with node to the right' })
-- vim.keymap.set('n', '<C-S-j>', '<C-w>J', { desc = 'Move window to the lower' })
-- vim.keymap.set('n', '<C-S-k>', '<C-w>K', { desc = 'Move window to the upper' })
-- Keybinds to make split navigation easier.
-- Use CTRL+<hjkl> to switch between windows
@@ -84,11 +138,6 @@ vim.keymap.set({ 'i', 's' }, '<C-H>', function()
end
end, { desc = 'Go back a snippet slot', silent = true })
vim.keymap.set('n', '<C-S-h>', '<C-w>H', { desc = 'Move window to the left' })
vim.keymap.set('n', '<C-S-l>', '<C-w>L', { desc = 'Move window to the right' })
vim.keymap.set('n', '<C-S-j>', '<C-w>J', { desc = 'Move window to the lower' })
vim.keymap.set('n', '<C-S-k>', '<C-w>K', { desc = 'Move window to the upper' })
vim.keymap.set('n', '<Leader>.', '<Cmd>tabnext<CR>', { desc = 'Next tab' })
vim.keymap.set('n', '<Leader>,', '<Cmd>tabprevious<CR>', { desc = 'Previous tab' })
@@ -204,79 +253,79 @@ local function open_test()
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 = { '<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' })
-- vim.keymap.set('i', '<Tab>', function()
-- local copilot = require 'copilot.suggestion'