Skip to content

Instantly share code, notes, and snippets.

@yochem
Created April 23, 2019 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yochem/84173f4ea73173819b477d1fbdb4cedc to your computer and use it in GitHub Desktop.
Save yochem/84173f4ea73173819b477d1fbdb4cedc to your computer and use it in GitHub Desktop.
SCRIPT /Users/Yochem/.config/nvim/pack/kite/start/vim-plugin/plugin/kite.vim
Sourced 1 time
Total time: 0.050532
Self time: 0.000945
count total (s) self (s)
1 0.000010 if exists('g:loaded_kite') || &cp || v:version < 700
finish
endif
1 0.000002 let g:loaded_kite = 1
1 0.000256 0.000232 filetype on
1 0.000004 if !exists('g:kite_auto_complete')
1 0.000003 let g:kite_auto_complete = 1
1 0.000001 endif
1 0.000003 if !exists('g:kite_documentation_continual')
1 0.000002 let g:kite_documentation_continual = 0
1 0.000001 endif
1 0.000002 if !exists('g:kite_log')
1 0.000001 let g:kite_log = 0
1 0.000001 endif
1 0.000002 if !exists('g:kite_short_timeout')
1 0.000002 let g:kite_short_timeout = 120 " ms
1 0.000001 endif
1 0.000002 if !exists('g:kite_long_timeout')
1 0.000002 let g:kite_long_timeout = 400 " ms
1 0.000001 endif
1 0.000008 if !(has('nvim') || has('job'))
call kite#utils#warn('disabled - requires nvim or vim with the +job feature')
finish
endif
1 0.000003 if !(has('nvim') || has('timers'))
call kite#utils#warn('disabled - requires nvim or vim with the +timers feature')
finish
endif
1 0.049225 0.000142 if kite#utils#windows()
" Avoid taskbar flashing on Windows when executing system() calls.
set noshelltemp
endif
1 0.000683 0.000201 call kite#init()
1 0.000004 augroup Kite
1 0.000229 autocmd!
1 0.000007 autocmd BufEnter * call kite#bufenter()
1 0.000001 augroup END
1 0.000015 nnoremap <silent> <Plug>(kite-docs) :call kite#docs#docs()<CR>
1 0.000006 command! KiteDocsAtCursor call kite#docs#docs()
1 0.000003 command! KiteOpenCopilot call kite#client#copilot()
1 0.000003 command! KiteGeneralSettings call kite#client#settings()
1 0.000003 command! KitePermissions call kite#client#permissions()
1 0.000003 command! KiteHelp call kite#utils#generate_help() | help kite
1 0.000003 command! KiteDisableAutoStart call kite#disable_auto_start()
1 0.000003 command! KiteEnableAutoStart call kite#enable_auto_start()
SCRIPT /Users/Yochem/.config/nvim/pack/kite/start/vim-plugin/autoload/kite/utils.vim
Sourced 1 time
Total time: 0.049071
Self time: 0.000764
count total (s) self (s)
" Values for s:os are used in plugin directory structure
" and also metric values.
1 0.000009 if has('win64') || has('win32') || has('win32unix')
let s:os = 'windows'
else
1 0.048370 0.000069 let uname = substitute(system('uname'), '\n', '', '') " Darwin or Linux
1 0.000013 let s:os = uname ==? 'Darwin' ? 'macos' : 'linux'
1 0.000002 endif
1 0.000003 function! kite#utils#windows()
return s:os ==# 'windows'
endfunction
1 0.000002 function! kite#utils#macos()
return s:os ==# 'macos'
endfunction
1 0.000007 let s:separator = !exists('+shellslash') || &shellslash ? '/' : '\'
1 0.000031 let s:plugin_dir = expand('<sfile>:p:h:h:h')
1 0.000005 let s:doc_dir = s:plugin_dir.s:separator.'doc'
1 0.000003 let s:lib_dir = s:plugin_dir.s:separator.'lib'
1 0.000003 let s:lib_subdir = s:lib_dir.s:separator.(s:os)
1 0.000002 let s:vim_version = ''
1 0.000002 let s:plugin_version = ''
1 0.000002 function! kite#utils#vim_version()
if !empty(s:vim_version)
return s:vim_version
endif
let s:vim_version = kite#utils#normalise_version(execute('version'))
return s:vim_version
endfunction
1 0.000002 function! kite#utils#normalise_version(version)
let lines = split(a:version, '\n')
if lines[0] =~ 'NVIM'
return lines[0] " e.g. NVIM v0.2.2
else
let [major, minor] = [v:version / 100, v:version % 100]
let patch_line = match(lines, ': \d')
let patches = substitute(split(lines[patch_line], ': ')[1], ' ', '', 'g')
return join([major, minor, patches], '.') " e.g. 8.1.1-582
endif
endfunction
1 0.000002 function! kite#utils#plugin_version()
if !empty(s:plugin_version)
return s:plugin_version
endif
let s:plugin_version = readfile(s:plugin_dir.s:separator.'VERSION')[0]
return s:plugin_version
endfunction
" From tpope/vim-fugitive
1 0.000004 function! s:winshell()
return kite#utils#windows() && &shellcmdflag !~# '^-'
endfunction
" From tpope/vim-fugitive
1 0.000002 function! s:shellescape(arg)
if a:arg =~ '^[A-Za-z0-9_/.-]\+$'
return a:arg
elseif s:winshell()
return '"'.substitute(substitute(a:arg, '"', '""', 'g'), '%', '"%"', 'g').'"'
else
return shellescape(a:arg)
endif
endfunction
1 0.000018 0.000012 if kite#utils#windows()
let s:settings_dir = join([$LOCALAPPDATA, 'Kite'], s:separator)
else
1 0.000009 let s:settings_dir = join([$HOME, '.kite'], s:separator)
1 0.000001 endif
1 0.000011 if !isdirectory(s:settings_dir)
call mkdir(s:settings_dir, 'p')
endif
1 0.000004 let s:settings_path = s:settings_dir.s:separator.'vim-plugin.json'
" Get the value for the given key.
" If the key has not been set, returns the default value if given
" (i.e. the optional argument) or -1 otherwise.
1 0.000002 function! kite#utils#get_setting(key, ...)
let settings = s:settings()
return get(settings, a:key, (a:0 ? a:1 : -1))
endfunction
" Sets the value for the key.
1 0.000002 function! kite#utils#set_setting(key, value)
let settings = s:settings()
let settings[a:key] = a:value
let json_str = json_encode(settings)
call writefile([json_str], s:settings_path)
endfunction
1 0.000002 function! s:settings()
if filereadable(s:settings_path)
let json_str = join(readfile(s:settings_path), '')
return json_decode(json_str)
else
return {}
endif
endfunction
1 0.000001 function! kite#utils#generate_help()
execute 'helptags' s:doc_dir
endfunction
1 0.000003 function! kite#utils#os()
return s:os
endfunction
1 0.000002 function! kite#utils#lib(filename)
return s:lib_subdir.s:separator.a:filename
endfunction
1 0.000001 function! kite#utils#kite_installed()
return !empty(s:kite_install_path())
endfunction
" Returns the kite installation path including the filename, or an empty string if not installed.
1 0.000002 function! s:kite_install_path()
if kite#utils#windows()
let output = kite#async#sync('reg query HKEY_LOCAL_MACHINE\Software\Kite\AppData /v InstallPath /s /reg:64')
let lines = filter(split(output, '\n'), 'v:val =~ "InstallPath"')
if empty(lines)
return ''
endif
return substitute(lines[0], '\v^\s+InstallPath\s+REG_\w+\s+', '', '').s:separator.'kited.exe'
elseif kite#utils#macos()
return kite#async#sync('mdfind ''kMDItemCFBundleIdentifier = "com.kite.Kite" || kMDItemCFBundleIdentifier = "enterprise.kite.Kite"''')
else
return exepath('/opt/kite/kited')
endif
endfunction
1 0.000001 function! kite#utils#kite_running()
if kite#utils#windows()
let [cmd, process] = ['tasklist /FI "IMAGENAME eq kited.exe"', '^kited.exe']
elseif kite#utils#macos()
let [cmd, process] = ['ps -axco command', '^Kite$']
else
let [cmd, process] = ['ps -axco command', '^kited$']
endif
return match(split(kite#async#sync(cmd), '\n'), process) > -1
endfunction
1 0.000002 function! kite#utils#launch_kited()
if kite#utils#kite_running()
return
endif
let path = s:kite_install_path()
if empty(path)
return
endif
if kite#utils#windows()
let $KITE_SKIP_ONBOARDING = 1
silent execute "!start" s:shellescape(path)
elseif kite#utils#macos()
call system('open -a '.path.' --args "--plugin-launch"')
else
silent execute '!'.path.' --plugin-launch >/dev/null 2>&1 &'
endif
endfunction
" Optional argument is response dictionary (from kite#client#parse_response).
1 0.000001 function! kite#utils#logged_in(...)
if a:0
return a:1.status == 200
else
return kite#client#logged_in(function('kite#utils#logged_in'))
endif
endfunction
" msg - a list or a string
1 0.000001 function! kite#utils#log(msg)
if g:kite_log
if type(a:msg) == v:t_string
let msg = [a:msg]
else
let msg = a:msg
endif
call writefile(msg, 'kite-vim.log', 'a')
endif
endfunction
1 0.000002 function! kite#utils#warn(msg)
echohl WarningMsg
echo 'Kite: '.a:msg
echohl None
let v:warningmsg = a:msg
endfunction
1 0.000002 function! kite#utils#info(msg)
echohl Question
echo a:msg
echohl None
endfunction
" Returns the absolute path to the current file after resolving symlinks.
"
" url_format - when truthy, return the path in a URL-compatible format.
1 0.000001 function! kite#utils#filepath(url_format)
let path = resolve(expand('%:p'))
if a:url_format
let path = substitute(path, '[\/]', ':', 'g')
if kite#utils#windows()
let path = substitute(path, '^\(\a\)::', '\1:', '')
let path = ':windows:'.path
endif
let path = kite#utils#url_encode(path)
endif
return path
endfunction
" Returns a 2-element list of 0-based character indices into the buffer.
"
" When no text is selected, both elements are the cursor position.
"
" When text is selected, the elements are the start (inclusive) and
" end (exclusive) of the selection.
"
" Returns [-1, -1] when not in normal, insert, or visual mode.
1 0.000002 function! kite#utils#selected_region_characters()
return s:selected_region('c')
endfunction
" Returns a 2-element list of 0-based byte indices into the buffer.
"
" When no text is selected, both elements are the cursor position.
"
" When text is selected, the elements are the start (inclusive) and
" end (exclusive) of the selection.
"
" Returns [-1, -1] when not in normal, insert, or visual mode.
1 0.000001 function! kite#utils#selected_region_bytes()
return s:selected_region('b')
endfunction
" Returns a 2-element list of 0-based indices into the buffer.
"
" When no text is selected, both elements are the cursor position.
"
" When text is selected, the elements are the start (inclusive) and
" end (exclusive) of the selection.
"
" Returns [-1, -1] when not in normal, insert, or visual mode.
"
" param type (String) - 'c' for character indices, 'b' for byte indices
"
" NOTE: the cursor is moved during the function (but finishes where it started).
1 0.000002 function! s:selected_region(type)
if mode() ==# 'n' || mode() ==# 'i'
if a:type == 'c'
let offset = kite#utils#character_offset()
else
let offset = kite#utils#byte_offset_start()
endif
return [offset, offset]
endif
if mode() ==? 'v'
let pos_start = getpos('v')
let pos_end = getpos('.')
if (pos_start[1] > pos_end[1]) || (pos_start[1] == pos_end[1] && pos_start[2] > pos_end[2])
let [pos_start, pos_end] = [pos_end, pos_start]
endif
" switch to normal mode
execute "normal! \<Esc>"
call setpos('.', pos_start)
if a:type == 'c'
let offset1 = kite#utils#character_offset()
else
let offset1 = kite#utils#byte_offset_start()
endif
call setpos('.', pos_end)
" end position is exclusive
if a:type == 'c'
let offset2 = kite#utils#character_offset() + 1
else
let offset2 = kite#utils#byte_offset_end() + 1
endif
" restore visual selection
normal! gv
return [offset1, offset2]
endif
return [-1, -1]
endfunction
" Returns the 0-based index of the cursor in the buffer.
"
" Returns -1 when the buffer is empty.
1 0.000002 function! kite#utils#cursor_characters()
if mode() ==? 'v'
" switch to normal mode
execute "normal! \<Esc>"
let cursor = kite#utils#character_offset()
" restore visual selection
normal! gv
return cursor
endif
return kite#utils#character_offset()
endfunction
" Returns the 0-based index into the buffer of the cursor position.
" Returns -1 when the buffer is empty.
"
" Does not work in visual mode.
1 0.000001 function! kite#utils#character_offset()
" wordcount().cursor_chars is 1-based so we need to subtract 1.
let offset = wordcount().cursor_chars - 1
" In insert mode the cursor isn't really between two characters;
" it is actually on the second character, but that's what we want
" anyway.
" If the cursor is just before (i.e. on) the end of the line, and
" the file has dos line endings, wordcount().cursor_chars will
" regard the cursor as on the second character of the \r\n. In this
" case we want the offset of the first, i.e. the \r.
if col('.') == col('$') && &ff ==# 'dos'
let offset -= 1
endif
return offset
endfunction
" Returns the 0-based index into the buffer of the cursor position.
" If the cursor is on a multibyte character, it reports the character's
" first byte.
1 0.000001 function! kite#utils#byte_offset_start()
let offset = line2byte(line('.')) - 1 + col('.') - 1
if offset < 0
let offset = 0
endif
return offset
endfunction
" Returns the 0-based index into the buffer of the cursor position.
" If the cursor is on a multibyte character, it reports the character's
" last byte.
1 0.000001 function! kite#utils#byte_offset_end()
let offset = wordcount().cursor_bytes - 1
if offset < 0
let offset = 0
endif
return offset
endfunction
1 0.000001 function! kite#utils#buffer_contents()
let line_ending = {"unix": "\n", "dos": "\r\n", "mac": "\r"}[&fileformat]
return join(getline(1, '$'), line_ending).(&eol ? line_ending : '')
endfunction
" Similar to the goto command, but for characters.
" index is 1-based, the start of the file.
1 0.000002 function! kite#utils#goto_character(index)
call search('\m\%^\_.\{'.a:index.'}', 'es')
" The search() function above counts a newline as 1 character even if it is
" actually 2. Therefore we need to adjust the cursor position when newlines
" are 2 characters.
if &ff ==# 'dos'
let [_whichwrap, &whichwrap] = [&whichwrap, "h,l"]
let delta = wordcount().cursor_chars - a:index
while delta != 0
" Cannot land on a newline character.
if (delta == -1 || delta == -2) && col('.') == col('$') - 1
break
endif
execute "normal! ".delta.(delta > 0 ? 'h' : 'l')
let delta = wordcount().cursor_chars - a:index
endwhile
let &whichwrap = _whichwrap
endif
endfunction
" Returns the MD5 hash of the buffer contents.
1 0.000001 function! kite#utils#buffer_md5()
return s:MD5(kite#utils#buffer_contents())
endfunction
" https://github.com/tpope/vim-unimpaired/blob/3a7759075cca5b0dc29ce81f2747489b6c8e36a7/plugin/unimpaired.vim#L327-L329
1 0.000001 function! kite#utils#url_encode(str)
return substitute(a:str,'[^A-Za-z0-9_.~-]','\="%".printf("%02X",char2nr(submatch(0)))','g')
endfunction
" Capitalises the first letter of str.
1 0.000002 function! kite#utils#capitalize(str)
return substitute(a:str, '^.', '\u\0', '')
endfunction
1 0.000002 function! kite#utils#map_join(list, prop, sep)
return join(map(copy(a:list), {_,v -> v[a:prop]}), a:sep)
endfunction
" Returns a list of lines, each no longer than length.
" The last line may be longer than length if it has no spaces.
" Assumes str is a constructor or function call.
"
" Example: json.dumps
"
" dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, encoding, default, sort_keys, *args, **kwargs)
"
" - becomes when wrapped:
"
" dumps(obj, skipkeys, ensure_ascii, check_circular,
" allow_nan, cls, indent, separators, encoding,
" default, sort_keys, *args, **kwargs)
"
1 0.000002 function! kite#utils#wrap(str, length)
let lines = []
let str = a:str
let [prefix; str] = split(a:str, '(\zs')
let str = join(str)
while v:true
let line = prefix.str
if len(line) <= a:length
call add(lines, line)
break
endif
let i = strridx(str[0:a:length-len(prefix)], ' ')
if i == -1
call add(lines, line)
break
endif
let line = prefix . str[0:i-1]
call add(lines, line)
let str = str[i+1:]
let prefix = repeat(' ', len(prefix))
endwhile
return lines
endfunction
1 0.000002 function! kite#utils#coerce(dict, key, default)
if has_key(a:dict, a:key)
let v = a:dict[a:key]
if type(v) == type(a:default) " check type in case of null
return v
endif
endif
return a:default
endfunction
1 0.000002 function! kite#utils#present(dict, key)
return has_key(a:dict, a:key) && !empty(a:dict[a:key])
endfunction
1 0.000002 function! s:chomp(str)
return substitute(a:str, '\n$', '', '')
endfunction
1 0.000002 function! s:md5(text)
return s:chomp(system('md5', a:text))
endfunction
1 0.000002 function! s:md5sum(text)
return split(system('md5sum', a:text), ' ')[0]
endfunction
1 0.000001 function! s:md5bin(text)
return s:chomp(system(s:md5_binary, a:text))
endfunction
1 0.000050 if executable('md5')
1 0.000008 let s:MD5 = function('s:md5')
1 0.000002 elseif executable('md5sum')
let s:MD5 = function('s:md5sum')
else
let s:md5_binary = kite#utils#lib('md5Sum.exe')
let s:MD5 = function('s:md5bin')
endif
SCRIPT /Users/Yochem/.config/nvim/pack/kite/start/vim-plugin/autoload/kite.vim
Sourced 1 time
Total time: 0.000192
Self time: 0.000192
count total (s) self (s)
1 0.000006 let s:status_poll_interval = 5 * 1000 " 5sec in milliseconds
1 0.000002 let s:plan_poll_interval = 30 * 1000 " 30sec in milliseconds
1 0.000002 let s:timer = -1
1 0.000002 function kite#enable_auto_start()
call kite#utils#set_setting('start_kited_at_startup', 1)
call s:launch_kited()
call kite#utils#info('Kite: auto-start enabled')
endfunction
1 0.000001 function kite#disable_auto_start()
call kite#utils#set_setting('start_kited_at_startup', 0)
call kite#utils#info('Kite: auto-start disabled')
endfunction
1 0.000001 function kite#statusline()
if exists('b:kite_status')
return b:kite_status
else
return ''
endif
endfunction
1 0.000001 function! kite#max_file_size()
return 1048576 " 1MB
endfunction
1 0.000002 function! kite#init()
call s:launch_kited()
if &pumheight == 0
set pumheight=10
endif
if &updatetime == 4000
set updatetime=100
endif
set shortmess+=c
call s:configure_completeopt()
call s:start_plan_timer()
endfunction
1 0.000001 function! kite#bufenter()
if s:supported_language()
call s:setup_events()
call s:setup_mappings()
setlocal completefunc=kite#completion#complete
call kite#events#event('focus')
call kite#status#status()
call s:start_status_timer()
else
call s:stop_status_timer()
endif
endfunction
1 0.000002 function s:setup_events()
augroup KiteEvents
autocmd! * <buffer>
autocmd CursorHold <buffer> call kite#events#event('selection')
autocmd TextChanged,TextChangedI <buffer> call kite#events#event('edit')
autocmd FocusGained <buffer> call kite#events#event('focus')
autocmd InsertCharPre <buffer> call kite#completion#insertcharpre()
autocmd TextChangedI <buffer> call kite#completion#autocomplete()
if exists('g:kite_documentation_continual') && g:kite_documentation_continual
autocmd CursorHold,CursorHoldI <buffer> call kite#docs#docs()
endif
augroup END
endfunction
1 0.000001 function! s:setup_mappings()
" When the pop-up menu is closed with <C-e>, <C-y>, or <CR>,
" the TextChangedI event is fired again, which re-opens the
" pop-up menu. To avoid this, we set a flag when one of those
" keys is pressed.
"
" Note the <CR> mapping can conflict with vim-endwise because vim-endwise
" also maps <CR>. There are two ways around the conflict:
"
" - Either:
"
" let g:kite_deconflict_cr = 1
"
" This works but you will see the mapping echoed in the status line
" because vim-endwise ignores the <silent> when it re-maps the map.
"
" - Or use vim-endwise's experimental abbreviations instead:
"
" let g:endwise_abbreviations = 1
" let g:endwise_no_mappings = 1
"
inoremap <buffer> <expr> <C-e> kite#completion#popup_exit("\<C-e>")
inoremap <buffer> <expr> <C-y> kite#completion#popup_exit("\<C-y>")
if exists('g:kite_deconflict_cr') && g:kite_deconflict_cr
inoremap <silent> <buffer> <CR> <C-R>=kite#completion#popup_exit('')<CR><CR>
else
inoremap <buffer> <expr> <CR> kite#completion#popup_exit("\<CR>")
endif
" InsertCharPre is not fired for non-printable characters such as backspace.
" TextChangedI is not fired when the pop-up menu is open. Therefore use
" an insert-mode mapping to force completion to re-occur when backspace is
" pressed while the pop-up menu is open.
"
" This can cause problems in gVim <= 8.0.1806. #123.
if !(kite#utils#windows() && has('gui_running') && (v:version < 800 || (v:version == 800 && !has('patch1806'))))
inoremap <buffer> <expr> <BS> pumvisible() ? kite#completion#backspace() : "\<BS>"
endif
if exists('g:kite_tab_complete')
inoremap <buffer> <expr> <Tab> pumvisible() ? "\<C-y>" : "\<Tab>"
endif
if empty(maparg('K', 'n')) && !hasmapto('(kite-docs)', 'n')
nmap <silent> <buffer> K <Plug>(kite-docs)
endif
endfunction
1 0.000002 function! s:start_status_timer()
if s:timer == -1
let s:timer = timer_start(s:status_poll_interval,
\ function('kite#status#status'),
\ {'repeat': -1}
\ )
else
call timer_pause(s:timer, 0) " unpause
endif
endfunction
1 0.000002 function! s:stop_status_timer()
call timer_pause(s:timer, 1)
endfunction
1 0.000001 function! s:start_plan_timer()
call timer_start(s:plan_poll_interval,
\ function('kite#plan#check'),
\ {'repeat': -1}
\ )
endfunction
" Configure &completeopt if and only if it has not been set already.
"
" Note there's no way to distinguish the option not having been set from
" the option having been set by hand to the default value. So if the user
" sets the option by hand to the default value we will re-configure it.
"
" The alternative is simply to leave the option alone.
1 0.000002 function! s:configure_completeopt()
" Display the option's value. If it has been set somewhere, there
" will be a second line showing the location.
redir => output
silent verbose set completeopt
redir END
let lines = len(split(output, '\n'))
" Don't (re-)configure option if:
" - (option has been set somewhere) OR
" - (option hasn't been set / option was set by hand AND is not the default value)
if lines > 1 || (lines == 1 && &completeopt !=# 'menu,preview') | return | endif
" completeopt is not global-local.
set completeopt-=menu
set completeopt+=menuone
set completeopt-=longest
set completeopt-=preview
set completeopt+=noinsert
set completeopt-=noselect
endfunction
1 0.000002 function! s:launch_kited()
if kite#utils#get_setting('start_kited_at_startup', 1)
call kite#utils#launch_kited()
endif
endfunction
1 0.000002 function! s:supported_language()
return expand('%:e') == 'py'
endfunction
FUNCTION kite#utils#cursor_characters()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if mode() ==? 'v'
" switch to normal mode
execute "normal! \<Esc>"
let cursor = kite#utils#character_offset()
" restore visual selection
normal! gv
return cursor
endif
return kite#utils#character_offset()
FUNCTION kite#utils#kite_running()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if kite#utils#windows()
let [cmd, process] = ['tasklist /FI "IMAGENAME eq kited.exe"', '^kited.exe']
elseif kite#utils#macos()
let [cmd, process] = ['ps -axco command', '^Kite$']
else
let [cmd, process] = ['ps -axco command', '^kited$']
endif
return match(split(kite#async#sync(cmd), '\n'), process) > -1
FUNCTION kite#utils#windows()
Called 2 times
Total time: 0.000010
Self time: 0.000010
count total (s) self (s)
2 0.000006 return s:os ==# 'windows'
FUNCTION kite#utils#set_setting()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
let settings = s:settings()
let settings[a:key] = a:value
let json_str = json_encode(settings)
call writefile([json_str], s:settings_path)
FUNCTION kite#utils#buffer_md5()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:MD5(kite#utils#buffer_contents())
FUNCTION kite#utils#lib()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:lib_subdir.s:separator.a:filename
FUNCTION kite#utils#present()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return has_key(a:dict, a:key) && !empty(a:dict[a:key])
FUNCTION kite#utils#filepath()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
let path = resolve(expand('%:p'))
if a:url_format
let path = substitute(path, '[\/]', ':', 'g')
if kite#utils#windows()
let path = substitute(path, '^\(\a\)::', '\1:', '')
let path = ':windows:'.path
endif
let path = kite#utils#url_encode(path)
endif
return path
FUNCTION <SNR>36_start_status_timer()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if s:timer == -1
let s:timer = timer_start(s:status_poll_interval, function('kite#status#status'), {'repeat': -1} )
else
call timer_pause(s:timer, 0) " unpause
endif
FUNCTION kite#init()
Called 1 time
Total time: 0.000248
Self time: 0.000041
count total (s) self (s)
1 0.000130 0.000007 call s:launch_kited()
1 0.000002 if &pumheight == 0
1 0.000007 set pumheight=10
1 0.000001 endif
1 0.000002 if &updatetime == 4000
set updatetime=100
endif
1 0.000007 set shortmess+=c
1 0.000075 0.000007 call s:configure_completeopt()
1 0.000019 0.000004 call s:start_plan_timer()
FUNCTION kite#utils#kite_installed()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return !empty(s:kite_install_path())
FUNCTION kite#utils#map_join()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return join(map(copy(a:list), {_,v -> v[a:prop]}), a:sep)
FUNCTION kite#utils#launch_kited()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if kite#utils#kite_running()
return
endif
let path = s:kite_install_path()
if empty(path)
return
endif
if kite#utils#windows()
let $KITE_SKIP_ONBOARDING = 1
silent execute "!start" s:shellescape(path)
elseif kite#utils#macos()
call system('open -a '.path.' --args "--plugin-launch"')
else
silent execute '!'.path.' --plugin-launch >/dev/null 2>&1 &'
endif
FUNCTION kite#utils#byte_offset_start()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
let offset = line2byte(line('.')) - 1 + col('.') - 1
if offset < 0
let offset = 0
endif
return offset
FUNCTION <SNR>35_winshell()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return kite#utils#windows() && &shellcmdflag !~# '^-'
FUNCTION kite#utils#logged_in()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if a:0
return a:1.status == 200
else
return kite#client#logged_in(function('kite#utils#logged_in'))
endif
FUNCTION kite#utils#buffer_contents()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
let line_ending = {"unix": "\n", "dos": "\r\n", "mac": "\r"}[&fileformat]
return join(getline(1, '$'), line_ending).(&eol ? line_ending : '')
FUNCTION <SNR>36_stop_status_timer()
Called 1 time
Total time: 0.000004
Self time: 0.000004
count total (s) self (s)
1 0.000003 call timer_pause(s:timer, 1)
FUNCTION kite#utils#wrap()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
let lines = []
let str = a:str
let [prefix; str] = split(a:str, '(\zs')
let str = join(str)
while v:true
let line = prefix.str
if len(line) <= a:length
call add(lines, line)
break
endif
let i = strridx(str[0:a:length-len(prefix)], ' ')
if i == -1
call add(lines, line)
break
endif
let line = prefix . str[0:i-1]
call add(lines, line)
let str = str[i+1:]
let prefix = repeat(' ', len(prefix))
endwhile
return lines
FUNCTION <SNR>35_chomp()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return substitute(a:str, '\n$', '', '')
FUNCTION kite#utils#os()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:os
FUNCTION kite#utils#normalise_version()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
let lines = split(a:version, '\n')
if lines[0] =~ 'NVIM'
return lines[0] " e.g. NVIM v0.2.2
else
let [major, minor] = [v:version / 100, v:version % 100]
let patch_line = match(lines, ': \d')
let patches = substitute(split(lines[patch_line], ': ')[1], ' ', '', 'g')
return join([major, minor, patches], '.') " e.g. 8.1.1-582
endif
FUNCTION <SNR>35_kite_install_path()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if kite#utils#windows()
let output = kite#async#sync('reg query HKEY_LOCAL_MACHINE\Software\Kite\AppData /v InstallPath /s /reg:64')
let lines = filter(split(output, '\n'), 'v:val =~ "InstallPath"')
if empty(lines)
return ''
endif
return substitute(lines[0], '\v^\s+InstallPath\s+REG_\w+\s+', '', '').s:separator.'kited.exe'
elseif kite#utils#macos()
return kite#async#sync('mdfind ''kMDItemCFBundleIdentifier = "com.kite.Kite" || kMDItemCFBundleIdentifier = "enterprise.kite.Kite"''')
else
return exepath('/opt/kite/kited')
endif
FUNCTION <SNR>36_supported_language()
Called 1 time
Total time: 0.000006
Self time: 0.000006
count total (s) self (s)
1 0.000005 return expand('%:e') == 'py'
FUNCTION kite#utils#byte_offset_end()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
let offset = wordcount().cursor_bytes - 1
if offset < 0
let offset = 0
endif
return offset
FUNCTION <SNR>35_shellescape()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if a:arg =~ '^[A-Za-z0-9_/.-]\+$'
return a:arg
elseif s:winshell()
return '"'.substitute(substitute(a:arg, '"', '""', 'g'), '%', '"%"', 'g').'"'
else
return shellescape(a:arg)
endif
FUNCTION <SNR>36_setup_mappings()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
" When the pop-up menu is closed with <C-e>, <C-y>, or <CR>,
" the TextChangedI event is fired again, which re-opens the
" pop-up menu. To avoid this, we set a flag when one of those
" keys is pressed.
"
" Note the <CR> mapping can conflict with vim-endwise because vim-endwise
" also maps <CR>. There are two ways around the conflict:
"
" - Either:
"
" let g:kite_deconflict_cr = 1
"
" This works but you will see the mapping echoed in the status line
" because vim-endwise ignores the <silent> when it re-maps the map.
"
" - Or use vim-endwise's experimental abbreviations instead:
"
" let g:endwise_abbreviations = 1
" let g:endwise_no_mappings = 1
"
inoremap <buffer> <expr> <C-e> kite#completion#popup_exit("\<C-e>")
inoremap <buffer> <expr> <C-y> kite#completion#popup_exit("\<C-y>")
if exists('g:kite_deconflict_cr') && g:kite_deconflict_cr
inoremap <silent> <buffer> <CR> <C-R>=kite#completion#popup_exit('')<CR><CR>
else
inoremap <buffer> <expr> <CR> kite#completion#popup_exit("\<CR>")
endif
" InsertCharPre is not fired for non-printable characters such as backspace.
" TextChangedI is not fired when the pop-up menu is open. Therefore use
" an insert-mode mapping to force completion to re-occur when backspace is
" pressed while the pop-up menu is open.
"
" This can cause problems in gVim <= 8.0.1806. #123.
if !(kite#utils#windows() && has('gui_running') && (v:version < 800 || (v:version == 800 && !has('patch1806'))))
inoremap <buffer> <expr> <BS> pumvisible() ? kite#completion#backspace() : "\<BS>"
endif
if exists('g:kite_tab_complete')
inoremap <buffer> <expr> <Tab> pumvisible() ? "\<C-y>" : "\<Tab>"
endif
if empty(maparg('K', 'n')) && !hasmapto('(kite-docs)', 'n')
nmap <silent> <buffer> K <Plug>(kite-docs)
endif
FUNCTION <SNR>36_configure_completeopt()
Called 1 time
Total time: 0.000068
Self time: 0.000068
count total (s) self (s)
" Display the option's value. If it has been set somewhere, there
" will be a second line showing the location.
1 0.000006 redir => output
1 0.000015 silent verbose set completeopt
1 0.000003 redir END
1 0.000013 let lines = len(split(output, '\n'))
" Don't (re-)configure option if:
" - (option has been set somewhere) OR
" - (option hasn't been set / option was set by hand AND is not the default value)
1 0.000005 if lines > 1 || (lines == 1 && &completeopt !=# 'menu,preview') | return | endif
" completeopt is not global-local.
1 0.000008 set completeopt-=menu
1 0.000003 set completeopt+=menuone
1 0.000002 set completeopt-=longest
1 0.000002 set completeopt-=preview
1 0.000002 set completeopt+=noinsert
1 0.000002 set completeopt-=noselect
FUNCTION kite#utils#url_encode()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return substitute(a:str,'[^A-Za-z0-9_.~-]','\="%".printf("%02X",char2nr(submatch(0)))','g')
FUNCTION kite#utils#log()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if g:kite_log
if type(a:msg) == v:t_string
let msg = [a:msg]
else
let msg = a:msg
endif
call writefile(msg, 'kite-vim.log', 'a')
endif
FUNCTION kite#utils#capitalize()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return substitute(a:str, '^.', '\u\0', '')
FUNCTION <SNR>36_launch_kited()
Called 1 time
Total time: 0.000124
Self time: 0.000011
count total (s) self (s)
1 0.000120 0.000007 if kite#utils#get_setting('start_kited_at_startup', 1)
call kite#utils#launch_kited()
endif
FUNCTION kite#utils#macos()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:os ==# 'macos'
FUNCTION <SNR>35_md5bin()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:chomp(system(s:md5_binary, a:text))
FUNCTION kite#enable_auto_start()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
call kite#utils#set_setting('start_kited_at_startup', 1)
call s:launch_kited()
call kite#utils#info('Kite: auto-start enabled')
FUNCTION <SNR>35_selected_region()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if mode() ==# 'n' || mode() ==# 'i'
if a:type == 'c'
let offset = kite#utils#character_offset()
else
let offset = kite#utils#byte_offset_start()
endif
return [offset, offset]
endif
if mode() ==? 'v'
let pos_start = getpos('v')
let pos_end = getpos('.')
if (pos_start[1] > pos_end[1]) || (pos_start[1] == pos_end[1] && pos_start[2] > pos_end[2])
let [pos_start, pos_end] = [pos_end, pos_start]
endif
" switch to normal mode
execute "normal! \<Esc>"
call setpos('.', pos_start)
if a:type == 'c'
let offset1 = kite#utils#character_offset()
else
let offset1 = kite#utils#byte_offset_start()
endif
call setpos('.', pos_end)
" end position is exclusive
if a:type == 'c'
let offset2 = kite#utils#character_offset() + 1
else
let offset2 = kite#utils#byte_offset_end() + 1
endif
" restore visual selection
normal! gv
return [offset1, offset2]
endif
return [-1, -1]
FUNCTION <SNR>35_md5sum()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return split(system('md5sum', a:text), ' ')[0]
FUNCTION kite#utils#plugin_version()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if !empty(s:plugin_version)
return s:plugin_version
endif
let s:plugin_version = readfile(s:plugin_dir.s:separator.'VERSION')[0]
return s:plugin_version
FUNCTION kite#utils#warn()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
echohl WarningMsg
echo 'Kite: '.a:msg
echohl None
let v:warningmsg = a:msg
FUNCTION kite#bufenter()
Called 1 time
Total time: 0.000044
Self time: 0.000034
count total (s) self (s)
1 0.000015 0.000009 if s:supported_language()
call s:setup_events()
call s:setup_mappings()
setlocal completefunc=kite#completion#complete
call kite#events#event('focus')
call kite#status#status()
call s:start_status_timer()
else
1 0.000011 0.000007 call s:stop_status_timer()
1 0.000001 endif
FUNCTION <SNR>35_md5()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:chomp(system('md5', a:text))
FUNCTION kite#max_file_size()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return 1048576 " 1MB
FUNCTION kite#utils#selected_region_characters()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:selected_region('c')
FUNCTION kite#statusline()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if exists('b:kite_status')
return b:kite_status
else
return ''
endif
FUNCTION kite#utils#selected_region_bytes()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
return s:selected_region('b')
FUNCTION kite#utils#get_setting()
Called 1 time
Total time: 0.000113
Self time: 0.000012
count total (s) self (s)
1 0.000108 0.000006 let settings = s:settings()
1 0.000005 return get(settings, a:key, (a:0 ? a:1 : -1))
FUNCTION kite#utils#generate_help()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
execute 'helptags' s:doc_dir
FUNCTION kite#utils#goto_character()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
call search('\m\%^\_.\{'.a:index.'}', 'es')
" The search() function above counts a newline as 1 character even if it is
" actually 2. Therefore we need to adjust the cursor position when newlines
" are 2 characters.
if &ff ==# 'dos'
let [_whichwrap, &whichwrap] = [&whichwrap, "h,l"]
let delta = wordcount().cursor_chars - a:index
while delta != 0
" Cannot land on a newline character.
if (delta == -1 || delta == -2) && col('.') == col('$') - 1
break
endif
execute "normal! ".delta.(delta > 0 ? 'h' : 'l')
let delta = wordcount().cursor_chars - a:index
endwhile
let &whichwrap = _whichwrap
endif
FUNCTION kite#utils#coerce()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if has_key(a:dict, a:key)
let v = a:dict[a:key]
if type(v) == type(a:default) " check type in case of null
return v
endif
endif
return a:default
FUNCTION <SNR>36_setup_events()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
augroup KiteEvents
autocmd! * <buffer>
autocmd CursorHold <buffer> call kite#events#event('selection')
autocmd TextChanged,TextChangedI <buffer> call kite#events#event('edit')
autocmd FocusGained <buffer> call kite#events#event('focus')
autocmd InsertCharPre <buffer> call kite#completion#insertcharpre()
autocmd TextChangedI <buffer> call kite#completion#autocomplete()
if exists('g:kite_documentation_continual') && g:kite_documentation_continual
autocmd CursorHold,CursorHoldI <buffer> call kite#docs#docs()
endif
augroup END
FUNCTION <SNR>35_settings()
Called 1 time
Total time: 0.000102
Self time: 0.000102
count total (s) self (s)
1 0.000028 if filereadable(s:settings_path)
1 0.000055 let json_str = join(readfile(s:settings_path), '')
1 0.000017 return json_decode(json_str)
else
return {}
endif
FUNCTION kite#utils#vim_version()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
if !empty(s:vim_version)
return s:vim_version
endif
let s:vim_version = kite#utils#normalise_version(execute('version'))
return s:vim_version
FUNCTION kite#utils#info()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
echohl Question
echo a:msg
echohl None
FUNCTION kite#disable_auto_start()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
call kite#utils#set_setting('start_kited_at_startup', 0)
call kite#utils#info('Kite: auto-start disabled')
FUNCTION kite#utils#character_offset()
Called 0 times
Total time: 0.000000
Self time: 0.000000
count total (s) self (s)
" wordcount().cursor_chars is 1-based so we need to subtract 1.
let offset = wordcount().cursor_chars - 1
" In insert mode the cursor isn't really between two characters;
" it is actually on the second character, but that's what we want
" anyway.
" If the cursor is just before (i.e. on) the end of the line, and
" the file has dos line endings, wordcount().cursor_chars will
" regard the cursor as on the second character of the \r\n. In this
" case we want the offset of the first, i.e. the \r.
if col('.') == col('$') && &ff ==# 'dos'
let offset -= 1
endif
return offset
FUNCTION <SNR>36_start_plan_timer()
Called 1 time
Total time: 0.000014
Self time: 0.000014
count total (s) self (s)
1 0.000014 call timer_start(s:plan_poll_interval, function('kite#plan#check'), {'repeat': -1} )
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
1 0.000248 0.000041 kite#init()
1 0.000124 0.000011 <SNR>36_launch_kited()
1 0.000113 0.000012 kite#utils#get_setting()
1 0.000102 <SNR>35_settings()
1 0.000068 <SNR>36_configure_completeopt()
1 0.000044 0.000034 kite#bufenter()
1 0.000014 <SNR>36_start_plan_timer()
2 0.000010 kite#utils#windows()
1 0.000006 <SNR>36_supported_language()
1 0.000004 <SNR>36_stop_status_timer()
kite#utils#launch_kited()
kite#utils#byte_offset_start()
<SNR>35_winshell()
kite#utils#logged_in()
kite#utils#buffer_contents()
kite#utils#wrap()
<SNR>35_chomp()
kite#utils#os()
kite#utils#normalise_version()
<SNR>35_kite_install_path()
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
1 0.000102 <SNR>35_settings()
1 0.000068 <SNR>36_configure_completeopt()
1 0.000248 0.000041 kite#init()
1 0.000044 0.000034 kite#bufenter()
1 0.000014 <SNR>36_start_plan_timer()
1 0.000113 0.000012 kite#utils#get_setting()
1 0.000124 0.000011 <SNR>36_launch_kited()
2 0.000010 kite#utils#windows()
1 0.000006 <SNR>36_supported_language()
1 0.000004 <SNR>36_stop_status_timer()
<SNR>35_kite_install_path()
kite#utils#byte_offset_end()
<SNR>35_shellescape()
<SNR>36_setup_mappings()
kite#utils#url_encode()
kite#utils#log()
kite#utils#capitalize()
kite#utils#macos()
<SNR>35_md5bin()
kite#enable_auto_start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment