diff --git a/init.vim b/init.vim index fe71984..8649414 100755 --- a/init.vim +++ b/init.vim @@ -36,11 +36,11 @@ source ~/.config/nvim/plugin-confs/null-ls.lua source ~/.config/nvim/plugin-confs/nvim-cmp.lua source ~/.config/nvim/plugin-confs/lsp-format.lua source ~/.config/nvim/plugin-confs/nvim-lint.lua +source ~/.config/nvim/plugin-confs/codecompanion.lua source ~/.config/nvim/plugin-confs/luasnip.lua source ~/.config/nvim/plugin-confs/fidget.lua source ~/.config/nvim/plugin-confs/rainbow-delimiters.lua " source ~/.config/nvim/plugin-confs/symbols-outline.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 diff --git a/keybindings.vim b/keybindings.vim index a695f98..8fa2ab0 100644 --- a/keybindings.vim +++ b/keybindings.vim @@ -54,25 +54,23 @@ nnoremap bp :bprev nnoremap ca :lua vim.lsp.buf.code_action() nnoremap cA :lua vim.lsp.buf.code_action() +nnoremap cc :CodeCompanionChat +nnoremap ci :CodeCompanion nnoremap cd :Telescope diagnostics nnoremap cDn :lua vim.diagnostic.goto_next() nnoremap cDp :lua vim.diagnostic.goto_prev() nnoremap cl :lua vim.diagnostic.setloclist() nnoremap cp :vert Copilot panel -nnoremap Ci :lua require('chatgpt').edit_with_instructions() -nnoremap Cd :ChatGPTRun docstring -nnoremap Ct :ChatGPTRun add_tests -nnoremap Co :ChatGPTRun optimize_code -nnoremap Cs :ChatGPTRun summarize -nnoremap Cf :ChatGPTRun fix_bugs -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_code +nnoremap Ca :CodeCompanionActions +nnoremap Cc :CodeCompanionChat +nnoremap Cc :CodeCompanionChat +nnoremap Ci :CodeCompanion +nnoremap Ct :CodeCompanionChat Toggle +vnoremap Cc :CodeCompanionChat Add +vnoremap Ce :CodeCompanion /explain +vnoremap Cf :CodeCompanion /fix +vnoremap Cl :CodeCompanion /lsp +vnoremap CT :CodeCompanion /tests nnoremap db :lua require("dap").toggle_breakpoint() nnoremap dc :lua require("dap").continue() @@ -157,7 +155,7 @@ nnoremap n :NvimTreeToggle nnoremap ob :Telescope file_browser -nnoremap oc :ChatGPT +nnoremap oc :CodeCompanionChat nnoremap oC :e ~/.config/nvim/init.vim nnoremap oB :FloatermNew --title=btop --opener=vsplit btop nnoremap od :FloatermNew --title=lazydocker --opener=vsplit lazydocker @@ -184,6 +182,7 @@ nnoremap tp :FloatermToggle ipython nnoremap tP :FloatermToggle ipython-full nnoremap tt :FloatermToggle split-term nnoremap td :DBUIToggle +nnoremap tc :CodeCompanionChat Toggle nnoremap Tc :Telescope color_names theme=dropdown layout_config={width=0.45,height=25,prompt_position="bottom"} layout_strategy=vertical nnoremap Tg :Telescope glyph theme=dropdown layout_config={width=0.45,height=35,prompt_position="bottom"} layout_strategy=vertical nnoremap Tn :Telescope notify diff --git a/lua/codecompanion/fidget-spinner.lua b/lua/codecompanion/fidget-spinner.lua new file mode 100644 index 0000000..35cb025 --- /dev/null +++ b/lua/codecompanion/fidget-spinner.lua @@ -0,0 +1,71 @@ +local progress = require("fidget.progress") + +local M = {} + +function M:init() + local group = vim.api.nvim_create_augroup("CodeCompanionFidgetHooks", {}) + + vim.api.nvim_create_autocmd({ "User" }, { + pattern = "CodeCompanionRequestStarted", + group = group, + callback = function(request) + local handle = M:create_progress_handle(request) + M:store_progress_handle(request.data.id, handle) + end, + }) + + vim.api.nvim_create_autocmd({ "User" }, { + pattern = "CodeCompanionRequestFinished", + group = group, + callback = function(request) + local handle = M:pop_progress_handle(request.data.id) + if handle then + M:report_exit_status(handle, request) + handle:finish() + end + end, + }) +end + +M.handles = {} + +function M:store_progress_handle(id, handle) + M.handles[id] = handle +end + +function M:pop_progress_handle(id) + local handle = M.handles[id] + M.handles[id] = nil + return handle +end + +function M:create_progress_handle(request) + return progress.handle.create({ + title = " Requesting assistance (" .. request.data.strategy .. ")", + message = "In progress...", + lsp_client = { + name = M:llm_role_title(request.data.adapter), + }, + }) +end + +function M:llm_role_title(adapter) + local parts = {} + table.insert(parts, adapter.formatted_name) + if adapter.model and adapter.model ~= "" then + table.insert(parts, "(" .. adapter.model .. ")") + end + return table.concat(parts, " ") +end + +function M:report_exit_status(handle, request) + if request.data.status == "success" then + handle.message = "Completed" + elseif request.data.status == "error" then + handle.message = " Error" + else + handle.message = "󰜺 Cancelled" + end +end + +return M diff --git a/lua/plugins.lua b/lua/plugins.lua index 6bdeeee..25efe98 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -90,167 +90,19 @@ require('packer').startup(function(use) use { "zbirenbaum/copilot-cmp" } -- }}} - -- CHATGPT {{{ use({ - "jackMort/ChatGPT.nvim", - commit = "24bcca7", - config = function() - require("chatgpt").setup({ - api_key_cmd = "cat /home/sudacode/.openaikey", - yank_register = "+", - edit_with_instructions = { - diff = false, - keymaps = { - close = "", - accept = "", - toggle_diff = "", - toggle_settings = "", - toggle_help = "", - cycle_windows = "", - use_output_as_input = "" - } - }, - chat = { - welcome_message = WELCOME_MESSAGE, - loading_text = "Loading, please wait ...", - question_sign = "", -- 🙂 - answer_sign = "ﮧ", -- 🤖 - border_left_sign = "", - border_right_sign = "", - max_line_length = 120, - sessions_window = { - active_sign = "  ", - inactive_sign = "  ", - current_line_sign = "", - 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 = "", - next_message = "", - prev_message = "", - select_session = "", - rename_session = "r", - delete_session = "d", - draft_message = "", - edit_message = "e", - delete_message = "d", - toggle_settings = "", - toggle_sessions = "", - toggle_help = "", - 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 = { - setting_sign = "  ", - border = { style = "rounded", text = { top = " Settings " } }, - win_options = { - winhighlight = "Normal:Normal,FloatBorder:FloatBorder" - } - }, - help_window = { - setting_sign = "  ", - border = { style = "rounded", text = { top = " Help " } }, - 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 = "gpt-3.5-turbo", - frequency_penalty = 0, - presence_penalty = 0, - temperature = 0, - top_p = 1, - n = 1 - }, - use_openai_functions_for_edits = false, - actions_paths = {}, - show_quickfixes_cmd = "Trouble quickfix", - predefined_chat_gpt_prompts = - "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv", - highlights = { - help_key = "@symbol", - help_description = "@comment" - } - }) - end, + "olimorris/codecompanion.nvim", requires = { - "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim", - "nvim-telescope/telescope.nvim" - } + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "j-hui/fidget.nvim" + }, + init = function() + require("plugins.codecompanion.fidget-spinner"):init() + end, }) - -- }}} use({ "iamcco/markdown-preview.nvim", run = function() vim.fn["mkdp#util#install"]() end @@ -291,9 +143,9 @@ require('packer').startup(function(use) -- DADBOD {{{ - use { 'tpope/vim-dadbod' } - use { 'kristijanhusak/vim-dadbod-ui' } - use { 'kristijanhusak/vim-dadbod-completion' } + -- use { 'tpope/vim-dadbod' } + -- use { 'kristijanhusak/vim-dadbod-ui' } + -- use { 'kristijanhusak/vim-dadbod-completion' } -- }}} diff --git a/plugin-confs/codecompanion.lua b/plugin-confs/codecompanion.lua new file mode 100644 index 0000000..8f93248 --- /dev/null +++ b/plugin-confs/codecompanion.lua @@ -0,0 +1,15 @@ +require("codecompanion").setup({ + strategies = { + chat = { + adapter = "copilot", + }, + inline = { + adapter = "copilot", + }, + }, + display = { + action_palette = { + provider = "telescope" + } + } +}) diff --git a/plugin-confs/lualine.lua b/plugin-confs/lualine.lua index 5b22f12..c6a2cab 100644 --- a/plugin-confs/lualine.lua +++ b/plugin-confs/lualine.lua @@ -1,52 +1,103 @@ -require('lualine').setup { - options = { - icons_enabled = true, - theme = 'codedark', - -- theme = 'dracula', - -- theme = 'horizon', - -- theme = 'onedark', - component_separators = { left = '', right = '' }, - section_separators = { left = '', right = ''}, - disabled_filetypes = {}, - always_divide_middle = true, - }, - sections = { - lualine_a = { 'mode' }, - lualine_b = { 'branch', 'diff' }, - lualine_c = { 'filename' }, - lualine_x = { - { - 'diagnostics', - 'fileformat', - symbols = { - unix = '', -- e712 - dos = '', -- e70f - mac = '', -- e711 - } - }, 'encoding', 'fileformat', { 'filetype', colored = true, icon_only = false } }, - lualine_y = { 'progress' }, - lualine_z = { 'location' } - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { - { - 'filename', - file_status = true, -- Displays file status (readonly status, modified status) - path = 0, -- 0: Just the filename - shorting_target = 40, -- Shortens path to leave 40 spaces in the window - symbols = { - modified = '[+]', -- Text to show when the file is modified. - readonly = '[-]', -- Text to show when the file is non-modifiable or readonly. - unnamed = '[No Name]', -- Text to show for unnamed buffers. - } - }, - }, - lualine_x = { 'location' }, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - extensions = { 'quickfix', 'fzf', 'nvim-tree', 'symbols-outline', 'fugitive' } +local M = require("lualine.component"):extend() + +M.processing = false +M.spinner_index = 1 + +local spinner_symbols = { + "⠋", + "⠙", + "⠹", + "⠸", + "⠼", + "⠴", + "⠦", + "⠧", + "⠇", + "⠏", } +local spinner_symbols_len = 10 + +-- Initializer +function M:init(options) + M.super.init(self, options) + + local group = vim.api.nvim_create_augroup("CodeCompanionHooks", {}) + + vim.api.nvim_create_autocmd({ "User" }, { + pattern = "CodeCompanionRequest*", + group = group, + callback = function(request) + if request.match == "CodeCompanionRequestStarted" then + self.processing = true + elseif request.match == "CodeCompanionRequestFinished" then + self.processing = false + end + end, + }) +end + +-- Function that runs every time statusline is updated +function M:update_status() + if self.processing then + self.spinner_index = (self.spinner_index % spinner_symbols_len) + 1 + return spinner_symbols[self.spinner_index] + else + return nil + end +end + +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'codedark', + -- theme = 'dracula', + -- theme = 'horizon', + -- theme = 'onedark', + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + disabled_filetypes = {}, + always_divide_middle = true, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff' }, + lualine_c = { 'filename', M }, + lualine_x = { + { + 'diagnostics', + 'fileformat', + symbols = { + unix = '', -- e712 + dos = '', -- e70f + mac = '', -- e711 + } + }, 'encoding', 'fileformat', { 'filetype', colored = true, icon_only = false } }, + lualine_y = { 'progress' }, + lualine_z = { 'location' } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { + { + 'filename', + file_status = true, -- Displays file status (readonly status, modified status) + path = 0, -- 0: Just the filename + shorting_target = 40, -- Shortens path to leave 40 spaces in the window + symbols = { + modified = '[+]', -- Text to show when the file is modified. + readonly = '[-]', -- Text to show when the file is non-modifiable or readonly. + unnamed = '[No Name]', -- Text to show for unnamed buffers. + } + }, + M + }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + extensions = { 'quickfix', 'fzf', 'nvim-tree', 'symbols-outline', 'fugitive' } +} + +-- return M diff --git a/plugin-confs/nvim-cmp.lua b/plugin-confs/nvim-cmp.lua index 1753399..772059a 100644 --- a/plugin-confs/nvim-cmp.lua +++ b/plugin-confs/nvim-cmp.lua @@ -157,7 +157,9 @@ cmp.setup({ -- }) }, sources = cmp.config.sources({ - { name = "copilot", group_index = 2 }, { name = "path", group_index = 2 }, + { name = "copilot", group_index = 2 }, + { name = "codecompanion", group_index = 2 }, + { name = "path", group_index = 2 }, { name = 'nvim_lsp', group_index = 2 }, { name = 'nvim_lsp_signature_help', group_index = 2 }, { name = 'nvim_lsp_document_symbol', group_index = 2 }, @@ -183,8 +185,11 @@ cmp.setup({ priority_weight = 2, comparators = { require("copilot_cmp.comparators").prioritize, + cmp.config.compare.offset, + cmp.config.compare.exact, require("copilot_cmp.comparators").score, require("copilot_cmp.comparators").recently_used, + cmp.config.compare.locality, require("copilot_cmp.comparators").kind, require("copilot_cmp.comparators").sort_text, require("copilot_cmp.comparators").length, @@ -223,37 +228,37 @@ for _, lsp in ipairs(servers) do lspconfig[lsp].setup { on_attach = require("lsp-format").on_attach, on_init = function(client) - if client.workspace_folders then - local path = client.workspace_folders[1].name - if path ~= vim.fn.stdpath('config') and (vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc')) then - return + if client.workspace_folders then + local path = client.workspace_folders[1].name + if path ~= vim.fn.stdpath('config') and (vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc')) then + return + end end - end - client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { + client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { runtime = { - -- Tell the language server which version of Lua you're using - -- (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT' + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT' }, -- Make the server aware of Neovim runtime files workspace = { - checkThirdParty = false, - library = { - vim.env.VIMRUNTIME - -- Depending on the usage, you might want to add additional paths here. - -- "${3rd}/luv/library" - -- "${3rd}/busted/library", - } - -- or pull in all of 'runtimepath'. NOTE: this is a lot slower and will cause issues when working on your own configuration (see https://github.com/neovim/nvim-lspconfig/issues/3189) - -- library = vim.api.nvim_get_runtime_file("", true) + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME + -- Depending on the usage, you might want to add additional paths here. + -- "${3rd}/luv/library" + -- "${3rd}/busted/library", + } + -- or pull in all of 'runtimepath'. NOTE: this is a lot slower and will cause issues when working on your own configuration (see https://github.com/neovim/nvim-lspconfig/issues/3189) + -- library = vim.api.nvim_get_runtime_file("", true) } - }) + }) end, - capabilities = capabilities, - callSnippet = "Replace", - settings = { - Lua = {} - } + capabilities = capabilities, + callSnippet = "Replace", + settings = { + Lua = {} + } } else lspconfig[lsp].setup { on_attach = require("lsp-format").on_attach, capabilities = capabilities } @@ -263,4 +268,4 @@ end -- cmp.event:on("menu_opened", -- function() vim.b.copilot_suggestion_hidden = true end) -- cmp.event:on("menu_closed", - -- function() vim.b.copilot_suggestion_hidden = false end) +-- function() vim.b.copilot_suggestion_hidden = false end)