Skip to content

Commit 8b03e8f

Browse files
committed
allow to just switch to chat with :AIC, fixes #147
1 parent 3054656 commit 8b03e8f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

autoload/vim_ai.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ function! vim_ai#AIChatRun(uses_range, config, ...) range abort
289289
let l:instruction = a:0 > 0 ? a:1 : ""
290290
let l:is_selection = a:uses_range && a:firstline == line("'<") && a:lastline == line("'>")
291291
let l:selection = s:GetSelectionOrRange(l:is_selection, a:uses_range, a:firstline, a:lastline)
292+
let l:started_from_chat = &filetype == 'aichat'
292293

293294
let l:config_input = {
294295
\ "config_default": g:vim_ai_chat,
@@ -301,6 +302,7 @@ function! vim_ai#AIChatRun(uses_range, config, ...) range abort
301302
let l:context = py3eval("make_ai_context(unwrap('l:config_input'))")
302303
let l:config = l:context['config']
303304
let l:context['prompt'] = a:0 > 0 || a:uses_range ? l:context['prompt'] : ''
305+
let l:context['started_from_chat'] = l:started_from_chat
304306

305307
try
306308
call s:set_paste(l:config)

py/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def run_ai_chat(context):
2828
config = make_config(context['config'])
2929
config_options = config['options']
3030
roles = context['roles']
31+
started_from_chat = context['started_from_chat'] == '1'
3132

3233
def initialize_chat_window():
3334
file_content = vim.eval('trim(join(getline(1, "$"), "\n"))')
@@ -87,7 +88,11 @@ def initialize_chat_window():
8788

8889
try:
8990
last_content = messages[-1]["content"][-1]
90-
if last_content['type'] != 'text' or last_content['text']:
91+
92+
# if empty :AIC has been called outside of the chat, just init/switch to the chat but don't trigger the request (#147)
93+
should_imediately_answer = prompt or started_from_chat
94+
awaiting_response = last_content['type'] != 'text' or last_content['text']
95+
if awaiting_response and should_imediately_answer:
9196
vim.command("redraw")
9297

9398
print('Answering...')

0 commit comments

Comments
 (0)