From 250a1d7388353c524285c05196cbe620e1c73adb Mon Sep 17 00:00:00 2001 From: sudacode Date: Tue, 15 Aug 2023 17:07:20 -0700 Subject: [PATCH] updates --- init.vim | 26 ++++---- keybindings.vim | 35 +++++------ lua/code_action_utils.lua | 15 +++++ lua/plugins.lua | 129 ++++++++++++++++++++++++++++++++++++++ plugin-confs/chatgpt.lua | 113 +-------------------------------- plugin-confs/nvim-cmp.lua | 4 +- 6 files changed, 177 insertions(+), 145 deletions(-) mode change 100644 => 100755 init.vim create mode 100644 lua/code_action_utils.lua diff --git a/init.vim b/init.vim old mode 100644 new mode 100755 index 0db1d0c..3e14814 --- a/init.vim +++ b/init.vim @@ -7,7 +7,7 @@ autocmd FileType help wincmd L autocmd FileType man wincmd L " make terminal not have line numbers autocmd TermOpen * setlocal nonumber norelativenumber - +" call code actions function lua require('settings') lua require('plugins') source ~/.config/nvim/keybindings.vim @@ -34,7 +34,7 @@ source ~/.config/nvim/plugin-confs/null-ls.lua source ~/.config/nvim/plugin-confs/nvim-cmp.lua source ~/.config/nvim/plugin-confs/fidget.lua " source ~/.config/nvim/plugin-confs/symbols-outline.lua -source ~/.config/nvim/plugin-confs/chatgpt.lua +" source ~/.config/nvim/plugin-confs/chatgpt.lua source ~/.config/nvim/plugin-confs/nvim-colorizer.lua source ~/.config/nvim/plugin-confs/nvim-dap-python.lua source ~/.config/nvim/plugin-confs/nvim-dap-bash.lua @@ -59,20 +59,18 @@ source ~/.config/nvim/plugin-confs/github-theme.lua source ~/.config/nvim/plugin-confs/onedarkpro.lua source ~/.config/nvim/plugin-confs/catppuccin.lua -" source ~/.config/nvim/lua/toggle_lsp_diagnostics.lua - " CUSTOM COMMANDS -command! -bang -nargs=? -complete=dir Files - \ call fzf#vim#files(, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh']}), 0) +" command! -bang -nargs=? -complete=dir Files +" \ call fzf#vim#files(, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh']}), 0) -command! -bang -nargs=? -complete=dir AllFiles - \ call fzf#run(fzf#wrap('allfiles', fzf#vim#with_preview({'dir': , 'sink': 'e', 'source': 'rg --files --hidden --no-ignore', 'options': ['--layout=reverse', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh']}), 0)) +" command! -bang -nargs=? -complete=dir AllFiles +" \ call fzf#run(fzf#wrap('allfiles', fzf#vim#with_preview({'dir': , 'sink': 'e', 'source': 'rg --files --hidden --no-ignore', 'options': ['--layout=reverse', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh']}), 0)) -command! -bang -nargs=? -complete=dir Lines - \ call fzf#vim#lines(, ({'options': ['--layout=reverse']}), 0) +" command! -bang -nargs=? -complete=dir Lines +" \ call fzf#vim#lines(, ({'options': ['--layout=reverse']}), 0) -command! -bang -nargs=? -complete=dir Buffers - \ call fzf#vim#buffers(, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh']}), 0) +" command! -bang -nargs=? -complete=dir Buffers +" \ call fzf#vim#buffers(, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh']}), 0) command! Reload execute "source ~/.config/nvim/init.vim" command! Config execute ":e ~/.config/nvim/init.vim" @@ -89,3 +87,7 @@ command! PS execute ":PackerSync" " colorscheme catppuccin highlight Pmenu ctermfg=white ctermbg=black gui=NONE guifg=white guibg=#282C34 highlight PmenuSel guifg=purple guibg=red + +" run code actions on cursor hold if lsp is attached +"autocmd CursorHold,CursorHoldI * lua require('code_action_utils').code_action_listener() +autocmd CursorHold,CursorHoldI * lua if vim.tbl_isempty(vim.lsp.buf_get_clients()) then require('code_action_utils').code_action_listener() end diff --git a/keybindings.vim b/keybindings.vim index 61cfe75..888f712 100644 --- a/keybindings.vim +++ b/keybindings.vim @@ -1,21 +1,29 @@ - nmap zz nmap n nzzzv nmap N Nzzzv +" paste visually without yanking to clipboard xnoremap p "_dP -nnoremap :set paste!set paste? -nnoremap :set spell!set spell? - " reselect visual selection after indent vnoremap < >gv +" move selected line(s) up or down and respect indent vnoremap J :m '>+1gv=gv vnoremap K :m '<-2gv=gv -" for toggling/hiding the split-term +" search +nnoremap // :Telescope current_buffer_fuzzy_find +nnoremap ?? :Telescope lsp_document_symbols + +" nnoremap Q !!$SHELL +" nnoremap rn :lua vim.lsp.buf.rename() + +nnoremap :bnext +nnoremap :bprev + +nnoremap :wa:FloatermToggle floatterm tnoremap :FloatermToggle floatterm tnoremap tnoremap tt :FloatermToggle split-term @@ -23,13 +31,6 @@ tnoremap tf :FloatermToggle floatterm tnoremap tp :FloatermToggle ipython tnoremap tP :FloatermToggle ipython-full -nnoremap :bnext -nnoremap :bprev -nnoremap :wa:FloatermToggle floatterm - -" open file under cursor, create if necessary -nnoremap // :Telescope current_buffer_fuzzy_find -nnoremap ?? :BLines nnoremap gA :lua vim.lsp.buf.code_actions() nnoremap gd :Telescope lsp_definitions @@ -44,17 +45,13 @@ nnoremap gl :lua vim.lsp.buf.code_lens() nnoremap gr :Telescope lsp_references nnoremap gs :lua vim.lsp.buf.signature_help() -nnoremap Q !!$SHELL - -nnoremap rn :lua vim.lsp.buf.rename() - - nnoremap bb :Telescope buffers nnoremap bk :bdelete nnoremap bn :bnext nnoremap bp :bprev nnoremap ca :lua vim.lsp.buf.code_action() +nnoremap cA :lua vim.lsp.buf.code_action() nnoremap cd :Telescope diagnostics nnoremap cDn :lua vim.diagnostic.goto_next() nnoremap cDp :lua vim.diagnostic.goto_prev() @@ -66,14 +63,14 @@ nnoremap Ct :ChatGPTRun add_tests nnoremap Co :ChatGPTRun optimize_code nnoremap Cs :ChatGPTRun summarize nnoremap Cf :ChatGPTRun fix_bugs -nnoremap Ce :ChatGPTRun explain +nnoremap Ce :ChatGPTRun explain_code xnoremap Ci :lua require('chatgpt').edit_with_instructions() xnoremap Cd :ChatGPTRun docstring xnoremap Ct :ChatGPTRun add_tests xnoremap Co :ChatGPTRun optimize_code xnoremap Cs :ChatGPTRun summarize xnoremap Cf :ChatGPTRun fix_bugs -xnoremap Ce :ChatGPTRun explain +xnoremap Ce :ChatGPTRun explain_code nnoremap db :lua require("dap").toggle_breakpoint() nnoremap dc :lua require("dap").continue() diff --git a/lua/code_action_utils.lua b/lua/code_action_utils.lua new file mode 100644 index 0000000..4fea507 --- /dev/null +++ b/lua/code_action_utils.lua @@ -0,0 +1,15 @@ +local M = {} + +local lsp_util = vim.lsp.util + +function M.code_action_listener() + local context = { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() } + local params = lsp_util.make_range_params() + params.context = context + vim.lsp.buf_request(0, 'textDocument/codeAction', params, + function(err, result, ctx, config) + -- do something with result - e.g. check if empty and show some indication such as a sign + end) +end + +return M diff --git a/lua/plugins.lua b/lua/plugins.lua index f9de423..1beb664 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -25,6 +25,7 @@ require('packer').startup(function(use) -- LSP/DEV {{{ + -- COPILOT {{{ use { "zbirenbaum/copilot.lua", event = "VimEnter", @@ -85,9 +86,132 @@ require('packer').startup(function(use) } use { "zbirenbaum/copilot-cmp" } + -- }}} use({ "jackMort/ChatGPT.nvim", commit = "24bcca7", + config = function() + require("chatgpt").setup({ + api_key_cmd = "cat /home/stickuser/.config/openai/apikey", + yank_register = "+", + edit_with_instructions = { + diff = false, + keymaps = { + close = "", + accept = "", + toggle_diff = "", + toggle_settings = "", + cycle_windows = "", + use_output_as_input = "" + } + }, + chat = { + welcome_message = "HELLO FREUD", + loading_text = "Loading, please wait ...", + question_sign = "", + answer_sign = "ﮧ", + max_line_length = 120, + sessions_window = { + border = { + style = "rounded", + text = { top = " Sessions " } + }, + win_options = { + winhighlight = "Normal:Normal,FloatBorder:FloatBorder" + } + }, + keymaps = { + close = { "" }, + yank_last = "", + yank_last_code = "", + scroll_up = "", + scroll_down = "", + new_session = "", + cycle_windows = "", + cycle_modes = "", + select_session = "", + rename_session = "r", + delete_session = "d", + draft_message = "", + toggle_settings = "", + toggle_message_role = "", + toggle_system_role_open = "", + stop_generating = "" + } + }, + popup_layout = { + default = "center", + center = { width = "80%", height = "80%" }, + right = { width = "30%", width_settings_open = "50%" } + }, + popup_window = { + border = { + highlight = "FloatBorder", + style = "rounded", + text = { top = " ChatGPT " } + }, + win_options = { + wrap = true, + linebreak = true, + foldcolumn = "1", + winhighlight = "Normal:Normal,FloatBorder:FloatBorder" + }, + buf_options = { filetype = "markdown" } + }, + system_window = { + border = { + highlight = "FloatBorder", + style = "rounded", + text = { top = " SYSTEM " } + }, + win_options = { + wrap = true, + linebreak = true, + foldcolumn = "2", + winhighlight = "Normal:Normal,FloatBorder:FloatBorder" + } + }, + popup_input = { + prompt = "  ", + border = { + highlight = "FloatBorder", + style = "rounded", + text = { top_align = "center", top = " Prompt " } + }, + win_options = { + winhighlight = "Normal:Normal,FloatBorder:FloatBorder" + }, + submit = "", + submit_n = "", + max_visible_lines = 20 + }, + settings_window = { + border = { style = "rounded", text = { top = " Settings " } }, + win_options = { + winhighlight = "Normal:Normal,FloatBorder:FloatBorder" + } + }, + openai_params = { + model = "gpt-3.5-turbo", + frequency_penalty = 0, + presence_penalty = 0, + max_tokens = 300, + temperature = 0, + top_p = 1, + n = 1 + }, + openai_edit_params = { + model = "code-davinci-edit-001", + temperature = 0, + top_p = 1, + n = 1 + }, + actions_paths = {}, + show_quickfixes_cmd = "Trouble quickfix", + predefined_chat_gpt_prompts = + "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv" + }) + end, requires = { "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim" @@ -113,6 +237,9 @@ require('packer').startup(function(use) use { 'onsails/lspkind-nvim' } use { 'jose-elias-alvarez/null-ls.nvim' } use 'folke/neodev.nvim' + + -- DAP {{{ + use 'mfussenegger/nvim-dap' use { "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap" } } use { 'mfussenegger/nvim-dap-python' } @@ -120,6 +247,8 @@ require('packer').startup(function(use) -- }}} + -- }}} + -- UI {{{ use { diff --git a/plugin-confs/chatgpt.lua b/plugin-confs/chatgpt.lua index 38c9c5b..8b13789 100644 --- a/plugin-confs/chatgpt.lua +++ b/plugin-confs/chatgpt.lua @@ -1,112 +1 @@ -require("chatgpt").setup({ - api_key_cmd = "cat /home/sudacode/.config/openai/apikey", - yank_register = "+", - edit_with_instructions = { - diff = false, - keymaps = { - close = "", - accept = "", - toggle_diff = "", - toggle_settings = "", - cycle_windows = "", - use_output_as_input = "" - } - }, - chat = { - welcome_message = WELCOME_MESSAGE, - loading_text = "Loading, please wait ...", - question_sign = "", - answer_sign = "ﮧ", - max_line_length = 120, - sessions_window = { - border = { style = "rounded", text = { top = " Sessions " } }, - win_options = { - winhighlight = "Normal:Normal,FloatBorder:FloatBorder" - } - }, - keymaps = { - close = { "" }, - yank_last = "", - yank_last_code = "", - scroll_up = "", - scroll_down = "", - new_session = "", - cycle_windows = "", - cycle_modes = "", - select_session = "", - rename_session = "r", - delete_session = "d", - draft_message = "", - toggle_settings = "", - toggle_message_role = "", - toggle_system_role_open = "", - stop_generating = "" - } - }, - popup_layout = { - default = "center", - center = { width = "80%", height = "80%" }, - right = { width = "30%", width_settings_open = "50%" } - }, - popup_window = { - border = { - highlight = "FloatBorder", - style = "rounded", - text = { top = " ChatGPT " } - }, - win_options = { - wrap = true, - linebreak = true, - foldcolumn = "1", - winhighlight = "Normal:Normal,FloatBorder:FloatBorder" - }, - buf_options = { filetype = "markdown" } - }, - system_window = { - border = { - highlight = "FloatBorder", - style = "rounded", - text = { top = " SYSTEM " } - }, - win_options = { - wrap = true, - linebreak = true, - foldcolumn = "2", - winhighlight = "Normal:Normal,FloatBorder:FloatBorder" - } - }, - popup_input = { - prompt = "  ", - border = { - highlight = "FloatBorder", - style = "rounded", - text = { top_align = "center", top = " Prompt " } - }, - win_options = { winhighlight = "Normal:Normal,FloatBorder:FloatBorder" }, - submit = "", - submit_n = "", - max_visible_lines = 20 - }, - settings_window = { - border = { style = "rounded", text = { top = " Settings " } }, - win_options = { winhighlight = "Normal:Normal,FloatBorder:FloatBorder" } - }, - openai_params = { - model = "gpt-3.5-turbo", - frequency_penalty = 0, - presence_penalty = 0, - max_tokens = 300, - temperature = 0, - top_p = 1, - n = 1 - }, - openai_edit_params = { - model = "code-davinci-edit-001", - temperature = 0, - top_p = 1, - n = 1 - }, - actions_paths = {}, - show_quickfixes_cmd = "Trouble quickfix", - predefined_chat_gpt_prompts = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv" -}) + diff --git a/plugin-confs/nvim-cmp.lua b/plugin-confs/nvim-cmp.lua index 2867628..ad47ffc 100644 --- a/plugin-confs/nvim-cmp.lua +++ b/plugin-confs/nvim-cmp.lua @@ -213,8 +213,8 @@ cmp.setup.cmdline(':', { local capabilities = require('cmp_nvim_lsp').default_capabilities() local servers = { - 'bashls', 'jedi_language_server', 'sqlls', 'jsonls', 'yamlls', 'vimls', - 'dotls', 'dockerls', 'html', 'cssls', 'lua_ls' + 'bashls', 'jedi_language_server', 'jsonls', 'yamlls', 'vimls', 'dotls', + 'dockerls', 'html', 'cssls', 'lua_ls' } for _, lsp in ipairs(servers) do if lsp == 'lua_ls' then