forked from github/copilot.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.vim
More file actions
69 lines (60 loc) · 1.71 KB
/
Copy pathlogger.vim
File metadata and controls
69 lines (60 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
if exists('g:autoloaded_copilot_log')
finish
endif
let g:autoloaded_copilot_log = 1
if !exists('s:log_file')
let s:log_file = tempname() . '-copilot.log'
try
call writefile([], s:log_file)
catch
endtry
endif
function! copilot#logger#File() abort
return s:log_file
endfunction
function! copilot#logger#Raw(level, message) abort
if $COPILOT_AGENT_VERBOSE !~# '^\%(1\|true\)$' && a:level < 1
return
endif
let lines = type(a:message) == v:t_list ? copy(a:message) : split(a:message, "\n", 1)
try
if !filewritable(s:log_file)
return
endif
call map(lines, { k, L -> type(L) == v:t_func ? call(L, []) : L })
call writefile(lines, s:log_file, 'a')
catch
endtry
endfunction
function! copilot#logger#Trace(...) abort
call copilot#logger#Raw(-1, a:000)
endfunction
function! copilot#logger#Debug(...) abort
call copilot#logger#Raw(0, a:000)
endfunction
function! copilot#logger#Info(...) abort
call copilot#logger#Raw(1, a:000)
endfunction
function! copilot#logger#Warn(...) abort
call copilot#logger#Raw(2, a:000)
endfunction
function! copilot#logger#Error(...) abort
call copilot#logger#Raw(3, a:000)
endfunction
function! copilot#logger#Exception() abort
if !empty(v:exception) && v:exception !=# 'Vim:Interrupt'
call copilot#logger#Error('Exception: ' . v:exception . ' @ ' . v:throwpoint)
let agent = copilot#RunningAgent()
if !empty(agent)
if v:throwpoint =~# '[\/]'
let throwpoint = '[redacted]'
else
let throwpoint = v:throwpoint
endif
call agent.Request('telemetry/exception', {
\ 'origin': 'copilot.vim',
\ 'stacktrace': v:exception . ' @ ' . throwpoint,
\ })
endif
endif
endfunction