feat: add extension in telescope command (#380)

This commit is contained in:
Raphael
2021-01-04 20:00:54 +08:00
committed by GitHub
parent 71ea4130a2
commit 5d121ee58c

View File

@@ -49,18 +49,26 @@ cnoremap <silent> <Plug>(TelescopeFuzzyCommandSearch) <C-\>e
" Telescope builtin lists " Telescope builtin lists
function! s:telescope_complete(...) function! s:telescope_complete(...)
return join(luaeval('vim.tbl_keys(require("telescope.builtin"))'), "\n") let l:builtin_list = luaeval('vim.tbl_keys(require("telescope.builtin"))')
let l:extensions_list = luaeval('vim.tbl_keys(require("telescope._extensions").manager)')
return join(extend(l:builtin_list,l:extensions_list),"\n")
endfunction endfunction
" TODO: If the lua datatype contains complex type,It will cause convert to " TODO: If the lua datatype contains complex type,It will cause convert to
" viml datatype failed. So current doesn't support config telescope.themes " viml datatype failed. So current doesn't support config telescope.themes
function! s:load_command(builtin,...) abort function! s:load_command(builtin,...) abort
let opts = {} let opts = {}
let type = ''
" range command args " range command args
" if arg in lua code is table type,we split command string by `,` to vimscript " if arg in lua code is table type,we split command string by `,` to vimscript
" list type. " list type.
for arg in a:000 for arg in a:000
if stridx(arg,'=') < 0
let type = arg
continue
endif
let opt = split(arg,'=') let opt = split(arg,'=')
if opt[0] == 'find_command' || opt[0] == 'vimgrep_arguments' if opt[0] == 'find_command' || opt[0] == 'vimgrep_arguments'
let opts[opt[0]] = split(opt[1],',') let opts[opt[0]] = split(opt[1],',')
@@ -70,7 +78,23 @@ function! s:load_command(builtin,...) abort
endfor endfor
let telescope = v:lua.require('telescope.builtin') let telescope = v:lua.require('telescope.builtin')
let extensions = v:lua.require('telescope._extensions').manager
if has_key(telescope,a:builtin)
call telescope[a:builtin](opts) call telescope[a:builtin](opts)
return
endif
if has_key(extensions,a:builtin)
if has_key(extensions[a:builtin],a:builtin)
call extensions[a:builtin][a:builtin](opts)
return
endif
if has_key(extensions[a:builtin],type)
call extensions[a:builtin][type](opts)
endif
endif
endfunction endfunction
" Telescope Commands with complete " Telescope Commands with complete