summaryrefslogtreecommitdiffstats
path: root/autoload/requirements.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/requirements.vim')
-rw-r--r--autoload/requirements.vim70
1 files changed, 41 insertions, 29 deletions
diff --git a/autoload/requirements.vim b/autoload/requirements.vim
index 3d783794..1132d7b2 100644
--- a/autoload/requirements.vim
+++ b/autoload/requirements.vim
@@ -2,35 +2,47 @@ if polyglot#init#is_disabled(expand('<sfile>:p'), 'requirements', 'autoload/requ
finish
endif
-" the Requirements File Format syntax support for Vim
-" Version: 1.6.0
-" Author: raimon <raimon49@hotmail.com>
-" License: MIT LICENSE
-" The MIT License (MIT)
-"
-" Copyright (c) 2015 raimon
-"
-" Permission is hereby granted, free of charge, to any person obtaining a copy
-" of this software and associated documentation files (the "Software"), to deal
-" in the Software without restriction, including without limitation the rights
-" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-" copies of the Software, and to permit persons to whom the Software is
-" furnished to do so, subject to the following conditions:
-"
-" The above copyright notice and this permission notice shall be included in all
-" copies or substantial portions of the Software.
-"
-" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-" SOFTWARE.
+""
+" @section Introduction, intro
+" @library
+" <doc/@plugin(name).txt> is generated by <https://github.com/google/vimdoc>.
+" See <README.md> for more information about installation and screenshots.
-let s:save_cpo = &cpo
-set cpo&vim
+""
+" Update cache.
+function! requirements#update_cache() abort
+ let s:items = []
+ let l:pip_items = split(system('COMP_WORDS="pip install -" COMP_CWORD=2 PIP_AUTO_COMPLETE=1 pip'))
+ let l:pypi_items = split(system('pip-cache pkgnames'))
+ for l:item in l:pip_items
+ let s:items += [{'word': l:item, 'menu': 'pip'}]
+ endfor
+ for l:item in l:pypi_items
+ let s:items += [{'word': l:item, 'menu': 'pypi'}]
+ endfor
+ call writefile([json_encode(s:items)], s:cache)
+endfunction
-let &cpo = s:save_cpo
-unlet s:save_cpo
+if exists('*stdpath')
+ let s:cache_dir_home = stdpath('cache')
+else
+ let s:cache_dir_home = $HOME . '/.cache/nvim'
+endif
+let s:cache_dir = s:cache_dir_home . '/requirements.vim'
+call mkdir(s:cache_dir, 'p')
+""
+" Completion cache path.
+call g:requirements#utils#plugin.Flag('g:requirements#cache',
+ \ s:cache_dir . '/requirements.json'
+ \ )
+let s:cache = g:requirements#cache
+try
+ let s:items = json_decode(readfile(s:cache)[0])
+catch /\v^Vim%(\(\a+\))?:E(684|484|491):/
+ call requirements#update_cache()
+ let s:items = json_decode(readfile(s:cache)[0])
+endtry
+""
+" Completion cache contents. For program.
+call g:requirements#utils#plugin.Flag('g:requirements#items', s:items)
" vim: et sw=4 ts=4 sts=4: