Skip to content
Merged
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
2 changes: 1 addition & 1 deletion autoload/vim_ai.vim
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function! vim_ai#AIEditRun(uses_range, config, ...) range abort
\ "user_instruction": l:instruction,
\ "user_selection": l:selection,
\ "is_selection": l:is_selection,
\ "command_type": 'complete',
\ "command_type": 'edit',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madox2 this change is unrelated to this PR, but it's useful for my change and looks like an omission after the role changes?

\}
let l:context = py3eval("make_ai_context(unwrap('l:config_input'))")
let l:config = l:context['config']
Expand Down
2 changes: 1 addition & 1 deletion py/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _chunks_to_sections(chunks):
yield chunk['content']

chunks = make_chat_text_chunks(messages, options)
render_text_chunks(_chunks_to_sections(chunks))
render_text_chunks(_chunks_to_sections(chunks), append_to_eol=True)

vim.command("normal! a\n\n>>> user\n\n")
vim.command("redraw")
Expand Down
3 changes: 2 additions & 1 deletion py/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

def run_ai_completition(context):
prompt = context['prompt']
command_type = context['command_type']
config = make_config(context['config'])
config_options = config['options']
config_ui = config['ui']
Expand Down Expand Up @@ -46,7 +47,7 @@ def chat_engine(prompt):
print('Completing...')
vim.command("redraw")
text_chunks = engines[engine](prompt)
render_text_chunks(text_chunks)
render_text_chunks(text_chunks, append_to_eol=command_type == 'complete')
clear_echo_message()
except BaseException as error:
handle_completion_error(error)
Expand Down
1 change: 1 addition & 0 deletions py/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def make_ai_context(params):
prompt = make_prompt(config_prompt, user_prompt, user_selection, selection_boundary)

return {
'command_type': command_type,
'config': final_config,
'prompt': prompt,
}
4 changes: 3 additions & 1 deletion py/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def need_insert_before_cursor():
raise ValueError("Unexpected getpos value, it should be a list with two elements")
return pos[1] == "1" # determines if visual selection starts on the first window column

def render_text_chunks(chunks):
def render_text_chunks(chunks, append_to_eol=False):
generating_text = False
full_text = ''
insert_before_cursor = need_insert_before_cursor()
Expand All @@ -102,6 +102,8 @@ def render_text_chunks(chunks):
if insert_before_cursor:
vim.command("normal! i" + text)
insert_before_cursor = False
elif append_to_eol: # for cases when virtualedit=all is set, to avoid empty space
vim.command("normal! A" + text)
else:
vim.command("normal! a" + text)
vim.command("undojoin")
Expand Down
Loading