Skip to content

Commit 0d69cfa

Browse files
committed
Treat 'exec' & 'include' roles same as '>>> user'
1 parent 9840efa commit 0d69cfa

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

py/chat.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def run_ai_chat(context):
1010
config_ui = config['ui']
1111

1212
def initialize_chat_window():
13-
lines = vim.eval('getline(1, "$")')
14-
contains_user_prompt = '>>> user' in lines
13+
file_content = vim.eval('trim(join(getline(1, "$"), "\n"))')
14+
contains_user_prompt = re.search(r"^>>> (user|exec|include)", file_content, flags=re.MULTILINE)
1515
if not contains_user_prompt:
1616
# user role not found, put whole file content as an user prompt
1717
vim.command("normal! gg")
@@ -30,10 +30,9 @@ def initialize_chat_window():
3030
vim_break_undo_sequence()
3131
vim.command("redraw")
3232

33-
file_content = vim.eval('trim(join(getline(1, "$"), "\n"))')
34-
role_lines = re.findall(r'(^>>> user|^>>> system|^<<< thinking|^<<< assistant).*', file_content, flags=re.MULTILINE)
35-
if not role_lines[-1].startswith(">>> user"):
36-
# last role is not user, most likely completion was cancelled before
33+
last_role = re.match(r".*^>>> (\w+)", file_content, flags=re.DOTALL | re.MULTILINE)
34+
if last_role and last_role.group(1) not in ('user', 'include', 'exec'):
35+
# last role is not a user role, most likely completion was cancelled before
3736
vim.command("normal! o")
3837
vim.command("normal! i\n>>> user\n\n")
3938

0 commit comments

Comments
 (0)