mirror of
https://github.com/raimon49/requirements.txt.vim.git
synced 2025-12-16 06:27:07 +08:00
10
addon-info.json
Normal file
10
addon-info.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "requirements",
|
||||||
|
"description": "the Requirements File Format syntax support for Vim",
|
||||||
|
"version": "1.7.1",
|
||||||
|
"author": "raimon",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/raimon49/requirements.txt.vim"
|
||||||
|
}
|
||||||
|
}
|
||||||
20
autoload/coc/source/requirements.vim
Normal file
20
autoload/coc/source/requirements.vim
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
""
|
||||||
|
" https://github.com/neoclide/coc.nvim/wiki/Create-custom-source
|
||||||
|
function! coc#source#requirements#init() abort
|
||||||
|
return {
|
||||||
|
\ 'shortcut': 'pip',
|
||||||
|
\ 'priority': 9,
|
||||||
|
\ 'filetypes': ['requirements'],
|
||||||
|
\ }
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
""
|
||||||
|
" https://github.com/neoclide/coc.nvim/wiki/Create-custom-source
|
||||||
|
"
|
||||||
|
" Completion pip option and PYPI package names.
|
||||||
|
" Note: completion PYPI package names need install pip-cache from PYPI,
|
||||||
|
" and run `pip-cache update` first to generate cache.
|
||||||
|
function! coc#source#requirements#complete(opt, cb) abort
|
||||||
|
call a:cb(g:requirements#items)
|
||||||
|
endfunction
|
||||||
|
" vim: et sw=4 ts=4 sts=4:
|
||||||
44
autoload/requirements.vim
Normal file
44
autoload/requirements.vim
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
""
|
||||||
|
" @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.
|
||||||
|
|
||||||
|
""
|
||||||
|
" 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
|
||||||
|
|
||||||
|
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:
|
||||||
11
autoload/requirements/utils.vim
Normal file
11
autoload/requirements/utils.vim
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
""
|
||||||
|
" @section Configuration, config
|
||||||
|
|
||||||
|
function! s:Flag(name, default) abort
|
||||||
|
let l:scope = get(split(a:name, ':'), 0, 'g:')
|
||||||
|
let l:name = get(split(a:name, ':'), -1)
|
||||||
|
let {l:scope}:{l:name} = get({l:scope}:, l:name, a:default)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let g:requirements#utils#plugin = {'Flag': funcref('s:Flag')}
|
||||||
|
" vim: et sw=4 ts=4 sts=4:
|
||||||
2
doc/.gitignore
vendored
Normal file
2
doc/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!/.gitignore
|
||||||
Reference in New Issue
Block a user