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:
Christopher Brewin
2024-12-12 03:29:10 +10:00
committed by GitHub
parent 3b33170097
commit 78dd9b0a6d
13 changed files with 695 additions and 224 deletions

View File

@@ -58,17 +58,17 @@ M.shell_run = function(input_cmd)
-- powershell then we can just run the cmd
if shell:match("powershell") or shell:match("pwsh") then
cmd = input_cmd
elseif vim.fn.has("wsl") > 0 then
elseif fn.has("wsl") > 0 then
-- wsl: powershell.exe -Command 'command "/path"'
cmd = "powershell.exe -NoProfile -Command '" .. input_cmd:gsub("'", '"') .. "'"
elseif vim.fn.has("win32") > 0 then
elseif fn.has("win32") > 0 then
cmd = 'powershell.exe -NoProfile -Command "' .. input_cmd:gsub('"', "'") .. '"'
else
-- linux and macos we wil just do sh -c
cmd = "sh -c " .. vim.fn.shellescape(input_cmd)
cmd = "sh -c " .. fn.shellescape(input_cmd)
end
local output = vim.fn.system(cmd)
local output = fn.system(cmd)
local code = vim.v.shell_error
return { stdout = output, code = code }
@@ -562,10 +562,10 @@ function M.debounce(func, delay)
end
function M.winline(winid)
local current_win = vim.api.nvim_get_current_win()
vim.api.nvim_set_current_win(winid)
local line = vim.fn.winline()
vim.api.nvim_set_current_win(current_win)
local current_win = api.nvim_get_current_win()
api.nvim_set_current_win(winid)
local line = fn.winline()
api.nvim_set_current_win(current_win)
return line
end
@@ -725,7 +725,7 @@ function M.get_or_create_buffer_with_filepath(filepath)
api.nvim_set_current_buf(buf)
-- Use the edit command to load the file content and set the buffer name
vim.cmd("edit " .. vim.fn.fnameescape(filepath))
vim.cmd("edit " .. fn.fnameescape(filepath))
return buf
end
@@ -823,4 +823,13 @@ function M.get_current_selection_diagnostics(bufnr, selection)
return selection_diagnostics
end
function M.uniform_path(path)
local project_root = M.get_project_root()
local abs_path = Path:new(project_root):joinpath(path):absolute()
local relative_path = Path:new(abs_path):make_relative(project_root)
return relative_path
end
function M.is_same_file(filepath_a, filepath_b) return M.uniform_path(filepath_a) == M.uniform_path(filepath_b) end
return M