Skip to content

Commit df203c1

Browse files
committed
Copilot.vim 1.3.0
1 parent 4b3f322 commit df203c1

File tree

4 files changed

+48
-23
lines changed

4 files changed

+48
-23
lines changed

autoload/copilot.vim

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ if !exists('s:github') && $CODESPACES ==# 'true' && len($GITHUB_TOKEN)
9292
let s:github = {'oauth_token': $GITHUB_TOKEN, 'user': empty($GITHUB_USER) ? 'codespace-user': $GITHUB_USER}
9393
endif
9494

95+
function! s:StatusNotification(params, ...) abort
96+
let status = get(a:params, 'status', '')
97+
if status ==? 'error'
98+
let s:agent_error = a:params.message
99+
else
100+
unlet! s:agent_error
101+
endif
102+
endfunction
103+
95104
function! copilot#Init(...) abort
96105
call timer_start(0, { _ -> s:Start() })
97106
endfunction
@@ -101,6 +110,7 @@ function! s:Start() abort
101110
return
102111
endif
103112
let s:agent = copilot#agent#New({'notifications': {
113+
\ 'statusNotification': function('s:StatusNotification'),
104114
\ 'PanelSolution': function('copilot#panel#Solution'),
105115
\ 'PanelSolutionsDone': function('copilot#panel#SolutionsDone'),
106116
\ }})
@@ -622,8 +632,12 @@ function s:NetworkStatusMessage() abort
622632
return err
623633
endif
624634
try
635+
let info = copilot#agent#EditorInfo()
625636
let response = copilot#HttpRequest('https://copilot-proxy.githubusercontent.com/_ping',
626-
\ {'timeout': 5000, 'headers': {'Agent-Version': 'agent/' . copilot#agent#Version()}})
637+
\ {'timeout': 5000, 'headers': {
638+
\ 'Editor-Version': info.editorInfo.name . '/' . info.editorInfo.version,
639+
\ 'Editor-Plugin-Version': info.editorPluginInfo.name . '/' . info.editorPluginInfo.version,
640+
\ }})
627641
if response.status == 466
628642
return "Server error:\n" . substitute(response.body, "\n$", '', '')
629643
endif
@@ -695,8 +709,8 @@ function! s:commands.status(opts) abort
695709
return
696710
endif
697711

698-
if has_key(copilot#Agent(), 'upgrade_message')
699-
echo 'Copilot: ' . copilot#Agent().upgrade_message
712+
if exists('s:agent_error')
713+
echo 'Copilot: ' . s:agent_error
700714
return
701715
endif
702716

autoload/copilot/agent.vim

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ let g:autoloaded_copilot_agent = 1
55

66
scriptencoding utf-8
77

8-
let s:plugin_version = '1.2.3'
9-
10-
function! copilot#agent#Version() abort
11-
return s:plugin_version
12-
endfunction
8+
let s:plugin_version = '1.3.0'
139

1410
let s:error_exit = -1
1511

@@ -169,10 +165,6 @@ function! s:OnMessage(agent, body, ...) abort
169165
call timer_start(0, { _ -> a:agent.notifications[response.method](params) })
170166
elseif response.method ==# 'LogMessage'
171167
call copilot#logger#Raw(get(params, 'level', 3), get(params, 'message', ''))
172-
let upgrade_message = matchstr(get(params, 'message', ''), '\<Unhandled status from server:,466,\zs.*')
173-
if len(upgrade_message)
174-
let a:agent.upgrade_message = upgrade_message
175-
endif
176168
endif
177169
elseif has_key(a:agent.methods, response.method)
178170
call timer_start(0, function('s:DispatchMessage', [a:agent, a:agent.methods[response.method], id, params]))

autoload/copilot/doc.vim

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ let g:autoloaded_copilot_prompt = 1
55

66
scriptencoding utf-8
77

8+
let s:slash = exists('+shellslash') ? '\' : '/'
9+
810
function copilot#doc#UTF16Width(str) abort
911
return strchars(substitute(a:str, "\\%#=2[^\u0001-\uffff]", " ", 'g'))
1012
endfunction
@@ -21,7 +23,7 @@ function copilot#doc#LanguageForFileType(filetype) abort
2123
return get(s:language_normalization_map, empty(filetype) ? "text" : filetype, filetype)
2224
endfunction
2325

24-
function! copilot#doc#RelativePath() abort
26+
function! s:RelativePath(absolute) abort
2527
if exists('b:copilot_relative_path')
2628
return b:copilot_relative_path
2729
elseif exists('b:copilot_root')
@@ -31,20 +33,37 @@ function! copilot#doc#RelativePath() abort
3133
else
3234
let root = getcwd()
3335
endif
34-
let root .= '/'
35-
let absolute = expand('%:p')
36-
if strpart(tr(absolute, 'A-Z\', 'a-z/'), 0, len(root)) ==# tr(root, 'A-Z\', 'a-z/')
37-
return strpart(absolute, len(root))
36+
let root = tr(root, s:slash, '/') . '/'
37+
if strpart(tr(a:absolute, 'A-Z', 'a-z'), 0, len(root)) ==# tr(root, 'A-Z', 'a-z')
38+
return strpart(a:absolute, len(root))
3839
else
39-
return expand('%:t')
40+
return fnamemodify(a:absolute, ':t')
4041
endif
4142
endfunction
4243

44+
function! s:UrlEncode(str) abort
45+
return substitute(iconv(a:str, 'latin1', 'utf-8'),'[^A-Za-z0-9._~!$&''()*+,;=:@/-]','\="%".printf("%02X",char2nr(submatch(0)))','g')
46+
endfunction
47+
4348
function! copilot#doc#Get() abort
49+
let absolute = tr(@%, s:slash, '/')
50+
if absolute !~# '^\a\+:\|^/\|^$' && &buftype =~# '^\%(nowrite\)\=$'
51+
let absolute = substitute(tr(getcwd(), s:slash, '/'), '/\=$', '/', '') . absolute
52+
endif
53+
if has('win32') && absolute =~# '^\a://\@!'
54+
let uri = 'file:///' . strpart(absolute, 0, 2) . s:UrlEncode(strpart(absolute, 2))
55+
elseif absolute =~# '^/'
56+
let uri = 'file://' . s:UrlEncode(absolute)
57+
elseif absolute =~# '^\a[[:alnum:].+-]*:\|^$'
58+
let uri = absolute
59+
else
60+
let uri = ''
61+
endif
4462
let doc = {
4563
\ 'languageId': copilot#doc#LanguageForFileType(&filetype),
46-
\ 'path': expand('%:p'),
47-
\ 'relativePath': copilot#doc#RelativePath(),
64+
\ 'path': absolute,
65+
\ 'uri': uri,
66+
\ 'relativePath': s:RelativePath(absolute),
4867
\ 'insertSpaces': &expandtab ? v:true : v:false,
4968
\ 'tabSize': shiftwidth(),
5069
\ 'indentSize': shiftwidth(),

copilot/dist/agent.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)