|
1 | 1 | scriptencoding utf-8 |
2 | 2 |
|
3 | | -let s:has_nvim_ghost_text = has('nvim-0.7') && exists('*nvim_buf_get_mark') |
4 | | -let s:vim_minimum_version = '9.0.0185' |
5 | | -let s:has_vim_ghost_text = has('patch-' . s:vim_minimum_version) && has('textprop') |
6 | | -let s:has_ghost_text = s:has_nvim_ghost_text || s:has_vim_ghost_text |
| 3 | + s:has_nvim_ghost_text = has('nvim-0.7') && exists('*nvim_buf_get_mark') |
| 4 | + s:vim_minimum_version = '9.0.0185' |
| 5 | + s:has_vim_ghost_text = has('patch-' . s:vim_minimum_version) && has('textprop') |
| 6 | + s:has_ghost_text = s:has_nvim_ghost_text || s:has_vim_ghost_text |
7 | 7 |
|
8 | | -let s:hlgroup = 'CopilotSuggestion' |
9 | | -let s:annot_hlgroup = 'CopilotAnnotation' |
| 8 | + s:hlgroup = 'CopilotSuggestion' |
| 9 | + s:annot_hlgroup = 'CopilotAnnotation' |
10 | 10 |
|
11 | | -if s:has_vim_ghost_text && empty(prop_type_get(s:hlgroup)) |
| 11 | + s:has_vim_ghost_text && empty(prop_type_get(s:hlgroup)) |
12 | 12 | call prop_type_add(s:hlgroup, {'highlight': s:hlgroup}) |
13 | 13 | endif |
14 | | -if s:has_vim_ghost_text && empty(prop_type_get(s:annot_hlgroup)) |
| 14 | + s:has_vim_ghost_text && empty(prop_type_get(s:annot_hlgroup)) |
15 | 15 | call prop_type_add(s:annot_hlgroup, {'highlight': s:annot_hlgroup}) |
16 | 16 | endif |
17 | 17 |
|
18 | | -function! s:Echo(msg) abort |
19 | | - if has('nvim') && &cmdheight == 0 |
20 | | - call v:lua.vim.notify(a:msg, v:null, {'title': 'GitHub Copilot'}) |
21 | | - else |
| 18 | +! s:Echo(msg) abort |
| 19 | + has('nvim') && &cmdheight == 0 |
| 20 | + call v:lua.vim.notify(a:msg, v: , {'title': 'GitHub Copilot'}) |
| 21 | + |
22 | 22 | echo a:msg |
23 | 23 | endif |
24 | 24 | endfunction |
25 | 25 |
|
26 | | -function! copilot#Init(...) abort |
| 26 | + ! copilot#Init(...) abort |
27 | 27 | call copilot#util#Defer({ -> exists('s:client') || s:Start() }) |
28 | 28 | endfunction |
29 | 29 |
|
30 | | -function! s:Running() abort |
31 | | - return exists('s:client.job') || exists('s:client.client_id') |
| 30 | + ! s:Running() abort |
| 31 | + exists('s:client.job') || exists('s:client.client_id') |
32 | 32 | endfunction |
33 | 33 |
|
34 | | -function! s:Start() abort |
35 | | - if s:Running() || exists('s:client.startup_error') |
36 | | - return |
| 34 | + ! s:Start() abort |
| 35 | + s:Running() || exists('s:client.startup_error') |
| 36 | + |
37 | 37 | endif |
38 | | - let s:client = copilot#client#New() |
| 38 | + s:client = copilot#client#New() |
39 | 39 | endfunction |
40 | 40 |
|
41 | | -function! s:Stop() abort |
42 | | - if exists('s:client') |
43 | | - let client = remove(s:, 'client') |
| 41 | + ! s:Stop() abort |
| 42 | + exists('s:client') |
| 43 | + client = remove(s:, 'client') |
44 | 44 | call client.Close() |
45 | 45 | endif |
46 | 46 | endfunction |
47 | 47 |
|
48 | | -function! copilot#Client() abort |
| 48 | + ! copilot#Client() abort |
49 | 49 | call s:Start() |
50 | | - return s:client |
| 50 | + s:client |
51 | 51 | endfunction |
52 | 52 |
|
53 | | -function! copilot#RunningClient() abort |
54 | | - if s:Running() |
55 | | - return s:client |
56 | | - else |
57 | | - return v:null |
| 53 | + ! copilot#RunningClient() abort |
| 54 | + s:Running() |
| 55 | + s:client |
| 56 | + |
| 57 | + v: |
58 | 58 | endif |
59 | 59 | endfunction |
60 | 60 |
|
61 | | -if has('nvim-0.7') && !has(luaeval('vim.version().api_prerelease') ? 'nvim-0.8.1' : 'nvim-0.8.0') |
62 | | - let s:editor_warning = 'Neovim 0.7 support is deprecated and will be dropped in a future release of copilot.vim.' |
| 61 | + has('nvim-0.7') && !has(luaeval('vim.version().api_prerelease') ? 'nvim-0.8.1' : 'nvim-0.8.0') |
| 62 | + s:editor_warning = 'Neovim 0.7 support is deprecated and will be dropped in a future release of copilot.vim.' |
63 | 63 | endif |
64 | | -if has('vim_starting') && exists('s:editor_warning') |
| 64 | + has('vim_starting') && exists('s:editor_warning') |
65 | 65 | call copilot#logger#Warn(s:editor_warning) |
66 | 66 | endif |
67 | | -function! s:EditorVersionWarning() abort |
68 | | - if exists('s:editor_warning') |
| 67 | + ! s:EditorVersionWarning() abort |
| 68 | + exists('s:editor_warning') |
69 | 69 | echohl WarningMsg |
70 | 70 | echo 'Warning: ' . s:editor_warning |
71 | 71 | echohl None |
72 | 72 | endif |
73 | 73 | endfunction |
74 | 74 |
|
75 | | -function! copilot#Request(method, params, ...) abort |
76 | | - let client = copilot#Client() |
77 | | - return call(client.Request, [a:method, a:params] + a:000) |
| 75 | + ! copilot#Request(method, params, ...) abort |
| 76 | + client = copilot#Client() |
| 77 | + call(client.Request, [a:method, a:params] + a:000) |
78 | 78 | endfunction |
79 | 79 |
|
80 | | -function! copilot#Call(method, params, ...) abort |
81 | | - let client = copilot#Client() |
82 | | - return call(client.Call, [a:method, a:params] + a:000) |
| 80 | + ! copilot#Call(method, params, ...) abort |
| 81 | + client = copilot#Client() |
| 82 | + call(client.Call, [a:method, a:params] + a:000) |
83 | 83 | endfunction |
84 | 84 |
|
85 | | -function! copilot#Notify(method, params, ...) abort |
86 | | - let client = copilot#Client() |
87 | | - return call(client.Notify, [a:method, a:params] + a:000) |
| 85 | + ! copilot#Notify(method, params, ...) abort |
| 86 | + client = copilot#Client() |
| 87 | + call(client.Notify, [a:method, a:params] + a:000) |
88 | 88 | endfunction |
89 | 89 |
|
90 | | -function! copilot#NvimNs() abort |
91 | | - return nvim_create_namespace('github-copilot') |
| 90 | + ! copilot#NvimNs() abort |
| 91 | + nvim_create_namespace('github-copilot') |
92 | 92 | endfunction |
93 | 93 |
|
94 | | -function! copilot#Clear() abort |
95 | | - if exists('g:_copilot_timer') |
| 94 | + ! copilot#Clear() abort |
| 95 | + exists('g:_copilot_timer') |
96 | 96 | call timer_stop(remove(g:, '_copilot_timer')) |
97 | 97 | endif |
98 | | - if exists('b:_copilot') |
| 98 | + exists('b:_copilot') |
99 | 99 | call copilot#client#Cancel(get(b:_copilot, 'first', {})) |
100 | 100 | call copilot#client#Cancel(get(b:_copilot, 'cycling', {})) |
101 | 101 | endif |
102 | 102 | call s:UpdatePreview() |
103 | 103 | unlet! b:_copilot |
104 | | - return '' |
| 104 | + '' |
105 | 105 | endfunction |
106 | 106 |
|
107 | | -function! copilot#Dismiss() abort |
| 107 | + ! copilot#Dismiss() abort |
108 | 108 | call copilot#Clear() |
109 | 109 | call s:UpdatePreview() |
110 | | - return '' |
| 110 | + '' |
111 | 111 | endfunction |
112 | 112 |
|
113 | | -let s:filetype_defaults = { |
| 113 | + s:filetype_defaults = { |
114 | 114 | \ 'gitcommit': 0, |
115 | 115 | \ 'gitrebase': 0, |
116 | 116 | \ 'hgcommit': 0, |
117 | 117 | \ 'svn': 0, |
118 | 118 | \ 'cvs': 0, |
119 | 119 | \ '.': 0} |
120 | 120 |
|
121 | | -function! s:BufferDisabled() abort |
122 | | - if &buftype =~# '^\%(help\|prompt\|quickfix\|terminal\)$' |
123 | | - return 5 |
| 121 | + ! s:BufferDisabled() abort |
| 122 | + &buftype =~# '^\%(help\|prompt\|quickfix\|terminal\)$' |
| 123 | + 5 |
124 | 124 | endif |
125 | | - if exists('b:copilot_disabled') |
126 | | - return empty(b:copilot_disabled) ? 0 : 3 |
| 125 | + exists('b:copilot_disabled') |
| 126 | + empty(b:copilot_disabled) ? 0 : 3 |
127 | 127 | endif |
128 | | - if exists('b:copilot_enabled') |
129 | | - return empty(b:copilot_enabled) ? 4 : 0 |
| 128 | + exists('b:copilot_enabled') |
| 129 | + empty(b:copilot_enabled) ? 4 : 0 |
130 | 130 | endif |
131 | | - let short = empty(&l:filetype) ? '.' : split(&l:filetype, '\.', 1)[0] |
132 | | - let config = {} |
133 | | - if type(get(g:, 'copilot_filetypes')) == v:t_dict |
134 | | - let config = g:copilot_filetypes |
| 131 | + short = empty(&l:filetype) ? '.' : split(&l:filetype, '\.', 1)[0] |
| 132 | + config = {} |
| 133 | + type(get(g:, 'copilot_filetypes')) == v:t_dict |
| 134 | + config = g:copilot_filetypes |
135 | 135 | endif |
136 | | - if has_key(config, &l:filetype) |
137 | | - return empty(config[&l:filetype]) |
138 | | - elseif has_key(config, short) |
139 | | - return empty(config[short]) |
140 | | - elseif has_key(config, '*') |
141 | | - return empty(config['*']) |
142 | | - else |
143 | | - return get(s:filetype_defaults, short, 1) == 0 ? 2 : 0 |
| 136 | + has_key(config, &l:filetype) |
| 137 | + empty(config[&l:filetype]) |
| 138 | + has_key(config, short) |
| 139 | + empty(config[short]) |
| 140 | + has_key(config, '*') |
| 141 | + empty(config['*']) |
| 142 | + |
| 143 | + get(s:filetype_defaults, short, 1) == 0 ? 2 : 0 |
144 | 144 | endif |
145 | 145 | endfunction |
146 | 146 |
|
147 | | -function! copilot#Enabled() abort |
148 | | - return get(g:, 'copilot_enabled', 1) |
| 147 | + ! copilot#Enabled() abort |
| 148 | + get(g:, 'copilot_enabled', 1) |
149 | 149 | \ && empty(s:BufferDisabled()) |
150 | 150 | endfunction |
151 | 151 |
|
152 | | -let s:inline_invoked = 1 |
153 | | -let s:inline_automatic = 2 |
| 152 | + s:inline_invoked = 1 |
| 153 | + s:inline_automatic = 2 |
154 | 154 |
|
155 | | -function! copilot#Complete(...) abort |
156 | | - if exists('g:_copilot_timer') |
| 155 | + ! copilot#Complete(...) abort |
| 156 | + exists('g:_copilot_timer') |
157 | 157 | call timer_stop(remove(g:, '_copilot_timer')) |
158 | 158 | endif |
159 | | - let target = [bufnr(''), getbufvar('', 'changedtick'), line('.'), col('.')] |
| 159 | + target = [bufnr(''), getbufvar('', 'changedtick'), line('.'), col('.')] |
160 | 160 | if !exists('b:_copilot.target') || b:_copilot.target !=# target |
161 | | - if exists('b:_copilot.first') |
| 161 | + exists('b:_copilot.first') |
162 | 162 | call copilot#client#Cancel(b:_copilot.first) |
163 | | - endif |
| 163 | + end |
164 | 164 | if exists('b:_copilot.cycling') |
165 | 165 | call copilot#client#Cancel(b:_copilot.cycling) |
166 | | - endif |
167 | | - let params = { |
| 166 | + end |
| 167 | + params = { |
168 | 168 | \ 'textDocument': {'uri': bufnr('')}, |
169 | 169 | \ 'position': copilot#util#AppendPosition(), |
170 | 170 | \ 'formattingOptions': {'insertSpaces': &expandtab ? v:true : v:false, 'tabSize': shiftwidth()}, |
171 | 171 | \ 'context': {'triggerKind': s:inline_automatic}} |
172 | | - let b:_copilot = { |
| 172 | + b:_copilot = { |
173 | 173 | \ 'target': target, |
174 | 174 | \ 'params': params, |
175 | 175 | \ 'first': copilot#Request('textDocument/inlineCompletion', params)} |
176 | | - let g:_copilot_last = b:_copilot |
177 | | - endif |
178 | | - let completion = b:_copilot.first |
179 | | - if !a:0 |
180 | | - return completion.Await() |
181 | | - else |
| 176 | + g:_copilot_last = b:_copilot |
| 177 | + end |
| 178 | + completion = b:_copilot.first |
| 179 | + !a:0 |
| 180 | + completion.Await() |
| 181 | + |
182 | 182 | call copilot#client#Result(completion, function(a:1, [b:_copilot])) |
183 | 183 | if a:0 > 1 |
184 | 184 | call copilot#client#Error(completion, function(a:2, [b:_copilot])) |
|
0 commit comments