1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 00:30:05 +08:00

Add command APIs

This commit is contained in:
wsdjeg 2017-10-17 15:37:29 +08:00
parent f1594388cb
commit b067b95bf9
3 changed files with 62 additions and 6 deletions

View 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

View File

@ -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

View File

@ -0,0 +1,4 @@
Execute ( SpaceVim api: data#list ):
let cmd = SpaceVim#api#import('vim#command')
let cmd.options = {}
AssertEqual cmd.complete('', '', ''), ''