summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorRaphael <glepnir@gopherhub.org>2021-01-08 08:47:46 +0800
committerGitHub <noreply@github.com>2021-01-08 01:47:46 +0100
commita089c674837ee1216748b1af6726798cec458371 (patch)
tree79117ede6ac1fcbad79e2a992c7df72fa5e8456b /plugin
parent1d6195ff643ed153eb0f233b32f1becc68c79ee6 (diff)
refactor telescope command (#398)
* refactor telescope command * addd telescope default options support * fix variable name wrong * convert command line string to lua type * add comment. * update readme for use theme in commandline * enhance complete in commandline * enhance complete in commandline * enhance covert commandline options
Diffstat (limited to 'plugin')
-rw-r--r--plugin/telescope.vim71
1 files changed, 41 insertions, 30 deletions
diff --git a/plugin/telescope.vim b/plugin/telescope.vim
index 697457b..54dd6e6 100644
--- a/plugin/telescope.vim
+++ b/plugin/telescope.vim
@@ -53,53 +53,64 @@ cnoremap <silent> <Plug>(TelescopeFuzzyCommandSearch) <C-\>e
\ }"<CR><CR>
" Telescope builtin lists
-function! s:telescope_complete(...)
+function! s:telescope_complete(arg,line,pos)
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")
+ let l:options_list = luaeval('vim.tbl_keys(require("telescope.config").values)')
+ let ext_type = v:lua.require('telescope._extensions').manager
+ let l:ext_type_list = []
+
+ for val in values(ext_type)
+ if len(val) > 1
+ call extend(l:ext_type_list,keys(val))
+ endif
+ endfor
+
+ let list = [extend(l:builtin_list,l:extensions_list),l:options_list]
+ let l = split(a:line[:a:pos-1], '\%(\%(\%(^\|[^\\]\)\\\)\@<!\s\)\+', 1)
+ let n = len(l) - index(l, 'Telescope') - 2
+
+ if n == 0
+ return join(list[0],"\n")
+ endif
+
+ if n == 1
+ if index(l:extensions_list,l[1]) >= 0
+ return join(l:ext_type_list,"\n")
+ endif
+ return join(list[1],"\n")
+ endif
+
+ if n > 1
+ return join(list[1],"\n")
+ endif
endfunction
-" TODO: If the lua datatype contains complex type,It will cause convert to
-" viml datatype failed. So current doesn't support config telescope.themes
function! s:load_command(builtin,...) abort
- let opts = {}
- let type = ''
+ let user_opts = {}
+ let user_opts.cmd = a:builtin
+ let user_opts.opts = {}
" range command args
" if arg in lua code is table type,we split command string by `,` to vimscript
" list type.
for arg in a:000
if stridx(arg,'=') < 0
- let type = arg
+ let user_opts.extension_type = arg
continue
endif
-
- let opt = split(arg,'=')
- if opt[0] == 'find_command' || opt[0] == 'vimgrep_arguments'
- let opts[opt[0]] = split(opt[1],',')
+ " split args by =
+ let arg_list = split(arg,'=')
+ if arg_list[0] == 'find_command' || arg_list[0] == 'vimgrep_arguments'
+ let user_opts.opts[arg_list[0]] = split(arg_list[1],',')
+ elseif arg_list[0] == 'theme'
+ let user_opts.theme = arg_list[1]
else
- let opts[opt[0]] = opt[1]
+ let user_opts.opts[arg_list[0]] = arg_list[1]
endif
endfor
- 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)
- 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
-
+ call v:lua.require('telescope.command').run_command(user_opts)
endfunction
" Telescope Commands with complete