Skip to content

Commit 027a1bf

Browse files
committed
wip completion in context area
1 parent 9881c85 commit 027a1bf

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

lua/eca/completion/context.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function M.resolve_completion_item(completion_item, callback)
7878
if context_item.type == "file" then
7979
completion_item.documentation = documentation(context_item, 20)
8080
end
81+
vim.api.nvim_exec_autocmds("User", {
82+
pattern = { "EcaChatContextUpdated" },
83+
data = completion_item.data.context_item,
84+
})
8185
callback(completion_item)
8286
end
8387
end

lua/eca/sidebar.lua

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function M.new(id, mediator)
6262
}
6363
instance._welcome_message_applied = false
6464
instance._contexts_placeholder_line = ""
65+
instance._contexts_to_resolve = {}
6566

6667
require("eca.observer").subscribe("sidebar-" .. id, function(message)
6768
instance:handle_chat_content(message)
@@ -188,6 +189,7 @@ function M:reset()
188189
self._current_status = ""
189190
self._welcome_message_applied = false
190191
self._contexts_placeholder_line = ""
192+
self._contexts_to_resolve = {}
191193
end
192194

193195
function M:new_chat()
@@ -379,14 +381,26 @@ end
379381
---@private
380382
---@param container NuiSplit
381383
function M:_setup_input_events(container)
384+
vim.api.nvim_create_autocmd("User", {
385+
pattern = { "EcaChatContextUpdated" },
386+
callback = function(event)
387+
local context_to_resolve = {
388+
path = event.data.path,
389+
name = vim.fn.fnamemodify(event.data.path, ":.")
390+
}
391+
392+
table.insert(self._contexts_to_resolve, context_to_resolve)
393+
end,
394+
})
395+
382396
-- prevent contexts line or input prefix from being deleted
383397
vim.api.nvim_buf_attach(container.bufnr, false, {
384398
on_lines = function(_, buf, _changedtick, first, _last, _new_last, _bytecount)
385-
if first ~= 0 and first ~= 1 then
386-
return
387-
end
388-
389399
vim.schedule(function()
400+
if first ~= 0 and first ~= 1 then
401+
return
402+
end
403+
390404
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
391405

392406
-- handle empty buffer
@@ -417,10 +431,6 @@ function M:_setup_input_events(container)
417431
local contexts_line = lines[contexts_row + 1] or nil
418432
local contexts_placeholder_line = self._contexts_placeholder_line or ""
419433

420-
-- Logger.test(lines)
421-
-- Logger.test("first line changed: " .. first)
422-
-- Logger.test(prefix_mark)
423-
424434
if prefix_row == contexts_row then
425435
-- prefix line missing, restore
426436
if contexts_line == contexts_placeholder_line then
@@ -459,13 +469,14 @@ function M:_setup_input_events(container)
459469
if #contexts_line > #self._contexts_placeholder_line then
460470
local placeholders = vim.split(contexts_line, "@", { plain = true, trimempty = false })
461471

462-
vim.notify("placeholders: " .. vim.inspect(placeholders), vim.log.levels.DEBUG)
463-
464472
if #placeholders[#placeholders] < 1 then
465473
self:_update_input_display()
466474
return
467475
end
468476

477+
vim.notify("Contexts line: " .. contexts_line, vim.log.levels.DEBUG)
478+
vim.notify("Contexts to resolve: " .. vim.inspect(self._contexts_to_resolve), vim.log.levels.DEBUG)
479+
469480
return
470481
end
471482

0 commit comments

Comments
 (0)