Skip to content

Commit 622b66c

Browse files
authored
Merge pull request #148 from juodumas-forks/do-not-add-space-on-each-line-of-assistant-response
Fix empty space on assistant responses line when 'virtualedit=all' is set.
2 parents e2b9341 + d626067 commit 622b66c

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

autoload/vim_ai.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function! vim_ai#AIEditRun(uses_range, config, ...) range abort
187187
\ "user_instruction": l:instruction,
188188
\ "user_selection": l:selection,
189189
\ "is_selection": l:is_selection,
190-
\ "command_type": 'complete',
190+
\ "command_type": 'edit',
191191
\}
192192
let l:context = py3eval("make_ai_context(unwrap('l:config_input'))")
193193
let l:config = l:context['config']

py/chat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _chunks_to_sections(chunks):
7878
yield chunk['content']
7979

8080
chunks = make_chat_text_chunks(messages, options)
81-
render_text_chunks(_chunks_to_sections(chunks))
81+
render_text_chunks(_chunks_to_sections(chunks), append_to_eol=True)
8282

8383
vim.command("normal! a\n\n>>> user\n\n")
8484
vim.command("redraw")

py/complete.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
def run_ai_completition(context):
66
prompt = context['prompt']
7+
command_type = context['command_type']
78
config = make_config(context['config'])
89
config_options = config['options']
910
config_ui = config['ui']
@@ -46,7 +47,7 @@ def chat_engine(prompt):
4647
print('Completing...')
4748
vim.command("redraw")
4849
text_chunks = engines[engine](prompt)
49-
render_text_chunks(text_chunks)
50+
render_text_chunks(text_chunks, append_to_eol=command_type == 'complete')
5051
clear_echo_message()
5152
except BaseException as error:
5253
handle_completion_error(error)

py/context.py

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def make_ai_context(params):
153153
prompt = make_prompt(config_prompt, user_prompt, user_selection, selection_boundary)
154154

155155
return {
156+
'command_type': command_type,
156157
'config': final_config,
157158
'prompt': prompt,
158159
}

py/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def need_insert_before_cursor():
8989
raise ValueError("Unexpected getpos value, it should be a list with two elements")
9090
return pos[1] == "1" # determines if visual selection starts on the first window column
9191

92-
def render_text_chunks(chunks):
92+
def render_text_chunks(chunks, append_to_eol=False):
9393
generating_text = False
9494
full_text = ''
9595
insert_before_cursor = need_insert_before_cursor()
@@ -102,6 +102,8 @@ def render_text_chunks(chunks):
102102
if insert_before_cursor:
103103
vim.command("normal! i" + text)
104104
insert_before_cursor = False
105+
elif append_to_eol: # for cases when virtualedit=all is set, to avoid empty space
106+
vim.command("normal! A" + text)
105107
else:
106108
vim.command("normal! a" + text)
107109
vim.command("undojoin")

0 commit comments

Comments
 (0)