Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and implement manual_render #273

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/codeium/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function M.defaults()
filetypes = {},
default_filetype_enabled = true,
manual = false,
manual_render = false,
idle_delay = 75,
virtual_text_priority = 65535,
map_keys = true,
Expand Down
34 changes: 25 additions & 9 deletions lua/codeium/virtual_text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local codeium_status = "idle"
--- @field cancel function
--- @field request_id number
--- @field request_data table
--- @field rendered boolean | nil

--- @type Completions | nil
local completions
Expand Down Expand Up @@ -173,7 +174,7 @@ local function completion_inserter(current_completion, insert_text)

server.accept_completion(current_completion.completion.completionId)

return '<C-g>u' .. delete_range .. insert_text .. cursor_text
return "<C-g>u" .. delete_range .. insert_text .. cursor_text
end

function M.accept()
Expand Down Expand Up @@ -225,10 +226,12 @@ local function render_current_completion()
end

local current_completion = M.get_current_completion_item()
if current_completion == nil then
if current_completion == nil or not completions then
return ""
end

completions.rendered = true

local parts = current_completion.completionParts or {}

local inline_cumulative_cols = 0
Expand Down Expand Up @@ -386,7 +389,7 @@ local function get_document(buf_id, cur_line, cur_col)
end

--- @param opts { bufnr: number, timer: any }?
function M.complete(opts)
function M.complete(opts, force_render)
if opts then
if opts.timer ~= idle_timer then
return
Expand All @@ -399,6 +402,10 @@ function M.complete(opts)
end
end

if force_render == nil then
force_render = false
end

if idle_timer then
vim.fn.timer_stop(idle_timer)
idle_timer = nil
Expand Down Expand Up @@ -452,7 +459,7 @@ function M.complete(opts)
end

if json and json.state and json.state.state == "CODEIUM_STATE_SUCCESS" and json.completionItems then
M.handle_completions(json.completionItems)
M.handle_completions(json.completionItems, force_render)
end
end
)
Expand All @@ -463,14 +470,17 @@ function M.complete(opts)
}
end

function M.handle_completions(completion_items)
function M.handle_completions(completion_items, force_render)
if not completions then
return
end
completions.items = completion_items
completions.index = 0
completions.rendered = false
codeium_status = "completions"
render_current_completion()
if (not config.options.virtual_text.manual_render) or force_render then
render_current_completion()
end
end

function M.filetype_enabled(bufnr)
Expand All @@ -494,10 +504,16 @@ function M.debounced_complete()
end

function M.cycle_or_complete()
if M.get_current_completion_item() == nil then
M.complete()
local current_completions = M.get_current_completion_item()

if current_completions == nil then
M.complete(nil, true)
else
M.cycle_completions(1)
if completions and completions.rendered then
M.cycle_completions(1)
else
render_current_completion()
end
end
end

Expand Down