Skip to content

Commit 604849b

Browse files
committed
fix empty resource sharing
Signed-off-by: Tomas Slusny <[email protected]>
1 parent 7d2f140 commit 604849b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

lua/CopilotChat/client.lua

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,23 @@ local function generate_selection_message(selection)
161161
end
162162

163163
--- Generate messages for the given resources
164-
--- @param resource CopilotChat.client.Resource
165-
--- @return CopilotChat.client.Message?
166-
local function generate_resource_message(resource)
167-
if not resource.data or resource.data == '' then
168-
return nil
169-
end
170-
171-
local content = generate_content_block(resource.data, BIG_FILE_THRESHOLD, 1)
172-
173-
return {
174-
content = string.format(RESOURCE_FORMAT, resource.name, resource.type, content),
175-
role = 'user',
176-
}
164+
--- @param resources CopilotChat.client.Resource[]
165+
--- @return table<CopilotChat.client.Message>
166+
local function generate_resource_messages(resources)
167+
return vim
168+
.iter(resources or {})
169+
:filter(function(resource)
170+
return resource.data and resource.data ~= ''
171+
end)
172+
:map(function(resource)
173+
local content = generate_content_block(resource.data, BIG_FILE_THRESHOLD, 1)
174+
175+
return {
176+
content = string.format(RESOURCE_FORMAT, resource.name, resource.type, content),
177+
role = 'user',
178+
}
179+
end)
180+
:totable()
177181
end
178182

179183
--- Generate ask request
@@ -355,7 +359,7 @@ function Client:ask(prompt, opts)
355359
local tool_calls = utils.ordered_map()
356360
local generated_messages = {}
357361
local selection_message = opts.selection and generate_selection_message(opts.selection)
358-
local resource_messages = vim.tbl_map(generate_resource_message, opts.resources or {})
362+
local resource_messages = generate_resource_messages(opts.resources)
359363

360364
if selection_message then
361365
table.insert(generated_messages, selection_message)

0 commit comments

Comments
 (0)