support custom table type keyword (#450)
* support custom table type keyword * remove custom split function use vim.split * remove unused varable fix test * rewrite get extensions subcommand * add comment * remove blankline * check the param in default options * revert * add register keyword function
This commit is contained in:
@@ -66,7 +66,7 @@ end
|
|||||||
-- opts = {
|
-- opts = {
|
||||||
-- cwd = '***',
|
-- cwd = '***',
|
||||||
-- }
|
-- }
|
||||||
function command.run_command(args)
|
local function run_command(args)
|
||||||
local user_opts = args or {}
|
local user_opts = args or {}
|
||||||
if next(user_opts) == nil and not user_opts.cmd then
|
if next(user_opts) == nil and not user_opts.cmd then
|
||||||
print('[Telescope] your command miss args')
|
print('[Telescope] your command miss args')
|
||||||
@@ -101,4 +101,56 @@ function command.run_command(args)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- @Summary get extensions sub command
|
||||||
|
-- register extensions dap gh etc.
|
||||||
|
-- input in command line `Telescope gh <TAB>`
|
||||||
|
-- It will show a list that all extensions sub command list
|
||||||
|
-- ['commands','list_breakpoints','variables','issues','gist','pull_request']
|
||||||
|
function command.get_extensions_subcommand()
|
||||||
|
local exts = require('telescope._extensions').manager
|
||||||
|
local complete_ext_table = {}
|
||||||
|
for _,value in pairs(exts) do
|
||||||
|
if type(value) == "table" then
|
||||||
|
for key,_ in pairs(value) do
|
||||||
|
table.insert(complete_ext_table,key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return complete_ext_table
|
||||||
|
end
|
||||||
|
|
||||||
|
local split_keywords = {
|
||||||
|
['find_command'] = true,
|
||||||
|
['vimgrep_arguments'] = true,
|
||||||
|
['sections'] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function command.register_keyword(keyword)
|
||||||
|
split_keywords[keyword] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function command.load_command(cmd,...)
|
||||||
|
local args = {...}
|
||||||
|
local user_opts = {}
|
||||||
|
user_opts['cmd'] = cmd
|
||||||
|
user_opts.opts = {}
|
||||||
|
|
||||||
|
for _,arg in ipairs(args) do
|
||||||
|
if arg:find('=',1) == nil then
|
||||||
|
user_opts['extension_type'] = arg
|
||||||
|
else
|
||||||
|
local param = vim.split(arg,'=')
|
||||||
|
if param[1] == 'theme' then
|
||||||
|
user_opts['theme'] = param[2]
|
||||||
|
elseif split_keywords[param[1]] then
|
||||||
|
user_opts.opts[param[1]] = vim.split(param[2],',')
|
||||||
|
else
|
||||||
|
user_opts.opts[param[1]] = param[2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
run_command(user_opts)
|
||||||
|
end
|
||||||
|
|
||||||
return command
|
return command
|
||||||
|
|||||||
@@ -60,16 +60,7 @@ function! s:telescope_complete(arg,line,pos)
|
|||||||
let l:builtin_list = luaeval('vim.tbl_keys(require("telescope.builtin"))')
|
let l:builtin_list = luaeval('vim.tbl_keys(require("telescope.builtin"))')
|
||||||
let l:extensions_list = luaeval('vim.tbl_keys(require("telescope._extensions").manager)')
|
let l:extensions_list = luaeval('vim.tbl_keys(require("telescope._extensions").manager)')
|
||||||
let l:options_list = luaeval('vim.tbl_keys(require("telescope.config").values)')
|
let l:options_list = luaeval('vim.tbl_keys(require("telescope.config").values)')
|
||||||
let ext_type = v:lua.require('telescope._extensions').manager
|
let l:extensions_subcommand_list = luaeval('require("telescope.command").get_extensions_subcommand()')
|
||||||
let l:ext_type_list = []
|
|
||||||
|
|
||||||
if !empty(ext_type)
|
|
||||||
for val in values(ext_type)
|
|
||||||
if type(val) == 3
|
|
||||||
call extend(l:ext_type_list,keys(val))
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
|
|
||||||
let list = [extend(l:builtin_list,l:extensions_list),l:options_list]
|
let list = [extend(l:builtin_list,l:extensions_list),l:options_list]
|
||||||
let l = split(a:line[:a:pos-1], '\%(\%(\%(^\|[^\\]\)\\\)\@<!\s\)\+', 1)
|
let l = split(a:line[:a:pos-1], '\%(\%(\%(^\|[^\\]\)\\\)\@<!\s\)\+', 1)
|
||||||
@@ -81,7 +72,7 @@ function! s:telescope_complete(arg,line,pos)
|
|||||||
|
|
||||||
if n == 1
|
if n == 1
|
||||||
if index(l:extensions_list,l[1]) >= 0
|
if index(l:extensions_list,l[1]) >= 0
|
||||||
return join(l:ext_type_list,"\n")
|
return join(l:extensions_subcommand_list,"\n")
|
||||||
endif
|
endif
|
||||||
return join(list[1],"\n")
|
return join(list[1],"\n")
|
||||||
endif
|
endif
|
||||||
@@ -91,32 +82,5 @@ function! s:telescope_complete(arg,line,pos)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:load_command(builtin,...) abort
|
|
||||||
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 user_opts.extension_type = arg
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
" 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 user_opts.opts[arg_list[0]] = arg_list[1]
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
call v:lua.require('telescope.command').run_command(user_opts)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Telescope Commands with complete
|
" Telescope Commands with complete
|
||||||
command! -nargs=+ -complete=custom,s:telescope_complete Telescope call s:load_command(<f-args>)
|
command! -nargs=+ -complete=custom,s:telescope_complete Telescope lua require('telescope.command').load_command(<f-args>)
|
||||||
|
|||||||
Reference in New Issue
Block a user