@@ -19,19 +19,16 @@ if s:has_vim_ghost_text && empty(prop_type_get(s:annot_hlgroup))
1919 call prop_type_add (s: annot_hlgroup , {' highlight' : s: annot_hlgroup })
2020endif
2121
22- if len ($XDG_CONFIG_HOME )
23- let s: config_root = $XDG_CONFIG_HOME
24- elseif has (' win32' )
25- let s: config_root = expand (' ~/AppData/Local' )
26- else
27- let s: config_root = expand (' ~/.config' )
28- endif
29- let s: config_root .= ' /github-copilot'
30- if ! isdirectory (s: config_root )
31- call mkdir (s: config_root , ' p' , 0700 )
32- endif
33-
34- let s: config_hosts = s: config_root . ' /hosts.json'
22+ function ! s: EditorConfiguration () abort
23+ let filetypes = copy (s: filetype_defaults )
24+ if type (get (g: , ' copilot_filetypes' )) == v: t_dict
25+ call extend (filetypes, g: copilot_filetypes )
26+ endif
27+ return {
28+ \ ' enableAutoCompletions' : ! empty (get (g: , ' copilot_enabled' , 1 )),
29+ \ ' disabledLanguages' : sort (keys (filter (filetypes, { k , v - > empty (v ) }))),
30+ \ }
31+ endfunction
3532
3633function ! s: StatusNotification (params, ... ) abort
3734 let status = get (a: params , ' status' , ' ' )
@@ -46,15 +43,20 @@ function! copilot#Init(...) abort
4643 call timer_start (0 , { _ - > s: Start () })
4744endfunction
4845
46+ function ! s: Running () abort
47+ return exists (' s:agent.job' ) || exists (' s:agent.client_id' )
48+ endfunction
49+
4950function ! s: Start () abort
50- if exists ( ' s:agent.job ' ) || exists ( ' s:agent.client_id ' )
51+ if s: Running ( )
5152 return
5253 endif
5354 let s: agent = copilot#agent#New ({' notifications' : {
5455 \ ' statusNotification' : function (' s:StatusNotification' ),
5556 \ ' PanelSolution' : function (' copilot#panel#Solution' ),
5657 \ ' PanelSolutionsDone' : function (' copilot#panel#SolutionsDone' ),
57- \ }})
58+ \ },
59+ \ ' editorConfiguration' : s: EditorConfiguration ()})
5860endfunction
5961
6062function ! s: Stop () abort
@@ -84,20 +86,6 @@ function! copilot#Notify(method, params, ...) abort
8486 return call (agent.Notify, [a: method , a: params ] + a: 000 )
8587endfunction
8688
87- function ! s: ReadTerms () abort
88- let file = s: config_root . ' /terms.json'
89- try
90- if filereadable (file )
91- let terms = json_decode (join (readfile (file )))
92- if type (terms) == v: t_dict
93- return terms
94- endif
95- endif
96- catch
97- endtry
98- return {}
99- endfunction
100-
10189function ! copilot#NvimNs () abort
10290 return nvim_create_namespace (' github-copilot' )
10391endfunction
@@ -137,14 +125,14 @@ let s:filetype_defaults = {
137125
138126function ! s: BufferDisabled () abort
139127 if exists (' b:copilot_disabled' )
140- return b: copilot_disabled ? 3 : 0
128+ return empty ( b: copilot_disabled) ? 0 : 3
141129 endif
142130 if exists (' b:copilot_enabled' )
143- return b: copilot_enabled ? 0 : 4
131+ return empty ( b: copilot_enabled) ? 4 : 0
144132 endif
145133 let short = empty (&l: filetype ) ? ' .' : split (&l: filetype , ' \.' , 1 )[0 ]
146134 let config = get (g: , ' copilot_filetypes' , {})
147- if has_key (config, &l: filetype )
135+ if type (config) == v: t_dict && has_key (config, &l: filetype )
148136 return empty (config[&l: filetype ])
149137 elseif has_key (config, short)
150138 return empty (config[short])
@@ -372,6 +360,11 @@ function! s:UpdatePreview() abort
372360 let data.hl_mode = ' combine'
373361 call nvim_buf_set_extmark (0 , copilot#NvimNs (), line (' .' )-1 , col (' .' )-1 , data)
374362 else
363+ let trail = strpart (getline (' .' ), col (' .' ) - 1 )
364+ while ! empty (trail) && trail[-1 ] == # text[0 ][-1 ]
365+ let trail = trail[:-2 ]
366+ let text[0 ] = text[0 ][:-2 ]
367+ endwhile
375368 call prop_add (line (' .' ), col (' .' ), {' type' : s: hlgroup , ' text' : text[0 ]})
376369 for line in text[1 :]
377370 call prop_add (line (' .' ), 0 , {' type' : s: hlgroup , ' text_align' : ' below' , ' text' : line })
@@ -398,21 +391,22 @@ function! s:HandleTriggerResult(result) abort
398391 call s: UpdatePreview ()
399392endfunction
400393
394+ function ! copilot#Suggest () abort
395+ try
396+ call copilot#Complete (function (' s:HandleTriggerResult' ), function (' s:HandleTriggerResult' ))
397+ catch
398+ call copilot#logger#Exception ()
399+ endtry
400+ return ' '
401+ endfunction
402+
401403function ! s: Trigger (bufnr , timer) abort
402404 let timer = get (g: , ' _copilot_timer' , -1 )
403405 unlet ! g: _copilot_timer
404406 if a: bufnr !=# bufnr (' ' ) || a: timer isnot # timer || mode () !=# ' i'
405407 return
406408 endif
407- if exists (' s:auth_request' )
408- let g: _copilot_timer = timer_start (100 , function (' s:Trigger' , [a: bufnr ]))
409- return
410- endif
411- try
412- call copilot#Complete (function (' s:HandleTriggerResult' ), function (' s:HandleTriggerResult' ))
413- catch
414- call copilot#logger#Exception ()
415- endtry
409+ return copilot#Suggest ()
416410endfunction
417411
418412function ! copilot#IsMapped () abort
@@ -579,6 +573,12 @@ function! s:commands.status(opts) abort
579573 return
580574 endif
581575
576+ let status = copilot#Call (' checkStatus' , {})
577+ if status.status == # ' NotAuthorized'
578+ echo ' Copilot: Not authorized'
579+ return
580+ endif
581+
582582 echo ' Copilot: Enabled and online'
583583endfunction
584584
@@ -610,8 +610,10 @@ function! s:commands.setup(opts) abort
610610
611611 if has_key (data, ' verificationUri' )
612612 let uri = data.verificationUri
613- let @+ = data.userCode
614- let @* = data.userCode
613+ if has (' clipboard' )
614+ let @+ = data.userCode
615+ let @* = data.userCode
616+ endif
615617 echo " First copy your one-time code: " . data.userCode
616618 try
617619 if len (&mouse )
@@ -677,6 +679,16 @@ function! s:commands.version(opts) abort
677679 endif
678680endfunction
679681
682+ function ! s: UpdateEditorConfiguration () abort
683+ try
684+ if s: Running ()
685+ call copilot#Notify (' notifyChangeConfiguration' , {' settings' : s: EditorConfiguration ()})
686+ endif
687+ catch
688+ call copilot#logger#Exception ()
689+ endtry
690+ endfunction
691+
680692let s: feedback_url = ' https://github.com/github-community/community/discussions/categories/copilot'
681693function ! s: commands .feedback (opts) abort
682694 echo s: feedback_url
@@ -697,10 +709,12 @@ endfunction
697709
698710function ! s: commands .disable (opts) abort
699711 let g: copilot_enabled = 0
712+ call s: UpdateEditorConfiguration ()
700713endfunction
701714
702715function ! s: commands .enable (opts) abort
703716 let g: copilot_enabled = 1
717+ call s: UpdateEditorConfiguration ()
704718endfunction
705719
706720function ! s: commands .panel (opts) abort
0 commit comments