add menu plugin

This commit is contained in:
Gered 2024-10-06 21:50:07 -04:00
parent d51dad3e12
commit 33e762d6a5
3 changed files with 386 additions and 0 deletions

View file

@ -48,4 +48,6 @@
"trouble.nvim": { "branch": "main", "commit": "6efc446226679fda0547c0fd6a7892fd5f5b15d8" },
"vim-sleuth": { "branch": "master", "commit": "cd9d382e33bb817abe7f10cdc3a606bf1d491d75" },
"which-key.nvim": { "branch": "main", "commit": "bfec3d6bc0a9b0b2cb11644642f78c2c3915eef0" }
"volt": { "branch": "main", "commit": "43f72b49037c191eb3cfe26ba7a5574b4bfce226" },
"which-key.nvim": { "branch": "main", "commit": "fb070344402cfc662299d9914f5546d840a22126" }
}

View file

@ -16,4 +16,17 @@ function M.in_cargo_project()
return M.get_cargo_project_file() ~= ''
end
function M.in_git_project()
return vim.fn.finddir('.git', '.;') ~= ''
end
function M.contains(tbl, v)
for i, value in ipairs(tbl) do
if value == v then
return true
end
end
return false
end
return M

371
nvim/lua/plugins/menu.lua Normal file
View file

@ -0,0 +1,371 @@
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.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_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_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
return {
{
'nvchad/volt',
{
'nvchad/menu',
config = function()
local ignore_ft = {
'help',
'Outline',
'trouble',
}
vim.keymap.set('n', '<RightMouse>', function()
if not helper.contains(ignore_ft, vim.bo.ft) then
vim.cmd.exec '"normal! \\<RightMouse>"'
require('menu').open(get_default_menu 'n', { mouse = true })
end
end, {})
end,
},
},
}