Skip to content

Commit

Permalink
Step 60
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Jun 1, 2024
1 parent 1851729 commit e39a2e4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
5 changes: 1 addition & 4 deletions lua/fittencode/bindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ function M.setup_autocmds()
api.nvim_create_autocmd({ 'TextChangedI' }, {
group = Base.augroup('TextChanged'),
pattern = '*',
callback = function()
callback = function(param)
-- Log.debug('TextChangedI')
if not Config.options.inline_completion.auto_triggering_completion then
return
end
if ignore then
return
end
Expand Down
23 changes: 18 additions & 5 deletions lua/fittencode/engines/inline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ local generate_one_stage_timer = nil
function M.generate_one_stage(row, col, force, delaytime, on_success, on_error)
if not force and model:cache_hit(row, col) and M.has_suggestions() then
status:update(SC.SUGGESTIONS_READY)
render_virt_text_segments(model:get_suggestions_segments())
Log.debug('CACHE HIT')
local segments = model:get_suggestions_segments()
render_virt_text_segments(segments)
schedule(on_success, model:make_new_trim_commmited_suggestions())
return
else
Expand Down Expand Up @@ -264,10 +266,21 @@ local function _accept_impl(range, direction, mode)
return
end
Lines.clear_virt_text()
local commited = false
if mode == 'stage' and range == 'all' then
set_text_event_filter(model:get_suggestions_segments().stage)
model:sync_commit()
else
local segments = model:get_suggestions_segments()
if not segments then
return
end
if model:is_initial_state() then
mode = 'commit'
else
set_text_event_filter(segments.stage)
model:sync_commit()
commited = true
end
end
if not commited then
local updated = model:accept({
mode = mode,
range = range,
Expand Down Expand Up @@ -360,6 +373,7 @@ function M.lazy_inline_completion()
if not suggestions_modify_enabled() then
return
end
Lines.clear_virt_text()
local window = api.nvim_get_current_win()
local buffer = api.nvim_win_get_buf(window)
local row, col = Base.get_cursor(window)
Expand All @@ -368,7 +382,6 @@ function M.lazy_inline_completion()
return
end
if model:is_advance(row, col, char) then
Lines.clear_virt_text()
model:accept({
mode = 'commit',
range = 'char',
Expand Down
24 changes: 18 additions & 6 deletions lua/fittencode/engines/inline/model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ end
---@param cache SuggestionsCache
---@return number?, number?
local function _next_all(cache)
local lines = cache.lines
if not lines then
return nil
end
return #lines, #lines[#lines]
return
end

local NEXT = {
Expand All @@ -153,6 +149,11 @@ local function _accept(cache, row, col, direction, range)
if direction == 'forward' then
local next = next_fx(cache, row, col)
if next == nil then
if range == 'all' then
row = #lines
col = #lines[row]
return row, col
end
row = row + 1
if row <= #lines then
if range == 'word' then
Expand Down Expand Up @@ -377,7 +378,7 @@ function InlineModel:accept(opts)
if not next_row or not next_col then
return
end
local cursor = { next_col, next_col }
local cursor = { next_row, next_col }

---@type AcceptIncrementalUpdates
local updated = {
Expand Down Expand Up @@ -502,4 +503,15 @@ function InlineModel:sync_commit()
self.cache.commit_cursor = self.cache.stage_cursor
end

function InlineModel:is_initial_state()
local stage_cursor = self.cache.stage_cursor
if not stage_cursor or not stage_cursor[1] or not stage_cursor[2] then
return true
end
if (stage_cursor[1] == 0 or stage_cursor[1] == 1) and stage_cursor[2] == 0 then
return true
end
return false
end

return InlineModel
3 changes: 2 additions & 1 deletion lua/fittencode/views/lines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,12 @@ function M.render_virt_text(opts)
M.clear_virt_text()
end, show_time)
end

-- api.nvim_command('redraw!')
end

function M.clear_virt_text()
api.nvim_buf_clear_namespace(0, namespace, 0, -1)
-- api.nvim_command('redraw!')
end

-- When we edit some complex documents, extmark will not be able to draw correctly.
Expand Down

0 comments on commit e39a2e4

Please sign in to comment.