Skip to content

Commit

Permalink
extend menu and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheavni committed Nov 24, 2023
1 parent befa3c8 commit 9c1d49c
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 271 deletions.
47 changes: 43 additions & 4 deletions .config/nvim/lua/plugins/dap.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
local actions = function()
local dap = require 'dap'
local dapui = require 'dapui'
return {
['continue (F5)'] = function()
dap.continue()
end,
['step over'] = function()
dap.step_over()
end,
['step into'] = function()
dap.step_into()
end,
['step out'] = function()
dap.step_out()
end,
['toggle breakpoint'] = function()
dap.toggle_breakpoint()
end,
['clear all breakpoints'] = function()
dap.clear_breakpoints()
end,
['open repl'] = function()
dap.repl.open()
end,
['run last'] = function()
dap.run_last()
end,
['ui'] = function()
dapui.toggle()
end,
['log level trace'] = function()
dap.set_log_level 'TRACE'
vim.cmd 'DapShowLog'
end,
}
end

local M = {
'mfussenegger/nvim-dap',
init = function()
vim.api.nvim_create_user_command('DAP', function()
require('user.menu').set_dap_actions()
require('dap').toggle_breakpoint()
require 'dap'
require('dapui').toggle()
end, {})
end,
Expand Down Expand Up @@ -48,9 +85,8 @@ M.config = function()
require('telescope').load_extension 'dap'
local dapui = require 'dapui'
dapui.setup()
require('nvim-dap-virtual-text').setup()
require('nvim-dap-virtual-text').setup { enabled = true }

vim.g.dap_virtual_text = true
vim.fn.sign_define('DapBreakpoint', { text = '🛑', texthl = '', linehl = '', numhl = '' })
vim.fn.sign_define('DapBreakpointRejected', { text = '', texthl = '', linehl = '', numhl = '' })
vim.fn.sign_define('DapStopped', { text = '⭕️', texthl = '', linehl = '', numhl = '' })
Expand All @@ -59,6 +95,9 @@ M.config = function()
nnoremap('<F5>', '<cmd>lua require("dap").continue()<cr>', opts.no_remap)
nnoremap('<leader>bp', '<cmd>lua require("dap").toggle_breakpoint()<cr>', opts.no_remap)

-- Actions
require('user.menu').add_actions('DAP', actions())

-- Python
require('dap-python').setup '/usr/local/bin/python3'
require('dap-python').setup(vim.fn.stdpath 'data' .. '/mason/packages/debugpy/venv/bin/python3')
Expand Down
155 changes: 153 additions & 2 deletions .config/nvim/lua/plugins/git.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,154 @@
local actions_pretty_print = function(message)
require('user.utils').pretty_print(message, 'Git Actions', '')
end

local actions = function()
return {
['Change branch (F4)'] = function()
require('user.git-branches').open()
end,
['Checkout new branch (:Gcb {new_branch})'] = function()
_G.create_new_branch { args = '' }
end,
['Work in Progress commit (on git window - wip)'] = function()
vim.cmd 'call Enter_Wip_Moshe()'
actions_pretty_print 'Created a work in progress commit.'
end,
['Diff File History'] = function()
vim.ui.input({ prompt = 'Enter file path (empty for current file): ' }, function(file_to_check)
if file_to_check == '' then
file_to_check = '%'
end

vim.cmd('DiffviewFileHistory ' .. file_to_check)
end)
end,
['Diff with branch'] = function()
vim.ui.input({ prompt = 'Enter branch to diff with: ' }, function(branch_to_diff)
if not branch_to_diff then
actions_pretty_print 'Canceled.'
return
end
vim.cmd('DiffviewOpen origin/' .. branch_to_diff .. '..HEAD')
end)
end,
['Diff file with branch'] = function()
vim.ui.input({ prompt = 'Enter branch to diff with: ' }, function(branch_to_diff)
if not branch_to_diff then
actions_pretty_print 'Canceled.'
return
end
vim.cmd('DiffviewFileHistory ' .. branch_to_diff)
end)
end,
['Diff close'] = function()
vim.cmd 'DiffviewClose'
end,
['Blame'] = function()
vim.cmd 'G blame'
end,
['Pull origin master (:Gpom)'] = function()
vim.cmd 'Gpom'
actions_pretty_print 'Pulled from origin master.'
end,
['Pull origin {branch}'] = function()
vim.ui.input({ default = 'main', prompt = 'Enter branch to pull from: ' }, function(branch_to_pull)
if not branch_to_pull then
actions_pretty_print 'Canceled.'
return
end
vim.cmd('G pull origin ' .. branch_to_pull)
actions_pretty_print('Pulled from origin ' .. branch_to_pull)
end)
end,
['Merge origin/master (:Gmom)'] = function()
vim.cmd 'Gmom'
actions_pretty_print 'Merged with origin/master. (might need to fetch new commits)'
end,
['Open Status / Menu (<leader>gg / :G)'] = function()
vim.cmd 'Git'
end,
['Open GitHub on this line (:ToGithub)'] = function()
vim.cmd 'ToGithub'
end,
['Log'] = function()
vim.cmd 'G log --all --decorate --oneline'
end,
['See all tags'] = function()
local tags = vim.fn.FugitiveExecute('tag').stdout
vim.ui.select(tags, { prompt = 'Select tag to copy to clipboard' }, function(selection)
if not selection then
actions_pretty_print 'Canceled.'
return
end
vim.fn.setreg('+', selection)
actions_pretty_print('Copied ' .. selection .. ' to clipboard.')
end)
end,
['Create tag'] = function()
vim.ui.input({ prompt = 'Enter tag name to create: ' }, function(input)
if not input then
actions_pretty_print 'Canceled.'
return
end
vim.cmd('G tag ' .. input)
vim.ui.select({ 'Yes', 'No' }, { prompt = 'Push?' }, function(choice)
if choice == 'Yes' then
vim.cmd 'G push --tags'
actions_pretty_print('Tag ' .. input .. ' created and pushed.')
else
actions_pretty_print('Tag ' .. input .. ' created.')
end
end)
end)
end,
['Delete tag'] = function()
local tags = vim.fn.FugitiveExecute('tag').stdout

vim.ui.select(tags, { prompt = 'Enter tag name to delete' }, function(input)
if not input then
actions_pretty_print 'Canceled.'
return
end
actions_pretty_print('Deleting tag ' .. input .. ' locally...')
vim.cmd('G tag -d ' .. input)
vim.ui.select({ 'Yes', 'No' }, { prompt = 'Remove from remote?' }, function(choice)
if choice == 'Yes' then
actions_pretty_print('Deleting tag ' .. input .. ' from remote...')
vim.cmd('G push origin :refs/tags/' .. input)
actions_pretty_print('Tag ' .. input .. ' deleted from local and remote.')
else
actions_pretty_print('Tag ' .. input .. ' deleted locally.')
end
end)
end)
end,
['Find in all commits'] = function()
local rev_list = vim.fn.FugitiveExecute({ 'rev-list', '--all' }).stdout
vim.ui.input({ prompt = 'Enter search term: ' }, function(search_term)
if not search_term then
actions_pretty_print 'Canceled.'
return
end
actions_pretty_print('Searching for ' .. search_term .. ' in all commits...')
vim.cmd('silent Ggrep ' .. vim.fn.fnameescape(search_term) .. ' ' .. table.concat(rev_list, ' '))
end)
end,
['Push (:Gp)'] = function()
vim.cmd 'Gp'
end,
['Pull (:Gl)'] = function()
vim.cmd 'Gl'
end,
['Add (Stage) All'] = function()
vim.cmd 'G add -A'
end,
['Unstage All'] = function()
vim.cmd 'G reset'
end,
}
end

local fugitive_config = function()
local utils = require 'user.utils'
local nmap = utils.nmap
Expand Down Expand Up @@ -198,9 +349,9 @@ endfunction
----------------------
-- Git actions menu --
----------------------
local actions = require('user.actions').git
require('user.menu').add_actions('Git', actions())
nmap('<leader>gm', function()
vim.ui.select(vim.tbl_keys(actions), { prompt = 'Choose git action' }, function(choice)
vim.ui.select(vim.tbl_keys(actions()), { prompt = 'Choose git action' }, function(choice)
if choice then
actions[choice]()
end
Expand Down
53 changes: 52 additions & 1 deletion .config/nvim/lua/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
local actions = function()
return {
['Format (<leader>lp)'] = function()
require('plugins.lsp.formatting').format()
end,
['Code Actions (<leader>la)'] = function()
vim.lsp.buf.code_action()
end,
['Code Lens (<leader>lx)'] = function()
vim.lsp.codelens.run()
end,
['Show Definition (gd)'] = function()
vim.cmd 'Lspsaga peek_definition'
end,
['Show Declaration (gD)'] = function()
vim.lsp.buf.declaration()
end,
['Show Type Definition (gy)'] = function()
vim.lsp.buf.type_definition()
end,
['Show Implementation (gi)'] = function()
vim.lsp.buf.implementation()
end,
['Find References (gr)'] = function()
vim.cmd 'Lspsaga finder'
end,
['Signature Help (<leader>lk)'] = function()
vim.lsp.buf.signature_help()
end,
['Signature Documentation (K)'] = function()
-- vim.lsp.buf.hover()
vim.cmd 'Lspsaga hover_doc'
end,
['Rename symbol (<leader>lrn)'] = function()
vim.cmd 'Lspsaga rename ++project'
end,
['Diagnostics quickfix list (<leader>lq)'] = function()
vim.diagnostic.setqflist()
end,
['Clear Diagnostics'] = function()
vim.diagnostic.reset()
end,
['Delete Log'] = function()
vim.fn.system { 'rm', '-rf', vim.lsp.get_log_path() }
end,
['Add YAML Schema Modeline'] = function()
require('user.additional-schemas').init()
end,
}
end

function _G.lsp_tmp_write(should_delete)
local tmp = vim.fn.tempname()
vim.cmd(string.format('write %s', tmp))
Expand Down Expand Up @@ -148,7 +199,7 @@ M.init = function()
end

M.config = function(_, opts)
require('user.menu').set_lsp_actions()
require('user.menu').add_actions('LSP', actions())
require('plugins.lsp.handlers').setup()

-- Set formatting of lsp log
Expand Down
Loading

0 comments on commit 9c1d49c

Please sign in to comment.