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 = 'tt', }, { name = ' Toggle Outline', cmd = function() vim.cmd 'Outline' end, rtxt = '', }, { name = '󱖫 Toggle Buffer Diagnostics', cmd = function() vim.cmd 'Trouble diagnostics toggle pinned=true filter.buf=0' end, rtxt = '', }, { name = '󱖫 Toggle Inline Diagnostics', cmd = function() vim.diagnostic.enable(not vim.diagnostic.is_enabled()) end, rtxt = 'tn', }, { name = 'separator' }, { name = 'Format Buffer', cmd = function() require('conform').format { async = true, lsp_format = 'fallback' } end, rtxt = '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 = 'c', }) end if helper.is_golang_filetype() then table.insert(menu, 1, { name = '󰟓 Golang Actions', hl = 'ExBlue', items = get_golang_menu(), rtxt = 'g', }) end if helper.in_git_project() then table.insert(menu, 1, { name = ' Git Actions', hl = 'ExGreen', items = get_git_menu(), rtxt = '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 = '', }, { name = ' Open in horizontal split', cmd = function() nvim_tree.node.open.horizontal(current_node()) end, rtxt = '', }, { 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 = '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 = 'th', }, } end function get_rust_menu() return { { name = 'Code Actions', cmd = function() vim.cmd 'RustLsp codeAction' end, rtxt = 'ra', }, { name = 'separator' }, { name = ' Run Last Target', hl = 'ExGreen', cmd = function() vim.cmd 'RustLsp! runnables' end, rtxt = 'rr', }, { name = ' Runnables', hl = 'ExGreen', cmd = function() vim.cmd 'RustLsp runnables' end, rtxt = 'rR', }, { name = '󰃤 Debug Last Target', hl = 'ExBlue', cmd = function() vim.cmd 'RustLsp! debuggables' end, rtxt = 'rd', }, { name = '󰃤 Debuggables', hl = 'ExBlue', cmd = function() vim.cmd 'RustLsp debuggables' end, rtxt = 'rD', }, { name = '󰸞 Testables', hl = 'ExRed', cmd = function() vim.cmd 'RustLsp testables' end, rtxt = 'rt', }, { name = 'separator' }, { name = 'Open Cargo.toml', cmd = function() vim.cmd 'RustLsp openCargo' end, rtxt = 'ro', }, { name = 'Reload Workspace', cmd = function() vim.cmd 'RustLsp reloadWorkspace' end, rtxt = 'rl', }, } end function get_cmake_menu() return { { name = 'Build', hl = 'ExRed', cmd = function() vim.cmd 'CMakeBuild' end, rtxt = 'cb', }, { name = 'Clean', cmd = function() vim.cmd 'CMakeClean' end, rtxt = 'cc', }, { name = 'Select Build Target', cmd = function() vim.cmd 'CMakeSelectBuildTarget' end, rtxt = 'cB', }, { name = 'Select Build Type', cmd = function() vim.cmd 'CMakeSelectBuildType' end, rtxt = 'cp', }, { name = 'separator' }, { name = ' Run', hl = 'ExGreen', cmd = function() vim.cmd 'CMakeRun' end, rtxt = 'cr', }, { name = '󰃤 Debug', hl = 'ExBlue', cmd = function() vim.cmd 'CMakeDebug' end, rtxt = 'cd', }, { name = 'Select Launch Target', cmd = function() vim.cmd 'CMakeSelectLaunchTarget' end, rtxt = 'cl', }, { name = ' Target Settings', cmd = function() vim.cmd 'CMakeTargetSettings' end, rtxt = 'cs', }, { name = 'separator' }, { name = 'Generate', cmd = function() vim.cmd 'CMakeGenerate' end, rtxt = 'cg', }, { name = ' Project Settings', cmd = function() vim.cmd 'CMakeSettings' end, rtxt = 'cS', }, } end function get_golang_menu() return { { name = 'Code Actions', cmd = function() vim.cmd 'GoCodeAction' end, rtxt = 'ga', }, { name = 'Code Lens Actions', cmd = function() vim.cmd 'GoCodeLenAct' end, rtxt = 'gA', }, { name = 'separator' }, { name = 'Build', hl = 'ExRed', cmd = function() vim.cmd 'GoBuild' end, rtxt = 'gb', }, { name = ' Run', hl = 'ExGreen', cmd = function() vim.cmd 'GoRun' end, rtxt = 'gr', }, { name = '󰃤 Debug', hl = 'ExBlue', cmd = function() vim.cmd 'GoDebug' end, rtxt = 'gd', }, { name = '󰸞 Test', hl = 'ExRed', cmd = function() vim.cmd 'GoTest' end, rtxt = 'gt', }, { name = 'separator' }, { name = 'Format', cmd = function() vim.cmd 'GoFmt' end, rtxt = 'gf', }, { name = 'Imports', cmd = function() vim.cmd 'GoImports' end, rtxt = 'gi', }, { name = 'Get', cmd = function() vim.cmd 'GoGet' end, rtxt = 'gg', }, { name = 'separator' }, { name = 'Install Dependent Tools', cmd = function() vim.cmd 'GoInstallBinaries' end, rtxt = 'gN', }, { name = 'Update Dependent Tools', cmd = function() vim.cmd = 'GoUpdateBinaries' end, rtxt = 'gU', }, } end function get_git_menu() local gitsigns = require 'gitsigns' return { { name = 'Stage hunk', cmd = gitsigns.stage_hunk, rtxt = 'hs', }, { name = 'Reset hunk', cmd = gitsigns.reset_hunk, rtxt = 'hr', }, { name = 'Undo stage hunk', cmd = gitsigns.undo_stage_hunk, rtxt = 'hu', }, { name = 'separator' }, { name = 'Stage buffer', cmd = gitsigns.stage_buffer, rtxt = 'hS', }, { name = 'Reset buffer', cmd = gitsigns.reset_buffer, rtxt = 'hR', }, { name = 'separator' }, { name = 'Blame line', cmd = gitsigns.blame_line, rtxt = 'hb', }, { name = ' Toggle Current line blame', cmd = gitsigns.toggle_current_line_blame, rtxt = 'tb', }, { name = 'separator' }, { name = 'Preview hunk', cmd = gitsigns.preview_hunk, rtxt = 'hp', }, { name = 'Diff against index', cmd = gitsigns.diffthis, rtxt = 'hd', }, { name = 'Diff against last commit', cmd = function() gitsigns.diffthis '@' end, rtxt = '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 = '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', '', function() if not helper.contains(ignore_ft, vim.bo.ft) then vim.cmd.exec '"normal! \\"' 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, }, }, }