Skip to content

Commit 3094dd8

Browse files
committed
refactor(chat): improve yank functionality and types
Update yank functionality to use closest chat block instead of diff content. Add proper type annotations for contexts and prompts tables. Clean up unnecessary comment and improve type definition for callback function. This change makes the yank feature more intuitive by copying the actual chat block content rather than diff changes.
1 parent 1077e33 commit 3094dd8

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

lua/CopilotChat/config/contexts.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local utils = require('CopilotChat.utils')
66
---@field input fun(callback: fun(input: string?), source: CopilotChat.source)?
77
---@field resolve fun(input: string?, source: CopilotChat.source):table<CopilotChat.context.embed>
88

9+
---@type table<string, CopilotChat.config.context>
910
return {
1011
buffer = {
1112
description = 'Includes specified buffer in chat context. Supports input (default current).',

lua/CopilotChat/config/mappings.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ end
9999
---@field normal string?
100100
---@field insert string?
101101
---@field detail string?
102-
---@field callback fun(overlay: CopilotChat.ui.Overlay, diff: CopilotChat.ui.Diff.Diff, chat: CopilotChat.ui.Chat, source: CopilotChat.source)
102+
---@field callback fun(overlay: CopilotChat.ui.Overlay, diff: CopilotChat.ui.Diff, chat: CopilotChat.ui.Chat, source: CopilotChat.source)
103103

104104
---@class CopilotChat.config.mapping.yank_diff : CopilotChat.config.mapping
105105
---@field register string?
@@ -121,7 +121,6 @@ end
121121
---@field show_info CopilotChat.config.mapping?
122122
---@field show_context CopilotChat.config.mapping?
123123
---@field show_help CopilotChat.config.mapping?
124-
125124
return {
126125
complete = {
127126
insert = '<Tab>',
@@ -317,12 +316,12 @@ return {
317316
normal = 'gy',
318317
register = '"', -- Default register to use for yanking
319318
callback = function(overlay, diff, chat)
320-
local content = get_diff(chat)
321-
if not content then
319+
local block = chat:get_closest_block()
320+
if not block then
322321
return
323322
end
324323

325-
vim.fn.setreg(copilot.config.mappings.yank_diff.register, content.change)
324+
vim.fn.setreg(copilot.config.mappings.yank_diff.register, block.content)
326325
end,
327326
},
328327

lua/CopilotChat/config/prompts.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Your task is to modify the provided code according to the user's request. Follow
7979
Remember: Your response should ONLY contain file headers with line numbers and code blocks for direct replacement.
8080
]]
8181

82+
---@type table<string, CopilotChat.config.prompt>
8283
return {
8384
COPILOT_INSTRUCTIONS = {
8485
system_prompt = COPILOT_INSTRUCTIONS,

0 commit comments

Comments
 (0)