├── plugin └── nvimapi.vim ├── README.md ├── LICENSE └── autoload └── nvimapi.vim /plugin/nvimapi.vim: -------------------------------------------------------------------------------- 1 | highlight default link NvimApiFunc Function 2 | highlight default link NvimApiType Type 3 | highlight default link NvimApiVoid Identifier 4 | highlight default link NvimApiReturnSymbol NonText 5 | 6 | command! -bang NvimAPI call nvimapi#display(0) 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nvim-api-viewer 2 | 3 | Display [Neovim][1] API functions in a buffer for reference. 4 | 5 | ## Install 6 | 7 | Follow your package manager's instructions. 8 | 9 | ## Usage 10 | 11 | `:NvimAPI` opens a buffer and displays API functions. `:NvimAPI!` displays 12 | deprecated functions. 13 | 14 | 15 | [1]: https://github.com/neovim/neovim 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | Copyright (c) 2016 Tommy Allen 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /autoload/nvimapi.vim: -------------------------------------------------------------------------------- 1 | let s:deprecated = 0 2 | 3 | function! s:version() abort 4 | if !exists('*execute') 5 | return '' 6 | endif 7 | 8 | return matchstr(execute('silent version'), 'NVIM v\zs[0-9.]\+') 9 | endfunction 10 | 11 | function! s:show_buffer() abort 12 | let new = 0 13 | let win = bufwinnr('nvim://api') 14 | if win == -1 15 | silent split | enew 16 | setlocal noswapfile 17 | silent file nvim://api 18 | let new = 1 19 | else 20 | execute win 'wincmd w' 21 | endif 22 | silent setlocal bufhidden buftype=nofile filetype=help noswapfile 23 | return new 24 | endfunction 25 | 26 | function! s:uadd(list, item) abort 27 | if index(a:list, a:item) == -1 28 | call add(a:list, a:item) 29 | endif 30 | endfunction 31 | 32 | function! s:format(info) abort 33 | for p in a:info.parameters 34 | if p[0] !~# 'ArrayOf' 35 | call s:uadd(s:var_types, p[0]) 36 | endif 37 | endfor 38 | let out = a:info.name.'(' 39 | \.join(map(copy(a:info.parameters), 'join(v:val, " ")'), ', ').')' 40 | \.' -> '.a:info.return_type 41 | 42 | if has_key(a:info, 'deprecated_since') 43 | let out .= ' [deprecated]' 44 | endif 45 | return out 46 | endfunction 47 | 48 | function! s:sort_key(name) abort 49 | let parts = split(a:name, '_') 50 | let prefix = [] 51 | if parts[0] =~# 'n\?vim' 52 | let prefix = [parts[0]] 53 | let parts = parts[1:] 54 | endif 55 | return join(prefix + reverse(parts), '_') 56 | endfunction 57 | 58 | function! s:func_sort(a, b) abort 59 | let a = s:sort_key(a:a) 60 | let b = s:sort_key(a:b) 61 | 62 | if a < b 63 | return -1 64 | elseif a > b 65 | return 1 66 | endif 67 | return 0 68 | endfunction 69 | 70 | function! s:syntax() abort 71 | silent! syntax clear NvimApiFunc NvimApiType 72 | execute 'syntax keyword NvimApiFunc' join(s:seen, ' ') 73 | execute 'syntax match NvimApiType #\<\%('.join(s:var_types, '\|').'\)\># containedin=ALL' 74 | execute 'syntax keyword NvimApiVoid void ArrayOf' 75 | execute 'syntax match NvimApiReturnSymbol #->#' 76 | endfunction 77 | 78 | function! nvimapi#display(bang) abort 79 | let ver = s:version() 80 | if empty(ver) || !exists('*api_info') 81 | echohl ErrorMsg 82 | echo 'api_info() is not available.' 83 | return 84 | endif 85 | 86 | if !s:show_buffer() && a:bang == s:deprecated 87 | call s:syntax() 88 | return 89 | endif 90 | 91 | %delete 92 | 93 | let s:deprecated = a:bang 94 | let s:var_types = [] 95 | let s:seen = [] 96 | let api = api_info() 97 | let functions = {} 98 | for item in api.functions 99 | let functions[item.name] = item 100 | endfor 101 | 102 | if ver == '0.1.5' 103 | $put =['Note: Functions for Window, Buffer, and Tabpage are deprecated and have', 104 | \ ' been prefixed with `nvim_` starting from `0.1.6`.', ''] 105 | endif 106 | 107 | for [type_name, type_info] in items(api.types) 108 | $put =[type_name.'~', ''] 109 | let funcs = [] 110 | for [func_name, func_info] in items(functions) 111 | if has_key(func_info, 'deprecated_since') && !s:deprecated 112 | continue 113 | endif 114 | 115 | if !has_key(type_info, 'prefix') 116 | let type_info.prefix = tolower(type_name).'_' 117 | endif 118 | 119 | if func_name =~# '^'.type_info.prefix 120 | call s:uadd(s:seen, func_name) 121 | call s:uadd(funcs, func_name) 122 | endif 123 | endfor 124 | 125 | for func_name in sort(funcs, 's:func_sort') 126 | $put =' '.s:format(functions[func_name]) 127 | endfor 128 | $put =[''] 129 | endfor 130 | 131 | $put =['Misc~', ''] 132 | let funcs = [] 133 | for [func_name, func_info] in items(functions) 134 | if has_key(func_info, 'deprecated_since') && !s:deprecated 135 | continue 136 | endif 137 | if index(s:seen, func_name) == -1 138 | call s:uadd(s:seen, func_name) 139 | call s:uadd(funcs, func_name) 140 | endif 141 | endfor 142 | 143 | for func_name in sort(funcs, 's:func_sort') 144 | $put =' '.s:format(functions[func_name]) 145 | endfor 146 | $put =[''] 147 | 148 | call s:syntax() 149 | call cursor(1, 1) 150 | delete 151 | endfunction 152 | --------------------------------------------------------------------------------