@@ -44,7 +44,7 @@ function! s:StatusNotification(params, ...) abort
4444endfunction
4545
4646function ! copilot#Init (... ) abort
47- call timer_start (0 , { _ - > s: Start () })
47+ call timer_start (0 , { _ - > exists ( ' s:agent ' ) || s: Start () })
4848endfunction
4949
5050function ! s: Running () abort
@@ -401,6 +401,9 @@ function! s:HandleTriggerResult(result) abort
401401endfunction
402402
403403function ! copilot#Suggest () abort
404+ if ! s: Running ()
405+ return ' '
406+ endif
404407 try
405408 call copilot#Complete (function (' s:HandleTriggerResult' ), function (' s:HandleTriggerResult' ))
406409 catch
@@ -418,13 +421,8 @@ function! s:Trigger(bufnr, timer) abort
418421 return copilot#Suggest ()
419422endfunction
420423
421- function ! copilot#IsMapped () abort
422- return get (g: , ' copilot_assume_mapped' ) ||
423- \ hasmapto (' copilot#Accept(' , ' i' )
424- endfunction
425-
426424function ! copilot#Schedule (... ) abort
427- if ! s: has_ghost_text || ! copilot#Enabled () || ! copilot#IsMapped ()
425+ if ! s: has_ghost_text || ! copilot#Enabled ()
428426 call copilot#Clear ()
429427 return
430428 endif
@@ -434,6 +432,20 @@ function! copilot#Schedule(...) abort
434432 let g: _copilot_timer = timer_start (delay, function (' s:Trigger' , [bufnr (' ' )]))
435433endfunction
436434
435+ function ! s: SyncTextDocument (bufnr , ... ) abort
436+ try
437+ return copilot#Agent ().SyncTextDocument (a: bufnr )
438+ catch
439+ call copilot#logger#Exception ()
440+ endtry
441+ endfunction
442+
443+ function ! copilot#OnFileType () abort
444+ if empty (s: BufferDisabled ())
445+ call timer_start (0 , function (' s:SyncTextDocument' , [bufnr (' ' )]))
446+ endif
447+ endfunction
448+
437449function ! copilot#OnInsertLeave () abort
438450 return copilot#Clear ()
439451endfunction
@@ -547,8 +559,6 @@ function! s:EnabledStatusMessage() abort
547559 else
548560 return " Vim " . s: vim_minimum_version . " required to support ghost text"
549561 endif
550- elseif ! copilot#IsMapped ()
551- return ' <Tab> map has been disabled or is claimed by another plugin'
552562 elseif ! get (g: , ' copilot_enabled' , 1 )
553563 return ' Disabled globally by :Copilot disable'
554564 elseif buf_disabled is # 5
0 commit comments