feat(context): add a ui for selecting and adding files to the sidebar as context (#912)
* feat(sidebar): supports select files chore (context) update add type annotations to context functions chore (sidebar) remove unused notify function call refactor (sidebar) remove setting search file to file path chore (sidebar) remove nvim_notify debugging api call * feat (files) allow selecting a file by string via cmp suggestion menu * chore (context) refactor to allow context using @file with a context view * refactor (context) refactor seletected file types as an array of path and content * refactor (config) remove unused configuration options * refactor (sidebar) remove unused unbild key * refactor (context) remove unused imports * refactor (mentions) update mentions to support items with callback functions and removal of the underlying selection. * fix (sidebar) add file context as a window that is visitable via the tab key * refactor (file_content) remove file content as an input to llm * feat (sidebar) support suggesting and applying code in all languages that are in the context * feat (sidebar) configurable mapping for removing a file from the context. * feat (context_view) configure hints for the context view for adding and deleting a file. * feat (context) add hints for the context view. * fix (sidebar) type when scrolling the results buffer. * refactor (selected files) refactor llm stream to accept an array of selected file metadata * refactor: context => selected_files --------- Co-authored-by: yetone <yetoneful@gmail.com>
This commit is contained in:
committed by
GitHub
parent
3b33170097
commit
78dd9b0a6d
@@ -44,4 +44,37 @@ function mentions_source:complete(_, callback)
|
||||
})
|
||||
end
|
||||
|
||||
---@param completion_item table
|
||||
---@param callback fun(response: {behavior: number})
|
||||
function mentions_source:execute(completion_item, callback)
|
||||
local current_line = api.nvim_get_current_line()
|
||||
local label = completion_item.label:match("^@(%S+)") -- Extract mention command without '@' and space
|
||||
|
||||
-- Find the corresponding mention
|
||||
local selected_mention
|
||||
for _, mention in ipairs(self.mentions) do
|
||||
if mention.command == label then
|
||||
selected_mention = mention
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Execute the mention's callback if it exists
|
||||
if selected_mention and type(selected_mention.callback) == "function" then
|
||||
selected_mention.callback(selected_mention)
|
||||
-- Get the current cursor position
|
||||
local row, col = unpack(api.nvim_win_get_cursor(0))
|
||||
|
||||
-- Replace the current line with the new line (removing the mention)
|
||||
local new_line = current_line:gsub(vim.pesc(completion_item.label), "")
|
||||
api.nvim_buf_set_lines(0, row - 1, row, false, { new_line })
|
||||
|
||||
-- Adjust the cursor position if needed
|
||||
local new_col = math.min(col, #new_line)
|
||||
api.nvim_win_set_cursor(0, { row, new_col })
|
||||
end
|
||||
|
||||
callback({ behavior = require("cmp").ConfirmBehavior.Insert })
|
||||
end
|
||||
|
||||
return mentions_source
|
||||
|
||||
Reference in New Issue
Block a user