@@ -10,8 +10,8 @@ def run_ai_chat(context):
10
10
config_ui = config ['ui' ]
11
11
12
12
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 )
15
15
if not contains_user_prompt :
16
16
# user role not found, put whole file content as an user prompt
17
17
vim .command ("normal! gg" )
@@ -30,10 +30,9 @@ def initialize_chat_window():
30
30
vim_break_undo_sequence ()
31
31
vim .command ("redraw" )
32
32
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
37
36
vim .command ("normal! o" )
38
37
vim .command ("normal! i\n >>> user\n \n " )
39
38
0 commit comments