mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 02:40:05 +08:00
Add command APIs
This commit is contained in:
parent
f1594388cb
commit
b067b95bf9
12
autoload/SpaceVim/api/vim/command.vim
Normal file
12
autoload/SpaceVim/api/vim/command.vim
Normal file
@ -0,0 +1,12 @@
|
||||
let s:self = {}
|
||||
|
||||
let s:self.options = {}
|
||||
|
||||
function! s:self.complete(ArgLead, CmdLine, CursorPos) abort
|
||||
return join(keys(self.options), "\n")
|
||||
endfunction
|
||||
|
||||
|
||||
function! SpaceVim#api#vim#command#get()
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
@ -6,6 +6,7 @@
|
||||
" License: MIT license
|
||||
"=============================================================================
|
||||
|
||||
" init plugin values
|
||||
|
||||
let s:options = {
|
||||
\ '-f' : {
|
||||
@ -18,15 +19,54 @@ let s:options = {
|
||||
\ },
|
||||
\ }
|
||||
|
||||
if !exists('Pmd_Cmd')
|
||||
let g:Pmd_Cmd = ['pmd']
|
||||
endif
|
||||
|
||||
if !exists('Pmd_Cache_Dir')
|
||||
let g:Pmd_Cache_Dir = '~/.cache/pmd/'
|
||||
endif
|
||||
|
||||
if !exists('Pmd_Rulesets')
|
||||
let g:Pmd_Rulesets = ["-R", "java-basic,java-design", "-property", "xsltFilename=my-own.xs"]
|
||||
endif
|
||||
|
||||
" load SpaceVim APIs
|
||||
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:CMD = SpaceVim#api#import('vim#command')
|
||||
|
||||
" set APIs
|
||||
|
||||
let s:CMD.options = s:options
|
||||
|
||||
function! s:on_pmd_stdout(id, data, event) abort
|
||||
echom string(a:data)
|
||||
endfunction
|
||||
|
||||
function! s:on_pmd_stderr(id, data, event) abort
|
||||
echom string(a:data)
|
||||
endfunction
|
||||
|
||||
function! s:on_pmd_exit(id, data, event) abort
|
||||
echom string(a:data)
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#pmd#run(...)
|
||||
|
||||
|
||||
|
||||
let argv = g:Pmd_Cmd + ['-cache', g:Pmd_Cache_Dir]
|
||||
let argv += a:000 + g:Pmd_Rulesets
|
||||
echom s:JOB.start(argv,
|
||||
\ {
|
||||
\ 'on_stdout' : function('s:on_pmd_stdout'),
|
||||
\ 'on_stderr' : function('s:on_pmd_stderr'),
|
||||
\ 'on_exit' : function('s:on_pmd_exit'),
|
||||
\ }
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
let s:CMD = SpaceVim#api#import('vim#command')
|
||||
let s:CMD.options = s:options
|
||||
|
||||
function! SpaceVim#plugins#pmd#complete(...)
|
||||
|
||||
return '-f'
|
||||
function! SpaceVim#plugins#pmd#complete(ArgLead, CmdLine, CursorPos)
|
||||
return s:CMD.complete(a:ArgLead, a:CmdLine, a:CursorPos)
|
||||
endfunction
|
||||
|
4
test/api/vim/command.vader
Normal file
4
test/api/vim/command.vader
Normal file
@ -0,0 +1,4 @@
|
||||
Execute ( SpaceVim api: data#list ):
|
||||
let cmd = SpaceVim#api#import('vim#command')
|
||||
let cmd.options = {}
|
||||
AssertEqual cmd.complete('', '', ''), ''
|
Loading…
Reference in New Issue
Block a user