620 lines
12 KiB
Lua
620 lines
12 KiB
Lua
local helper = require 'helper'
|
|
|
|
function get_default_menu()
|
|
local menu = {
|
|
{
|
|
name = ' LSP Actions',
|
|
hl = 'ExBlue',
|
|
items = get_lsp_menu(),
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = ' Toggle Terminal',
|
|
hl = 'ExRed',
|
|
cmd = function()
|
|
require('toggleterm').toggle()
|
|
end,
|
|
rtxt = '<leader>tt',
|
|
},
|
|
{
|
|
name = ' Toggle Outline',
|
|
cmd = function()
|
|
vim.cmd 'Outline'
|
|
end,
|
|
rtxt = '<F2>',
|
|
},
|
|
{
|
|
name = ' Toggle Buffer Diagnostics',
|
|
cmd = function()
|
|
vim.cmd 'Trouble diagnostics toggle pinned=true filter.buf=0'
|
|
end,
|
|
rtxt = '<F3>',
|
|
},
|
|
{
|
|
name = ' Toggle Inline Diagnostics',
|
|
cmd = function()
|
|
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
|
|
end,
|
|
rtxt = '<leader>tn',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Format Buffer',
|
|
cmd = function()
|
|
require('conform').format { async = true, lsp_format = 'fallback' }
|
|
end,
|
|
rtxt = '<leader>f',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Copy Content',
|
|
cmd = 'y+',
|
|
},
|
|
{
|
|
name = 'Delete Content',
|
|
cmd = '%d',
|
|
},
|
|
}
|
|
|
|
if helper.in_cargo_project() then
|
|
table.insert(menu, 1, {
|
|
name = ' Rust Actions',
|
|
hl = 'ExBlue',
|
|
items = get_rust_menu(),
|
|
})
|
|
end
|
|
|
|
if helper.in_cmake_project() then
|
|
table.insert(menu, 1, {
|
|
name = ' CMake Actions',
|
|
hl = 'ExBlue',
|
|
items = get_cmake_menu(),
|
|
rtxt = '<leader>c',
|
|
})
|
|
end
|
|
|
|
if helper.is_golang_filetype() then
|
|
table.insert(menu, 1, {
|
|
name = ' Golang Actions',
|
|
hl = 'ExBlue',
|
|
items = get_golang_menu(),
|
|
rtxt = '<leader>g',
|
|
})
|
|
end
|
|
|
|
if helper.in_git_project() then
|
|
table.insert(menu, 1, {
|
|
name = ' Git Actions',
|
|
hl = 'ExGreen',
|
|
items = get_git_menu(),
|
|
rtxt = '<leader>h',
|
|
})
|
|
end
|
|
|
|
return menu
|
|
end
|
|
|
|
function get_nvim_tree_menu()
|
|
local nvim_tree = require 'nvim-tree.api'
|
|
local current_node = nvim_tree.tree.get_node_under_cursor
|
|
return {
|
|
{
|
|
name = ' New file',
|
|
hl = 'ExBlue',
|
|
cmd = function()
|
|
nvim_tree.fs.create(current_node())
|
|
end,
|
|
rtxt = 'a',
|
|
},
|
|
{
|
|
name = ' New folder',
|
|
hl = 'ExBlue',
|
|
cmd = function()
|
|
nvim_tree.fs.create(current_node())
|
|
end,
|
|
rtxt = 'a',
|
|
},
|
|
{
|
|
name = 'separator',
|
|
},
|
|
{
|
|
name = ' Open',
|
|
hl = 'ExGreen',
|
|
cmd = function()
|
|
nvim_tree.node.open.edit(current_node())
|
|
end,
|
|
rtxt = 'o',
|
|
},
|
|
{
|
|
name = ' Open in vertical split',
|
|
cmd = function()
|
|
nvim_tree.node.open.vertical(current_node())
|
|
end,
|
|
rtxt = '<C-v>',
|
|
},
|
|
{
|
|
name = ' Open in horizontal split',
|
|
cmd = function()
|
|
nvim_tree.node.open.horizontal(current_node())
|
|
end,
|
|
rtxt = '<C-x>',
|
|
},
|
|
{
|
|
name = 'separator',
|
|
},
|
|
{
|
|
name = ' Cut',
|
|
cmd = function()
|
|
nvim_tree.fs.cut(current_node())
|
|
end,
|
|
rtxt = 'x',
|
|
},
|
|
{
|
|
name = ' Copy',
|
|
cmd = function()
|
|
nvim_tree.fs.copy.node(current_node())
|
|
end,
|
|
rtxt = 'c',
|
|
},
|
|
{
|
|
name = ' Paste',
|
|
cmd = function()
|
|
nvim_tree.fs.paste(current_node())
|
|
end,
|
|
rtxt = 'p',
|
|
},
|
|
{
|
|
name = 'Copy absolute path',
|
|
cmd = function()
|
|
nvim_tree.fs.copy.absolute_path(current_node())
|
|
end,
|
|
rtxt = 'gy',
|
|
},
|
|
{
|
|
name = 'Copy relative path',
|
|
cmd = function()
|
|
nvim_tree.fs.copy.relative_path(current_node())
|
|
end,
|
|
rtxt = 'Y',
|
|
},
|
|
{
|
|
name = 'Copy filename',
|
|
cmd = function()
|
|
nvim_tree.fs.copy.filename(current_node())
|
|
end,
|
|
rtxt = 'y',
|
|
},
|
|
{
|
|
name = 'separator',
|
|
},
|
|
{
|
|
name = ' Rename',
|
|
cmd = function()
|
|
nvim_tree.fs.rename(current_node())
|
|
end,
|
|
rtxt = 'r',
|
|
},
|
|
{
|
|
name = ' Delete',
|
|
hl = 'ExRed',
|
|
cmd = function()
|
|
nvim_tree.fs.remove(current_node())
|
|
end,
|
|
rtxt = 'd',
|
|
},
|
|
}
|
|
end
|
|
|
|
function get_lsp_menu()
|
|
return {
|
|
{
|
|
name = 'Code Actions',
|
|
cmd = function()
|
|
vim.lsp.buf.code_action()
|
|
end,
|
|
rtxt = '<leader>la',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Goto Definition',
|
|
cmd = vim.lsp.buf.definition,
|
|
rtxt = 'gd',
|
|
},
|
|
{
|
|
name = 'Goto Declaration',
|
|
cmd = vim.lsp.buf.declaration,
|
|
rtxt = 'gD',
|
|
},
|
|
{
|
|
name = 'Goto References',
|
|
cmd = function()
|
|
require('telescope.builtin').lsp_references()
|
|
end,
|
|
rtxt = 'gr',
|
|
},
|
|
{
|
|
name = 'Goto Implementation',
|
|
cmd = function()
|
|
require('telescope.builtin').lsp_implementations()
|
|
end,
|
|
rtxt = 'gI',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Show signature help',
|
|
cmd = vim.lsp.buf.signature_help,
|
|
},
|
|
{
|
|
name = 'Show symbol help',
|
|
cmd = vim.lsp.buf.hover,
|
|
rtxt = 'K',
|
|
},
|
|
{
|
|
name = ' Toggle inlay hints',
|
|
cmd = function()
|
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
|
|
end,
|
|
rtxt = '<leader>th',
|
|
},
|
|
}
|
|
end
|
|
|
|
function get_rust_menu()
|
|
return {
|
|
{
|
|
name = 'Code Actions',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp codeAction'
|
|
end,
|
|
rtxt = '<leader>ra',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = ' Run Last Target',
|
|
hl = 'ExGreen',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp! runnables'
|
|
end,
|
|
rtxt = '<leader>rr',
|
|
},
|
|
{
|
|
name = ' Runnables',
|
|
hl = 'ExGreen',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp runnables'
|
|
end,
|
|
rtxt = '<leader>rR',
|
|
},
|
|
{
|
|
name = ' Debug Last Target',
|
|
hl = 'ExBlue',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp! debuggables'
|
|
end,
|
|
rtxt = '<leader>rd',
|
|
},
|
|
{
|
|
name = ' Debuggables',
|
|
hl = 'ExBlue',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp debuggables'
|
|
end,
|
|
rtxt = '<leader>rD',
|
|
},
|
|
{
|
|
name = ' Testables',
|
|
hl = 'ExRed',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp testables'
|
|
end,
|
|
rtxt = '<leader>rt',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Open Cargo.toml',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp openCargo'
|
|
end,
|
|
rtxt = '<leader>ro',
|
|
},
|
|
{
|
|
name = 'Reload Workspace',
|
|
cmd = function()
|
|
vim.cmd 'RustLsp reloadWorkspace'
|
|
end,
|
|
rtxt = '<leader>rl',
|
|
},
|
|
}
|
|
end
|
|
|
|
function get_cmake_menu()
|
|
return {
|
|
{
|
|
name = 'Build',
|
|
hl = 'ExRed',
|
|
cmd = function()
|
|
vim.cmd 'CMakeBuild'
|
|
end,
|
|
rtxt = '<leader>cb',
|
|
},
|
|
{
|
|
name = 'Clean',
|
|
cmd = function()
|
|
vim.cmd 'CMakeClean'
|
|
end,
|
|
rtxt = '<leader>cc',
|
|
},
|
|
{
|
|
name = 'Select Build Target',
|
|
cmd = function()
|
|
vim.cmd 'CMakeSelectBuildTarget'
|
|
end,
|
|
rtxt = '<leader>cB',
|
|
},
|
|
{
|
|
name = 'Select Build Type',
|
|
cmd = function()
|
|
vim.cmd 'CMakeSelectBuildType'
|
|
end,
|
|
rtxt = '<leader>cp',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = ' Run',
|
|
hl = 'ExGreen',
|
|
cmd = function()
|
|
vim.cmd 'CMakeRun'
|
|
end,
|
|
rtxt = '<leader>cr',
|
|
},
|
|
{
|
|
name = ' Debug',
|
|
hl = 'ExBlue',
|
|
cmd = function()
|
|
vim.cmd 'CMakeDebug'
|
|
end,
|
|
rtxt = '<leader>cd',
|
|
},
|
|
{
|
|
name = 'Select Launch Target',
|
|
cmd = function()
|
|
vim.cmd 'CMakeSelectLaunchTarget'
|
|
end,
|
|
rtxt = '<leader>cl',
|
|
},
|
|
{
|
|
name = ' Target Settings',
|
|
cmd = function()
|
|
vim.cmd 'CMakeTargetSettings'
|
|
end,
|
|
rtxt = '<leader>cs',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Generate',
|
|
cmd = function()
|
|
vim.cmd 'CMakeGenerate'
|
|
end,
|
|
rtxt = '<leader>cg',
|
|
},
|
|
{
|
|
name = ' Project Settings',
|
|
cmd = function()
|
|
vim.cmd 'CMakeSettings'
|
|
end,
|
|
rtxt = '<leader>cS',
|
|
},
|
|
}
|
|
end
|
|
|
|
function get_golang_menu()
|
|
return {
|
|
{
|
|
name = 'Code Actions',
|
|
cmd = function()
|
|
vim.cmd 'GoCodeAction'
|
|
end,
|
|
rtxt = '<leader>ga',
|
|
},
|
|
{
|
|
name = 'Code Lens Actions',
|
|
cmd = function()
|
|
vim.cmd 'GoCodeLenAct'
|
|
end,
|
|
rtxt = '<leader>gA',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Build',
|
|
hl = 'ExRed',
|
|
cmd = function()
|
|
vim.cmd 'GoBuild'
|
|
end,
|
|
rtxt = '<leader>gb',
|
|
},
|
|
{
|
|
name = ' Run',
|
|
hl = 'ExGreen',
|
|
cmd = function()
|
|
vim.cmd 'GoRun'
|
|
end,
|
|
rtxt = '<leader>gr',
|
|
},
|
|
{
|
|
name = ' Debug',
|
|
hl = 'ExBlue',
|
|
cmd = function()
|
|
vim.cmd 'GoDebug'
|
|
end,
|
|
rtxt = '<leader>gd',
|
|
},
|
|
{
|
|
name = ' Test',
|
|
hl = 'ExRed',
|
|
cmd = function()
|
|
vim.cmd 'GoTest'
|
|
end,
|
|
rtxt = '<leader>gt',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Format',
|
|
cmd = function()
|
|
vim.cmd 'GoFmt'
|
|
end,
|
|
rtxt = '<leader>gf',
|
|
},
|
|
{
|
|
name = 'Imports',
|
|
cmd = function()
|
|
vim.cmd 'GoImports'
|
|
end,
|
|
rtxt = '<leader>gi',
|
|
},
|
|
{
|
|
name = 'Get',
|
|
cmd = function()
|
|
vim.cmd 'GoGet'
|
|
end,
|
|
rtxt = '<leader>gg',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Install Dependent Tools',
|
|
cmd = function()
|
|
vim.cmd 'GoInstallBinaries'
|
|
end,
|
|
rtxt = '<leader>gN',
|
|
},
|
|
{
|
|
name = 'Update Dependent Tools',
|
|
cmd = function()
|
|
vim.cmd = 'GoUpdateBinaries'
|
|
end,
|
|
rtxt = '<leader>gU',
|
|
},
|
|
}
|
|
end
|
|
|
|
function get_git_menu()
|
|
local gitsigns = require 'gitsigns'
|
|
return {
|
|
{
|
|
name = 'Stage hunk',
|
|
cmd = gitsigns.stage_hunk,
|
|
rtxt = '<leader>hs',
|
|
},
|
|
{
|
|
name = 'Reset hunk',
|
|
cmd = gitsigns.reset_hunk,
|
|
rtxt = '<leader>hr',
|
|
},
|
|
{
|
|
name = 'Undo stage hunk',
|
|
cmd = gitsigns.undo_stage_hunk,
|
|
rtxt = '<leader>hu',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Stage buffer',
|
|
cmd = gitsigns.stage_buffer,
|
|
rtxt = '<leader>hS',
|
|
},
|
|
{
|
|
name = 'Reset buffer',
|
|
cmd = gitsigns.reset_buffer,
|
|
rtxt = '<leader>hR',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Blame line',
|
|
cmd = gitsigns.blame_line,
|
|
rtxt = '<leader>hb',
|
|
},
|
|
{
|
|
name = ' Toggle Current line blame',
|
|
cmd = gitsigns.toggle_current_line_blame,
|
|
rtxt = '<leader>tb',
|
|
},
|
|
{ name = 'separator' },
|
|
{
|
|
name = 'Preview hunk',
|
|
cmd = gitsigns.preview_hunk,
|
|
rtxt = '<leader>hp',
|
|
},
|
|
{
|
|
name = 'Diff against index',
|
|
cmd = gitsigns.diffthis,
|
|
rtxt = '<leader>hd',
|
|
},
|
|
{
|
|
name = 'Diff against last commit',
|
|
cmd = function()
|
|
gitsigns.diffthis '@'
|
|
end,
|
|
rtxt = '<leader>hD',
|
|
},
|
|
}
|
|
end
|
|
|
|
local quit_only_ft = {
|
|
'help',
|
|
'Outline',
|
|
'trouble',
|
|
'toggleterm',
|
|
'man',
|
|
}
|
|
|
|
function add_close_quit_menuitem(tbl)
|
|
if table.getn(tbl) > 0 then
|
|
table.insert(tbl, { name = 'separator' })
|
|
end
|
|
if not helper.contains(quit_only_ft, vim.bo.ft) then
|
|
table.insert(tbl, {
|
|
name = ' Close Buffer',
|
|
cmd = 'BufferClose',
|
|
rtxt = '<leader>bd',
|
|
})
|
|
end
|
|
table.insert(tbl, {
|
|
name = ' Quit Window',
|
|
cmd = 'q',
|
|
rtxt = 'q',
|
|
})
|
|
end
|
|
|
|
return {
|
|
{
|
|
'nvchad/volt',
|
|
{
|
|
'nvchad/menu',
|
|
config = function()
|
|
local ignore_ft = {
|
|
'dapui_scopes',
|
|
'dapui_breakpoints',
|
|
'dapui_stacks',
|
|
'dapui_watches',
|
|
'dap-repl',
|
|
'dapui_console',
|
|
}
|
|
vim.keymap.set('n', '<RightMouse>', function()
|
|
if not helper.contains(ignore_ft, vim.bo.ft) then
|
|
vim.cmd.exec '"normal! \\<RightMouse>"'
|
|
local menu
|
|
if vim.bo.ft == 'NvimTree' then
|
|
menu = get_nvim_tree_menu()
|
|
elseif helper.contains(quit_only_ft, vim.bo.ft) then
|
|
menu = {}
|
|
add_close_quit_menuitem(menu)
|
|
else
|
|
menu = get_default_menu()
|
|
add_close_quit_menuitem(menu)
|
|
end
|
|
require('menu').open(menu, { mouse = true })
|
|
end
|
|
end, {})
|
|
end,
|
|
},
|
|
},
|
|
}
|