@@ -5,6 +5,8 @@ let g:autoloaded_copilot_prompt = 1
55
66scriptencoding utf- 8
77
8+ let s: slash = exists (' +shellslash' ) ? ' \' : ' /'
9+
810function copilot#doc#UTF16Width (str) abort
911 return strchars (substitute (a: str , " \\ %#=2[^\u0001 -\uffff ]" , " " , ' g' ))
1012endfunction
@@ -21,7 +23,7 @@ function copilot#doc#LanguageForFileType(filetype) abort
2123 return get (s: language_normalization_map , empty (filetype ) ? " text" : filetype , filetype )
2224endfunction
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
4142endfunction
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+
4348function ! 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 (),
0 commit comments