From 7bd447093ad44cbbc98c932204c7f36f914de69b Mon Sep 17 00:00:00 2001 From: ChewCW Date: Mon, 27 Jan 2025 09:55:53 +0800 Subject: [PATCH 1/7] fix: improve visual selection handling Use `nvim_buf_get_text` instead of `nvim_buf_get_lines` to properly handle column positions in visual selections. Add special handling for Visual Line mode by adjusting start and end columns accordingly. --- lua/CopilotChat/init.lua | 75 +++++++++++++++++++++++--------------- lua/CopilotChat/select.lua | 24 +++++++++--- 2 files changed, 63 insertions(+), 36 deletions(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 914ada6b..2ba46682 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -18,10 +18,12 @@ local WORD = '([^%s]+)' --- @class CopilotChat.source --- @field bufnr number --- @field winnr number +--- @field mode string --- @class CopilotChat.state --- @field copilot CopilotChat.Copilot? --- @field source CopilotChat.source? +--- @field source_mode string? --- @field last_prompt string? --- @field last_response string? --- @field chat CopilotChat.ui.Chat? @@ -34,6 +36,9 @@ local state = { -- Current state tracking source = nil, + -- Window visual selection tracking + source_mode = nil, + -- Last state tracking last_prompt = nil, last_response = nil, @@ -50,13 +55,14 @@ local state = { local function get_selection(config) local bufnr = state.source and state.source.bufnr local winnr = state.source and state.source.winnr + state.source.mode = state.source_mode or 'n' if - config - and config.selection - and utils.buf_valid(bufnr) - and winnr - and vim.api.nvim_win_is_valid(winnr) + config + and config.selection + and utils.buf_valid(bufnr) + and winnr + and vim.api.nvim_win_is_valid(winnr) then return config.selection(state.source) end @@ -79,10 +85,10 @@ local function highlight_selection(clear, config) local selection = get_selection(config) if - not selection - or not utils.buf_valid(selection.bufnr) - or not selection.start_line - or not selection.end_line + not selection + or not utils.buf_valid(selection.bufnr) + or not selection.start_line + or not selection.end_line then return end @@ -102,6 +108,7 @@ local function update_selection(config) state.source = { bufnr = vim.api.nvim_win_get_buf(prev_winnr), winnr = prev_winnr, + mode = state.source_mode or 'n', } end @@ -148,7 +155,7 @@ local function get_diff(config) -- If we found a valid buffer, get the reference content if bufnr and utils.buf_valid(bufnr) then reference = - table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') + table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') filetype = vim.bo[bufnr].filetype end end @@ -180,7 +187,8 @@ local function jump_to_diff(winnr, bufnr, start_line, end_line, config) pcall(vim.api.nvim_buf_set_mark, bufnr, '>', end_line, 0, {}) pcall(vim.api.nvim_buf_set_mark, bufnr, '[', start_line, 0, {}) pcall(vim.api.nvim_buf_set_mark, bufnr, ']', end_line, 0, {}) - update_selection(config) + local mode = vim.fn.mode() + update_selection(config, mode) end ---@param diff CopilotChat.ui.Diff.Diff? @@ -593,6 +601,8 @@ end --- Open the chat window. ---@param config CopilotChat.config.shared? function M.open(config) + local source_mode = vim.fn.mode() + -- If we are already in chat window, do nothing if state.chat:active() then return @@ -603,6 +613,7 @@ function M.open(config) state.source = { bufnr = vim.api.nvim_get_current_buf(), winnr = vim.api.nvim_get_current_win(), + mode = source_mode, } return end @@ -621,6 +632,7 @@ end --- Toggle the chat window. ---@param config CopilotChat.config.shared? function M.toggle(config) + state.source_mode = vim.fn.mode() if state.chat:visible() then M.close() else @@ -684,6 +696,8 @@ end ---@param prompt string? ---@param config CopilotChat.config.shared? function M.ask(prompt, config) + state.source_mode = vim.fn.mode() + M.open(config) prompt = vim.trim(prompt or '') @@ -730,7 +744,7 @@ function M.ask(prompt, config) local has_output = false local query_ok, filtered_embeddings = - pcall(context.filter_embeddings, state.copilot, prompt, embeddings) + pcall(context.filter_embeddings, state.copilot, prompt, embeddings) if not query_ok then async.util.scheduler() @@ -742,21 +756,21 @@ function M.ask(prompt, config) end local ask_ok, response, token_count, token_max_count = - pcall(state.copilot.ask, state.copilot, prompt, { - selection = selection, - embeddings = filtered_embeddings, - system_prompt = system_prompt, - model = selected_model, - agent = selected_agent, - temperature = config.temperature, - no_history = config.headless, - on_progress = vim.schedule_wrap(function(token) - if not config.headless then - state.chat:append(token) - end - has_output = true - end), - }) + pcall(state.copilot.ask, state.copilot, prompt, { + selection = selection, + embeddings = filtered_embeddings, + system_prompt = system_prompt, + model = selected_model, + agent = selected_agent, + temperature = config.temperature, + no_history = config.headless, + on_progress = vim.schedule_wrap(function(token) + if not config.headless then + state.chat:append(token) + end + has_output = true + end), + }) async.util.scheduler() @@ -1084,9 +1098,9 @@ function M.setup(config) map_key('jump_to_diff', bufnr, function() if - not state.source - or not state.source.winnr - or not vim.api.nvim_win_is_valid(state.source.winnr) + not state.source + or not state.source.winnr + or not vim.api.nvim_win_is_valid(state.source.winnr) then return end @@ -1117,6 +1131,7 @@ function M.setup(config) end) map_key('quickfix_diffs', bufnr, function() + local source_mode = vim.fn.mode() local selection = get_selection(state.chat.config) local items = {} diff --git a/lua/CopilotChat/select.lua b/lua/CopilotChat/select.lua index e6b76587..a1c1043a 100644 --- a/lua/CopilotChat/select.lua +++ b/lua/CopilotChat/select.lua @@ -51,9 +51,10 @@ end --- @param source CopilotChat.source --- @return CopilotChat.select.selection|nil function M.visual(source) - local bufnr = source.bufnr - local start_line = unpack(vim.api.nvim_buf_get_mark(bufnr, '<')) - local finish_line = unpack(vim.api.nvim_buf_get_mark(bufnr, '>')) + local bufnr = source.bufnr or 0 + local mode = source.mode + local start_line, start_col = unpack(vim.api.nvim_buf_get_mark(bufnr, '<')) + local finish_line, finish_col = unpack(vim.api.nvim_buf_get_mark(bufnr, '>')) if start_line == 0 or finish_line == 0 then return nil end @@ -61,10 +62,20 @@ function M.visual(source) start_line, finish_line = finish_line, start_line end - local ok, lines = pcall(vim.api.nvim_buf_get_lines, bufnr, start_line - 1, finish_line, false) - if not ok then - return nil + -- Visual Line mode, adjusting the end column + local ok, lines + if mode == "V" then + ok, lines = pcall(vim.api.nvim_buf_get_lines, bufnr, start_line - 1, finish_line, false) + if not ok then + return nil + end + else + ok, lines = pcall(vim.api.nvim_buf_get_text, bufnr, start_line - 1, start_col, finish_line - 1, finish_col + 1, {}) + if not ok then + return nil + end end + local lines_content = table.concat(lines, '\n') if vim.trim(lines_content) == '' then return nil @@ -85,6 +96,7 @@ end --- @param source CopilotChat.source --- @return CopilotChat.select.selection|nil function M.buffer(source) + source.mode = nil local bufnr = source.bufnr local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) if not lines or #lines == 0 then From 2d8ea52068779a589f0aa062a1327f230f7c979a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 04:49:30 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lua/CopilotChat/init.lua | 58 +++++++++++++++++++------------------- lua/CopilotChat/select.lua | 12 ++++++-- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 2ba46682..64124a0f 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -58,11 +58,11 @@ local function get_selection(config) state.source.mode = state.source_mode or 'n' if - config - and config.selection - and utils.buf_valid(bufnr) - and winnr - and vim.api.nvim_win_is_valid(winnr) + config + and config.selection + and utils.buf_valid(bufnr) + and winnr + and vim.api.nvim_win_is_valid(winnr) then return config.selection(state.source) end @@ -85,10 +85,10 @@ local function highlight_selection(clear, config) local selection = get_selection(config) if - not selection - or not utils.buf_valid(selection.bufnr) - or not selection.start_line - or not selection.end_line + not selection + or not utils.buf_valid(selection.bufnr) + or not selection.start_line + or not selection.end_line then return end @@ -155,7 +155,7 @@ local function get_diff(config) -- If we found a valid buffer, get the reference content if bufnr and utils.buf_valid(bufnr) then reference = - table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') + table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') filetype = vim.bo[bufnr].filetype end end @@ -744,7 +744,7 @@ function M.ask(prompt, config) local has_output = false local query_ok, filtered_embeddings = - pcall(context.filter_embeddings, state.copilot, prompt, embeddings) + pcall(context.filter_embeddings, state.copilot, prompt, embeddings) if not query_ok then async.util.scheduler() @@ -756,21 +756,21 @@ function M.ask(prompt, config) end local ask_ok, response, token_count, token_max_count = - pcall(state.copilot.ask, state.copilot, prompt, { - selection = selection, - embeddings = filtered_embeddings, - system_prompt = system_prompt, - model = selected_model, - agent = selected_agent, - temperature = config.temperature, - no_history = config.headless, - on_progress = vim.schedule_wrap(function(token) - if not config.headless then - state.chat:append(token) - end - has_output = true - end), - }) + pcall(state.copilot.ask, state.copilot, prompt, { + selection = selection, + embeddings = filtered_embeddings, + system_prompt = system_prompt, + model = selected_model, + agent = selected_agent, + temperature = config.temperature, + no_history = config.headless, + on_progress = vim.schedule_wrap(function(token) + if not config.headless then + state.chat:append(token) + end + has_output = true + end), + }) async.util.scheduler() @@ -1098,9 +1098,9 @@ function M.setup(config) map_key('jump_to_diff', bufnr, function() if - not state.source - or not state.source.winnr - or not vim.api.nvim_win_is_valid(state.source.winnr) + not state.source + or not state.source.winnr + or not vim.api.nvim_win_is_valid(state.source.winnr) then return end diff --git a/lua/CopilotChat/select.lua b/lua/CopilotChat/select.lua index a1c1043a..8d820b5c 100644 --- a/lua/CopilotChat/select.lua +++ b/lua/CopilotChat/select.lua @@ -64,13 +64,21 @@ function M.visual(source) -- Visual Line mode, adjusting the end column local ok, lines - if mode == "V" then + if mode == 'V' then ok, lines = pcall(vim.api.nvim_buf_get_lines, bufnr, start_line - 1, finish_line, false) if not ok then return nil end else - ok, lines = pcall(vim.api.nvim_buf_get_text, bufnr, start_line - 1, start_col, finish_line - 1, finish_col + 1, {}) + ok, lines = pcall( + vim.api.nvim_buf_get_text, + bufnr, + start_line - 1, + start_col, + finish_line - 1, + finish_col + 1, + {} + ) if not ok then return nil end From e19352421d6185bcf02a444d1fdeed7a942b7019 Mon Sep 17 00:00:00 2001 From: ChewCW Date: Mon, 27 Jan 2025 12:55:37 +0800 Subject: [PATCH 3/7] fix: remove default value for source.bufnr --- lua/CopilotChat/select.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/CopilotChat/select.lua b/lua/CopilotChat/select.lua index 8d820b5c..fce3e25f 100644 --- a/lua/CopilotChat/select.lua +++ b/lua/CopilotChat/select.lua @@ -51,7 +51,7 @@ end --- @param source CopilotChat.source --- @return CopilotChat.select.selection|nil function M.visual(source) - local bufnr = source.bufnr or 0 + local bufnr = source.bufnr local mode = source.mode local start_line, start_col = unpack(vim.api.nvim_buf_get_mark(bufnr, '<')) local finish_line, finish_col = unpack(vim.api.nvim_buf_get_mark(bufnr, '>')) From c4f391798ca4a942c11bf3313cd9d31bbcbb0666 Mon Sep 17 00:00:00 2001 From: ChewCW Date: Mon, 27 Jan 2025 13:16:26 +0800 Subject: [PATCH 4/7] feat: add column support for selection highlighting - Updated `get_selection` and `highlight_selection` functions to handle start and end columns for more precise selection highlighting. - Modified `ask` function to maintain consistent indentation. - Added `start_col` and `end_col` fields to selection object in `select.lua`. --- lua/CopilotChat/init.lua | 77 +++++++++++++++++++++----------------- lua/CopilotChat/select.lua | 4 ++ 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 64124a0f..cc654b78 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -58,11 +58,11 @@ local function get_selection(config) state.source.mode = state.source_mode or 'n' if - config - and config.selection - and utils.buf_valid(bufnr) - and winnr - and vim.api.nvim_win_is_valid(winnr) + config + and config.selection + and utils.buf_valid(bufnr) + and winnr + and vim.api.nvim_win_is_valid(winnr) then return config.selection(state.source) end @@ -85,19 +85,28 @@ local function highlight_selection(clear, config) local selection = get_selection(config) if - not selection - or not utils.buf_valid(selection.bufnr) - or not selection.start_line - or not selection.end_line + not selection + or not utils.buf_valid(selection.bufnr) + or not selection.start_line + or not selection.end_line then return end - vim.api.nvim_buf_set_extmark(selection.bufnr, selection_ns, selection.start_line - 1, 0, { - hl_group = 'CopilotChatSelection', - end_row = selection.end_line, - strict = false, - }) + if selection.start_col and selection.end_col then + vim.api.nvim_buf_set_extmark(selection.bufnr, selection_ns, selection.start_line - 1, selection.start_col, { + hl_group = 'CopilotChatSelection', + end_row = selection.end_line - 1, + end_col = selection.end_col, + strict = false, + }) + else + vim.api.nvim_buf_set_extmark(selection.bufnr, selection_ns, selection.start_line - 1, 0, { + hl_group = 'CopilotChatSelection', + end_row = selection.end_line, + strict = false, + }) + end end --- Updates the selection based on previous window @@ -155,7 +164,7 @@ local function get_diff(config) -- If we found a valid buffer, get the reference content if bufnr and utils.buf_valid(bufnr) then reference = - table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') + table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') filetype = vim.bo[bufnr].filetype end end @@ -744,7 +753,7 @@ function M.ask(prompt, config) local has_output = false local query_ok, filtered_embeddings = - pcall(context.filter_embeddings, state.copilot, prompt, embeddings) + pcall(context.filter_embeddings, state.copilot, prompt, embeddings) if not query_ok then async.util.scheduler() @@ -756,21 +765,21 @@ function M.ask(prompt, config) end local ask_ok, response, token_count, token_max_count = - pcall(state.copilot.ask, state.copilot, prompt, { - selection = selection, - embeddings = filtered_embeddings, - system_prompt = system_prompt, - model = selected_model, - agent = selected_agent, - temperature = config.temperature, - no_history = config.headless, - on_progress = vim.schedule_wrap(function(token) - if not config.headless then - state.chat:append(token) - end - has_output = true - end), - }) + pcall(state.copilot.ask, state.copilot, prompt, { + selection = selection, + embeddings = filtered_embeddings, + system_prompt = system_prompt, + model = selected_model, + agent = selected_agent, + temperature = config.temperature, + no_history = config.headless, + on_progress = vim.schedule_wrap(function(token) + if not config.headless then + state.chat:append(token) + end + has_output = true + end), + }) async.util.scheduler() @@ -1098,9 +1107,9 @@ function M.setup(config) map_key('jump_to_diff', bufnr, function() if - not state.source - or not state.source.winnr - or not vim.api.nvim_win_is_valid(state.source.winnr) + not state.source + or not state.source.winnr + or not vim.api.nvim_win_is_valid(state.source.winnr) then return end diff --git a/lua/CopilotChat/select.lua b/lua/CopilotChat/select.lua index fce3e25f..baa3507d 100644 --- a/lua/CopilotChat/select.lua +++ b/lua/CopilotChat/select.lua @@ -8,6 +8,8 @@ ---@field content string ---@field start_line number ---@field end_line number +---@field start_col number +---@field end_col number ---@field filename string ---@field filetype string ---@field bufnr number @@ -95,6 +97,8 @@ function M.visual(source) filetype = vim.bo[bufnr].filetype, start_line = start_line, end_line = finish_line, + start_col = start_col, + end_col = finish_col, bufnr = bufnr, diagnostics = get_diagnostics_in_range(bufnr, start_line, finish_line), } From ce4614a59661552b4095476e46d43d8243022dab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 05:16:47 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lua/CopilotChat/init.lua | 76 ++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index cc654b78..0f683139 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -58,11 +58,11 @@ local function get_selection(config) state.source.mode = state.source_mode or 'n' if - config - and config.selection - and utils.buf_valid(bufnr) - and winnr - and vim.api.nvim_win_is_valid(winnr) + config + and config.selection + and utils.buf_valid(bufnr) + and winnr + and vim.api.nvim_win_is_valid(winnr) then return config.selection(state.source) end @@ -85,21 +85,27 @@ local function highlight_selection(clear, config) local selection = get_selection(config) if - not selection - or not utils.buf_valid(selection.bufnr) - or not selection.start_line - or not selection.end_line + not selection + or not utils.buf_valid(selection.bufnr) + or not selection.start_line + or not selection.end_line then return end if selection.start_col and selection.end_col then - vim.api.nvim_buf_set_extmark(selection.bufnr, selection_ns, selection.start_line - 1, selection.start_col, { - hl_group = 'CopilotChatSelection', - end_row = selection.end_line - 1, - end_col = selection.end_col, - strict = false, - }) + vim.api.nvim_buf_set_extmark( + selection.bufnr, + selection_ns, + selection.start_line - 1, + selection.start_col, + { + hl_group = 'CopilotChatSelection', + end_row = selection.end_line - 1, + end_col = selection.end_col, + strict = false, + } + ) else vim.api.nvim_buf_set_extmark(selection.bufnr, selection_ns, selection.start_line - 1, 0, { hl_group = 'CopilotChatSelection', @@ -164,7 +170,7 @@ local function get_diff(config) -- If we found a valid buffer, get the reference content if bufnr and utils.buf_valid(bufnr) then reference = - table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') + table.concat(vim.api.nvim_buf_get_lines(bufnr, start_line - 1, end_line, false), '\n') filetype = vim.bo[bufnr].filetype end end @@ -753,7 +759,7 @@ function M.ask(prompt, config) local has_output = false local query_ok, filtered_embeddings = - pcall(context.filter_embeddings, state.copilot, prompt, embeddings) + pcall(context.filter_embeddings, state.copilot, prompt, embeddings) if not query_ok then async.util.scheduler() @@ -765,21 +771,21 @@ function M.ask(prompt, config) end local ask_ok, response, token_count, token_max_count = - pcall(state.copilot.ask, state.copilot, prompt, { - selection = selection, - embeddings = filtered_embeddings, - system_prompt = system_prompt, - model = selected_model, - agent = selected_agent, - temperature = config.temperature, - no_history = config.headless, - on_progress = vim.schedule_wrap(function(token) - if not config.headless then - state.chat:append(token) - end - has_output = true - end), - }) + pcall(state.copilot.ask, state.copilot, prompt, { + selection = selection, + embeddings = filtered_embeddings, + system_prompt = system_prompt, + model = selected_model, + agent = selected_agent, + temperature = config.temperature, + no_history = config.headless, + on_progress = vim.schedule_wrap(function(token) + if not config.headless then + state.chat:append(token) + end + has_output = true + end), + }) async.util.scheduler() @@ -1107,9 +1113,9 @@ function M.setup(config) map_key('jump_to_diff', bufnr, function() if - not state.source - or not state.source.winnr - or not vim.api.nvim_win_is_valid(state.source.winnr) + not state.source + or not state.source.winnr + or not vim.api.nvim_win_is_valid(state.source.winnr) then return end From 9fa555134129ac892a09dbe2d3601a5cb5a6317d Mon Sep 17 00:00:00 2001 From: ChewCW Date: Sun, 16 Feb 2025 07:38:15 +0800 Subject: [PATCH 6/7] feat(telescope): add callback support for pick action Add an optional callback parameter to telescope.pick() function that gets called after an action is selected. This allows for custom handling of selected actions instead of the default ask behavior. --- lua/CopilotChat/integrations/telescope.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/CopilotChat/integrations/telescope.lua b/lua/CopilotChat/integrations/telescope.lua index e636aeb6..fb61c4f1 100644 --- a/lua/CopilotChat/integrations/telescope.lua +++ b/lua/CopilotChat/integrations/telescope.lua @@ -13,7 +13,8 @@ local M = {} --- Pick an action from a list of actions ---@param pick_actions CopilotChat.integrations.actions?: A table with the actions to pick from ---@param opts table?: Telescope options -function M.pick(pick_actions, opts) +---@param action_callback function?: A callback to run after the action is picked +function M.pick(pick_actions, opts, action_callback) if not pick_actions or not pick_actions.actions or vim.tbl_isempty(pick_actions.actions) then return end @@ -52,7 +53,11 @@ function M.pick(pick_actions, opts) end vim.defer_fn(function() - chat.ask(pick_actions.actions[selected[1]].prompt, pick_actions.actions[selected[1]]) + if not action_callback then + chat.ask(pick_actions.actions[selected[1]].prompt, pick_actions.actions[selected[1]]) + return + end + action_callback(selected) end, 100) end) return true From 7788e73b12cd67cbbd5cdb3382e4478bcce00d07 Mon Sep 17 00:00:00 2001 From: ChewCW Date: Sun, 16 Feb 2025 08:36:41 +0800 Subject: [PATCH 7/7] feat(prompt): change prompt trigger from '/' to '!' Change the trigger character for prompts from '/' to '!' to avoid conflicts with Neovim's search functionality. This improves the user experience by preventing accidental searches when using CopilotChat prompts. --- lua/CopilotChat/config/prompts.lua | 12 ++++++------ lua/CopilotChat/init.lua | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lua/CopilotChat/config/prompts.lua b/lua/CopilotChat/config/prompts.lua index 137fed4f..88a6b18e 100644 --- a/lua/CopilotChat/config/prompts.lua +++ b/lua/CopilotChat/config/prompts.lua @@ -93,10 +93,10 @@ return { system_prompt = COPILOT_GENERATE, }, Explain = { - prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code as paragraphs of text.', + prompt = '> !COPILOT_EXPLAIN\n\nWrite an explanation for the selected code as paragraphs of text.', }, Review = { - prompt = '> /COPILOT_REVIEW\n\nReview the selected code.', + prompt = '> !COPILOT_REVIEW\n\nReview the selected code.', callback = function(response, source) local diagnostics = {} for line in response:gmatch('[^\r\n]+') do @@ -138,16 +138,16 @@ return { end, }, Fix = { - prompt = '> /COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.', + prompt = '> !COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.', }, Optimize = { - prompt = '> /COPILOT_GENERATE\n\nOptimize the selected code to improve performance and readability.', + prompt = '> !COPILOT_GENERATE\n\nOptimize the selected code to improve performance and readability.', }, Docs = { - prompt = '> /COPILOT_GENERATE\n\nPlease add documentation comments to the selected code.', + prompt = '> !COPILOT_GENERATE\n\nPlease add documentation comments to the selected code.', }, Tests = { - prompt = '> /COPILOT_GENERATE\n\nPlease generate tests for my code.', + prompt = '> !COPILOT_GENERATE\n\nPlease generate tests for my code.', }, Commit = { prompt = '> #git:staged\n\nWrite commit message for the change with commitizen convention. Make sure the title has maximum 50 characters and message is wrapped at 72 characters. Wrap the whole message in code block with language gitcommit.', diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 420521b2..56437da9 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -231,7 +231,7 @@ local function resolve_prompts(prompt, config) end depth = depth + 1 - inner_prompt = string.gsub(inner_prompt, '/' .. WORD, function(match) + inner_prompt = string.gsub(inner_prompt, '!' .. WORD, function(match) local p = prompts_to_use[match] if p then local resolved_prompt, resolved_config = resolve(p.prompt or '', p) @@ -239,7 +239,7 @@ local function resolve_prompts(prompt, config) return resolved_prompt end - return '/' .. match + return '!' .. match end) depth = depth - 1 @@ -521,8 +521,8 @@ end ---@return table function M.complete_info() return { - triggers = { '@', '/', '#', '$' }, - pattern = [[\%(@\|/\|#\|\$\)\S*]], + triggers = { '@', '!', '#', '$' }, + pattern = [[\%(@\|!\|#\|\$\)\S*]], } end @@ -547,7 +547,7 @@ function M.complete_items(callback) end items[#items + 1] = { - word = '/' .. name, + word = '!' .. name, abbr = name, kind = kind, info = info, @@ -965,11 +965,11 @@ function M.setup(config) -- Handle removed commands vim.api.nvim_create_user_command('CopilotChatFixDiagnostic', function() utils.deprecate('CopilotChatFixDiagnostic', 'CopilotChatFix') - M.ask('/Fix') + M.ask('!Fix') end, { force = true }) vim.api.nvim_create_user_command('CopilotChatCommitStaged', function() utils.deprecate('CopilotChatCommitStaged', 'CopilotChatCommit') - M.ask('/Commit') + M.ask('!Commit') end, { force = true }) M.config = vim.tbl_deep_extend('force', default_config, config or {}) @@ -1050,7 +1050,7 @@ function M.setup(config) chat_help = chat_help .. '`@` to select an agent\n' chat_help = chat_help .. '`#` to select a context\n' chat_help = chat_help .. '`#:` to select input for context\n' - chat_help = chat_help .. '`/` to select a prompt\n' + chat_help = chat_help .. '`!` to select a prompt\n' chat_help = chat_help .. '`$` to select a model\n' chat_help = chat_help .. '`> ` to make a sticky prompt (copied to next prompt)\n'