Skip to content

Commit caf387f

Browse files
committed
refactor: optimize file list processing order
Move file list chunking before content processing to ensure consistent ordering of operations and improve code flow. Also increase TOP_RELATED constant from 20 to 25 for better related files detection. The chunking logic now runs first, followed by optional content processing, which makes the code more maintainable and logical in its execution order.
1 parent 55c1991 commit caf387f

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

lua/CopilotChat/context.lua

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ local OFF_SIDE_RULE_LANGUAGES = {
6565
}
6666

6767
local TOP_SYMBOLS = 100
68-
local TOP_RELATED = 20
68+
local TOP_RELATED = 25
6969
local MULTI_FILE_THRESHOLD = 5
7070

7171
--- Compute the cosine similarity between two vectors
@@ -324,6 +324,24 @@ function M.files(winnr, with_content)
324324

325325
local out = {}
326326

327+
-- Create file list in chunks
328+
local chunk_size = 100
329+
for i = 1, #files, chunk_size do
330+
local chunk = {}
331+
for j = i, math.min(i + chunk_size - 1, #files) do
332+
table.insert(chunk, files[j])
333+
end
334+
335+
local chunk_number = math.floor(i / chunk_size)
336+
local chunk_name = chunk_number == 0 and 'file_map' or 'file_map' .. tostring(chunk_number)
337+
338+
table.insert(out, {
339+
content = table.concat(chunk, '\n'),
340+
filename = chunk_name,
341+
filetype = 'text',
342+
})
343+
end
344+
327345
-- Read all files if we want content as well
328346
if with_content then
329347
async.util.scheduler()
@@ -346,26 +364,6 @@ function M.files(winnr, with_content)
346364
table.insert(out, file_data)
347365
end
348366
end
349-
350-
return out
351-
end
352-
353-
-- Create file list in chunks
354-
local chunk_size = 100
355-
for i = 1, #files, chunk_size do
356-
local chunk = {}
357-
for j = i, math.min(i + chunk_size - 1, #files) do
358-
table.insert(chunk, files[j])
359-
end
360-
361-
local chunk_number = math.floor(i / chunk_size)
362-
local chunk_name = chunk_number == 0 and 'file_map' or 'file_map' .. tostring(chunk_number)
363-
364-
table.insert(out, {
365-
content = table.concat(chunk, '\n'),
366-
filename = chunk_name,
367-
filetype = 'text',
368-
})
369367
end
370368

371369
return out

0 commit comments

Comments
 (0)