From 440684edad0b56cb746c1f1aaef6a53aa703b2ce Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 18 May 2022 18:27:06 +0000 Subject: [PATCH 01/35] break(git_files): change show_untracked default to false (#842) --- doc/telescope.txt | 2 +- lua/telescope/builtin/git.lua | 2 +- lua/telescope/builtin/init.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 42f8da1..b79006b 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -977,7 +977,7 @@ builtin.git_files({opts}) *telescope.builtin.git_files()* (default: true) {show_untracked} (boolean) if true, adds `--others` flag to command and shows untracked files - (default: true) + (default: false) {recurse_submodules} (boolean) if true, adds the `--recurse-submodules` flag to command (default: false) diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index 5f6b17e..caff989 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -22,7 +22,7 @@ git.files = function(opts) return end - local show_untracked = utils.get_default(opts.show_untracked, true) + local show_untracked = utils.get_default(opts.show_untracked, false) local recurse_submodules = utils.get_default(opts.recurse_submodules, false) if show_untracked and recurse_submodules then utils.notify("builtin.git_files", { diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 4a99f3f..e9b695b 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -132,7 +132,7 @@ builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.files" ---@param opts table: options to pass to the picker ---@field cwd string: specify the path of the repo ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ----@field show_untracked boolean: if true, adds `--others` flag to command and shows untracked files (default: true) +---@field show_untracked boolean: if true, adds `--others` flag to command and shows untracked files (default: false) ---@field recurse_submodules boolean: if true, adds the `--recurse-submodules` flag to command (default: false) ---@field git_command table: command that will be exectued. {"git","ls-files","--exclude-standard","--cached"} builtin.git_files = require_on_exported_call("telescope.builtin.git").files From 4482c2b551a36b4a1d27a59e0d4d53a3fdb7ccbd Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 22 May 2022 10:33:01 +0200 Subject: [PATCH 02/35] chore: cleanup vim options (#1946) --- data/options/options.lua | 3257 ---------------------------- lua/telescope/builtin/internal.lua | 50 +- lua/telescope/make_entry.lua | 93 +- 3 files changed, 30 insertions(+), 3370 deletions(-) delete mode 100644 data/options/options.lua diff --git a/data/options/options.lua b/data/options/options.lua deleted file mode 100644 index 95861cc..0000000 --- a/data/options/options.lua +++ /dev/null @@ -1,3257 +0,0 @@ --- { --- { --- full_name='aleph', abbreviation='al', --- short_desc="ASCII code of the letter Aleph (Hebrew)", --- varname='p_aleph', pv_name=nil, --- type='number', list=nil, scope={'global'}, --- deny_duplicates=nil, --- enable_if=nil, --- defaults={condition=nil, if_true={vi=224, vim=0}, if_false=nil}, --- secure=nil, gettext=nil, noglob=nil, normal_fname_chars=nil, --- pri_mkrc=nil, deny_in_modelines=nil, normal_dname_chars=nil, --- modelineexpr=nil, --- expand=nil, nodefault=nil, no_mkrc=nil, vi_def=true, vim=true, --- alloced=nil, --- save_pv_indir=nil, --- redraw={'curswant'}, --- } --- } --- types: bool, number, string --- lists: (nil), comma, onecomma, flags, flagscomma --- scopes: global, buffer, window --- redraw options: statuslines, current_window, curent_window_only, --- current_buffer, all_windows, everything, curswant --- default: {vi=…[, vim=…]} --- defaults: {condition=#if condition, if_true=default, if_false=default} --- #if condition: --- string: #ifdef string --- !string: #ifndef string --- {string, string}: #if defined(string) && defined(string) --- {!string, !string}: #if !defined(string) && !defined(string) -local cstr = function(s) - return '"' .. s:gsub('["\\]', '\\%0'):gsub('\t', '\\t') .. '"' -end -local macros=function(s) - return function() - return s - end -end -local imacros=function(s) - return function() - return '(intptr_t)' .. s - end -end -N_=function(s) -- luacheck: ignore 211 (currently unused) - return function() - return 'N_(' .. cstr(s) .. ')' - end -end --- used for 'cinkeys' and 'indentkeys' -local indentkeys_default = '0{,0},0),0],:,0#,!^F,o,O,e'; -return { - cstr=cstr, - options={ - { - full_name='aleph', abbreviation='al', - short_desc=N_("ASCII code of the letter Aleph (Hebrew)"), - type='number', scope={'global'}, - vi_def=true, - redraw={'curswant'}, - varname='p_aleph', - defaults={if_true={vi=224}} - }, - { - full_name='arabic', abbreviation='arab', - short_desc=N_("Arabic as a default second language"), - type='bool', scope={'window'}, - vi_def=true, - vim=true, - redraw={'curswant'}, - defaults={if_true={vi=false}} - }, - { - full_name='arabicshape', abbreviation='arshape', - short_desc=N_("do shaping for Arabic characters"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - redraw={'all_windows', 'ui_option'}, - - varname='p_arshape', - defaults={if_true={vi=true}} - }, - { - full_name='allowrevins', abbreviation='ari', - short_desc=N_("allow CTRL-_ in Insert and Command-line mode"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_ari', - defaults={if_true={vi=false}} - }, - { - full_name='ambiwidth', abbreviation='ambw', - short_desc=N_("what to do with Unicode chars of ambiguous width"), - type='string', scope={'global'}, - vi_def=true, - redraw={'all_windows', 'ui_option'}, - varname='p_ambw', - defaults={if_true={vi="single"}} - }, - { - full_name='autochdir', abbreviation='acd', - short_desc=N_("change directory to the file in the current window"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_acd', - defaults={if_true={vi=false}} - }, - { - full_name='autoindent', abbreviation='ai', - short_desc=N_("take indent for new line from previous line"), - type='bool', scope={'buffer'}, - varname='p_ai', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='autoread', abbreviation='ar', - short_desc=N_("autom. read file when changed outside of Vim"), - type='bool', scope={'global', 'buffer'}, - varname='p_ar', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='autowrite', abbreviation='aw', - short_desc=N_("automatically write file if changed"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_aw', - defaults={if_true={vi=false}} - }, - { - full_name='autowriteall', abbreviation='awa', - short_desc=N_("as 'autowrite', but works with more commands"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_awa', - defaults={if_true={vi=false}} - }, - { - full_name='background', abbreviation='bg', - short_desc=N_("\"dark\" or \"light\", used for highlight colors"), - type='string', scope={'global'}, - vim=true, - redraw={'all_windows'}, - varname='p_bg', - defaults={if_true={vi="light",vim="dark"}} - }, - { - full_name='backspace', abbreviation='bs', - short_desc=N_("how backspace works at start of line"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vim=true, - varname='p_bs', - defaults={if_true={vi="", vim="indent,eol,start"}} - }, - { - full_name='backup', abbreviation='bk', - short_desc=N_("keep backup file after overwriting a file"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_bk', - defaults={if_true={vi=false}} - }, - { - full_name='backupcopy', abbreviation='bkc', - short_desc=N_("make backup as a copy, don't rename the file"), - type='string', list='onecomma', scope={'global', 'buffer'}, - deny_duplicates=true, - vim=true, - varname='p_bkc', - defaults={ - condition='UNIX', - if_true={vi="yes", vim="auto"}, - if_false={vi="auto", vim="auto"} - }, - }, - { - full_name='backupdir', abbreviation='bdir', - short_desc=N_("list of directories for the backup file"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - vi_def=true, - expand='nodefault', - varname='p_bdir', - defaults={if_true={vi=''}} - }, - { - full_name='backupext', abbreviation='bex', - short_desc=N_("extension used for the backup file"), - type='string', scope={'global'}, - normal_fname_chars=true, - vi_def=true, - varname='p_bex', - defaults={if_true={vi="~"}} - }, - { - full_name='backupskip', abbreviation='bsk', - short_desc=N_("no backup for files that match these patterns"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_bsk', - defaults={if_true={vi=""}} - }, - { - full_name='belloff', abbreviation='bo', - short_desc=N_("do not ring the bell for these reasons"), - type='string', list='comma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_bo', - defaults={if_true={vi="all"}} - }, - { - full_name='binary', abbreviation='bin', - short_desc=N_("read/write/edit file in binary mode"), - type='bool', scope={'buffer'}, - vi_def=true, - redraw={'statuslines'}, - varname='p_bin', - defaults={if_true={vi=false}} - }, - { - full_name='bomb', - short_desc=N_("a Byte Order Mark to the file"), - type='bool', scope={'buffer'}, - no_mkrc=true, - vi_def=true, - redraw={'statuslines'}, - varname='p_bomb', - defaults={if_true={vi=false}} - }, - { - full_name='breakat', abbreviation='brk', - short_desc=N_("characters that may cause a line break"), - type='string', list='flags', scope={'global'}, - vi_def=true, - redraw={'all_windows'}, - varname='p_breakat', - defaults={if_true={vi=" \t!@*-+;:,./?"}} - }, - { - full_name='breakindent', abbreviation='bri', - short_desc=N_("wrapped line repeats indent"), - type='bool', scope={'window'}, - vi_def=true, - vim=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='breakindentopt', abbreviation='briopt', - short_desc=N_("settings for 'breakindent'"), - type='string', list='onecomma', scope={'window'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - redraw={'current_buffer'}, - defaults={if_true={vi=""}}, - }, - { - full_name='browsedir', abbreviation='bsdir', - short_desc=N_("which directory to start browsing in"), - type='string', scope={'global'}, - vi_def=true, - enable_if=false, - }, - { - full_name='bufhidden', abbreviation='bh', - short_desc=N_("what to do when buffer is no longer in window"), - type='string', scope={'buffer'}, - noglob=true, - vi_def=true, - alloced=true, - varname='p_bh', - defaults={if_true={vi=""}} - }, - { - full_name='buflisted', abbreviation='bl', - short_desc=N_("whether the buffer shows up in the buffer list"), - type='bool', scope={'buffer'}, - noglob=true, - vi_def=true, - varname='p_bl', - defaults={if_true={vi=1}} - }, - { - full_name='buftype', abbreviation='bt', - short_desc=N_("special type of buffer"), - type='string', scope={'buffer'}, - noglob=true, - vi_def=true, - alloced=true, - varname='p_bt', - defaults={if_true={vi=""}} - }, - { - full_name='casemap', abbreviation='cmp', - short_desc=N_("specifies how case of letters is changed"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_cmp', - defaults={if_true={vi="internal,keepascii"}} - }, - { - full_name='cdpath', abbreviation='cd', - short_desc=N_("list of directories searched with \":cd\""), - type='string', list='comma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - expand=true, - secure=true, - varname='p_cdpath', - defaults={if_true={vi=",,"}} - }, - { - full_name='cedit', - short_desc=N_("used to open the command-line window"), - type='string', scope={'global'}, - varname='p_cedit', - defaults={if_true={vi="", vim=macros('CTRL_F_STR')}} - }, - { - full_name='channel', - short_desc=N_("Channel connected to the buffer"), - type='number', scope={'buffer'}, - no_mkrc=true, - nodefault=true, - varname='p_channel', - defaults={if_true={vi=0}} - }, - { - full_name='charconvert', abbreviation='ccv', - short_desc=N_("expression for character encoding conversion"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_ccv', - defaults={if_true={vi=""}} - }, - { - full_name='cindent', abbreviation='cin', - short_desc=N_("do C program indenting"), - type='bool', scope={'buffer'}, - vi_def=true, - vim=true, - varname='p_cin', - defaults={if_true={vi=false}} - }, - { - full_name='cinkeys', abbreviation='cink', - short_desc=N_("keys that trigger indent when 'cindent' is set"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - varname='p_cink', - defaults={if_true={vi=indentkeys_default}} - }, - { - full_name='cinoptions', abbreviation='cino', - short_desc=N_("how to do indenting when 'cindent' is set"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - varname='p_cino', - defaults={if_true={vi=""}} - }, - { - full_name='cinwords', abbreviation='cinw', - short_desc=N_("words where 'si' and 'cin' add an indent"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - varname='p_cinw', - defaults={if_true={vi="if,else,while,do,for,switch"}} - }, - { - full_name='clipboard', abbreviation='cb', - short_desc=N_("use the clipboard as the unnamed register"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_cb', - defaults={if_true={vi=""}} - }, - { - full_name='cmdheight', abbreviation='ch', - short_desc=N_("number of lines to use for the command-line"), - type='number', scope={'global'}, - vi_def=true, - redraw={'all_windows'}, - varname='p_ch', - defaults={if_true={vi=1}} - }, - { - full_name='cmdwinheight', abbreviation='cwh', - short_desc=N_("height of the command-line window"), - type='number', scope={'global'}, - vi_def=true, - varname='p_cwh', - defaults={if_true={vi=7}} - }, - { - full_name='colorcolumn', abbreviation='cc', - short_desc=N_("columns to highlight"), - type='string', list='onecomma', scope={'window'}, - deny_duplicates=true, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=""}} - }, - { - full_name='columns', abbreviation='co', - short_desc=N_("number of columns in the display"), - type='number', scope={'global'}, - no_mkrc=true, - vi_def=true, - redraw={'everything'}, - varname='p_columns', - defaults={if_true={vi=macros('DFLT_COLS')}} - }, - { - full_name='comments', abbreviation='com', - short_desc=N_("patterns that can start a comment line"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - redraw={'curswant'}, - varname='p_com', - defaults={if_true={vi="s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-"}} - }, - { - full_name='commentstring', abbreviation='cms', - short_desc=N_("template for comments; used for fold marker"), - type='string', scope={'buffer'}, - vi_def=true, - alloced=true, - redraw={'curswant'}, - varname='p_cms', - defaults={if_true={vi="/*%s*/"}} - }, - { - full_name='compatible', abbreviation='cp', - short_desc=N_("No description"), - type='bool', scope={'global'}, - redraw={'all_windows'}, - varname='p_force_off', - -- pri_mkrc isn't needed here, optval_default() - -- always returns TRUE for 'compatible' - defaults={if_true={vi=true, vim=false}} - }, - { - full_name='complete', abbreviation='cpt', - short_desc=N_("specify how Insert mode completion works"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - alloced=true, - varname='p_cpt', - defaults={if_true={vi=".,w,b,u,t,i", vim=".,w,b,u,t"}} - }, - { - full_name='concealcursor', abbreviation='cocu', - short_desc=N_("whether concealable text is hidden in cursor line"), - type='string', scope={'window'}, - vi_def=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi=""}} - }, - { - full_name='conceallevel', abbreviation='cole', - short_desc=N_("whether concealable text is shown or hidden"), - type='number', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=0}} - }, - { - full_name='completefunc', abbreviation='cfu', - short_desc=N_("function to be used for Insert mode completion"), - type='string', scope={'buffer'}, - secure=true, - vi_def=true, - alloced=true, - varname='p_cfu', - defaults={if_true={vi=""}} - }, - { - full_name='completeopt', abbreviation='cot', - short_desc=N_("options for Insert mode completion"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_cot', - defaults={if_true={vi="menu,preview"}} - }, - { - full_name='confirm', abbreviation='cf', - short_desc=N_("ask what to do about unsaved/read-only files"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_confirm', - defaults={if_true={vi=false}} - }, - { - full_name='copyindent', abbreviation='ci', - short_desc=N_("make 'autoindent' use existing indent structure"), - type='bool', scope={'buffer'}, - vi_def=true, - vim=true, - varname='p_ci', - defaults={if_true={vi=false}} - }, - { - full_name='cpoptions', abbreviation='cpo', - short_desc=N_("flags for Vi-compatible behavior"), - type='string', list='flags', scope={'global'}, - vim=true, - redraw={'all_windows'}, - varname='p_cpo', - defaults={if_true={vi=macros('CPO_VI'), vim=macros('CPO_VIM')}} - }, - { - full_name='cscopepathcomp', abbreviation='cspc', - short_desc=N_("how many components of the path to show"), - type='number', scope={'global'}, - vi_def=true, - vim=true, - varname='p_cspc', - defaults={if_true={vi=0}} - }, - { - full_name='cscopeprg', abbreviation='csprg', - short_desc=N_("command to execute cscope"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand=true, - varname='p_csprg', - defaults={if_true={vi="cscope"}} - }, - { - full_name='cscopequickfix', abbreviation='csqf', - short_desc=N_("use quickfix window for cscope results"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_csqf', - defaults={if_true={vi=""}} - }, - { - full_name='cscoperelative', abbreviation='csre', - short_desc=N_("Use cscope.out path basename as prefix"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_csre', - defaults={if_true={vi=0}} - }, - { - full_name='cscopetag', abbreviation='cst', - short_desc=N_("use cscope for tag commands"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_cst', - defaults={if_true={vi=0}} - }, - { - full_name='cscopetagorder', abbreviation='csto', - short_desc=N_("determines \":cstag\" search order"), - type='number', scope={'global'}, - vi_def=true, - vim=true, - varname='p_csto', - defaults={if_true={vi=0}} - }, - { - full_name='cscopeverbose', abbreviation='csverb', - short_desc=N_("give messages when adding a cscope database"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_csverbose', - defaults={if_true={vi=1}} - }, - { - full_name='cursorbind', abbreviation='crb', - short_desc=N_("move cursor in window as it moves in other windows"), - type='bool', scope={'window'}, - vi_def=true, - pv_name='p_crbind', - defaults={if_true={vi=false}} - }, - { - full_name='cursorcolumn', abbreviation='cuc', - short_desc=N_("highlight the screen column of the cursor"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window_only'}, - defaults={if_true={vi=false}} - }, - { - full_name='cursorline', abbreviation='cul', - short_desc=N_("highlight the screen line of the cursor"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window_only'}, - defaults={if_true={vi=false}} - }, - { - full_name='debug', - short_desc=N_("to \"msg\" to see all error messages"), - type='string', scope={'global'}, - vi_def=true, - varname='p_debug', - defaults={if_true={vi=""}} - }, - { - full_name='define', abbreviation='def', - short_desc=N_("pattern to be used to find a macro definition"), - type='string', scope={'global', 'buffer'}, - vi_def=true, - alloced=true, - redraw={'curswant'}, - varname='p_def', - defaults={if_true={vi="^\\s*#\\s*define"}} - }, - { - full_name='delcombine', abbreviation='deco', - short_desc=N_("delete combining characters on their own"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_deco', - defaults={if_true={vi=false}} - }, - { - full_name='dictionary', abbreviation='dict', - short_desc=N_("list of file names used for keyword completion"), - type='string', list='onecomma', scope={'global', 'buffer'}, - deny_duplicates=true, - normal_dname_chars=true, - vi_def=true, - expand=true, - varname='p_dict', - defaults={if_true={vi=""}} - }, - { - full_name='diff', - short_desc=N_("diff mode for the current window"), - type='bool', scope={'window'}, - noglob=true, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='diffexpr', abbreviation='dex', - short_desc=N_("expression used to obtain a diff file"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - redraw={'curswant'}, - varname='p_dex', - defaults={if_true={vi=""}} - }, - { - full_name='diffopt', abbreviation='dip', - short_desc=N_("options for using diff mode"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - redraw={'current_window'}, - varname='p_dip', - defaults={if_true={vi="internal,filler,closeoff"}} - }, - { - full_name='digraph', abbreviation='dg', - short_desc=N_("enable the entering of digraphs in Insert mode"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_dg', - defaults={if_true={vi=false}} - }, - { - full_name='directory', abbreviation='dir', - short_desc=N_("list of directory names for the swap file"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - vi_def=true, - expand='nodefault', - varname='p_dir', - defaults={if_true={vi=''}} - }, - { - full_name='display', abbreviation='dy', - short_desc=N_("list of flags for how to display text"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vim=true, - redraw={'all_windows'}, - varname='p_dy', - defaults={if_true={vi="", vim="lastline,msgsep"}} - }, - { - full_name='eadirection', abbreviation='ead', - short_desc=N_("in which direction 'equalalways' works"), - type='string', scope={'global'}, - vi_def=true, - varname='p_ead', - defaults={if_true={vi="both"}} - }, - { - full_name='edcompatible', abbreviation='ed', - short_desc=N_("No description"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_force_off', - defaults={if_true={vi=false}} - }, - { - full_name='emoji', abbreviation='emo', - short_desc=N_("No description"), - type='bool', scope={'global'}, - vi_def=true, - redraw={'all_windows', 'ui_option'}, - varname='p_emoji', - defaults={if_true={vi=true}} - }, - { - full_name='encoding', abbreviation='enc', - short_desc=N_("encoding used internally"), - type='string', scope={'global'}, - deny_in_modelines=true, - vi_def=true, - varname='p_enc', - defaults={if_true={vi=macros('ENC_DFLT')}} - }, - { - full_name='endofline', abbreviation='eol', - short_desc=N_("write for last line in file"), - type='bool', scope={'buffer'}, - no_mkrc=true, - vi_def=true, - redraw={'statuslines'}, - varname='p_eol', - defaults={if_true={vi=true}} - }, - { - full_name='equalalways', abbreviation='ea', - short_desc=N_("windows are automatically made the same size"), - type='bool', scope={'global'}, - vi_def=true, - redraw={'all_windows'}, - varname='p_ea', - defaults={if_true={vi=true}} - }, - { - full_name='equalprg', abbreviation='ep', - short_desc=N_("external program to use for \"=\" command"), - type='string', scope={'global', 'buffer'}, - secure=true, - vi_def=true, - expand=true, - varname='p_ep', - defaults={if_true={vi=""}} - }, - { - full_name='errorbells', abbreviation='eb', - short_desc=N_("ring the bell for error messages"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_eb', - defaults={if_true={vi=false}} - }, - { - full_name='errorfile', abbreviation='ef', - short_desc=N_("name of the errorfile for the QuickFix mode"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand=true, - varname='p_ef', - defaults={if_true={vi=macros('DFLT_ERRORFILE')}} - }, - { - full_name='errorformat', abbreviation='efm', - short_desc=N_("description of the lines in the error file"), - type='string', list='onecomma', scope={'global', 'buffer'}, - deny_duplicates=true, - vi_def=true, - varname='p_efm', - defaults={if_true={vi=macros('DFLT_EFM')}} - }, - { - full_name='eventignore', abbreviation='ei', - short_desc=N_("autocommand events that are ignored"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_ei', - defaults={if_true={vi=""}} - }, - { - full_name='expandtab', abbreviation='et', - short_desc=N_("use spaces when is inserted"), - type='bool', scope={'buffer'}, - vi_def=true, - vim=true, - varname='p_et', - defaults={if_true={vi=false}} - }, - { - full_name='exrc', abbreviation='ex', - short_desc=N_("read .nvimrc and .exrc in the current directory"), - type='bool', scope={'global'}, - secure=true, - vi_def=true, - varname='p_exrc', - defaults={if_true={vi=false}} - }, - { - full_name='fileencoding', abbreviation='fenc', - short_desc=N_("file encoding for multi-byte text"), - type='string', scope={'buffer'}, - no_mkrc=true, - vi_def=true, - alloced=true, - redraw={'statuslines', 'current_buffer'}, - varname='p_fenc', - defaults={if_true={vi=""}} - }, - { - full_name='fileencodings', abbreviation='fencs', - short_desc=N_("automatically detected character encodings"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_fencs', - defaults={if_true={vi="ucs-bom,utf-8,default,latin1"}} - }, - { - full_name='fileformat', abbreviation='ff', - short_desc=N_("file format used for file I/O"), - type='string', scope={'buffer'}, - no_mkrc=true, - vi_def=true, - alloced=true, - redraw={'curswant', 'statuslines'}, - varname='p_ff', - defaults={if_true={vi=macros('DFLT_FF')}} - }, - { - full_name='fileformats', abbreviation='ffs', - short_desc=N_("automatically detected values for 'fileformat'"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vim=true, - varname='p_ffs', - defaults={if_true={vi=macros('DFLT_FFS_VI'), vim=macros('DFLT_FFS_VIM')}} - }, - { - full_name='fileignorecase', abbreviation='fic', - short_desc=N_("ignore case when using file names"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_fic', - defaults={ - condition='CASE_INSENSITIVE_FILENAME', - if_true={vi=true}, - if_false={vi=false}, - } - }, - { - full_name='filetype', abbreviation='ft', - short_desc=N_("type of file, used for autocommands"), - type='string', scope={'buffer'}, - noglob=true, - normal_fname_chars=true, - vi_def=true, - alloced=true, - varname='p_ft', - defaults={if_true={vi=""}} - }, - { - full_name='fillchars', abbreviation='fcs', - short_desc=N_("characters to use for displaying special items"), - type='string', list='onecomma', scope={'global', 'window'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - redraw={'current_window'}, - varname='p_fcs', - defaults={if_true={vi=''}} - }, - { - full_name='fixendofline', abbreviation='fixeol', - short_desc=N_("make sure last line in file has "), - type='bool', scope={'buffer'}, - vi_def=true, - redraw={'statuslines'}, - varname='p_fixeol', - defaults={if_true={vi=true}} - }, - { - full_name='foldclose', abbreviation='fcl', - short_desc=N_("close a fold when the cursor leaves it"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - redraw={'current_window'}, - varname='p_fcl', - defaults={if_true={vi=""}} - }, - { - full_name='foldcolumn', abbreviation='fdc', - short_desc=N_("width of the column used to indicate folds"), - type='string', scope={'window'}, - vi_def=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="0"}} - }, - { - full_name='foldenable', abbreviation='fen', - short_desc=N_("set to display all folds open"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=true}} - }, - { - full_name='foldexpr', abbreviation='fde', - short_desc=N_("expression used when 'foldmethod' is \"expr\""), - type='string', scope={'window'}, - vi_def=true, - vim=true, - modelineexpr=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="0"}} - }, - { - full_name='foldignore', abbreviation='fdi', - short_desc=N_("ignore lines when 'foldmethod' is \"indent\""), - type='string', scope={'window'}, - vi_def=true, - vim=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="#"}} - }, - { - full_name='foldlevel', abbreviation='fdl', - short_desc=N_("close folds with a level higher than this"), - type='number', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=0}} - }, - { - full_name='foldlevelstart', abbreviation='fdls', - short_desc=N_("'foldlevel' when starting to edit a file"), - type='number', scope={'global'}, - vi_def=true, - redraw={'curswant'}, - varname='p_fdls', - defaults={if_true={vi=-1}} - }, - { - full_name='foldmarker', abbreviation='fmr', - short_desc=N_("markers used when 'foldmethod' is \"marker\""), - type='string', list='onecomma', scope={'window'}, - deny_duplicates=true, - vi_def=true, - vim=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="{{{,}}}"}} - }, - { - full_name='foldmethod', abbreviation='fdm', - short_desc=N_("folding type"), - type='string', scope={'window'}, - vi_def=true, - vim=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="manual"}} - }, - { - full_name='foldminlines', abbreviation='fml', - short_desc=N_("minimum number of lines for a fold to be closed"), - type='number', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=1}} - }, - { - full_name='foldnestmax', abbreviation='fdn', - short_desc=N_("maximum fold depth"), - type='number', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=20}} - }, - { - full_name='foldopen', abbreviation='fdo', - short_desc=N_("for which commands a fold will be opened"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - redraw={'curswant'}, - varname='p_fdo', - defaults={if_true={vi="block,hor,mark,percent,quickfix,search,tag,undo"}} - }, - { - full_name='foldtext', abbreviation='fdt', - short_desc=N_("expression used to display for a closed fold"), - type='string', scope={'window'}, - vi_def=true, - vim=true, - modelineexpr=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="foldtext()"}} - }, - { - full_name='formatexpr', abbreviation='fex', - short_desc=N_("expression used with \"gq\" command"), - type='string', scope={'buffer'}, - vi_def=true, - vim=true, - modelineexpr=true, - alloced=true, - varname='p_fex', - defaults={if_true={vi=""}} - }, - { - full_name='formatoptions', abbreviation='fo', - short_desc=N_("how automatic formatting is to be done"), - type='string', list='flags', scope={'buffer'}, - vim=true, - alloced=true, - varname='p_fo', - defaults={if_true={vi=macros('DFLT_FO_VI'), vim=macros('DFLT_FO_VIM')}} - }, - { - full_name='formatlistpat', abbreviation='flp', - short_desc=N_("pattern used to recognize a list header"), - type='string', scope={'buffer'}, - vi_def=true, - alloced=true, - varname='p_flp', - defaults={if_true={vi="^\\s*\\d\\+[\\]:.)}\\t ]\\s*"}} - }, - { - full_name='formatprg', abbreviation='fp', - short_desc=N_("name of external program used with \"gq\" command"), - type='string', scope={'global', 'buffer'}, - secure=true, - vi_def=true, - expand=true, - varname='p_fp', - defaults={if_true={vi=""}} - }, - { - full_name='fsync', abbreviation='fs', - short_desc=N_("whether to invoke fsync() after file write"), - type='bool', scope={'global'}, - secure=true, - vi_def=true, - varname='p_fs', - defaults={if_true={vi=false}} - }, - { - full_name='gdefault', abbreviation='gd', - short_desc=N_("the \":substitute\" flag 'g' is default on"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_gd', - defaults={if_true={vi=false}} - }, - { - full_name='grepformat', abbreviation='gfm', - short_desc=N_("format of 'grepprg' output"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_gefm', - defaults={if_true={vi=macros('DFLT_GREPFORMAT')}} - }, - { - full_name='grepprg', abbreviation='gp', - short_desc=N_("program to use for \":grep\""), - type='string', scope={'global', 'buffer'}, - secure=true, - vi_def=true, - expand=true, - varname='p_gp', - defaults={ - condition='WIN32', - -- Add an extra file name so that grep will always - -- insert a file name in the match line. */ - if_true={vi="findstr /n $* nul"}, - if_false={vi="grep -n $* /dev/null"} - } - }, - { - full_name='guicursor', abbreviation='gcr', - short_desc=N_("GUI: settings for cursor shape and blinking"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_guicursor', - defaults={if_true={vi="n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20"}} - }, - { - full_name='guifont', abbreviation='gfn', - short_desc=N_("GUI: Name(s) of font(s) to be used"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_guifont', - redraw={'ui_option'}, - defaults={if_true={vi=""}} - }, - { - full_name='guifontset', abbreviation='gfs', - short_desc=N_("GUI: Names of multi-byte fonts to be used"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_guifontset', - redraw={'ui_option'}, - defaults={if_true={vi=""}} - }, - { - full_name='guifontwide', abbreviation='gfw', - short_desc=N_("list of font names for double-wide characters"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - redraw={'ui_option'}, - varname='p_guifontwide', - defaults={if_true={vi=""}} - }, - { - full_name='guioptions', abbreviation='go', - short_desc=N_("GUI: Which components and options are used"), - type='string', list='flags', scope={'global'}, - vi_def=true, - redraw={'all_windows'}, - enable_if=false, - }, - { - full_name='guitablabel', abbreviation='gtl', - short_desc=N_("GUI: custom label for a tab page"), - type='string', scope={'global'}, - vi_def=true, - modelineexpr=true, - redraw={'current_window'}, - enable_if=false, - }, - { - full_name='guitabtooltip', abbreviation='gtt', - short_desc=N_("GUI: custom tooltip for a tab page"), - type='string', scope={'global'}, - vi_def=true, - redraw={'current_window'}, - enable_if=false, - }, - { - full_name='helpfile', abbreviation='hf', - short_desc=N_("full path name of the main help file"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand=true, - varname='p_hf', - defaults={if_true={vi=macros('DFLT_HELPFILE')}} - }, - { - full_name='helpheight', abbreviation='hh', - short_desc=N_("minimum height of a new help window"), - type='number', scope={'global'}, - vi_def=true, - varname='p_hh', - defaults={if_true={vi=20}} - }, - { - full_name='helplang', abbreviation='hlg', - short_desc=N_("preferred help languages"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_hlg', - defaults={if_true={vi=""}} - }, - { - full_name='hidden', abbreviation='hid', - short_desc=N_("don't unload buffer when it is |abandon|ed"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_hid', - defaults={if_true={vi=false}} - }, - { - full_name='highlight', abbreviation='hl', - short_desc=N_("sets highlighting mode for various occasions"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_hl', - defaults={if_true={vi=macros('HIGHLIGHT_INIT')}} - }, - { - full_name='history', abbreviation='hi', - short_desc=N_("number of command-lines that are remembered"), - type='number', scope={'global'}, - vim=true, - varname='p_hi', - defaults={if_true={vi=0, vim=10000}} - }, - { - full_name='hkmap', abbreviation='hk', - short_desc=N_("Hebrew keyboard mapping"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_hkmap', - defaults={if_true={vi=false}} - }, - { - full_name='hkmapp', abbreviation='hkp', - short_desc=N_("phonetic Hebrew keyboard mapping"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_hkmapp', - defaults={if_true={vi=false}} - }, - { - full_name='hlsearch', abbreviation='hls', - short_desc=N_("highlight matches with last search pattern"), - type='bool', scope={'global'}, - vim=true, - redraw={'all_windows'}, - varname='p_hls', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='icon', - short_desc=N_("Vim set the text of the window icon"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_icon', - defaults={if_true={vi=false}} - }, - { - full_name='iconstring', - short_desc=N_("to use for the Vim icon text"), - type='string', scope={'global'}, - vi_def=true, - modelineexpr=true, - varname='p_iconstring', - defaults={if_true={vi=""}} - }, - { - full_name='ignorecase', abbreviation='ic', - short_desc=N_("ignore case in search patterns"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_ic', - defaults={if_true={vi=false}} - }, - { - full_name='imcmdline', abbreviation='imc', - short_desc=N_("use IM when starting to edit a command line"), - type='bool', scope={'global'}, - vi_def=true, - enable_if=false, - defaults={if_true={vi=false}} - }, - { - full_name='imdisable', abbreviation='imd', - short_desc=N_("do not use the IM in any mode"), - type='bool', scope={'global'}, - vi_def=true, - enable_if=false, - defaults={if_true={vi=false}} - }, - { - full_name='iminsert', abbreviation='imi', - short_desc=N_("use :lmap or IM in Insert mode"), - type='number', scope={'buffer'}, - vi_def=true, - varname='p_iminsert', pv_name='p_imi', - defaults={ - if_true={vi=macros('B_IMODE_NONE')}, - } - }, - { - full_name='imsearch', abbreviation='ims', - short_desc=N_("use :lmap or IM when typing a search pattern"), - type='number', scope={'buffer'}, - vi_def=true, - varname='p_imsearch', pv_name='p_ims', - defaults={ - if_true={vi=macros('B_IMODE_USE_INSERT')}, - } - }, - { - full_name='inccommand', abbreviation='icm', - short_desc=N_("Live preview of substitution"), - type='string', scope={'global'}, - vi_def=true, - redraw={'all_windows'}, - varname='p_icm', - defaults={if_true={vi=""}} - }, - { - full_name='include', abbreviation='inc', - short_desc=N_("pattern to be used to find an include file"), - type='string', scope={'global', 'buffer'}, - vi_def=true, - alloced=true, - varname='p_inc', - defaults={if_true={vi="^\\s*#\\s*include"}} - }, - { - full_name='includeexpr', abbreviation='inex', - short_desc=N_("expression used to process an include line"), - type='string', scope={'buffer'}, - vi_def=true, - modelineexpr=true, - alloced=true, - varname='p_inex', - defaults={if_true={vi=""}} - }, - { - full_name='incsearch', abbreviation='is', - short_desc=N_("highlight match while typing search pattern"), - type='bool', scope={'global'}, - vim=true, - varname='p_is', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='indentexpr', abbreviation='inde', - short_desc=N_("expression used to obtain the indent of a line"), - type='string', scope={'buffer'}, - vi_def=true, - vim=true, - modelineexpr=true, - alloced=true, - varname='p_inde', - defaults={if_true={vi=""}} - }, - { - full_name='indentkeys', abbreviation='indk', - short_desc=N_("keys that trigger indenting with 'indentexpr'"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - varname='p_indk', - defaults={if_true={vi=indentkeys_default}} - }, - { - full_name='infercase', abbreviation='inf', - short_desc=N_("adjust case of match for keyword completion"), - type='bool', scope={'buffer'}, - vi_def=true, - varname='p_inf', - defaults={if_true={vi=false}} - }, - { - full_name='insertmode', abbreviation='im', - short_desc=N_("start the edit of a file in Insert mode"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_im', - defaults={if_true={vi=false}} - }, - { - full_name='isfname', abbreviation='isf', - short_desc=N_("characters included in file names and pathnames"), - type='string', list='comma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_isf', - defaults={ - condition='BACKSLASH_IN_FILENAME', - -- Excluded are: & and ^ are special in cmd.exe - -- ( and ) are used in text separating fnames */ - if_true={vi="@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,="}, - if_false={vi="@,48-57,/,.,-,_,+,,,#,$,%,~,="} - } - }, - { - full_name='isident', abbreviation='isi', - short_desc=N_("characters included in identifiers"), - type='string', list='comma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_isi', - defaults={if_true={vi="@,48-57,_,192-255"}} - }, - { - full_name='iskeyword', abbreviation='isk', - short_desc=N_("characters included in keywords"), - type='string', list='comma', scope={'buffer'}, - deny_duplicates=true, - vim=true, - alloced=true, - varname='p_isk', - defaults={if_true={vi="@,48-57,_", vim="@,48-57,_,192-255"}} - }, - { - full_name='isprint', abbreviation='isp', - short_desc=N_("printable characters"), - type='string', list='comma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - redraw={'all_windows'}, - varname='p_isp', - defaults={if_true={vi="@,161-255"} - } - }, - { - full_name='joinspaces', abbreviation='js', - short_desc=N_("two spaces after a period with a join command"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_js', - defaults={if_true={vi=true}} - }, - { - full_name='jumpoptions', abbreviation='jop', - short_desc=N_("Controls the behavior of the jumplist"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - varname='p_jop', - vim=true, - defaults={if_true={vim=''}} - }, - { - full_name='keymap', abbreviation='kmp', - short_desc=N_("name of a keyboard mapping"), - type='string', scope={'buffer'}, - normal_fname_chars=true, - pri_mkrc=true, - vi_def=true, - alloced=true, - redraw={'statuslines', 'current_buffer'}, - varname='p_keymap', pv_name='p_kmap', - defaults={if_true={vi=""}} - }, - { - full_name='keymodel', abbreviation='km', - short_desc=N_("enable starting/stopping selection with keys"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_km', - defaults={if_true={vi=""}} - }, - { - full_name='keywordprg', abbreviation='kp', - short_desc=N_("program to use for the \"K\" command"), - type='string', scope={'global', 'buffer'}, - secure=true, - vi_def=true, - expand=true, - varname='p_kp', - defaults={ - if_true={vi=":Man"}, - } - }, - { - full_name='langmap', abbreviation='lmap', - short_desc=N_("alphabetic characters for other language mode"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - vi_def=true, - varname='p_langmap', - defaults={if_true={vi=""}} - }, - { - full_name='langmenu', abbreviation='lm', - short_desc=N_("language to be used for the menus"), - type='string', scope={'global'}, - normal_fname_chars=true, - vi_def=true, - varname='p_lm', - defaults={if_true={vi=""}} - }, - { - full_name='langnoremap', abbreviation='lnr', - short_desc=N_("do not apply 'langmap' to mapped characters"), - type='bool', scope={'global'}, - varname='p_lnr', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='langremap', abbreviation='lrm', - short_desc=N_('No description'), - type='bool', scope={'global'}, - varname='p_lrm', - defaults={if_true={vi=true, vim=false}} - }, - { - full_name='laststatus', abbreviation='ls', - short_desc=N_("tells when last window has status lines"), - type='number', scope={'global'}, - vim=true, - redraw={'all_windows'}, - varname='p_ls', - defaults={if_true={vi=1,vim=2}} - }, - { - full_name='lazyredraw', abbreviation='lz', - short_desc=N_("don't redraw while executing macros"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_lz', - defaults={if_true={vi=false}} - }, - { - full_name='linebreak', abbreviation='lbr', - short_desc=N_("wrap long lines at a blank"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='lines', - short_desc=N_("of lines in the display"), - type='number', scope={'global'}, - no_mkrc=true, - vi_def=true, - redraw={'everything'}, - varname='p_lines', - defaults={if_true={vi=macros('DFLT_ROWS')}} - }, - { - full_name='linespace', abbreviation='lsp', - short_desc=N_("number of pixel lines to use between characters"), - type='number', scope={'global'}, - vi_def=true, - redraw={'ui_option'}, - varname='p_linespace', - defaults={if_true={vi=0}} - }, - { - full_name='lisp', - short_desc=N_("indenting for Lisp"), - type='bool', scope={'buffer'}, - vi_def=true, - varname='p_lisp', - defaults={if_true={vi=false}} - }, - { - full_name='lispwords', abbreviation='lw', - short_desc=N_("words that change how lisp indenting works"), - type='string', list='onecomma', scope={'global', 'buffer'}, - deny_duplicates=true, - vi_def=true, - varname='p_lispwords', pv_name='p_lw', - defaults={if_true={vi=macros('LISPWORD_VALUE')}} - }, - { - full_name='list', - short_desc=N_(" and "), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='listchars', abbreviation='lcs', - short_desc=N_("characters for displaying in list mode"), - type='string', list='onecomma', scope={'global', 'window'}, - deny_duplicates=true, - vim=true, - alloced=true, - redraw={'current_window'}, - varname='p_lcs', - defaults={if_true={vi="eol:$", vim="tab:> ,trail:-,nbsp:+"}} - }, - { - full_name='loadplugins', abbreviation='lpl', - short_desc=N_("load plugin scripts when starting up"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_lpl', - defaults={if_true={vi=true}} - }, - { - full_name='magic', - short_desc=N_("special characters in search patterns"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_magic', - defaults={if_true={vi=true}} - }, - { - full_name='makeef', abbreviation='mef', - short_desc=N_("name of the errorfile for \":make\""), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand=true, - varname='p_mef', - defaults={if_true={vi=""}} - }, - { - full_name='makeencoding', abbreviation='menc', - short_desc=N_("Converts the output of external commands"), - type='string', scope={'global', 'buffer'}, - vi_def=true, - varname='p_menc', - defaults={if_true={vi=""}} - }, - { - full_name='makeprg', abbreviation='mp', - short_desc=N_("program to use for the \":make\" command"), - type='string', scope={'global', 'buffer'}, - secure=true, - vi_def=true, - expand=true, - varname='p_mp', - defaults={if_true={vi="make"}} - }, - { - full_name='matchpairs', abbreviation='mps', - short_desc=N_("pairs of characters that \"%\" can match"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - varname='p_mps', - defaults={if_true={vi="(:),{:},[:]"}} - }, - { - full_name='matchtime', abbreviation='mat', - short_desc=N_("tenths of a second to show matching paren"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mat', - defaults={if_true={vi=5}} - }, - { - full_name='maxcombine', abbreviation='mco', - short_desc=N_("maximum nr of combining characters displayed"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mco', - defaults={if_true={vi=6}} - }, - { - full_name='maxfuncdepth', abbreviation='mfd', - short_desc=N_("maximum recursive depth for user functions"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mfd', - defaults={if_true={vi=100}} - }, - { - full_name='maxmapdepth', abbreviation='mmd', - short_desc=N_("maximum recursive depth for mapping"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mmd', - defaults={if_true={vi=1000}} - }, - { - full_name='maxmempattern', abbreviation='mmp', - short_desc=N_("maximum memory (in Kbyte) used for pattern search"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mmp', - defaults={if_true={vi=1000}} - }, - { - full_name='menuitems', abbreviation='mis', - short_desc=N_("maximum number of items in a menu"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mis', - defaults={if_true={vi=25}} - }, - { - full_name='mkspellmem', abbreviation='msm', - short_desc=N_("memory used before |:mkspell| compresses the tree"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand=true, - varname='p_msm', - defaults={if_true={vi="460000,2000,500"}} - }, - { - full_name='modeline', abbreviation='ml', - short_desc=N_("recognize modelines at start or end of file"), - type='bool', scope={'buffer'}, - vim=true, - varname='p_ml', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='modelineexpr', abbreviation='mle', - short_desc=N_("allow some options to be set in modeline"), - type='bool', scope={'global'}, - vi_def=true, - secure=true, - varname='p_mle', - defaults={if_true={vi=false}} - }, - { - full_name='modelines', abbreviation='mls', - short_desc=N_("number of lines checked for modelines"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mls', - defaults={if_true={vi=5}} - }, - { - full_name='modifiable', abbreviation='ma', - short_desc=N_("changes to the text are not possible"), - type='bool', scope={'buffer'}, - noglob=true, - vi_def=true, - varname='p_ma', - defaults={if_true={vi=true}} - }, - { - full_name='modified', abbreviation='mod', - short_desc=N_("buffer has been modified"), - type='bool', scope={'buffer'}, - no_mkrc=true, - vi_def=true, - redraw={'statuslines'}, - varname='p_mod', - defaults={if_true={vi=false}} - }, - { - full_name='more', - short_desc=N_("listings when the whole screen is filled"), - type='bool', scope={'global'}, - vim=true, - varname='p_more', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='mouse', - short_desc=N_("the use of mouse clicks"), - type='string', list='flags', scope={'global'}, - varname='p_mouse', - defaults={if_true={vi="", vim=""}} - }, - { - full_name='mousefocus', abbreviation='mousef', - short_desc=N_("keyboard focus follows the mouse"), - type='bool', scope={'global'}, - vi_def=true, - enable_if=false, - defaults={if_true={vi=false}} - }, - { - full_name='mousehide', abbreviation='mh', - short_desc=N_("hide mouse pointer while typing"), - type='bool', scope={'global'}, - vi_def=true, - enable_if=false, - defaults={if_true={vi=true}} - }, - { - full_name='mousemodel', abbreviation='mousem', - short_desc=N_("changes meaning of mouse buttons"), - type='string', scope={'global'}, - vi_def=true, - varname='p_mousem', - defaults={if_true={vi="extend"}} - }, - { - full_name='mouseshape', abbreviation='mouses', - short_desc=N_("shape of the mouse pointer in different modes"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - enable_if=false, - }, - { - full_name='mousetime', abbreviation='mouset', - short_desc=N_("max time between mouse double-click"), - type='number', scope={'global'}, - vi_def=true, - varname='p_mouset', - defaults={if_true={vi=500}} - }, - { - full_name='nrformats', abbreviation='nf', - short_desc=N_("number formats recognized for CTRL-A command"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - alloced=true, - varname='p_nf', - defaults={if_true={vi="bin,octal,hex", vim="bin,hex"}} - }, - { - full_name='number', abbreviation='nu', - short_desc=N_("print the line number in front of each line"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='numberwidth', abbreviation='nuw', - short_desc=N_("number of columns used for the line number"), - type='number', scope={'window'}, - vim=true, - redraw={'current_window'}, - defaults={if_true={vi=8, vim=4}} - }, - { - full_name='omnifunc', abbreviation='ofu', - short_desc=N_("function for filetype-specific completion"), - type='string', scope={'buffer'}, - secure=true, - vi_def=true, - alloced=true, - varname='p_ofu', - defaults={if_true={vi=""}} - }, - { - full_name='opendevice', abbreviation='odev', - short_desc=N_("allow reading/writing devices on MS-Windows"), - type='bool', scope={'global'}, - vi_def=true, - enable_if=false, - defaults={if_true={vi=false, vim=false}} - }, - { - full_name='operatorfunc', abbreviation='opfunc', - short_desc=N_("function to be called for |g@| operator"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_opfunc', - defaults={if_true={vi=""}} - }, - { - full_name='packpath', abbreviation='pp', - short_desc=N_("list of directories used for packages"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - vi_def=true, - expand=true, - varname='p_pp', - defaults={if_true={vi=''}} - }, - { - full_name='paragraphs', abbreviation='para', - short_desc=N_("nroff macros that separate paragraphs"), - type='string', scope={'global'}, - vi_def=true, - varname='p_para', - defaults={if_true={vi="IPLPPPQPP TPHPLIPpLpItpplpipbp"}} - }, - { - full_name='paste', - short_desc=N_("pasting text"), - type='bool', scope={'global'}, - pri_mkrc=true, - vi_def=true, - varname='p_paste', - defaults={if_true={vi=false}} - }, - { - full_name='pastetoggle', abbreviation='pt', - short_desc=N_("key code that causes 'paste' to toggle"), - type='string', scope={'global'}, - vi_def=true, - varname='p_pt', - defaults={if_true={vi=""}} - }, - { - full_name='patchexpr', abbreviation='pex', - short_desc=N_("expression used to patch a file"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_pex', - defaults={if_true={vi=""}} - }, - { - full_name='patchmode', abbreviation='pm', - short_desc=N_("keep the oldest version of a file"), - type='string', scope={'global'}, - normal_fname_chars=true, - vi_def=true, - varname='p_pm', - defaults={if_true={vi=""}} - }, - { - full_name='path', abbreviation='pa', - short_desc=N_("list of directories searched with \"gf\" et.al."), - type='string', list='comma', scope={'global', 'buffer'}, - deny_duplicates=true, - vi_def=true, - expand=true, - varname='p_path', - defaults={if_true={vi=".,/usr/include,,"}} - }, - { - full_name='preserveindent', abbreviation='pi', - short_desc=N_("preserve the indent structure when reindenting"), - type='bool', scope={'buffer'}, - vi_def=true, - vim=true, - varname='p_pi', - defaults={if_true={vi=false}} - }, - { - full_name='previewheight', abbreviation='pvh', - short_desc=N_("height of the preview window"), - type='number', scope={'global'}, - vi_def=true, - varname='p_pvh', - defaults={if_true={vi=12}} - }, - { - full_name='previewwindow', abbreviation='pvw', - short_desc=N_("identifies the preview window"), - type='bool', scope={'window'}, - noglob=true, - vi_def=true, - redraw={'statuslines'}, - defaults={if_true={vi=false}} - }, - { - full_name='printdevice', abbreviation='pdev', - short_desc=N_("name of the printer to be used for :hardcopy"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_pdev', - defaults={if_true={vi=""}} - }, - { - full_name='printencoding', abbreviation='penc', - short_desc=N_("encoding to be used for printing"), - type='string', scope={'global'}, - vi_def=true, - varname='p_penc', - defaults={if_true={vi=""}} - }, - { - full_name='printexpr', abbreviation='pexpr', - short_desc=N_("expression used to print PostScript for :hardcopy"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_pexpr', - defaults={if_true={vi=""}} - }, - { - full_name='printfont', abbreviation='pfn', - short_desc=N_("name of the font to be used for :hardcopy"), - type='string', scope={'global'}, - vi_def=true, - varname='p_pfn', - defaults={if_true={vi="courier"}} - }, - { - full_name='printheader', abbreviation='pheader', - short_desc=N_("format of the header used for :hardcopy"), - type='string', scope={'global'}, - vi_def=true, - varname='p_header', - defaults={if_true={vi="%<%f%h%m%=Page %N"}} - }, - { - full_name='printmbcharset', abbreviation='pmbcs', - short_desc=N_("CJK character set to be used for :hardcopy"), - type='string', scope={'global'}, - vi_def=true, - varname='p_pmcs', - defaults={if_true={vi=""}} - }, - { - full_name='printmbfont', abbreviation='pmbfn', - short_desc=N_("font names to be used for CJK output of :hardcopy"), - type='string', scope={'global'}, - vi_def=true, - varname='p_pmfn', - defaults={if_true={vi=""}} - }, - { - full_name='printoptions', abbreviation='popt', - short_desc=N_("controls the format of :hardcopy output"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_popt', - defaults={if_true={vi=""}} - }, - { - full_name='prompt', - short_desc=N_("enable prompt in Ex mode"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_prompt', - defaults={if_true={vi=true}} - }, - { - full_name='pumblend', abbreviation='pb', - short_desc=N_("Controls transparency level of popup menu"), - type='number', scope={'global'}, - vi_def=true, - redraw={'ui_option'}, - varname='p_pb', - defaults={if_true={vi=0}} - }, - { - full_name='pumheight', abbreviation='ph', - short_desc=N_("maximum height of the popup menu"), - type='number', scope={'global'}, - vi_def=true, - varname='p_ph', - defaults={if_true={vi=0}} - }, - { - full_name='pumwidth', abbreviation='pw', - short_desc=N_("minimum width of the popup menu"), - type='number', scope={'global'}, - vi_def=true, - varname='p_pw', - defaults={if_true={vi=15}} - }, - { - full_name='pyxversion', abbreviation='pyx', - short_desc=N_("selects default python version to use"), - type='number', scope={'global'}, - secure=true, - vi_def=true, - varname='p_pyx', - defaults={if_true={vi=0}} - }, - { - full_name='quoteescape', abbreviation='qe', - short_desc=N_("escape characters used in a string"), - type='string', scope={'buffer'}, - vi_def=true, - alloced=true, - varname='p_qe', - defaults={if_true={vi="\\"}} - }, - { - full_name='readonly', abbreviation='ro', - short_desc=N_("disallow writing the buffer"), - type='bool', scope={'buffer'}, - noglob=true, - vi_def=true, - redraw={'statuslines'}, - varname='p_ro', - defaults={if_true={vi=false}} - }, - { - full_name='redrawdebug', abbreviation='rdb', - short_desc=N_("Changes the way redrawing works (debug)"), - type='string', list='onecomma', scope={'global'}, - vi_def=true, - varname='p_rdb', - defaults={if_true={vi=''}} - }, - { - full_name='redrawtime', abbreviation='rdt', - short_desc=N_("timeout for 'hlsearch' and |:match| highlighting"), - type='number', scope={'global'}, - vi_def=true, - varname='p_rdt', - defaults={if_true={vi=2000}} - }, - { - full_name='regexpengine', abbreviation='re', - short_desc=N_("default regexp engine to use"), - type='number', scope={'global'}, - vi_def=true, - varname='p_re', - defaults={if_true={vi=0}} - }, - { - full_name='relativenumber', abbreviation='rnu', - short_desc=N_("show relative line number in front of each line"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='remap', - short_desc=N_("mappings to work recursively"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_remap', - defaults={if_true={vi=true}} - }, - { - full_name='report', - short_desc=N_("for reporting nr. of lines changed"), - type='number', scope={'global'}, - vi_def=true, - varname='p_report', - defaults={if_true={vi=2}} - }, - { - full_name='revins', abbreviation='ri', - short_desc=N_("inserting characters will work backwards"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_ri', - defaults={if_true={vi=false}} - }, - { - full_name='rightleft', abbreviation='rl', - short_desc=N_("window is right-to-left oriented"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='rightleftcmd', abbreviation='rlc', - short_desc=N_("commands for which editing works right-to-left"), - type='string', scope={'window'}, - vi_def=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="search"}} - }, - { - full_name='ruler', abbreviation='ru', - short_desc=N_("show cursor line and column in the status line"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - redraw={'statuslines'}, - varname='p_ru', - defaults={if_true={vi=true}} - }, - { - full_name='rulerformat', abbreviation='ruf', - short_desc=N_("custom format for the ruler"), - type='string', scope={'global'}, - vi_def=true, - alloced=true, - modelineexpr=true, - redraw={'statuslines'}, - varname='p_ruf', - defaults={if_true={vi=""}} - }, - { - full_name='runtimepath', abbreviation='rtp', - short_desc=N_("list of directories used for runtime files"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - vi_def=true, - expand='nodefault', - varname='p_rtp', - defaults={if_true={vi=''}} - }, - { - full_name='scroll', abbreviation='scr', - short_desc=N_("lines to scroll with CTRL-U and CTRL-D"), - type='number', scope={'window'}, - no_mkrc=true, - vi_def=true, - pv_name='p_scroll', - defaults={if_true={vi=0}} - }, - { - full_name='scrollback', abbreviation='scbk', - short_desc=N_("lines to scroll with CTRL-U and CTRL-D"), - type='number', scope={'buffer'}, - vi_def=true, - varname='p_scbk', - redraw={'current_buffer'}, - defaults={if_true={vi=-1}} - }, - { - full_name='scrollbind', abbreviation='scb', - short_desc=N_("scroll in window as other windows scroll"), - type='bool', scope={'window'}, - vi_def=true, - pv_name='p_scbind', - defaults={if_true={vi=false}} - }, - { - full_name='scrolljump', abbreviation='sj', - short_desc=N_("minimum number of lines to scroll"), - type='number', scope={'global'}, - vi_def=true, - vim=true, - varname='p_sj', - defaults={if_true={vi=1}} - }, - { - full_name='scrolloff', abbreviation='so', - short_desc=N_("minimum nr. of lines above and below cursor"), - type='number', scope={'global', 'window'}, - vi_def=true, - vim=true, - redraw={'all_windows'}, - varname='p_so', - defaults={if_true={vi=0}} - }, - { - full_name='scrollopt', abbreviation='sbo', - short_desc=N_("how 'scrollbind' should behave"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_sbo', - defaults={if_true={vi="ver,jump"}} - }, - { - full_name='sections', abbreviation='sect', - short_desc=N_("nroff macros that separate sections"), - type='string', scope={'global'}, - vi_def=true, - varname='p_sections', - defaults={if_true={vi="SHNHH HUnhsh"}} - }, - { - full_name='secure', - short_desc=N_("mode for reading .vimrc in current dir"), - type='bool', scope={'global'}, - secure=true, - vi_def=true, - varname='p_secure', - defaults={if_true={vi=false}} - }, - { - full_name='selection', abbreviation='sel', - short_desc=N_("what type of selection to use"), - type='string', scope={'global'}, - vi_def=true, - varname='p_sel', - defaults={if_true={vi="inclusive"}} - }, - { - full_name='selectmode', abbreviation='slm', - short_desc=N_("when to use Select mode instead of Visual mode"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_slm', - defaults={if_true={vi=""}} - }, - { - full_name='sessionoptions', abbreviation='ssop', - short_desc=N_("options for |:mksession|"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vim=true, - varname='p_ssop', - defaults={if_true={ - vi="blank,buffers,curdir,folds,help,options,tabpages,winsize", - vim="blank,buffers,curdir,folds,help,tabpages,winsize" - }} - }, - { - full_name='shada', abbreviation='sd', - short_desc=N_("use .shada file upon startup and exiting"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - varname='p_shada', - defaults={if_true={vi="", vim="!,'100,<50,s10,h"}} - }, - { - full_name='shadafile', abbreviation='sdf', - short_desc=N_("overrides the filename used for shada"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - secure=true, - varname='p_shadafile', - defaults={if_true={vi=""}} - }, - { - full_name='shell', abbreviation='sh', - short_desc=N_("name of shell to use for external commands"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand=true, - varname='p_sh', - defaults={ - condition='WIN32', - if_true={vi="cmd.exe"}, - if_false={vi="sh"} - } - }, - { - full_name='shellcmdflag', abbreviation='shcf', - short_desc=N_("flag to shell to execute one command"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_shcf', - defaults={ - condition='WIN32', - if_true={vi="/s /c"}, - if_false={vi="-c"} - } - }, - { - full_name='shellpipe', abbreviation='sp', - short_desc=N_("string to put output of \":make\" in error file"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_sp', - defaults={ - condition='WIN32', - if_true={vi=">%s 2>&1"}, - if_false={vi="| tee"}, - } - }, - { - full_name='shellquote', abbreviation='shq', - short_desc=N_("quote character(s) for around shell command"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_shq', - defaults={if_true={vi=""}} - }, - { - full_name='shellredir', abbreviation='srr', - short_desc=N_("string to put output of filter in a temp file"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_srr', - defaults={ - condition='WIN32', - if_true={vi=">%s 2>&1"}, - if_false={vi=">"} - } - }, - { - full_name='shellslash', abbreviation='ssl', - short_desc=N_("use forward slash for shell file names"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_ssl', - enable_if='BACKSLASH_IN_FILENAME', - defaults={if_true={vi=false}} - }, - { - full_name='shelltemp', abbreviation='stmp', - short_desc=N_("whether to use a temp file for shell commands"), - type='bool', scope={'global'}, - varname='p_stmp', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='shellxquote', abbreviation='sxq', - short_desc=N_("like 'shellquote', but include redirection"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_sxq', - defaults={ - condition='WIN32', - if_true={vi="\""}, - if_false={vi=""}, - } - }, - { - full_name='shellxescape', abbreviation='sxe', - short_desc=N_("characters to escape when 'shellxquote' is ("), - type='string', scope={'global'}, - secure=true, - vi_def=true, - varname='p_sxe', - defaults={if_true={vi=""}} - }, - { - full_name='shiftround', abbreviation='sr', - short_desc=N_("round indent to multiple of shiftwidth"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_sr', - defaults={if_true={vi=false}} - }, - { - full_name='shiftwidth', abbreviation='sw', - short_desc=N_("number of spaces to use for (auto)indent step"), - type='number', scope={'buffer'}, - vi_def=true, - varname='p_sw', - defaults={if_true={vi=8}} - }, - { - full_name='shortmess', abbreviation='shm', - short_desc=N_("list of flags, reduce length of messages"), - type='string', list='flags', scope={'global'}, - vim=true, - varname='p_shm', - defaults={if_true={vi="S", vim="filnxtToOF"}} - }, - { - full_name='showbreak', abbreviation='sbr', - short_desc=N_("string to use at the start of wrapped lines"), - type='string', scope={'global'}, - vi_def=true, - redraw={'all_windows'}, - varname='p_sbr', - defaults={if_true={vi=""}} - }, - { - full_name='showcmd', abbreviation='sc', - short_desc=N_("show (partial) command in status line"), - type='bool', scope={'global'}, - vim=true, - varname='p_sc', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='showfulltag', abbreviation='sft', - short_desc=N_("show full tag pattern when completing tag"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_sft', - defaults={if_true={vi=false}} - }, - { - full_name='showmatch', abbreviation='sm', - short_desc=N_("briefly jump to matching bracket if insert one"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_sm', - defaults={if_true={vi=false}} - }, - { - full_name='showmode', abbreviation='smd', - short_desc=N_("message on status line to show current mode"), - type='bool', scope={'global'}, - vim=true, - varname='p_smd', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='showtabline', abbreviation='stal', - short_desc=N_("tells when the tab pages line is displayed"), - type='number', scope={'global'}, - vi_def=true, - redraw={'all_windows', 'ui_option'}, - varname='p_stal', - defaults={if_true={vi=1}} - }, - { - full_name='sidescroll', abbreviation='ss', - short_desc=N_("minimum number of columns to scroll horizontal"), - type='number', scope={'global'}, - vi_def=true, - varname='p_ss', - defaults={if_true={vi=1}} - }, - { - full_name='sidescrolloff', abbreviation='siso', - short_desc=N_("min. nr. of columns to left and right of cursor"), - type='number', scope={'global', 'window'}, - vi_def=true, - vim=true, - redraw={'all_windows'}, - varname='p_siso', - defaults={if_true={vi=0}} - }, - { - full_name='signcolumn', abbreviation='scl', - short_desc=N_("when to display the sign column"), - type='string', scope={'window'}, - vi_def=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi="auto"}} - }, - { - full_name='smartcase', abbreviation='scs', - short_desc=N_("no ignore case when pattern has uppercase"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_scs', - defaults={if_true={vi=false}} - }, - { - full_name='smartindent', abbreviation='si', - short_desc=N_("smart autoindenting for C programs"), - type='bool', scope={'buffer'}, - vi_def=true, - vim=true, - varname='p_si', - defaults={if_true={vi=false}} - }, - { - full_name='smarttab', abbreviation='sta', - short_desc=N_("use 'shiftwidth' when inserting "), - type='bool', scope={'global'}, - vim=true, - varname='p_sta', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='softtabstop', abbreviation='sts', - short_desc=N_("number of spaces that uses while editing"), - type='number', scope={'buffer'}, - vi_def=true, - vim=true, - varname='p_sts', - defaults={if_true={vi=0}} - }, - { - full_name='spell', - short_desc=N_("spell checking"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=false}} - }, - { - full_name='spellcapcheck', abbreviation='spc', - short_desc=N_("pattern to locate end of a sentence"), - type='string', scope={'buffer'}, - vi_def=true, - alloced=true, - redraw={'current_buffer'}, - varname='p_spc', - defaults={if_true={vi="[.?!]\\_[\\])'\" ]\\+"}} - }, - { - full_name='spellfile', abbreviation='spf', - short_desc=N_("files where |zg| and |zw| store words"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - secure=true, - vi_def=true, - alloced=true, - expand=true, - varname='p_spf', - defaults={if_true={vi=""}} - }, - { - full_name='spelllang', abbreviation='spl', - short_desc=N_("language(s) to do spell checking for"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - expand=true, - redraw={'current_buffer'}, - varname='p_spl', - defaults={if_true={vi="en"}} - }, - { - full_name='spellsuggest', abbreviation='sps', - short_desc=N_("method(s) used to suggest spelling corrections"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - vi_def=true, - expand=true, - varname='p_sps', - defaults={if_true={vi="best"}} - }, - { - full_name='splitbelow', abbreviation='sb', - short_desc=N_("new window from split is below the current one"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_sb', - defaults={if_true={vi=false}} - }, - { - full_name='splitright', abbreviation='spr', - short_desc=N_("new window is put right of the current one"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_spr', - defaults={if_true={vi=false}} - }, - { - full_name='startofline', abbreviation='sol', - short_desc=N_("commands move cursor to first non-blank in line"), - type='bool', scope={'global'}, - vi_def=true, - vim=false, - varname='p_sol', - defaults={if_true={vi=false}} - }, - { - full_name='statusline', abbreviation='stl', - short_desc=N_("custom format for the status line"), - type='string', scope={'global', 'window'}, - vi_def=true, - alloced=true, - modelineexpr=true, - redraw={'statuslines'}, - varname='p_stl', - defaults={if_true={vi=""}} - }, - { - full_name='suffixes', abbreviation='su', - short_desc=N_("suffixes that are ignored with multiple match"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_su', - defaults={if_true={vi=".bak,~,.o,.h,.info,.swp,.obj"}} - }, - { - full_name='suffixesadd', abbreviation='sua', - short_desc=N_("suffixes added when searching for a file"), - type='string', list='onecomma', scope={'buffer'}, - deny_duplicates=true, - vi_def=true, - alloced=true, - varname='p_sua', - defaults={if_true={vi=""}} - }, - { - full_name='swapfile', abbreviation='swf', - short_desc=N_("whether to use a swapfile for a buffer"), - type='bool', scope={'buffer'}, - vi_def=true, - redraw={'statuslines'}, - varname='p_swf', - defaults={if_true={vi=true}} - }, - { - full_name='switchbuf', abbreviation='swb', - short_desc=N_("sets behavior when switching to another buffer"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_swb', - defaults={if_true={vi=""}} - }, - { - full_name='synmaxcol', abbreviation='smc', - short_desc=N_("maximum column to find syntax items"), - type='number', scope={'buffer'}, - vi_def=true, - redraw={'current_buffer'}, - varname='p_smc', - defaults={if_true={vi=3000}} - }, - { - full_name='syntax', abbreviation='syn', - short_desc=N_("syntax to be loaded for current buffer"), - type='string', scope={'buffer'}, - noglob=true, - normal_fname_chars=true, - vi_def=true, - alloced=true, - varname='p_syn', - defaults={if_true={vi=""}} - }, - { - full_name='tagfunc', abbreviation='tfu', - short_desc=N_("function used to perform tag searches"), - type='string', scope={'buffer'}, - vim=true, - vi_def=true, - varname='p_tfu', - defaults={if_true={vi=""}} - }, - { - full_name='tabline', abbreviation='tal', - short_desc=N_("custom format for the console tab pages line"), - type='string', scope={'global'}, - vi_def=true, - modelineexpr=true, - redraw={'all_windows'}, - varname='p_tal', - defaults={if_true={vi=""}} - }, - { - full_name='tabpagemax', abbreviation='tpm', - short_desc=N_("maximum number of tab pages for |-p| and \"tab all\""), - type='number', scope={'global'}, - vim=true, - varname='p_tpm', - defaults={if_true={vi=10, vim=50}} - }, - { - full_name='tabstop', abbreviation='ts', - short_desc=N_("number of spaces that in file uses"), - type='number', scope={'buffer'}, - vi_def=true, - redraw={'current_buffer'}, - varname='p_ts', - defaults={if_true={vi=8}} - }, - { - full_name='tagbsearch', abbreviation='tbs', - short_desc=N_("use binary searching in tags files"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_tbs', - defaults={if_true={vi=true}} - }, - { - full_name='tagcase', abbreviation='tc', - short_desc=N_("how to handle case when searching in tags files"), - type='string', scope={'global', 'buffer'}, - vim=true, - varname='p_tc', - defaults={if_true={vi="followic", vim="followic"}} - }, - { - full_name='taglength', abbreviation='tl', - short_desc=N_("number of significant characters for a tag"), - type='number', scope={'global'}, - vi_def=true, - varname='p_tl', - defaults={if_true={vi=0}} - }, - { - full_name='tagrelative', abbreviation='tr', - short_desc=N_("file names in tag file are relative"), - type='bool', scope={'global'}, - vim=true, - varname='p_tr', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='tags', abbreviation='tag', - short_desc=N_("list of file names used by the tag command"), - type='string', list='onecomma', scope={'global', 'buffer'}, - deny_duplicates=true, - vi_def=true, - expand=true, - varname='p_tags', - defaults={if_true={vi="./tags;,tags"}} - }, - { - full_name='tagstack', abbreviation='tgst', - short_desc=N_("push tags onto the tag stack"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_tgst', - defaults={if_true={vi=true}} - }, - { - full_name='termbidi', abbreviation='tbidi', - short_desc=N_("terminal takes care of bi-directionality"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_tbidi', - defaults={if_true={vi=false}} - }, - { - full_name='termencoding', abbreviation='tenc', - short_desc=N_("Terminal encodig"), - type='string', scope={'global'}, - vi_def=true, - defaults={if_true={vi=""}} - }, - { - full_name='termguicolors', abbreviation='tgc', - short_desc=N_("Terminal true color support"), - type='bool', scope={'global'}, - vi_def=false, - redraw={'ui_option'}, - varname='p_tgc', - defaults={if_true={vi=false}} - }, - { - full_name='terse', - short_desc=N_("hides notification of search wrap"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_terse', - defaults={if_true={vi=false}} - }, - { - full_name='textwidth', abbreviation='tw', - short_desc=N_("maximum width of text that is being inserted"), - type='number', scope={'buffer'}, - vi_def=true, - vim=true, - redraw={'current_buffer'}, - varname='p_tw', - defaults={if_true={vi=0}} - }, - { - full_name='thesaurus', abbreviation='tsr', - short_desc=N_("list of thesaurus files for keyword completion"), - type='string', list='onecomma', scope={'global', 'buffer'}, - deny_duplicates=true, - normal_dname_chars=true, - vi_def=true, - expand=true, - varname='p_tsr', - defaults={if_true={vi=""}} - }, - { - full_name='tildeop', abbreviation='top', - short_desc=N_("tilde command \"~\" behaves like an operator"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_to', - defaults={if_true={vi=false}} - }, - { - full_name='timeout', abbreviation='to', - short_desc=N_("time out on mappings and key codes"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_timeout', - defaults={if_true={vi=true}} - }, - { - full_name='timeoutlen', abbreviation='tm', - short_desc=N_("time out time in milliseconds"), - type='number', scope={'global'}, - vi_def=true, - varname='p_tm', - defaults={if_true={vi=1000}} - }, - { - full_name='title', - short_desc=N_("Vim set the title of the window"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_title', - defaults={if_true={vi=false}} - }, - { - full_name='titlelen', - short_desc=N_("of 'columns' used for window title"), - type='number', scope={'global'}, - vi_def=true, - varname='p_titlelen', - defaults={if_true={vi=85}} - }, - { - full_name='titleold', - short_desc=N_("title, restored when exiting"), - type='string', scope={'global'}, - secure=true, - no_mkrc=true, - vi_def=true, - varname='p_titleold', - defaults={if_true={vi=""}} - }, - { - full_name='titlestring', - short_desc=N_("to use for the Vim window title"), - type='string', scope={'global'}, - vi_def=true, - modelineexpr=true, - varname='p_titlestring', - defaults={if_true={vi=""}} - }, - { - full_name='ttimeout', - short_desc=N_("out on mappings"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_ttimeout', - defaults={if_true={vi=true}} - }, - { - full_name='ttimeoutlen', abbreviation='ttm', - short_desc=N_("time out time for key codes in milliseconds"), - type='number', scope={'global'}, - vi_def=true, - varname='p_ttm', - defaults={if_true={vi=50}} - }, - { - full_name='ttyfast', abbreviation='tf', - short_desc=N_("No description"), - type='bool', scope={'global'}, - no_mkrc=true, - vi_def=true, - varname='p_force_on', - defaults={if_true={vi=true}} - }, - { - full_name='undodir', abbreviation='udir', - short_desc=N_("where to store undo files"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - secure=true, - vi_def=true, - expand='nodefault', - varname='p_udir', - defaults={if_true={vi=''}} - }, - { - full_name='undofile', abbreviation='udf', - short_desc=N_("save undo information in a file"), - type='bool', scope={'buffer'}, - vi_def=true, - vim=true, - varname='p_udf', - defaults={if_true={vi=false}} - }, - { - full_name='undolevels', abbreviation='ul', - short_desc=N_("maximum number of changes that can be undone"), - type='number', scope={'global', 'buffer'}, - vi_def=true, - varname='p_ul', - defaults={if_true={vi=1000}} - }, - { - full_name='undoreload', abbreviation='ur', - short_desc=N_("max nr of lines to save for undo on a buffer reload"), - type='number', scope={'global'}, - vi_def=true, - varname='p_ur', - defaults={if_true={vi=10000}} - }, - { - full_name='updatecount', abbreviation='uc', - short_desc=N_("after this many characters flush swap file"), - type='number', scope={'global'}, - vi_def=true, - varname='p_uc', - defaults={if_true={vi=200}} - }, - { - full_name='updatetime', abbreviation='ut', - short_desc=N_("after this many milliseconds flush swap file"), - type='number', scope={'global'}, - vi_def=true, - varname='p_ut', - defaults={if_true={vi=4000}} - }, - { - full_name='verbose', abbreviation='vbs', - short_desc=N_("give informative messages"), - type='number', scope={'global'}, - vi_def=true, - varname='p_verbose', - defaults={if_true={vi=0}} - }, - { - full_name='verbosefile', abbreviation='vfile', - short_desc=N_("file to write messages in"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand=true, - varname='p_vfile', - defaults={if_true={vi=""}} - }, - { - full_name='viewdir', abbreviation='vdir', - short_desc=N_("directory where to store files with :mkview"), - type='string', scope={'global'}, - secure=true, - vi_def=true, - expand='nodefault', - varname='p_vdir', - defaults={if_true={vi=''}} - }, - { - full_name='viewoptions', abbreviation='vop', - short_desc=N_("specifies what to save for :mkview"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_vop', - defaults={if_true={vi="folds,options,cursor,curdir"}} - }, - { - -- Alias for "shada". - full_name='viminfo', abbreviation='vi', - short_desc=N_("Alias for shada"), - type='string', scope={'global'}, nodefault=true, - }, - { - -- Alias for "shadafile". - full_name='viminfofile', abbreviation='vif', - short_desc=N_("Alias for shadafile instead"), - type='string', scope={'global'}, nodefault=true, - }, - { - full_name='virtualedit', abbreviation='ve', - short_desc=N_("when to use virtual editing"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - vim=true, - redraw={'curswant'}, - varname='p_ve', - defaults={if_true={vi="", vim=""}} - }, - { - full_name='visualbell', abbreviation='vb', - short_desc=N_("use visual bell instead of beeping"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_vb', - defaults={if_true={vi=false}} - }, - { - full_name='warn', - short_desc=N_("for shell command when buffer was changed"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_warn', - defaults={if_true={vi=true}} - }, - { - full_name='whichwrap', abbreviation='ww', - short_desc=N_("allow specified keys to cross line boundaries"), - type='string', list='flagscomma', scope={'global'}, - vim=true, - varname='p_ww', - defaults={if_true={vi="", vim="b,s"}} - }, - { - full_name='wildchar', abbreviation='wc', - short_desc=N_("command-line character for wildcard expansion"), - type='number', scope={'global'}, - vim=true, - varname='p_wc', - defaults={if_true={vi=imacros('Ctrl_E'), vim=imacros('TAB')}} - }, - { - full_name='wildcharm', abbreviation='wcm', - short_desc=N_("like 'wildchar' but also works when mapped"), - type='number', scope={'global'}, - vi_def=true, - varname='p_wcm', - defaults={if_true={vi=0}} - }, - { - full_name='wildignore', abbreviation='wig', - short_desc=N_("files matching these patterns are not completed"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vi_def=true, - varname='p_wig', - defaults={if_true={vi=""}} - }, - { - full_name='wildignorecase', abbreviation='wic', - short_desc=N_("ignore case when completing file names"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_wic', - defaults={if_true={vi=false}} - }, - { - full_name='wildmenu', abbreviation='wmnu', - short_desc=N_("use menu for command line completion"), - type='bool', scope={'global'}, - vim=true, - varname='p_wmnu', - defaults={if_true={vi=false, vim=true}} - }, - { - full_name='wildmode', abbreviation='wim', - short_desc=N_("mode for 'wildchar' command-line expansion"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vim=true, - varname='p_wim', - defaults={if_true={vi="", vim="full"}} - }, - { - full_name='wildoptions', abbreviation='wop', - short_desc=N_("specifies how command line completion is done"), - type='string', list='onecomma', scope={'global'}, - deny_duplicates=true, - vim=true, - varname='p_wop', - defaults={if_true={vi='', vim='pum,tagfile'}} - }, - { - full_name='winaltkeys', abbreviation='wak', - short_desc=N_("when the windows system handles ALT keys"), - type='string', scope={'global'}, - vi_def=true, - varname='p_wak', - defaults={if_true={vi="menu"}} - }, - { - full_name='winblend', abbreviation='winbl', - short_desc=N_("Controls transparency level for floating windows"), - type='number', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=0}} - }, - { - full_name='winhighlight', abbreviation='winhl', - short_desc=N_("Setup window-local highlights"); - type='string', scope={'window'}, - vi_def=true, - alloced=true, - redraw={'current_window'}, - defaults={if_true={vi=""}} - }, - { - full_name='window', abbreviation='wi', - short_desc=N_("nr of lines to scroll for CTRL-F and CTRL-B"), - type='number', scope={'global'}, - vi_def=true, - varname='p_window', - defaults={if_true={vi=0}} - }, - { - full_name='winheight', abbreviation='wh', - short_desc=N_("minimum number of lines for the current window"), - type='number', scope={'global'}, - vi_def=true, - varname='p_wh', - defaults={if_true={vi=1}} - }, - { - full_name='winfixheight', abbreviation='wfh', - short_desc=N_("keep window height when opening/closing windows"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'statuslines'}, - defaults={if_true={vi=false}} - }, - { - full_name='winfixwidth', abbreviation='wfw', - short_desc=N_("keep window width when opening/closing windows"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'statuslines'}, - defaults={if_true={vi=false}} - }, - { - full_name='winminheight', abbreviation='wmh', - short_desc=N_("minimum number of lines for any window"), - type='number', scope={'global'}, - vi_def=true, - varname='p_wmh', - defaults={if_true={vi=1}} - }, - { - full_name='winminwidth', abbreviation='wmw', - short_desc=N_("minimal number of columns for any window"), - type='number', scope={'global'}, - vi_def=true, - varname='p_wmw', - defaults={if_true={vi=1}} - }, - { - full_name='winwidth', abbreviation='wiw', - short_desc=N_("minimal number of columns for current window"), - type='number', scope={'global'}, - vi_def=true, - varname='p_wiw', - defaults={if_true={vi=20}} - }, - { - full_name='wrap', - short_desc=N_("lines wrap and continue on the next line"), - type='bool', scope={'window'}, - vi_def=true, - redraw={'current_window'}, - defaults={if_true={vi=true}} - }, - { - full_name='wrapmargin', abbreviation='wm', - short_desc=N_("chars from the right where wrapping starts"), - type='number', scope={'buffer'}, - vi_def=true, - varname='p_wm', - defaults={if_true={vi=0}} - }, - { - full_name='wrapscan', abbreviation='ws', - short_desc=N_("searches wrap around the end of the file"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_ws', - defaults={if_true={vi=true}} - }, - { - full_name='write', - short_desc=N_("to a file is allowed"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_write', - defaults={if_true={vi=true}} - }, - { - full_name='writeany', abbreviation='wa', - short_desc=N_("write to file with no need for \"!\" override"), - type='bool', scope={'global'}, - vi_def=true, - varname='p_wa', - defaults={if_true={vi=false}} - }, - { - full_name='writebackup', abbreviation='wb', - short_desc=N_("make a backup before overwriting a file"), - type='bool', scope={'global'}, - vi_def=true, - vim=true, - varname='p_wb', - defaults={if_true={vi=true}} - }, - { - full_name='writedelay', abbreviation='wd', - short_desc=N_("delay this many msec for each char (for debug)"), - type='number', scope={'global'}, - vi_def=true, - varname='p_wd', - defaults={if_true={vi=0}} - }, - } -} diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 1f6612a..8fdde84 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -569,17 +569,20 @@ internal.search_history = function(opts) end internal.vim_options = function(opts) - -- Load vim options. - local vim_opts = loadfile(Path:new({ utils.data_directory(), "options", "options.lua" }):absolute())().options + local res = {} + for _, v in pairs(vim.api.nvim_get_all_options_info()) do + table.insert(res, v) + end + table.sort(res, function(left, right) + return left.name < right.name + end) pickers.new(opts, { prompt_title = "options", finder = finders.new_table { - results = vim_opts, + results = res, entry_maker = opts.entry_maker or make_entry.gen_from_vimoptions(opts), }, - -- TODO: previewer for Vim options - -- previewer = previewers.help.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function() actions.select_default:replace(function() @@ -591,41 +594,14 @@ internal.vim_options = function(opts) local esc = "" if vim.fn.mode() == "i" then - -- TODO: don't make this local esc = vim.api.nvim_replace_termcodes("", true, false, true) end - -- TODO: Make this actually work. - - -- actions.close(prompt_bufnr) - -- vim.api.nvim_win_set_var(vim.api.nvim_get_current_win(), "telescope", 1) - -- print(prompt_bufnr) - -- print(vim.fn.bufnr()) - -- vim.cmd([[ autocmd BufEnter ++nested ++once startinsert!]]) - -- print(vim.fn.winheight(0)) - - -- local prompt_winnr = vim.fn.getbufinfo(prompt_bufnr)[1].windows[1] - -- print(prompt_winnr) - - -- local float_opts = {} - -- float_opts.relative = "editor" - -- float_opts.anchor = "sw" - -- float_opts.focusable = false - -- float_opts.style = "minimal" - -- float_opts.row = vim.api.nvim_get_option("lines") - 2 -- TODO: inc `cmdheight` and `laststatus` in this calc - -- float_opts.col = 2 - -- float_opts.height = 10 - -- float_opts.width = string.len(selection.last_set_from)+15 - -- local buf = vim.api.nvim_create_buf(false, true) - -- vim.api.nvim_buf_set_lines(buf, 0, 0, false, - -- {"default value: abcdef", "last set from: " .. selection.last_set_from}) - -- local status_win = vim.api.nvim_open_win(buf, false, float_opts) - -- -- vim.api.nvim_win_set_option(status_win, "winblend", 100) - -- vim.api.nvim_win_set_option(status_win, "winhl", "Normal:PmenuSel") - -- -- vim.api.nvim_set_current_win(status_win) - -- vim.cmd[[redraw!]] - -- vim.cmd("autocmd CmdLineLeave : ++once echom 'beep'") - vim.api.nvim_feedkeys(string.format("%s:set %s=%s", esc, selection.name, selection.current_value), "m", true) + vim.api.nvim_feedkeys( + string.format("%s:set %s=%s", esc, selection.value.name, selection.value.value), + "m", + true + ) end) return true diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 703a00a..3280f2a 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -811,67 +811,6 @@ function make_entry.gen_from_buffer_lines(opts) end function make_entry.gen_from_vimoptions() - local process_one_opt = function(o) - local ok, value_origin - - local option = { - name = "", - description = "", - current_value = "", - default_value = "", - value_type = "", - set_by_user = false, - last_set_from = "", - } - - local is_global = false - for _, v in ipairs(o.scope) do - if v == "global" then - is_global = true - end - end - - if not is_global then - return - end - - if is_global then - option.name = o.full_name - - ok, option.current_value = pcall(vim.api.nvim_get_option, o.full_name) - if not ok then - return - end - - local str_funcname = o.short_desc() - option.description = assert(loadstring(str_funcname))() - -- if #option.description > opts.desc_col_length then - -- opts.desc_col_length = #option.description - -- end - - if o.defaults ~= nil then - option.default_value = o.defaults.if_true.vim or o.defaults.if_true.vi - end - - if type(option.default_value) == "function" then - option.default_value = "Macro: " .. option.default_value() - end - - option.value_type = (type(option.current_value) == "boolean" and "bool" or type(option.current_value)) - - if option.current_value ~= option.default_value then - option.set_by_user = true - value_origin = vim.fn.execute("verbose set " .. o.full_name .. "?") - if string.match(value_origin, "Last set from") then - -- TODO: parse file and line number as separate items - option.last_set_from = value_origin:gsub("^.*Last set from ", "") - end - end - - return option - end - end - local displayer = entry_display.create { separator = "", hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" }, @@ -884,25 +823,27 @@ function make_entry.gen_from_vimoptions() local make_display = function(entry) return displayer { - { entry.name, "Keyword" }, - { "[" .. entry.value_type .. "]", "Type" }, - utils.display_termcodes(tostring(entry.current_value)), - entry.description, + { entry.value.name, "Keyword" }, + { "[" .. entry.value.type .. "]", "Type" }, + utils.display_termcodes(tostring(entry.value.value)), } end - return function(line) - local entry = process_one_opt(line) - if not entry then - return - end + return function(o) + local entry = { + display = make_display, + value = { + name = o.name, + value = o.default, + type = o.type, + }, + ordinal = o.name, + } - entry.valid = true - entry.display = make_display - entry.value = line - entry.ordinal = line.full_name - -- entry.raw_value = d.raw_value - -- entry.last_set_from = d.last_set_from + local ok, value = pcall(vim.api.nvim_get_option, o.name) + if ok then + entry.value.value = value + end return entry end From edc6f55ba2565930310542b3023f00e88dd3e6a8 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 22 May 2022 11:32:55 +0200 Subject: [PATCH 03/35] docs: document limitations of file_ignore_patterns and transform_path (#1955) --- doc/telescope.txt | 44 ++++++++++++++++++++++++++++++++++++++++ lua/telescope/config.lua | 11 ++++++++++ lua/telescope/utils.lua | 17 ++++++++++++++++ scripts/gendocs.lua | 1 + 4 files changed, 73 insertions(+) diff --git a/doc/telescope.txt b/doc/telescope.txt index b79006b..0b769ee 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -655,6 +655,17 @@ telescope.setup({opts}) *telescope.setup()* Example: { "%.npz" } -- ignore all npz files See: https://www.lua.org/manual/5.1/manual.html#5.4.1 for more information about lua regex + Note: `file_ignore_patterns` will be used in all pickers that have a + file associated. This might lead to the problem that lsp_ pickers + aren't displaying results because they might be ignored by + `file_ignore_patterns`. For example, setting up node_modules as ignored + will never show node_modules in any results, even if you are + interested in lsp_ results. + + If you only want `file_ignore_patterns` for `find_files` and + `grep_string`/`live_grep` it is suggested that you setup `gitignore` + and have fd and or ripgrep installed because both tools will not show + `gitignore`d files on default. Default: nil @@ -1944,6 +1955,39 @@ resolver.resolve_anchor_pos() *telescope.resolve.resolve_anchor_pos()* +================================================================================ + *telescope.utils* + +Utilities for writing telescope pickers + +utils.transform_path({opts}, {path}) *telescope.utils.transform_path()* + Transform path is a util function that formats a path based on path_display + found in `opts` or the default value from config. It is meant to be used in + make_entry to have a uniform interface for builtins as well as extensions + utilizing the same user configuration Note: It is only supported inside + `make_entry`/`make_display` the use of this function outside of telescope + might yield to undefined behavior and will not be addressed by us + + + Parameters: ~ + {opts} (table) The opts the users passed into the picker. Might + contains a path_display key + {path} (string) The path that should be formated + + Return: ~ + string: The transformed path ready to be displayed + + +utils.notify({funname}, {opts}) *telescope.utils.notify()* + Telescope Wrapper around vim.notify + + + Parameters: ~ + {funname} (string) name of the function that will be + {opts} (table) opts.level string, opts.msg string, opts.once bool + + + ================================================================================ *telescope.actions* diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index f5cc3c6..88f8a59 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -783,6 +783,17 @@ append( Example: { "%.npz" } -- ignore all npz files See: https://www.lua.org/manual/5.1/manual.html#5.4.1 for more information about lua regex + Note: `file_ignore_patterns` will be used in all pickers that have a + file associated. This might lead to the problem that lsp_ pickers + aren't displaying results because they might be ignored by + `file_ignore_patterns`. For example, setting up node_modules as ignored + will never show node_modules in any results, even if you are + interested in lsp_ results. + + If you only want `file_ignore_patterns` for `find_files` and + `grep_string`/`live_grep` it is suggested that you setup `gitignore` + and have fd and or ripgrep installed because both tools will not show + `gitignore`d files on default. Default: nil]] ) diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 2a8de58..7692409 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -1,3 +1,10 @@ +---@tag telescope.utils +---@config { ["module"] = "telescope.utils" } + +---@brief [[ +--- Utilities for writing telescope pickers +---@brief ]] + local Path = require "plenary.path" local Job = require "plenary.job" @@ -210,6 +217,16 @@ local calc_result_length = function(truncate_len) return type(truncate_len) == "number" and len - truncate_len or len end +--- Transform path is a util function that formats a path based on path_display +--- found in `opts` or the default value from config. +--- It is meant to be used in make_entry to have a uniform interface for +--- builtins as well as extensions utilizing the same user configuration +--- Note: It is only supported inside `make_entry`/`make_display` the use of +--- this function outside of telescope might yield to undefined behavior and will +--- not be addressed by us +---@param opts table: The opts the users passed into the picker. Might contains a path_display key +---@param path string: The path that should be formated +---@return string: The transformed path ready to be displayed utils.transform_path = function(opts, path) if path == nil then return diff --git a/scripts/gendocs.lua b/scripts/gendocs.lua index 7016147..524cb04 100644 --- a/scripts/gendocs.lua +++ b/scripts/gendocs.lua @@ -17,6 +17,7 @@ docs.test = function() "./lua/telescope/themes.lua", "./lua/telescope/pickers/layout_strategies.lua", "./lua/telescope/config/resolve.lua", + "./lua/telescope/utils.lua", "./lua/telescope/actions/init.lua", "./lua/telescope/actions/state.lua", "./lua/telescope/actions/set.lua", From 7648e5d8914ecc65346ce7d1c49e1a5fe2979564 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 22 May 2022 11:36:56 +0200 Subject: [PATCH 04/35] chore: remove media and scratch directory --- media/demo_script.lua | 47 ----------------------- media/demo_script_2.lua | 30 --------------- media/simple_rg_example.hnt | 34 ----------------- media/worflow.txt | 26 ------------- scratch/batched_finder_and_sorter.lua | 55 --------------------------- scratch/piped_to_fzf.lua | 33 ---------------- scratch/slow_proc.sh | 11 ------ 7 files changed, 236 deletions(-) delete mode 100644 media/demo_script.lua delete mode 100644 media/demo_script_2.lua delete mode 100644 media/simple_rg_example.hnt delete mode 100644 media/worflow.txt delete mode 100644 scratch/batched_finder_and_sorter.lua delete mode 100644 scratch/piped_to_fzf.lua delete mode 100755 scratch/slow_proc.sh diff --git a/media/demo_script.lua b/media/demo_script.lua deleted file mode 100644 index 8074523..0000000 --- a/media/demo_script.lua +++ /dev/null @@ -1,47 +0,0 @@ -local finders = require('telescope.finders') -local previewers = require('telescope.previewers') -local pickers = require('telescope.pickers') -local sorters = require('telescope.sorters') - --- Get all the items from v:oldfiles that are valid files -local valid_oldfiles = vim.tbl_filter(function(val) - return 0 ~= vim.fn.filereadable(val) -end, vim.v.oldfiles) - --- print(vim.inspect(valid_oldfiles)) --- => { --- "/home/tj/blah.txt", --- "/home/tj/another_dir/file.py", --- ... --- } - --- Create a finder from a Lua list. -local oldfiles_finder = finders.new_table(valid_oldfiles) - --- Get a pre-defined sorter. --- Sorters return a "score" for each "Entry" found by a finder. --- --- This sorter is optimized to best find files in a fuzzy manner. -local oldfiles_sorter = sorters.get_fuzzy_file() - --- Get a pre-defined previewer. --- Previewers take the currently selected entry, --- and put a preview of it in a floating window -local oldfiles_previewer = previewers.cat - --- Create and run a Picker. --- Pickers are the main entry point to telescope. --- They manage the interactions between: --- Finder, --- Sorter, --- Previewer --- --- And provide the UI for the user. -pickers.new { - prompt = 'Oldfiles', - finder = oldfiles_finder, - sorter = oldfiles_sorter, - previewer = oldfiles_previewer, -}:find() - - diff --git a/media/demo_script_2.lua b/media/demo_script_2.lua deleted file mode 100644 index 9394ffc..0000000 --- a/media/demo_script_2.lua +++ /dev/null @@ -1,30 +0,0 @@ -local finders = require('telescope.finders') -local previewers = require('telescope.previewers') -local pickers = require('telescope.pickers') - --- Create a new finder. --- This finder, rather than taking a Lua list, --- generates a shell command that should be run. --- --- Each line of the shell command is converted to an entry, --- and is possible to preview with builtin previews. --- --- In this example, we use ripgrep to search over your entire directory --- live as you type. -local live_grepper = finders.new_job(function(prompt) - if not prompt or prompt == "" then - return nil - end - - return { 'rg', "--vimgrep", prompt} -end) - --- Create and run the Picker. --- --- NOTE: No sorter is needed to be passed. --- Results will be returned in the order they are received. -pickers.new({ - prompt = 'Live Grep', - finder = live_grepper, - previewer = previewers.vimgrep, -}):find() diff --git a/media/simple_rg_example.hnt b/media/simple_rg_example.hnt deleted file mode 100644 index a007479..0000000 --- a/media/simple_rg_example.hnt +++ /dev/null @@ -1,34 +0,0 @@ -### Simple demo to show the rg stuff -## key_delay 1 -## feed_full - -:e! ./scratch/simple_rg.lua\ -:set foldlevel=100\ -:luafile %\ - -## pause -## key_delay 80 - -Finder - -## key_delay 150 - -\ - -## pause -\ - -## pause -\ - -## pause -\ - -## pause -\ -:" Went to the file!\ - -## pause - -## feed_full -:qa!\ diff --git a/media/worflow.txt b/media/worflow.txt deleted file mode 100644 index e12d7ec..0000000 --- a/media/worflow.txt +++ /dev/null @@ -1,26 +0,0 @@ -+-------------------------------------------------------------------+ -| Picker:find()--------------------+ +------>Picker | -| | ^ | | | -| | | v | | -| | +----------------+ +----------------+ | -| +->| Finder + | Sorter | | -| +----------------+ +----------------+ | -| [1] | -| | -| | -| | -| | -| | -| | -+-------------------------------------------------------------------+ - -Picker starts a `finder`. - Finder returns a list of `entries` to Picker. - Picker can optionally sort w/ `Sorter`. - Picker can optionally preview selected with `Previewer` - - Then you can map stuff in the picker to decide what to do next. - - - - diff --git a/scratch/batched_finder_and_sorter.lua b/scratch/batched_finder_and_sorter.lua deleted file mode 100644 index c3e188b..0000000 --- a/scratch/batched_finder_and_sorter.lua +++ /dev/null @@ -1,55 +0,0 @@ -local actions = require('telescope.actions') -local finders = require('telescope.finders') -local previewers = require('telescope.previewers') -local pickers = require('telescope.pickers') -local sorters = require('telescope.sorters') -local utils = require('telescope.utils') - -local Job = require('plenary.job') - --- local live_grepper = finders.new { --- fn_command = function(_, prompt) --- -- TODO: Make it so that we can start searching on the first character. --- if not prompt or prompt == "" then --- return nil --- end - --- return { --- command = 'rg', --- args = {"--vimgrep", prompt}, --- } --- end --- } - -local f = function(prompt, process_result, process_complete) - local fzf = Job:new { - command = 'fzf'; - - writer = Job:new { - command = "fdfind", - args = nil, - cwd = "/home/tj/build/neovim", - - enable_handlers = false, - }, - - -- Still doesn't work if you don't pass these args and just run `fzf` - args = {'--no-sort', '--filter', prompt}; - } - - - local start = vim.fn.reltime() - print(vim.inspect(fzf:sync()), vim.fn.reltimestr(vim.fn.reltime(start))) -end - - --- Process all the files --- f("", nil, nil) --- Filter on nvimexec -f("nvim/executor", nil, nil) - --- pickers.new({}, { --- prompt = 'Live Grep', --- finder = f, --- previewer = previewers.vimgrep, --- }):find() diff --git a/scratch/piped_to_fzf.lua b/scratch/piped_to_fzf.lua deleted file mode 100644 index 98577bd..0000000 --- a/scratch/piped_to_fzf.lua +++ /dev/null @@ -1,33 +0,0 @@ -RELOAD('telescope') -RELOAD('plenary') - -local finders = require('telescope.finders') -local make_entry = require('telescope.make_entry') -local pickers = require('telescope.pickers') -local sorters = require('telescope.sorters') - -local Job = require('plenary.job') - -pickers.new { - prompt = "Piped FZF", - - finder = finders._new { - fn_command = function(_, prompt) - return { - command = 'fzf', - args = {'--no-sort', '--filter', prompt or ''}, - - writer = Job:new { - command = 'rg', - args = {'--files'}, - cwd = '/home/tj/', - - enable_handlers = false, - }, - } - end, - - entry_maker = make_entry.gen_from_file(), - sorter = sorters.get_fuzzy_file(), - }, -}:find() diff --git a/scratch/slow_proc.sh b/scratch/slow_proc.sh deleted file mode 100755 index a43811d..0000000 --- a/scratch/slow_proc.sh +++ /dev/null @@ -1,11 +0,0 @@ - -echo "hello" -sleep 1 -echo "help" -sleep 1 -echo "hi" -sleep 1 -echo "husband" -sleep 1 -echo "helper" - From 5510587ff488e9d6dfae66ba7e19bce090633329 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 22 May 2022 11:50:00 +0200 Subject: [PATCH 05/35] feat(vim_options): show scope information in display (#1956) Also make type, scope and value searchable --- lua/telescope/make_entry.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 3280f2a..c71849d 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -817,6 +817,7 @@ function make_entry.gen_from_vimoptions() items = { { width = 25 }, { width = 12 }, + { width = 11 }, { remaining = true }, }, } @@ -825,6 +826,7 @@ function make_entry.gen_from_vimoptions() return displayer { { entry.value.name, "Keyword" }, { "[" .. entry.value.type .. "]", "Type" }, + { "[" .. entry.value.scope .. "]", "Identifier" }, utils.display_termcodes(tostring(entry.value.value)), } end @@ -836,13 +838,17 @@ function make_entry.gen_from_vimoptions() name = o.name, value = o.default, type = o.type, + scope = o.scope, }, - ordinal = o.name, + ordinal = string.format("%s %s %s", o.name, o.type, o.scope), } local ok, value = pcall(vim.api.nvim_get_option, o.name) if ok then entry.value.value = value + entry.ordinal = entry.ordinal .. " " .. utils.display_termcodes(tostring(value)) + else + entry.ordinal = entry.ordinal .. " " .. utils.display_termcodes(tostring(o.default)) end return entry From a1aec79cb1abc5630f941bafbe83f6e00dcff316 Mon Sep 17 00:00:00 2001 From: fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> Date: Sun, 22 May 2022 12:08:07 +0200 Subject: [PATCH 06/35] feat: none strategy & control attachment (#1867) --- doc/telescope.txt | 1 + lua/telescope/config.lua | 3 ++- lua/telescope/pickers.lua | 24 +++++++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 0b769ee..43a5ccc 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -142,6 +142,7 @@ telescope.setup({opts}) *telescope.setup()* - "follow" - "row" - "closest" + - "none" *telescope.defaults.scroll_strategy* scroll_strategy: ~ diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 88f8a59..9da8b97 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -182,7 +182,8 @@ append( - "reset" (default) - "follow" - "row" - - "closest"]] + - "closest" + - "none"]] ) append( diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 12d6209..d7ee32d 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -83,6 +83,7 @@ function Picker:new(opts) _original_mode = vim.api.nvim_get_mode().mode, debounce = get_default(tonumber(opts.debounce), nil), + _finder_attached = true, default_text = opts.default_text, get_status_text = get_default(opts.get_status_text, config.values.get_status_text), _on_input_filter_cb = opts.on_input_filter_cb or function() end, @@ -505,10 +506,12 @@ function Picker:find() -- Register attach vim.api.nvim_buf_attach(prompt_bufnr, false, { on_lines = function(...) - find_id = self:_next_find_id() + if self._finder_attached then + find_id = self:_next_find_id() - status_updater { completed = false } - self._on_lines(...) + status_updater { completed = false } + self._on_lines(...) + end end, on_detach = function() @@ -1365,6 +1368,16 @@ function Picker:_do_selection(prompt) else self:set_selection(self:get_reset_row()) end + elseif selection_strategy == "none" then + if self._selection_entry then + local old_entry, old_row = self._selection_entry, self._selection_row + self:reset_selection() -- required to reset selection before updating prefix + if old_row >= 0 then + self:update_prefix(old_entry, old_row) + self.highlighter:hi_multiselect(old_row, self:is_multi_selected(old_entry)) + end + end + return else error("Unknown selection strategy: " .. selection_strategy) end @@ -1495,6 +1508,11 @@ function Picker:_reset_highlights() vim.api.nvim_buf_clear_namespace(self.results_bufnr, ns_telescope_matching, 0, -1) end +-- Toggles whether finder is attached to prompt buffer input +function Picker:_toggle_finder_attach() + self._finder_attached = not self._finder_attached +end + function Picker:_detach() self.finder:close() From 83b6cadb2c61b6eee6a8f0ec8bb4599c89b6ab57 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 22 May 2022 12:53:37 +0200 Subject: [PATCH 07/35] break: deprecate utils.get_default utils.if_nil (#1545) --- lua/telescope/actions/init.lua | 32 ++++++------- lua/telescope/builtin/files.lua | 2 +- lua/telescope/builtin/git.lua | 8 ++-- lua/telescope/builtin/internal.lua | 10 ++--- lua/telescope/builtin/lsp.lua | 2 +- lua/telescope/config.lua | 15 +++---- lua/telescope/config/resolve.lua | 8 ++-- lua/telescope/make_entry.lua | 4 +- lua/telescope/pickers.lua | 50 ++++++++++----------- lua/telescope/pickers/layout_strategies.lua | 23 +++++----- lua/telescope/sorters.lua | 2 +- lua/telescope/utils.lua | 6 ++- 12 files changed, 81 insertions(+), 81 deletions(-) diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 2c4624b..0413f33 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -1059,22 +1059,22 @@ end ---@param prompt_bufnr number: The prompt bufnr actions.which_key = function(prompt_bufnr, opts) opts = opts or {} - opts.max_height = utils.get_default(opts.max_height, 0.4) - opts.only_show_current_mode = utils.get_default(opts.only_show_current_mode, true) - opts.mode_width = utils.get_default(opts.mode_width, 1) - opts.keybind_width = utils.get_default(opts.keybind_width, 7) - opts.name_width = utils.get_default(opts.name_width, 30) - opts.line_padding = utils.get_default(opts.line_padding, 1) - opts.separator = utils.get_default(opts.separator, " -> ") - opts.close_with_action = utils.get_default(opts.close_with_action, true) - opts.normal_hl = utils.get_default(opts.normal_hl, "TelescopePrompt") - opts.border_hl = utils.get_default(opts.border_hl, "TelescopePromptBorder") - opts.winblend = utils.get_default(opts.winblend, config.values.winblend) - opts.column_padding = utils.get_default(opts.column_padding, " ") + opts.max_height = vim.F.if_nil(opts.max_height, 0.4) + opts.only_show_current_mode = vim.F.if_nil(opts.only_show_current_mode, true) + opts.mode_width = vim.F.if_nil(opts.mode_width, 1) + opts.keybind_width = vim.F.if_nil(opts.keybind_width, 7) + opts.name_width = vim.F.if_nil(opts.name_width, 30) + opts.line_padding = vim.F.if_nil(opts.line_padding, 1) + opts.separator = vim.F.if_nil(opts.separator, " -> ") + opts.close_with_action = vim.F.if_nil(opts.close_with_action, true) + opts.normal_hl = vim.F.if_nil(opts.normal_hl, "TelescopePrompt") + opts.border_hl = vim.F.if_nil(opts.border_hl, "TelescopePromptBorder") + opts.winblend = vim.F.if_nil(opts.winblend, config.values.winblend) + opts.column_padding = vim.F.if_nil(opts.column_padding, " ") -- Assigning into 'opts.column_indent' would override a number with a string and -- cause issues with subsequent calls, keep a local copy of the string instead - local column_indent = table.concat(utils.repeated_table(utils.get_default(opts.column_indent, 4), " ")) + local column_indent = table.concat(utils.repeated_table(vim.F.if_nil(opts.column_indent, 4), " ")) -- close on repeated keypress local km_bufs = (function() @@ -1111,9 +1111,9 @@ actions.which_key = function(prompt_bufnr, opts) local make_display = function(mapping) return displayer { - { mapping.mode, utils.get_default(opts.mode_hl, "TelescopeResultsConstant") }, - { mapping.keybind, utils.get_default(opts.keybind_hl, "TelescopeResultsVariable") }, - { mapping.name, utils.get_default(opts.name_hl, "TelescopeResultsFunction") }, + { mapping.mode, vim.F.if_nil(opts.mode_hl, "TelescopeResultsConstant") }, + { mapping.keybind, vim.F.if_nil(opts.keybind_hl, "TelescopeResultsVariable") }, + { mapping.name, vim.F.if_nil(opts.name_hl, "TelescopeResultsFunction") }, } end diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 3d4b1bf..3ebcdf4 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -272,7 +272,7 @@ end -- TODO: finish docs for opts.show_line files.treesitter = function(opts) - opts.show_line = utils.get_default(opts.show_line, true) + opts.show_line = vim.F.if_nil(opts.show_line, true) local has_nvim_treesitter, _ = pcall(require, "nvim-treesitter") if not has_nvim_treesitter then diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index caff989..74b7df9 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -22,8 +22,8 @@ git.files = function(opts) return end - local show_untracked = utils.get_default(opts.show_untracked, false) - local recurse_submodules = utils.get_default(opts.recurse_submodules, false) + local show_untracked = vim.F.if_nil(opts.show_untracked, false) + local recurse_submodules = vim.F.if_nil(opts.recurse_submodules, false) if show_untracked and recurse_submodules then utils.notify("builtin.git_files", { msg = "Git does not support both --others and --recurse-submodules", @@ -317,7 +317,7 @@ git.status = function(opts) end local gen_new_finder = function() - local expand_dir = utils.if_nil(opts.expand_dir, true, opts.expand_dir) + local expand_dir = vim.F.if_nil(opts.expand_dir, true) local git_cmd = { "git", "status", "-s", "--", "." } if expand_dir then @@ -374,7 +374,7 @@ local set_opts_cwd = function(opts) -- Find root of git directory and remove trailing newline characters local git_root, ret = utils.get_os_command_output({ "git", "rev-parse", "--show-toplevel" }, opts.cwd) - local use_git_root = utils.get_default(opts.use_git_root, true) + local use_git_root = vim.F.if_nil(opts.use_git_root, true) if ret ~= 0 then local in_worktree = utils.get_os_command_output({ "git", "rev-parse", "--is-inside-work-tree" }, opts.cwd) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 8fdde84..4f5ce4f 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -32,7 +32,7 @@ end local internal = {} internal.builtin = function(opts) - opts.include_extensions = utils.get_default(opts.include_extensions, false) + opts.include_extensions = vim.F.if_nil(opts.include_extensions, false) local objs = {} @@ -464,7 +464,7 @@ end internal.oldfiles = function(opts) opts = apply_cwd_only_aliases(opts) - opts.include_current_session = utils.get_default(opts.include_current_session, true) + opts.include_current_session = vim.F.if_nil(opts.include_current_session, true) local current_buffer = vim.api.nvim_get_current_buf() local current_file = vim.api.nvim_buf_get_name(current_buffer) @@ -610,8 +610,8 @@ internal.vim_options = function(opts) end internal.help_tags = function(opts) - opts.lang = utils.get_default(opts.lang, vim.o.helplang) - opts.fallback = utils.get_default(opts.fallback, true) + opts.lang = vim.F.if_nil(opts.lang, vim.o.helplang) + opts.fallback = vim.F.if_nil(opts.fallback, true) opts.file_ignore_patterns = {} local langs = vim.split(opts.lang, ",", true) @@ -714,7 +714,7 @@ internal.help_tags = function(opts) end internal.man_pages = function(opts) - opts.sections = utils.get_default(opts.sections, { "1" }) + opts.sections = vim.F.if_nil(opts.sections, { "1" }) assert(vim.tbl_islist(opts.sections), "sections should be a list") opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function() local is_darwin = vim.loop.os_uname().sysname == "Darwin" diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 2ec9f2d..46757fc 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -186,7 +186,7 @@ lsp.workspace_symbols = function(opts) return end - opts.ignore_filename = utils.get_default(opts.ignore_filename, false) + opts.ignore_filename = vim.F.if_nil(opts.ignore_filename, false) pickers.new(opts, { prompt_title = "LSP Workspace Symbols", diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 9da8b97..c5a9ebf 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -1,7 +1,6 @@ local strings = require "plenary.strings" local deprecated = require "telescope.deprecated" local sorters = require "telescope.sorters" -local if_nil = vim.F.if_nil local os_sep = require("plenary.path").path.sep local has_win = vim.fn.has "win32" == 1 @@ -69,7 +68,7 @@ config.descriptions = {} config.pickers = _TelescopeConfigurationPickers function config.set_pickers(pickers) - pickers = if_nil(pickers, {}) + pickers = vim.F.if_nil(pickers, {}) for k, v in pairs(pickers) do config.pickers[k] = v @@ -877,8 +876,8 @@ append( -- @param tele_defaults table: (optional) a table containing all of the defaults -- for telescope [defaults to `telescope_defaults`] function config.set_defaults(user_defaults, tele_defaults) - user_defaults = if_nil(user_defaults, {}) - tele_defaults = if_nil(tele_defaults, telescope_defaults) + user_defaults = vim.F.if_nil(user_defaults, {}) + tele_defaults = vim.F.if_nil(tele_defaults, telescope_defaults) -- Check if using layout keywords outside of `layout_config` deprecated.options(user_defaults) @@ -886,8 +885,8 @@ function config.set_defaults(user_defaults, tele_defaults) local function get(name, default_val) if name == "layout_config" then return smarter_depth_2_extend( - if_nil(user_defaults[name], {}), - vim.tbl_deep_extend("keep", if_nil(config.values[name], {}), if_nil(default_val, {})) + vim.F.if_nil(user_defaults[name], {}), + vim.tbl_deep_extend("keep", vim.F.if_nil(config.values[name], {}), vim.F.if_nil(default_val, {})) ) end if name == "history" or name == "cache_picker" or name == "preview" then @@ -896,8 +895,8 @@ function config.set_defaults(user_defaults, tele_defaults) end return smarter_depth_2_extend( - if_nil(user_defaults[name], {}), - vim.tbl_deep_extend("keep", if_nil(config.values[name], {}), if_nil(default_val, {})) + vim.F.if_nil(user_defaults[name], {}), + vim.tbl_deep_extend("keep", vim.F.if_nil(config.values[name], {}), vim.F.if_nil(default_val, {})) ) end return first_non_null(user_defaults[name], config.values[name], default_val) diff --git a/lua/telescope/config/resolve.lua b/lua/telescope/config/resolve.lua index 0c92ac6..6281a51 100644 --- a/lua/telescope/config/resolve.lua +++ b/lua/telescope/config/resolve.lua @@ -91,8 +91,6 @@ That's the next step to scrolling. --]] -local get_default = require("telescope.utils").get_default - local resolver = {} local _resolve_map = {} @@ -286,9 +284,9 @@ resolver.win_option = function(val, default) end return { - preview = get_default(val.preview, val_to_set), - results = get_default(val.results, val_to_set), - prompt = get_default(val.prompt, val_to_set), + preview = vim.F.if_nil(val.preview, val_to_set), + results = vim.F.if_nil(val.results, val_to_set), + prompt = vim.F.if_nil(val.prompt, val_to_set), } end end diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index c71849d..f4f0010 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -754,7 +754,7 @@ function make_entry.gen_from_picker(opts) return { value = entry, text = entry.prompt_title, - ordinal = string.format("%s %s", entry.prompt_title, utils.get_default(entry.default_text, "")), + ordinal = string.format("%s %s", entry.prompt_title, vim.F.if_nil(entry.default_text, "")), display = make_display, } end @@ -978,7 +978,7 @@ function make_entry.gen_from_diagnostics(opts) end)() local display_items = { - { width = utils.if_nil(signs, 8, 10) }, + { width = signs ~= nil and 10 or 8 }, { remaining = true }, } local line_width = vim.F.if_nil(opts.line_width, 0.5) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index d7ee32d..4cc1623 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -24,8 +24,6 @@ local p_window = require "telescope.pickers.window" local EntryManager = require "telescope.entry_manager" local MultiSelect = require "telescope.pickers.multi" -local get_default = utils.get_default - local truncate = require("plenary.strings").truncate local strdisplaywidth = require("plenary.strings").strdisplaywidth @@ -65,27 +63,27 @@ function Picker:new(opts) -- pcall(v.clear) -- end - local layout_strategy = get_default(opts.layout_strategy, config.values.layout_strategy) + local layout_strategy = vim.F.if_nil(opts.layout_strategy, config.values.layout_strategy) local obj = setmetatable({ - prompt_title = get_default(opts.prompt_title, config.values.prompt_title), - results_title = get_default(opts.results_title, config.values.results_title), + prompt_title = vim.F.if_nil(opts.prompt_title, config.values.prompt_title), + results_title = vim.F.if_nil(opts.results_title, config.values.results_title), -- either whats passed in by the user or whats defined by the previewer preview_title = opts.preview_title, - prompt_prefix = get_default(opts.prompt_prefix, config.values.prompt_prefix), - wrap_results = get_default(opts.wrap_results, config.values.wrap_results), - selection_caret = get_default(opts.selection_caret, config.values.selection_caret), - entry_prefix = get_default(opts.entry_prefix, config.values.entry_prefix), - multi_icon = get_default(opts.multi_icon, config.values.multi_icon), + prompt_prefix = vim.F.if_nil(opts.prompt_prefix, config.values.prompt_prefix), + wrap_results = vim.F.if_nil(opts.wrap_results, config.values.wrap_results), + selection_caret = vim.F.if_nil(opts.selection_caret, config.values.selection_caret), + entry_prefix = vim.F.if_nil(opts.entry_prefix, config.values.entry_prefix), + multi_icon = vim.F.if_nil(opts.multi_icon, config.values.multi_icon), - initial_mode = get_default(opts.initial_mode, config.values.initial_mode), + initial_mode = vim.F.if_nil(opts.initial_mode, config.values.initial_mode), _original_mode = vim.api.nvim_get_mode().mode, - debounce = get_default(tonumber(opts.debounce), nil), + debounce = vim.F.if_nil(tonumber(opts.debounce), nil), _finder_attached = true, default_text = opts.default_text, - get_status_text = get_default(opts.get_status_text, config.values.get_status_text), + get_status_text = vim.F.if_nil(opts.get_status_text, config.values.get_status_text), _on_input_filter_cb = opts.on_input_filter_cb or function() end, finder = assert(opts.finder, "Finder is required."), @@ -96,7 +94,7 @@ function Picker:new(opts) default_selection_index = opts.default_selection_index, - get_selection_window = get_default(opts.get_selection_window, config.values.get_selection_window), + get_selection_window = vim.F.if_nil(opts.get_selection_window, config.values.get_selection_window), cwd = opts.cwd, @@ -107,32 +105,32 @@ function Picker:new(opts) and opts._multi or MultiSelect:new(), - track = get_default(opts.track, false), + track = vim.F.if_nil(opts.track, false), stats = {}, attach_mappings = opts.attach_mappings, - file_ignore_patterns = get_default(opts.file_ignore_patterns, config.values.file_ignore_patterns), + file_ignore_patterns = vim.F.if_nil(opts.file_ignore_patterns, config.values.file_ignore_patterns), - scroll_strategy = get_default(opts.scroll_strategy, config.values.scroll_strategy), - sorting_strategy = get_default(opts.sorting_strategy, config.values.sorting_strategy), - tiebreak = get_default(opts.tiebreak, config.values.tiebreak), - selection_strategy = get_default(opts.selection_strategy, config.values.selection_strategy), + scroll_strategy = vim.F.if_nil(opts.scroll_strategy, config.values.scroll_strategy), + sorting_strategy = vim.F.if_nil(opts.sorting_strategy, config.values.sorting_strategy), + tiebreak = vim.F.if_nil(opts.tiebreak, config.values.tiebreak), + selection_strategy = vim.F.if_nil(opts.selection_strategy, config.values.selection_strategy), - push_cursor_on_edit = get_default(opts.push_cursor_on_edit, false), - push_tagstack_on_edit = get_default(opts.push_tagstack_on_edit, false), + push_cursor_on_edit = vim.F.if_nil(opts.push_cursor_on_edit, false), + push_tagstack_on_edit = vim.F.if_nil(opts.push_tagstack_on_edit, false), layout_strategy = layout_strategy, layout_config = config.smarter_depth_2_extend(opts.layout_config or {}, config.values.layout_config or {}), - __cycle_layout_list = get_default(opts.cycle_layout_list, config.values.cycle_layout_list), + __cycle_layout_list = vim.F.if_nil(opts.cycle_layout_list, config.values.cycle_layout_list), window = { - winblend = get_default( + winblend = vim.F.if_nil( opts.winblend, type(opts.window) == "table" and opts.window.winblend or config.values.winblend ), - border = get_default(opts.border, type(opts.window) == "table" and opts.window.border or config.values.border), - borderchars = get_default( + border = vim.F.if_nil(opts.border, type(opts.window) == "table" and opts.window.border or config.values.border), + borderchars = vim.F.if_nil( opts.borderchars, type(opts.window) == "table" and opts.window.borderchars or config.values.borderchars ), diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua index 3a84759..5e74b85 100644 --- a/lua/telescope/pickers/layout_strategies.lua +++ b/lua/telescope/pickers/layout_strategies.lua @@ -53,7 +53,6 @@ local resolve = require "telescope.config.resolve" local p_window = require "telescope.pickers.window" -local if_nil = vim.F.if_nil local get_border_size = function(opts) if opts.window.border == false then @@ -125,7 +124,7 @@ local function validate_layout_config(strategy_name, configuration, values, defa local valid_configuration_keys = get_valid_configuration_keys(configuration) -- If no default_layout_config provided, check Telescope's config values - default_layout_config = if_nil(default_layout_config, require("telescope.config").values.layout_config) + default_layout_config = vim.F.if_nil(default_layout_config, require("telescope.config").values.layout_config) local result = {} local get_value = function(k) @@ -263,7 +262,7 @@ local function make_documented_layout(name, layout_config, layout) validate_layout_config( name, layout_config, - vim.tbl_deep_extend("keep", if_nil(override_layout, {}), if_nil(self.layout_config, {})) + vim.tbl_deep_extend("keep", vim.F.if_nil(override_layout, {}), vim.F.if_nil(self.layout_config, {})) ) ) end @@ -320,7 +319,7 @@ layout_strategies.horizontal = make_documented_layout( -- Cap over/undersized width (with previewer) width, w_space = calc_size_and_spacing(width, max_columns, bs, 2, 4, 1) - preview.width = resolve.resolve_width(if_nil(layout_config.preview_width, function(_, cols) + preview.width = resolve.resolve_width(vim.F.if_nil(layout_config.preview_width, function(_, cols) if cols < 150 then return math.floor(cols * 0.4) elseif cols < 200 then @@ -588,7 +587,7 @@ layout_strategies.cursor = make_documented_layout( -- Cap over/undersized width (with preview) width, w_space = calc_size_and_spacing(width, max_columns, bs, 2, 4, 0) - preview.width = resolve.resolve_width(if_nil(layout_config.preview_width, 2 / 3))(self, width, max_lines) + preview.width = resolve.resolve_width(vim.F.if_nil(layout_config.preview_width, 2 / 3))(self, width, max_lines) prompt.width = width - preview.width - w_space results.width = prompt.width else @@ -694,7 +693,11 @@ layout_strategies.vertical = make_documented_layout( -- Cap over/undersized height (with previewer) height, h_space = calc_size_and_spacing(height, max_lines, bs, 3, 6, 2) - preview.height = resolve.resolve_height(if_nil(layout_config.preview_height, 0.5))(self, max_columns, height) + preview.height = resolve.resolve_height(vim.F.if_nil(layout_config.preview_height, 0.5))( + self, + max_columns, + height + ) else -- Cap over/undersized height (without previewer) height, h_space = calc_size_and_spacing(height, max_lines, bs, 2, 4, 1) @@ -764,8 +767,8 @@ layout_strategies.flex = make_documented_layout( horizontal = "Options to pass when switching to horizontal layout", }), function(self, max_columns, max_lines, layout_config) - local flip_columns = if_nil(layout_config.flip_columns, 100) - local flip_lines = if_nil(layout_config.flip_lines, 20) + local flip_columns = vim.F.if_nil(layout_config.flip_columns, 100) + local flip_lines = vim.F.if_nil(layout_config.flip_lines, 20) if max_columns < flip_columns and max_lines > flip_lines then self.__flex_strategy = "vertical" @@ -851,7 +854,7 @@ layout_strategies.bottom_pane = make_documented_layout( local tbln max_lines, tbln = calc_tabline(max_lines) - local height = if_nil(resolve.resolve_height(layout_config.height)(self, max_columns, max_lines), 25) + local height = vim.F.if_nil(resolve.resolve_height(layout_config.height)(self, max_columns, max_lines), 25) if type(layout_config.height) == "table" and type(layout_config.height.padding) == "number" then -- Since bottom_pane only has padding at the top, we only need half as much padding in total -- This doesn't match the vim help for `resolve.resolve_height`, but it matches expectations @@ -874,7 +877,7 @@ layout_strategies.bottom_pane = make_documented_layout( -- Cap over/undersized width (with preview) local width, w_space = calc_size_and_spacing(max_columns, max_columns, bs, 2, 4, 0) - preview.width = resolve.resolve_width(if_nil(layout_config.preview_width, 0.5))(self, width, max_lines) + preview.width = resolve.resolve_width(vim.F.if_nil(layout_config.preview_width, 0.5))(self, width, max_lines) results.width = width - preview.width - w_space else results.width = prompt.width diff --git a/lua/telescope/sorters.lua b/lua/telescope/sorters.lua index 8e266b3..3fb263a 100644 --- a/lua/telescope/sorters.lua +++ b/lua/telescope/sorters.lua @@ -602,7 +602,7 @@ end sorters.prefilter = function(opts) local sorter = opts.sorter - opts.delimiter = util.get_default(opts.delimiter, ":") + opts.delimiter = vim.F.if_nil(opts.delimiter, ":") sorter._delimiter = opts.delimiter sorter.tags = create_tag_set(opts.tag) sorter.filter_function = filter_function(opts) diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 7692409..07800b2 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -20,6 +20,7 @@ utils.get_separator = function() end utils.if_nil = function(x, was_nil, was_not_nil) + log.error "telescope.utils.if_nil is deprecated and will be removed. Please use vim.F.if_nil" if x == nil then return was_nil else @@ -28,6 +29,7 @@ utils.if_nil = function(x, was_nil, was_not_nil) end utils.get_default = function(x, default) + log.error "telescope.utils.get_default is deprecated and will be removed. Please use vim.F.if_nil" return utils.if_nil(x, default, x) end @@ -198,7 +200,7 @@ utils.path_tail = (function() end)() utils.is_path_hidden = function(opts, path_display) - path_display = path_display or utils.get_default(opts.path_display, require("telescope.config").values.path_display) + path_display = path_display or vim.F.if_nil(opts.path_display, require("telescope.config").values.path_display) return path_display == nil or path_display == "hidden" @@ -235,7 +237,7 @@ utils.transform_path = function(opts, path) return path end - local path_display = utils.get_default(opts.path_display, require("telescope.config").values.path_display) + local path_display = vim.F.if_nil(opts.path_display, require("telescope.config").values.path_display) local transformed_path = path From 6dc0a7d7c26d6620043cabf1dca3619fee6d3c62 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 29 May 2022 12:43:27 +0200 Subject: [PATCH 08/35] fix(resume): previewer if toggled (#1957) --- lua/telescope/builtin/internal.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 4f5ce4f..8a41500 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -144,6 +144,11 @@ internal.resume = function(opts) picker.cache_picker.disabled = true end opts.cache_picker = nil + picker.previewer = picker.all_previewers + if picker.hidden_previewer then + picker.hidden_previewer = nil + opts.previewer = vim.F.if_nil(opts.previewer, false) + end pickers.new(opts, picker):find() end From a6c9ae088e354c529db8bedf04166e1ab8a6f1b2 Mon Sep 17 00:00:00 2001 From: TheMeaningfulEngineer Date: Sun, 29 May 2022 19:54:31 +0200 Subject: [PATCH 09/35] feat: force buffer delete for terminal and improvements for Picker:delete_selection (#1943) --- lua/telescope/actions/init.lua | 4 +++- lua/telescope/pickers.lua | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 0413f33..0382014 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -1020,7 +1020,9 @@ end actions.delete_buffer = function(prompt_bufnr) local current_picker = action_state.get_current_picker(prompt_bufnr) current_picker:delete_selection(function(selection) - vim.api.nvim_buf_delete(selection.bufnr, { force = false }) + local force = vim.api.nvim_buf_get_option(selection.bufnr, "buftype") == "terminal" + local ok = pcall(vim.api.nvim_buf_delete, selection.bufnr, { force = force }) + return ok end) end diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 4cc1623..9397c57 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -693,7 +693,7 @@ end --- --- Example usage in telescope: --- - `actions.delete_buffer()` ----@param delete_cb function: called with each deleted selection +---@param delete_cb function: called for each selection fn(s) -> bool|nil (true|nil removes the entry from the results) function Picker:delete_selection(delete_cb) vim.validate { delete_cb = { delete_cb, "f" } } local original_selection_strategy = self.selection_strategy @@ -719,8 +719,10 @@ function Picker:delete_selection(delete_cb) return x > y end) for _, index in ipairs(selection_index) do - local selection = table.remove(self.finder.results, index) - delete_cb(selection) + local delete_cb_return = delete_cb(self.finder.results[index]) + if delete_cb_return == nil or delete_cb_return == true then + table.remove(self.finder.results, index) + end end if used_multi_select then From 8488cd5ac7a5c5b99773b5b8de5723ce4cedc796 Mon Sep 17 00:00:00 2001 From: Jeremy Neal Date: Mon, 6 Jun 2022 08:06:34 -0400 Subject: [PATCH 10/35] feat: no-ignore-parent shorthand option for find_files. (#1963) --- doc/telescope.txt | 29 ++++++++++++++++------------- lua/telescope/builtin/files.lua | 10 ++++++++++ lua/telescope/builtin/init.lua | 1 + 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 43a5ccc..9f3b339 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -878,19 +878,22 @@ builtin.find_files({opts}) *telescope.builtin.find_files()* {opts} (table) options to pass to the picker Options: ~ - {cwd} (string) root dir to search from (default: cwd, use - utils.buffer_dir() to search relative to - open buffer) - {find_command} (table) command line arguments for `find_files` to - use for the search, overrides default: - config - {follow} (boolean) if true, follows symlinks (i.e. uses `-L` - flag for the `find` command) - {hidden} (boolean) determines whether to show hidden files or - not (default: false) - {no_ignore} (boolean) show files ignored by .gitignore, .ignore, - etc. (default: false) - {search_dirs} (table) directory/directories to search in + {cwd} (string) root dir to search from (default: cwd, + use utils.buffer_dir() to search + relative to open buffer) + {find_command} (table) command line arguments for `find_files` + to use for the search, overrides + default: config + {follow} (boolean) if true, follows symlinks (i.e. uses + `-L` flag for the `find` command) + {hidden} (boolean) determines whether to show hidden files + or not (default: false) + {no_ignore} (boolean) show files ignored by .gitignore, + .ignore, etc. (default: false) + {no_ignore_parent} (boolean) show files ignored by .gitignore, + .ignore, etc. in parent dirs. (default: + false) + {search_dirs} (table) directory/directories to search in builtin.fd() *telescope.builtin.fd()* diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 3ebcdf4..f078f45 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -183,6 +183,7 @@ files.find_files = function(opts) local command = find_command[1] local hidden = opts.hidden local no_ignore = opts.no_ignore + local no_ignore_parent = opts.no_ignore_parent local follow = opts.follow local search_dirs = opts.search_dirs @@ -199,6 +200,9 @@ files.find_files = function(opts) if no_ignore then table.insert(find_command, "--no-ignore") end + if no_ignore_parent then + table.insert(find_command, "--no-ignore-parent") + end if follow then table.insert(find_command, "-L") end @@ -218,6 +222,9 @@ files.find_files = function(opts) if no_ignore ~= nil then log.warn "The `no_ignore` key is not available for the `find` command in `find_files`." end + if no_ignore_parent ~= nil then + log.warn "The `no_ignore_parent` key is not available for the `find` command in `find_files`." + end if follow then table.insert(find_command, 2, "-L") end @@ -234,6 +241,9 @@ files.find_files = function(opts) if no_ignore ~= nil then log.warn "The `no_ignore` key is not available for the Windows `where` command in `find_files`." end + if no_ignore_parent ~= nil then + log.warn "The `no_ignore_parent` key is not available for the Windows `where` command in `find_files`." + end if follow ~= nil then log.warn "The `follow` key is not available for the Windows `where` command in `find_files`." end diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index e9b695b..9fa6826 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -81,6 +81,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_s ---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command) ---@field hidden boolean: determines whether to show hidden files or not (default: false) ---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false) +---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false) ---@field search_dirs table: directory/directories to search in builtin.find_files = require_on_exported_call("telescope.builtin.files").find_files From 15f6a0bb08f934bc999c8b5e54fb574f5889558f Mon Sep 17 00:00:00 2001 From: Antoine Date: Thu, 9 Jun 2022 15:54:50 +0200 Subject: [PATCH 11/35] feat(tags): process tagfiles on the fly (#1989) --- lua/telescope/builtin/files.lua | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index f078f45..578f6de 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -422,6 +422,9 @@ end files.tags = function(opts) local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles() + for i, ctags_file in ipairs(tagfiles) do + tagfiles[i] = vim.fn.expand(ctags_file, true) + end if vim.tbl_isempty(tagfiles) then utils.notify("builtin.tags", { msg = "No tags file found. Create one with ctags -R", @@ -429,20 +432,11 @@ files.tags = function(opts) }) return end - - local results = {} - for _, ctags_file in ipairs(tagfiles) do - for line in Path:new(vim.fn.expand(ctags_file, true)):iter() do - results[#results + 1] = line - end - end + opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_ctags(opts)) pickers.new(opts, { prompt_title = "Tags", - finder = finders.new_table { - results = results, - entry_maker = opts.entry_maker or make_entry.gen_from_ctags(opts), - }, + finder = finders.new_oneshot_job(flatten { "cat", tagfiles }, opts), previewer = previewers.ctags.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function() From 6703c957e7d9a5dc5f91ceb59326ab7e05274642 Mon Sep 17 00:00:00 2001 From: Bjarki Baldursson Harksen <62466569+mrbjarksen@users.noreply.github.com> Date: Sun, 12 Jun 2022 11:08:30 +0000 Subject: [PATCH 12/35] feat: add option `use_default_opts` to `builtin.builtin` (#1996) --- doc/telescope.txt | 2 ++ lua/telescope/builtin/init.lua | 1 + lua/telescope/builtin/internal.lua | 10 ++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 9f3b339..f0f78ef 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1112,6 +1112,8 @@ builtin.builtin({opts}) *telescope.builtin.builtin()* Options: ~ {include_extensions} (boolean) if true will show the pickers of the installed extensions (default: false) + {use_default_opts} (boolean) if the selected picker should use its + default options (default: false) builtin.resume({opts}) *telescope.builtin.resume()* diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 9fa6826..ea871aa 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -205,6 +205,7 @@ builtin.git_stash = require_on_exported_call("telescope.builtin.git").stash --- Lists all of the community maintained pickers built into Telescope ---@param opts table: options to pass to the picker ---@field include_extensions boolean: if true will show the pickers of the installed extensions (default: false) +---@field use_default_opts boolean: if the selected picker should use its default options (default: false) builtin.builtin = require_on_exported_call("telescope.builtin.internal").builtin --- Opens the previous picker in the identical state (incl. multi selections) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 8a41500..e4a5704 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -33,6 +33,7 @@ local internal = {} internal.builtin = function(opts) opts.include_extensions = vim.F.if_nil(opts.include_extensions, false) + opts.use_default_opts = vim.F.if_nil(opts.use_default_opts, false) local objs = {} @@ -91,15 +92,20 @@ internal.builtin = function(opts) -- we do this to avoid any surprises opts.include_extensions = nil + local picker_opts + if not opts.use_default_opts then + picker_opts = opts + end + if string.match(selection.text, " : ") then -- Call appropriate function from extensions local split_string = vim.split(selection.text, " : ") local ext = split_string[1] local func = split_string[2] - require("telescope").extensions[ext][func](opts) + require("telescope").extensions[ext][func](picker_opts) else -- Call appropriate telescope builtin - require("telescope.builtin")[selection.text](opts) + require("telescope.builtin")[selection.text](picker_opts) end end) return true From 3f1f5b7e5284b6c341429169e32161795def7e65 Mon Sep 17 00:00:00 2001 From: Brian Di Palma <1597820+briandipalma@users.noreply.github.com> Date: Sun, 12 Jun 2022 12:15:39 +0100 Subject: [PATCH 13/35] feat: add `--follow` to bcommits (#1997) Yes the diff to parent preview will be blank but at the very least a user can follow a file around various moves and get access to the SHA-ID for the move. --- lua/telescope/builtin/git.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index 74b7df9..71203bb 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -112,7 +112,10 @@ git.bcommits = function(opts) opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) - local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit" }) + local git_command = vim.F.if_nil( + opts.git_command, + { "git", "log", "--pretty=oneline", "--abbrev-commit", "--follow" } + ) pickers.new(opts, { prompt_title = "Git BCommits", From 838c32d6a86c8a4b8f3333f66e797f7cad2e3c1b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 12 Jun 2022 20:29:10 +0800 Subject: [PATCH 14/35] refactor: make_entry more consistent (#1410) drops `ignore_filename`, use `path_display= { "hidden" }` Co-authored-by: Simon Hauser --- doc/telescope.txt | 68 ++++++++------ lua/telescope/builtin/init.lua | 25 +++-- lua/telescope/builtin/lsp.lua | 2 +- lua/telescope/make_entry.lua | 163 ++++++++++++++++++--------------- 4 files changed, 143 insertions(+), 115 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index f0f78ef..8d90dc2 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1195,9 +1195,11 @@ builtin.quickfix({opts}) *telescope.builtin.quickfix()* {opts} (table) options to pass to the picker Options: ~ - {ignore_filename} (boolean) dont show filenames (default: true) - {trim_text} (boolean) trim results text (default: false) - {nr} (number) specify the quickfix list number + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename section + (default: 30) + {nr} (number) specify the quickfix list number builtin.quickfixhistory({opts}) *telescope.builtin.quickfixhistory()* @@ -1219,8 +1221,10 @@ builtin.loclist({opts}) *telescope.builtin.loclist()* {opts} (table) options to pass to the picker Options: ~ - {ignore_filename} (boolean) dont show filenames (default: true) - {trim_text} (boolean) trim results text (default: false) + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename section + (default: 30) builtin.oldfiles({opts}) *telescope.builtin.oldfiles()* @@ -1419,8 +1423,10 @@ builtin.tagstack({opts}) *telescope.builtin.tagstack()* {opts} (table) options to pass to the picker Options: ~ - {ignore_filename} (boolean) dont show filenames (default: true) - {trim_text} (boolean) trim results text (default: false) + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename section + (default: 30) builtin.jumplist({opts}) *telescope.builtin.jumplist()* @@ -1431,8 +1437,10 @@ builtin.jumplist({opts}) *telescope.builtin.jumplist()* {opts} (table) options to pass to the picker Options: ~ - {ignore_filename} (boolean) dont show filenames (default: true) - {trim_text} (boolean) trim results text (default: false) + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename section + (default: 30) builtin.lsp_references({opts}) *telescope.builtin.lsp_references()* @@ -1449,6 +1457,8 @@ builtin.lsp_references({opts}) *telescope.builtin.lsp_references()* {include_current_line} (boolean) include current line (default: false) {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename + section (default: 30) builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()* @@ -1460,11 +1470,12 @@ builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()* {opts} (table) options to pass to the picker Options: ~ - {jump_type} (string) how to goto definition if there is only - one, values: "tab", "split", "vsplit", - "never" - {ignore_filename} (boolean) dont show filenames (default: true) - {trim_text} (boolean) trim results text (default: false) + {jump_type} (string) how to goto definition if there is only one, + values: "tab", "split", "vsplit", "never" + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename section + (default: 30) builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()* @@ -1476,11 +1487,12 @@ builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()* {opts} (table) options to pass to the picker Options: ~ - {jump_type} (string) how to goto definition if there is only - one, values: "tab", "split", "vsplit", - "never" - {ignore_filename} (boolean) dont show filenames (default: true) - {trim_text} (boolean) trim results text (default: false) + {jump_type} (string) how to goto definition if there is only one, + values: "tab", "split", "vsplit", "never" + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename section + (default: 30) builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()* @@ -1492,11 +1504,13 @@ builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()* {opts} (table) options to pass to the picker Options: ~ - {jump_type} (string) how to goto implementation if there is - only one, values: "tab", "split", - "vsplit", "never" - {ignore_filename} (boolean) dont show filenames (default: true) - {trim_text} (boolean) trim results text (default: false) + {jump_type} (string) how to goto implementation if there is only + one, values: "tab", "split", "vsplit", + "never" + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {fname_width} (number) defines the width of the filename section + (default: 30) builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()* @@ -1510,8 +1524,6 @@ builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()* {opts} (table) options to pass to the picker Options: ~ - {ignore_filename} (boolean) dont show filenames (default: - true) {show_line} (boolean) if true, shows the content of the line the tag is found on (default: false) @@ -1534,8 +1546,6 @@ builtin.lsp_workspace_symbols({opts}) *telescope.builtin.lsp_workspace_symbols() Options: ~ {query} (string) for what to query the workspace (default: "") - {ignore_filename} (boolean) dont show filenames (default: - false) {show_line} (boolean) if true, shows the content of the line the tag is found on (default: false) @@ -1556,8 +1566,6 @@ builtin.lsp_dynamic_workspace_symbols({opts}) *telescope.builtin.lsp_dynamic_wor {opts} (table) options to pass to the picker Options: ~ - {ignore_filename} (boolean) dont show filenames (default: - false) {show_line} (boolean) if true, shows the content of the line the symbol is found on (default: false) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index ea871aa..670b75f 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -245,8 +245,9 @@ builtin.commands = require_on_exported_call("telescope.builtin.internal").comman --- Lists items in the quickfix list, jumps to location on `` ---@param opts table: options to pass to the picker ----@field ignore_filename boolean: dont show filenames (default: true) +---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) ---@field nr number: specify the quickfix list number builtin.quickfix = require_on_exported_call("telescope.builtin.internal").quickfix @@ -257,8 +258,9 @@ builtin.quickfixhistory = require_on_exported_call("telescope.builtin.internal") --- Lists items from the current window's location list, jumps to location on `` ---@param opts table: options to pass to the picker ----@field ignore_filename boolean: dont show filenames (default: true) +---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) builtin.loclist = require_on_exported_call("telescope.builtin.internal").loclist --- Lists previously open files, opens on `` @@ -350,14 +352,16 @@ builtin.spell_suggest = require_on_exported_call("telescope.builtin.internal").s --- Lists the tag stack for the current window, jumps to tag on `` ---@param opts table: options to pass to the picker ----@field ignore_filename boolean: dont show filenames (default: true) +---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) builtin.tagstack = require_on_exported_call("telescope.builtin.internal").tagstack --- Lists items from Vim's jumplist, jumps to location on `` ---@param opts table: options to pass to the picker ----@field ignore_filename boolean: dont show filenames (default: true) +---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumplist -- @@ -371,35 +375,38 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumpli ---@field include_declaration boolean: include symbol declaration in the lsp references (default: true) ---@field include_current_line boolean: include current line (default: false) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) builtin.lsp_references = require_on_exported_call("telescope.builtin.lsp").references --- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope ---@param opts table: options to pass to the picker ---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never" ----@field ignore_filename boolean: dont show filenames (default: true) +---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").definitions --- Goto the definition of the type of the word under the cursor, if there's only one, --- otherwise show all options in Telescope ---@param opts table: options to pass to the picker ---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never" ----@field ignore_filename boolean: dont show filenames (default: true) +---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions --- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope ---@param opts table: options to pass to the picker ---@field jump_type string: how to goto implementation if there is only one, values: "tab", "split", "vsplit", "never" ----@field ignore_filename boolean: dont show filenames (default: true) +---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field fname_width number: defines the width of the filename section (default: 30) builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp").implementations --- Lists LSP document symbols in the current buffer --- - Default keymaps: --- - ``: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`) ---@param opts table: options to pass to the picker ----@field ignore_filename boolean: dont show filenames (default: true) ---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false) ---@field symbols string|table: filter results by symbol kind(s) ---@field ignore_symbols string|table: list of symbols to ignore @@ -411,7 +418,6 @@ builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.lsp") --- - ``: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`) ---@param opts table: options to pass to the picker ---@field query string: for what to query the workspace (default: "") ----@field ignore_filename boolean: dont show filenames (default: false) ---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false) ---@field symbols string|table: filter results by symbol kind(s) ---@field ignore_symbols string|table: list of symbols to ignore @@ -422,7 +428,6 @@ builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.lsp" --- - Default keymaps: --- - ``: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`) ---@param opts table: options to pass to the picker ----@field ignore_filename boolean: dont show filenames (default: false) ---@field show_line boolean: if true, shows the content of the line the symbol is found on (default: false) ---@field symbols string|table: filter results by symbol kind(s) ---@field ignore_symbols string|table: list of symbols to ignore diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 46757fc..410a068 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -144,7 +144,7 @@ lsp.document_symbols = function(opts) return end - opts.ignore_filename = opts.ignore_filename or true + opts.path_display = { "hidden" } pickers.new(opts, { prompt_title = "LSP Document Symbols", finder = finders.new_table { diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index f4f0010..940973b 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -26,6 +26,21 @@ local lsp_type_highlight = { ["Variable"] = "TelescopeResultsVariable", } +local get_filename_fn = function() + local bufnr_name_cache = {} + return function(bufnr) + bufnr = vim.F.if_nil(bufnr, 0) + local c = bufnr_name_cache[bufnr] + if c then + return c + end + + local n = vim.api.nvim_buf_get_name(bufnr) + bufnr_name_cache[bufnr] = n + return n + end +end + local make_entry = {} do @@ -309,40 +324,49 @@ end function make_entry.gen_from_quickfix(opts) opts = opts or {} + local show_line = vim.F.if_nil(opts.show_line, true) - local displayer = entry_display.create { - separator = "▏", - items = { - { width = 8 }, - { width = 0.45 }, - { remaining = true }, - }, + local hidden = utils.is_path_hidden(opts) + local items = { + { width = vim.F.if_nil(opts.fname_width, 30) }, + { remaining = true }, } - - local make_display = function(entry) - local filename = utils.transform_path(opts, entry.filename) - - local line_info = { table.concat({ entry.lnum, entry.col }, ":"), "TelescopeResultsLineNr" } - - if opts.trim_text then - entry.text = entry.text:gsub("^%s*(.-)%s*$", "%1") - end - - return displayer { - line_info, - entry.text:gsub(".* | ", ""), - filename, - } + if hidden then + items[1] = 8 + end + if not show_line then + table.remove(items, 1) end + local displayer = entry_display.create { separator = "▏", items = items } + + local make_display = function(entry) + local input = {} + if not hidden then + table.insert(input, string.format("%s:%d:%d", utils.transform_path(opts, entry.filename), entry.lnum, entry.col)) + else + table.insert(input, string.format("%4d:%2d", entry.lnum, entry.col)) + end + + if show_line then + local text = entry.text + if opts.trim_text then + text = text:gsub("^%s*(.-)%s*$", "%1") + end + text = text:gsub(".* | ", "") + table.insert(input, text) + end + + return displayer(input) + end + + local get_filename = get_filename_fn() return function(entry) - local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr) + local filename = vim.F.if_nil(entry.filename, get_filename(entry.bufnr)) return { - valid = true, - value = entry, - ordinal = (not opts.ignore_filename and filename or "") .. " " .. entry.text, + ordinal = (not hidden and filename or "") .. " " .. entry.text, display = make_display, bufnr = entry.bufnr, @@ -361,14 +385,22 @@ function make_entry.gen_from_lsp_symbols(opts) local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() + -- Default we have two columns, symbol and type(unbound) + -- If path is not hidden then its, filepath, symbol and type(still unbound) + -- If show_line is also set, type is bound to len 8 local display_items = { - { width = opts.symbol_width or 25 }, -- symbol - { width = opts.symbol_type_width or 8 }, -- symbol type - { remaining = true }, -- filename{:optional_lnum+col} OR content preview + { width = opts.symbol_width or 25 }, + { remaining = true }, } - if opts.ignore_filename and opts.show_line then - table.insert(display_items, 2, { width = 6 }) + local hidden = utils.is_path_hidden(opts) + if not hidden then + table.insert(display_items, 1, { width = vim.F.if_nil(opts.fname_width, 30) }) + end + + if opts.show_line then + -- bound type to len 8 or custom + table.insert(display_items, #display_items, { width = opts.symbol_type_width or 8 }) end local displayer = entry_display.create { @@ -376,51 +408,43 @@ function make_entry.gen_from_lsp_symbols(opts) hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" }, items = display_items, } + local type_highlight = vim.F.if_nil(opts.symbol_highlights or lsp_type_highlight) local make_display = function(entry) local msg - -- what to show in the last column: filename or symbol information - if opts.ignore_filename then -- ignore the filename and show line preview instead - -- TODO: fixme - if ignore_filename is set for workspace, bufnr will be incorrect - msg = vim.api.nvim_buf_get_lines(bufnr, entry.lnum - 1, entry.lnum, false)[1] or "" - msg = vim.trim(msg) + if opts.show_line then + msg = vim.trim(vim.F.if_nil(vim.api.nvim_buf_get_lines(bufnr, entry.lnum - 1, entry.lnum, false)[1], "")) + end + + if hidden then + return displayer { + entry.symbol_name, + { entry.symbol_type:lower(), type_highlight[entry.symbol_type] }, + msg, + } else - local filename = utils.transform_path(opts, entry.filename) - - if opts.show_line then -- show inline line info - filename = filename .. " [" .. entry.lnum .. ":" .. entry.col .. "]" - end - msg = filename + return displayer { + utils.transform_path(opts, entry.filename), + entry.symbol_name, + { entry.symbol_type:lower(), type_highlight[entry.symbol_type] }, + msg, + } end - - local type_highlight = opts.symbol_highlights or lsp_type_highlight - local display_columns = { - entry.symbol_name, - { entry.symbol_type:lower(), type_highlight[entry.symbol_type], type_highlight[entry.symbol_type] }, - msg, - } - - if opts.ignore_filename and opts.show_line then - table.insert(display_columns, 2, { entry.lnum .. ":" .. entry.col, "TelescopeResultsLineNr" }) - end - - return displayer(display_columns) end + local get_filename = get_filename_fn() return function(entry) - local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr) + local filename = vim.F.if_nil(entry.filename, get_filename(entry.bufnr)) local symbol_msg = entry.text local symbol_type, symbol_name = symbol_msg:match "%[(.+)%]%s+(.*)" - local ordinal = "" - if not opts.ignore_filename and filename then + if not hidden and filename then ordinal = filename .. " " end ordinal = ordinal .. symbol_name .. " " .. (symbol_type or "unknown") - return { - valid = true, + return { value = entry, ordinal = ordinal, display = make_display, @@ -484,8 +508,6 @@ function make_entry.gen_from_buffer(opts) local line_count = vim.api.nvim_buf_line_count(entry.bufnr) return { - valid = true, - value = bufname, ordinal = entry.bufnr .. " : " .. bufname, display = make_display, @@ -537,13 +559,12 @@ function make_entry.gen_from_treesitter(opts) return displayer(display_columns) end + local get_filename = get_filename_fn() return function(entry) local ts_utils = require "nvim-treesitter.ts_utils" local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node) local node_text = vim.treesitter.get_node_text(entry.node, bufnr) return { - valid = true, - value = entry.node, kind = entry.kind, ordinal = node_text .. " " .. (entry.kind or "unknown"), @@ -551,7 +572,7 @@ function make_entry.gen_from_treesitter(opts) node_text = node_text, - filename = vim.api.nvim_buf_get_name(bufnr), + filename = get_filename(bufnr), -- need to add one since the previewer substacts one lnum = start_row + 1, col = start_col, @@ -668,7 +689,6 @@ function make_entry.gen_from_registers(_) return function(entry) return { - valid = true, value = entry, ordinal = entry, content = vim.fn.getreg(entry), @@ -800,7 +820,6 @@ function make_entry.gen_from_buffer_lines(opts) end return { - valid = true, ordinal = entry.text, display = make_display, filename = entry.filename, @@ -982,7 +1001,8 @@ function make_entry.gen_from_diagnostics(opts) { remaining = true }, } local line_width = vim.F.if_nil(opts.line_width, 0.5) - if not utils.is_path_hidden(opts) then + local hidden = utils.is_path_hidden(opts) + if not hidden then table.insert(display_items, 2, { width = line_width }) end local displayer = entry_display.create { @@ -1000,10 +1020,6 @@ function make_entry.gen_from_diagnostics(opts) "Diagnostic" .. entry.type, } - --TODO(conni2461): I dont like that this is symbol lnum:col | msg | filename - -- i want: symbol filename:lnum:col | msg - -- or : symbol lnum:col | msg - -- I think this is more natural return displayer { line_info, entry.text, @@ -1014,7 +1030,7 @@ function make_entry.gen_from_diagnostics(opts) return function(entry) return { value = entry, - ordinal = ("%s %s"):format(not opts.ignore_filename and entry.filename or "", entry.text), + ordinal = ("%s %s"):format(not hidden and entry.filename or "", entry.text), display = make_display, filename = entry.filename, type = entry.type, @@ -1104,7 +1120,6 @@ function make_entry.gen_from_commands(_) definition = entry.definition, -- value = entry, - valid = true, ordinal = entry.name, display = make_display, } From 77e2b8ceea048b42773fc454658c17448caa2a93 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 12 Jun 2022 15:09:41 +0200 Subject: [PATCH 15/35] chore: cleanup autocmd builtin (#1947) --- lua/telescope/builtin/internal.lua | 103 +++++------------- lua/telescope/make_entry.lua | 26 ++--- lua/telescope/previewers/buffer_previewer.lua | 13 ++- 3 files changed, 46 insertions(+), 96 deletions(-) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index e4a5704..4519b93 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -1170,95 +1170,44 @@ internal.highlights = function(opts) end internal.autocommands = function(opts) - local autocmd_table = {} - - local pattern = {} - pattern.BUFFER = "" - pattern.EVENT = "[%a]+" - pattern.GROUP = "[%a%d_:]+" - pattern.INDENT = "^%s%s%s%s" -- match indentation of 4 spaces - - local event, group, ft_pat, cmd, source_file, source_lnum - local current_event, current_group, current_ft - - local inner_loop = function(line) - -- capture group and event - group, event = line:match("^(" .. pattern.GROUP .. ")%s+(" .. pattern.EVENT .. ")") - -- ..or just an event - if event == nil then - event = line:match("^(" .. pattern.EVENT .. ")") - end - - if event then - group = group or "" - if event ~= current_event or group ~= current_group then - current_event = event - current_group = group - end - return - end - - -- non event/group lines - ft_pat = line:match(pattern.INDENT .. "(%S+)") - if ft_pat then - if ft_pat:match "^%d+" then - ft_pat = "" - end - current_ft = ft_pat - - -- is there a command on the same line? - cmd = line:match(pattern.INDENT .. "%S+%s+(.+)") - - return - end - - if current_ft and cmd == nil then - -- trim leading spaces - cmd = line:gsub("^%s+", "") - return - end - - if current_ft and cmd then - source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$" - source_lnum = line:match "line (%d*)$" or "1" - if source_file then - local autocmd = {} - autocmd.event = current_event - autocmd.group = current_group - autocmd.ft_pattern = current_ft - autocmd.command = cmd - autocmd.source_file = source_file - autocmd.source_lnum = source_lnum - table.insert(autocmd_table, autocmd) - - cmd = nil - end - end - end - - local cmd_output = vim.fn.execute("verb autocmd *", "silent") - for line in cmd_output:gmatch "[^\r\n]+" do - inner_loop(line) - end - + local autocmds = vim.api.nvim_get_autocmds {} + table.sort(autocmds, function(lhs, rhs) + return lhs.event < rhs.event + end) pickers.new(opts, { prompt_title = "autocommands", finder = finders.new_table { - results = autocmd_table, + results = autocmds, entry_maker = opts.entry_maker or make_entry.gen_from_autocommands(opts), }, previewer = previewers.autocommands.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - action_set.select:replace(function(_, type) + action_set.select:replace_if(function() local selection = action_state.get_selected_entry() if selection == nil then - utils.__warn_no_selection "builtin.autocommands" - return + return false end - + local val = selection.value + local output = vim.fn.execute( + "verb autocmd " .. val.group_name .. " " .. val.event .. " " .. val.pattern, + "silent" + ) + for line in output:gmatch "[^\r\n]+" do + local source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$" + if source_file and source_file ~= "Lua" then + selection.filename = source_file + local source_lnum = line:match "line (%d*)$" or "1" + selection.lnum = tonumber(source_lnum) + selection.col = 1 + return false + end + end + return true + end, function() + local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) - vim.cmd(action_state.select_key_to_edit_key(type) .. " " .. selection.value) + print("You selected autocmd: " .. vim.inspect(selection.value)) end) return true diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 940973b..e206fd5 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -1054,26 +1054,24 @@ function make_entry.gen_from_autocommands(_) local make_display = function(entry) return displayer { - { entry.event, "vimAutoEvent" }, - { entry.group, "vimAugroup" }, - { entry.ft_pattern, "vimAutoCmdSfxList" }, - entry.command, + { entry.value.event, "vimAutoEvent" }, + { entry.value.group_name, "vimAugroup" }, + { entry.value.pattern, "vimAutoCmdSfxList" }, + entry.value.command, } end - -- TODO: dump current filtered items to buffer return function(entry) + local group_name = vim.F.if_nil(entry.group_name, "") return { - event = entry.event, - group = entry.group, - ft_pattern = entry.ft_pattern, - command = entry.command, - value = string.format("+%d %s", entry.source_lnum, entry.source_file), - source_file = entry.source_file, - source_lnum = entry.source_lnum, + value = { + event = entry.event, + group_name = group_name, + pattern = entry.pattern, + command = entry.command, + }, -- - valid = true, - ordinal = entry.event .. " " .. entry.group .. " " .. entry.ft_pattern .. " " .. entry.command, + ordinal = entry.event .. " " .. group_name .. " " .. entry.pattern .. " " .. entry.command, display = make_display, } end diff --git a/lua/telescope/previewers/buffer_previewer.lua b/lua/telescope/previewers/buffer_previewer.lua index 0db4365..1c3ca8a 100644 --- a/lua/telescope/previewers/buffer_previewer.lua +++ b/lua/telescope/previewers/buffer_previewer.lua @@ -881,12 +881,12 @@ previewers.autocommands = defaulter(function(_) end, get_buffer_by_name = function(_, entry) - return entry.group + return entry.value.group_name end, define_preview = function(self, entry, status) local results = vim.tbl_filter(function(x) - return x.group == entry.group + return x.value.group_name == entry.value.group_name end, status.picker.finder.results) if self.state.last_set_bufnr then @@ -894,9 +894,9 @@ previewers.autocommands = defaulter(function(_) end local selected_row = 0 - if self.state.bufname ~= entry.group then + if self.state.bufname ~= entry.value.group_name then local display = {} - table.insert(display, string.format(" augroup: %s - [ %d entries ]", entry.group, #results)) + table.insert(display, string.format(" augroup: %s - [ %d entries ]", entry.value.group_name, #results)) -- TODO: calculate banner width/string in setup() -- TODO: get column characters to be the same HL group as border table.insert(display, string.rep("─", vim.fn.getwininfo(status.preview_win)[1].width)) @@ -905,7 +905,10 @@ previewers.autocommands = defaulter(function(_) if item == entry then selected_row = idx end - table.insert(display, string.format(" %-14s▏%-08s %s", item.event, item.ft_pattern, item.command)) + table.insert( + display, + string.format(" %-14s▏%-08s %s", item.value.event, item.value.ft_pattern, item.value.command) + ) end vim.api.nvim_buf_set_option(self.state.bufnr, "filetype", "vim") From f6efef4c4183407860618832cf9c51b20d15e96d Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 12 Jun 2022 15:37:24 +0200 Subject: [PATCH 16/35] feat: `find_command` can be a function (#2000) --- doc/telescope.txt | 34 +++++++++++++++++---------------- lua/telescope/builtin/files.lua | 5 +++-- lua/telescope/builtin/init.lua | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 8d90dc2..7fc66e2 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -878,22 +878,24 @@ builtin.find_files({opts}) *telescope.builtin.find_files()* {opts} (table) options to pass to the picker Options: ~ - {cwd} (string) root dir to search from (default: cwd, - use utils.buffer_dir() to search - relative to open buffer) - {find_command} (table) command line arguments for `find_files` - to use for the search, overrides - default: config - {follow} (boolean) if true, follows symlinks (i.e. uses - `-L` flag for the `find` command) - {hidden} (boolean) determines whether to show hidden files - or not (default: false) - {no_ignore} (boolean) show files ignored by .gitignore, - .ignore, etc. (default: false) - {no_ignore_parent} (boolean) show files ignored by .gitignore, - .ignore, etc. in parent dirs. (default: - false) - {search_dirs} (table) directory/directories to search in + {cwd} (string) root dir to search from (default: + cwd, use utils.buffer_dir() to + search relative to open buffer) + {find_command} (function|table) cmd to use for the search. Can be + a fn(opts) -> tbl (default: + autodetect) + {follow} (boolean) if true, follows symlinks (i.e. + uses `-L` flag for the `find` + command) + {hidden} (boolean) determines whether to show hidden + files or not (default: false) + {no_ignore} (boolean) show files ignored by .gitignore, + .ignore, etc. (default: false) + {no_ignore_parent} (boolean) show files ignored by .gitignore, + .ignore, etc. in parent dirs. + (default: false) + {search_dirs} (table) directory/directories to search + in builtin.fd() *telescope.builtin.fd()* diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 578f6de..00c8d78 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -153,11 +153,12 @@ files.grep_string = function(opts) }):find() end --- TODO: Maybe just change this to `find`. --- TODO: Support `find` and maybe let people do other stuff with it as well. files.find_files = function(opts) local find_command = (function() if opts.find_command then + if type(opts.find_command) == "function" then + return opts.find_command(opts) + end return opts.find_command elseif 1 == vim.fn.executable "fd" then return { "fd", "--type", "f" } diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 670b75f..69c83ba 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -77,7 +77,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_s --- Search for files (respecting .gitignore) ---@param opts table: options to pass to the picker ---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer) ----@field find_command table: command line arguments for `find_files` to use for the search, overrides default: config +---@field find_command function|table: cmd to use for the search. Can be a fn(opts) -> tbl (default: autodetect) ---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command) ---@field hidden boolean: determines whether to show hidden files or not (default: false) ---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false) From ffcc2221d63aa89665e468be1dd8cd8e40e5f581 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 12 Jun 2022 16:02:21 +0200 Subject: [PATCH 17/35] docs: clarify docs around `search_dirs` and `map_entries` --- doc/telescope.txt | 14 ++++++++------ lua/telescope/actions/utils.lua | 2 +- lua/telescope/builtin/init.lua | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 7fc66e2..ce171f1 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -827,8 +827,8 @@ builtin.live_grep({opts}) *telescope.builtin.live_grep()* {grep_open_files} (boolean) if true, restrict search to open files only, mutually exclusive with `search_dirs` - {search_dirs} (table) directory/directories to search in, - mutually exclusive with + {search_dirs} (table) directory/directories/files to + search, mutually exclusive with `grep_open_files` {glob_pattern} (string) argument to be used with `--glob`, e.g. "*.toml", can use the opposite @@ -855,7 +855,8 @@ builtin.grep_string({opts}) *telescope.builtin.grep_string()* cwd, use utils.buffer_dir() to search relative to open buffer) {search} (string) the query to search - {search_dirs} (table) directory/directories to search in + {search_dirs} (table) directory/directories/files to + search {use_regex} (boolean) if true, special characters won't be escaped, allows for using regex (default: false) @@ -894,8 +895,8 @@ builtin.find_files({opts}) *telescope.builtin.find_files()* {no_ignore_parent} (boolean) show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false) - {search_dirs} (table) directory/directories to search - in + {search_dirs} (table) directory/directories/files to + search builtin.fd() *telescope.builtin.fd()* @@ -2830,7 +2831,8 @@ Generally used from within other |telescope.actions| utils.map_entries({prompt_bufnr}, {f}) *telescope.actions.utils.map_entries()* Apply `f` to the entries of the current picker. - Notes: - - Mapped entries may include results not visible in the results popup. + - Mapped entries include all currently filtered results, not just the + visible onces. - Indices are 1-indexed, whereas rows are 0-indexed. - Warning: `map_entries` has no return value. - The below example showcases how to collect results diff --git a/lua/telescope/actions/utils.lua b/lua/telescope/actions/utils.lua index 9684414..4e81db3 100644 --- a/lua/telescope/actions/utils.lua +++ b/lua/telescope/actions/utils.lua @@ -13,7 +13,7 @@ local utils = {} --- Apply `f` to the entries of the current picker. --- - Notes: ---- - Mapped entries may include results not visible in the results popup. +--- - Mapped entries include all currently filtered results, not just the visible onces. --- - Indices are 1-indexed, whereas rows are 0-indexed. --- - Warning: `map_entries` has no return value. --- - The below example showcases how to collect results diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 69c83ba..7a3fb14 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -54,7 +54,7 @@ end ---@param opts table: options to pass to the picker ---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer) ---@field grep_open_files boolean: if true, restrict search to open files only, mutually exclusive with `search_dirs` ----@field search_dirs table: directory/directories to search in, mutually exclusive with `grep_open_files` +---@field search_dirs table: directory/directories/files to search, mutually exclusive with `grep_open_files` ---@field glob_pattern string: argument to be used with `--glob`, e.g. "*.toml", can use the opposite "!*.toml" ---@field type_filter string: argument to be used with `--type`, e.g. "rust", see `rg --type-list` ---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on @@ -66,7 +66,7 @@ builtin.live_grep = require_on_exported_call("telescope.builtin.files").live_gre ---@param opts table: options to pass to the picker ---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer) ---@field search string: the query to search ----@field search_dirs table: directory/directories to search in +---@field search_dirs table: directory/directories/files to search ---@field use_regex boolean: if true, special characters won't be escaped, allows for using regex (default: false) ---@field word_match string: can be set to `-w` to enable exact word matches ---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on @@ -82,7 +82,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_s ---@field hidden boolean: determines whether to show hidden files or not (default: false) ---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false) ---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false) ----@field search_dirs table: directory/directories to search in +---@field search_dirs table: directory/directories/files to search builtin.find_files = require_on_exported_call("telescope.builtin.files").find_files --- This is an alias for the `find_files` picker From 3a72cc89024120d09f32d70689cc9cbe367fc2b4 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 12 Jun 2022 16:06:20 +0200 Subject: [PATCH 18/35] feat(builtin.lsp): implement builtin handlers for lsp.(incoming|outgoing)_calls (#1484) Fixes #863 --- README.md | 2 + doc/telescope.txt | 26 ++++++++++ lua/telescope/builtin/init.lua | 12 +++++ lua/telescope/builtin/lsp.lua | 90 +++++++++++++++++++++++++++++++++- 4 files changed, 128 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e6bd52..56c1d17 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,8 @@ Built-in functions. Ready to be bound to any key you like. | Functions | Description | |---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------| | `builtin.lsp_references` | Lists LSP references for word under the cursor | +| `builtin.lsp_incoming_calls` | Lists LSP incoming calls for word under the cursor | +| `builtin.lsp_outgoing_calls` | Lists LSP outgoing calls for word under the cursor | | `builtin.lsp_document_symbols` | Lists LSP document symbols in the current buffer | | `builtin.lsp_workspace_symbols` | Lists LSP document symbols in the current workspace | | `builtin.lsp_dynamic_workspace_symbols` | Dynamically Lists LSP for all workspace symbols | diff --git a/doc/telescope.txt b/doc/telescope.txt index ce171f1..78cc7e4 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1464,6 +1464,32 @@ builtin.lsp_references({opts}) *telescope.builtin.lsp_references()* section (default: 30) +builtin.lsp_incoming_calls({opts}) *telescope.builtin.lsp_incoming_calls()* + Lists LSP incoming calls for word under the cursor, jumps to reference on + `` + + + Parameters: ~ + {opts} (table) options to pass to the picker + + Options: ~ + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + + +builtin.lsp_outgoing_calls({opts}) *telescope.builtin.lsp_outgoing_calls()* + Lists LSP outgoing calls for word under the cursor, jumps to reference on + `` + + + Parameters: ~ + {opts} (table) options to pass to the picker + + Options: ~ + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + + builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()* Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 7a3fb14..20d9812 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -378,6 +378,18 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumpli ---@field fname_width number: defines the width of the filename section (default: 30) builtin.lsp_references = require_on_exported_call("telescope.builtin.lsp").references +--- Lists LSP incoming calls for word under the cursor, jumps to reference on `` +---@param opts table: options to pass to the picker +---@field show_line boolean: show results text (default: true) +---@field trim_text boolean: trim results text (default: false) +builtin.lsp_incoming_calls = require_on_exported_call("telescope.builtin.lsp").incoming_calls + +--- Lists LSP outgoing calls for word under the cursor, jumps to reference on `` +---@param opts table: options to pass to the picker +---@field show_line boolean: show results text (default: true) +---@field trim_text boolean: trim results text (default: false) +builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.lsp").outgoing_calls + --- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope ---@param opts table: options to pass to the picker ---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never" diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 410a068..85fabb0 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -52,9 +52,93 @@ lsp.references = function(opts) end) end -local function list_or_jump(action, title, opts) - opts = opts or {} +local function call_hierarchy(opts, method, title, direction, item) + vim.lsp.buf_request(opts.bufnr, method, { item = item }, function(err, result) + if err then + vim.api.nvim_err_writeln("Error handling " .. title .. ": " .. err) + return + end + if not result or vim.tbl_isempty(result) then + return + end + + local locations = {} + for _, ch_call in pairs(result) do + local ch_item = ch_call[direction] + for _, range in pairs(ch_call.fromRanges) do + table.insert(locations, { + filename = vim.uri_to_fname(ch_item.uri), + text = ch_item.name, + lnum = range.start.line + 1, + col = range.start.character + 1, + }) + end + end + + pickers.new(opts, { + prompt_title = title, + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + push_cursor_on_edit = true, + push_tagstack_on_edit = true, + }):find() + end) +end + +local function pick_call_hierarchy_item(call_hierarchy_items) + if not call_hierarchy_items then + return + end + if #call_hierarchy_items == 1 then + return call_hierarchy_items[1] + end + local items = {} + for i, item in pairs(call_hierarchy_items) do + local entry = item.detail or item.name + table.insert(items, string.format("%d. %s", i, entry)) + end + local choice = vim.fn.inputlist(items) + if choice < 1 or choice > #items then + return + end + return choice +end + +local function calls(opts, direction) + local params = vim.lsp.util.make_position_params() + vim.lsp.buf_request(opts.bufnr, "textDocument/prepareCallHierarchy", params, function(err, result) + if err then + vim.api.nvim_err_writeln("Error when preparing call hierarchy: " .. err) + return + end + + local call_hierarchy_item = pick_call_hierarchy_item(result) + if not call_hierarchy_item then + return + end + + if direction == "from" then + call_hierarchy(opts, "callHierarchy/incomingCalls", "LSP Incoming Calls", direction, call_hierarchy_item) + else + call_hierarchy(opts, "callHierarchy/outgoingCalls", "LSP Outgoing Calls", direction, call_hierarchy_item) + end + end) +end + +lsp.incoming_calls = function(opts) + calls(opts, "from") +end + +lsp.outgoing_calls = function(opts) + calls(opts, "to") +end + +local function list_or_jump(action, title, opts) local params = vim.lsp.util.make_position_params(opts.winnr) vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _) if err then @@ -271,6 +355,8 @@ local feature_map = { ["type_definitions"] = "typeDefinitionProvider", ["implementations"] = "implementationProvider", ["workspace_symbols"] = "workspaceSymbolProvider", + ["incoming_calls"] = "callHierarchyProvider", + ["outgoing_calls"] = "callHierarchyProvider", } local function apply_checks(mod) From db4635bddf4a4f48c9edce80ce5157275e6bba34 Mon Sep 17 00:00:00 2001 From: Dane Summers Date: Mon, 13 Jun 2022 12:42:00 -0400 Subject: [PATCH 19/35] fix(current_buffer_tags): tag-relative=never (#1970) --- lua/telescope/make_entry.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index e206fd5..efeb750 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -935,6 +935,7 @@ function make_entry.gen_from_ctags(opts) end end + local current_file_cache = {} return function(line) if line == "" or line:sub(1, 1) == "!" then return nil @@ -952,8 +953,14 @@ function make_entry.gen_from_ctags(opts) file = string.gsub(file, "/", "\\") end - if opts.only_current_file and file ~= current_file then - return nil + if opts.only_current_file then + if current_file_cache[file] == nil then + current_file_cache[file] = Path:new(file):normalize(cwd) == current_file + end + + if current_file_cache[file] == false then + return nil + end end local tag_entry = {} From bef86acb6c9ddf25602d28f4ad4980806f25420e Mon Sep 17 00:00:00 2001 From: Anton <14187674+antosha417@users.noreply.github.com> Date: Mon, 13 Jun 2022 19:51:48 +0300 Subject: [PATCH 20/35] feat(rg): pass multiple globs to rg by default (#2003) --- doc/telescope.txt | 42 +++++++++++++++++---------------- lua/telescope/builtin/files.lua | 6 ++++- lua/telescope/builtin/init.lua | 2 +- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 78cc7e4..15d957a 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -821,26 +821,28 @@ builtin.live_grep({opts}) *telescope.builtin.live_grep()* {opts} (table) options to pass to the picker Options: ~ - {cwd} (string) root dir to search from (default: - cwd, use utils.buffer_dir() to - search relative to open buffer) - {grep_open_files} (boolean) if true, restrict search to open - files only, mutually exclusive with - `search_dirs` - {search_dirs} (table) directory/directories/files to - search, mutually exclusive with - `grep_open_files` - {glob_pattern} (string) argument to be used with `--glob`, - e.g. "*.toml", can use the opposite - "!*.toml" - {type_filter} (string) argument to be used with `--type`, - e.g. "rust", see `rg --type-list` - {additional_args} (function) function(opts) which returns a table - of additional arguments to be passed - on - {max_results} (number) define a upper result value - {disable_coordinates} (boolean) don't show the line & row numbers - (default: false) + {cwd} (string) root dir to search from + (default: cwd, use + utils.buffer_dir() to search + relative to open buffer) + {grep_open_files} (boolean) if true, restrict search to open + files only, mutually exclusive + with `search_dirs` + {search_dirs} (table) directory/directories/files to + search, mutually exclusive with + `grep_open_files` + {glob_pattern} (string|table) argument to be used with + `--glob`, e.g. "*.toml", can use + the opposite "!*.toml" + {type_filter} (string) argument to be used with + `--type`, e.g. "rust", see `rg + --type-list` + {additional_args} (function) function(opts) which returns a + table of additional arguments to + be passed on + {max_results} (number) define a upper result value + {disable_coordinates} (boolean) don't show the line & row + numbers (default: false) builtin.grep_string({opts}) *telescope.builtin.grep_string()* diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 00c8d78..599dc55 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -76,8 +76,12 @@ files.live_grep = function(opts) additional_args[#additional_args + 1] = "--type=" .. opts.type_filter end - if opts.glob_pattern then + if type(opts.glob_pattern) == "string" then additional_args[#additional_args + 1] = "--glob=" .. opts.glob_pattern + elseif type(opts.glob_pattern) == "table" then + for i = 1, #opts.glob_pattern do + additional_args[#additional_args + 1] = "--glob=" .. opts.glob_pattern[i] + end end local live_grepper = finders.new_job(function(prompt) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 20d9812..145338b 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -55,7 +55,7 @@ end ---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer) ---@field grep_open_files boolean: if true, restrict search to open files only, mutually exclusive with `search_dirs` ---@field search_dirs table: directory/directories/files to search, mutually exclusive with `grep_open_files` ----@field glob_pattern string: argument to be used with `--glob`, e.g. "*.toml", can use the opposite "!*.toml" +---@field glob_pattern string|table: argument to be used with `--glob`, e.g. "*.toml", can use the opposite "!*.toml" ---@field type_filter string: argument to be used with `--type`, e.g. "rust", see `rg --type-list` ---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on ---@field max_results number: define a upper result value From 25b1bc8f17e1b658551cf2435fa2070dc96edc4e Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Mon, 13 Jun 2022 18:53:16 +0200 Subject: [PATCH 21/35] feat: clear previewer if no item is selected (#2004) --- lua/telescope/pickers.lua | 7 +++---- lua/telescope/previewers/previewer.lua | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 9397c57..1a45cd4 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -965,6 +965,9 @@ function Picker:set_selection(row) state.set_global_key("selected_entry", entry) if not entry then + -- also refresh previewer when there is no entry selected, so the preview window is cleared + self._selection_entry = entry + self:refresh_previewer() return end @@ -1068,10 +1071,6 @@ end --- Refresh the previewer based on the current `status` of the picker function Picker:refresh_previewer() local status = state.get_status(self.prompt_bufnr) - if not self._selection_entry then - -- if selection_entry is nil there is nothing to be previewed - return - end if self.previewer and status.preview_win and a.nvim_win_is_valid(status.preview_win) then self:_increment "previewed" diff --git a/lua/telescope/previewers/previewer.lua b/lua/telescope/previewers/previewer.lua index 834df2c..f986dac 100644 --- a/lua/telescope/previewers/previewer.lua +++ b/lua/telescope/previewers/previewer.lua @@ -1,3 +1,5 @@ +local utils = require "telescope.utils" + local Previewer = {} Previewer.__index = Previewer @@ -25,11 +27,19 @@ function Previewer:new(opts) _send_input = opts.send_input, _scroll_fn = opts.scroll_fn, preview_fn = opts.preview_fn, + _empty_bufnr = nil, }, Previewer) end function Previewer:preview(entry, status) if not entry then + if not self._empty_bufnr then + self._empty_bufnr = vim.api.nvim_create_buf(false, true) + end + + if vim.api.nvim_buf_is_valid(self._empty_bufnr) then + vim.api.nvim_win_set_buf(status.preview_win, self._empty_bufnr) + end return end @@ -47,7 +57,11 @@ end function Previewer:title(entry, dynamic) if dynamic == true and self._dyn_title_fn ~= nil then if entry == nil then - return nil + if self._title_fn ~= nil then + return self:_title_fn() + else + return "" + end end return self:_dyn_title_fn(entry) end @@ -57,6 +71,9 @@ function Previewer:title(entry, dynamic) end function Previewer:teardown() + if self._empty_bufnr then + utils.buf_delete(self._empty_bufnr) + end if self._teardown_func then self:_teardown_func() end From d1f3e12a353d4d04baa1f9096a0b720c713c37ee Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 26 Jun 2022 11:37:51 +0200 Subject: [PATCH 22/35] feat: add min max boundary to width, hight resolver (#2002) --- doc/telescope.txt | 14 +++++++--- lua/telescope/config/resolve.lua | 37 ++++++++++++++++++++++----- lua/tests/automated/resolver_spec.lua | 8 ++++++ 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 15d957a..a12bb09 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1947,14 +1947,17 @@ Provides "resolver functions" to allow more customisable inputs for options. resolver.resolve_height() *telescope.resolve.resolve_height()* Converts input to a function that returns the height. The input must take - one of four forms: + one of five forms: 1. 0 <= number < 1 This means total height as a percentage. 2. 1 <= number This means total height as a fixed number. 3. function Must have signature: function(self, max_columns, max_lines): number - 4. table of the form: {padding = `foo`} + 4. table of the form: { val, max = ..., min = ... } + val has to be in the first form 0 <= val < 1 and only one is given, + `min` or `max` as fixed number + 5. table of the form: {padding = `foo`} where `foo` has one of the previous three forms. The height is then set to be the remaining space after padding. For example, if the window has height 50, and the input is {padding = 5}, @@ -1967,14 +1970,17 @@ resolver.resolve_height() *telescope.resolve.resolve_height()* resolver.resolve_width() *telescope.resolve.resolve_width()* Converts input to a function that returns the width. The input must take - one of four forms: + one of five forms: 1. 0 <= number < 1 This means total width as a percentage. 2. 1 <= number This means total width as a fixed number. 3. function Must have signature: function(self, max_columns, max_lines): number - 4. table of the form: {padding = `foo`} + 4. table of the form: { val, max = ..., min = ... } + val has to be in the first form 0 <= val < 1 and only one is given, + `min` or `max` as fixed number + 5. table of the form: {padding = `foo`} where `foo` has one of the previous three forms. The width is then set to be the remaining space after padding. For example, if the window has width 100, and the input is {padding = 5}, diff --git a/lua/telescope/config/resolve.lua b/lua/telescope/config/resolve.lua index 6281a51..ad8936e 100644 --- a/lua/telescope/config/resolve.lua +++ b/lua/telescope/config/resolve.lua @@ -127,9 +127,6 @@ end] = function(selector, val) end end --- Tables TODO: --- ... {70, max} - -- function: -- Function must have same signature as get_window_layout -- function(self, max_columns, max_lines): number @@ -141,6 +138,26 @@ end] = function(_, val) return val end +_resolve_map[function(val) + return type(val) == "table" and val[1] >= 0 and val[1] < 1 and val["max"] ~= nil +end] = + function(selector, val) + return function(...) + local selected = select(selector, ...) + return math.min(math.floor(val[1] * selected), val["max"]) + end + end + +_resolve_map[function(val) + return type(val) == "table" and val[1] >= 0 and val[1] < 1 and val["min"] ~= nil +end] = + function(selector, val) + return function(...) + local selected = select(selector, ...) + return math.max(math.floor(val[1] * selected), val["min"]) + end + end + -- Add padding option _resolve_map[function(val) return type(val) == "table" and val["padding"] ~= nil @@ -162,7 +179,7 @@ end] = function(selector, val) end --- Converts input to a function that returns the height. ---- The input must take one of four forms: +--- The input must take one of five forms: --- 1. 0 <= number < 1
--- This means total height as a percentage. --- 2. 1 <= number
@@ -170,7 +187,10 @@ end --- 3. function
--- Must have signature: --- function(self, max_columns, max_lines): number ---- 4. table of the form: {padding = `foo`}
+--- 4. table of the form: { val, max = ..., min = ... }
+--- val has to be in the first form 0 <= val < 1 and only one is given, +--- `min` or `max` as fixed number +--- 5. table of the form: {padding = `foo`}
--- where `foo` has one of the previous three forms.
--- The height is then set to be the remaining space after padding. --- For example, if the window has height 50, and the input is {padding = 5}, @@ -188,7 +208,7 @@ resolver.resolve_height = function(val) end --- Converts input to a function that returns the width. ---- The input must take one of four forms: +--- The input must take one of five forms: --- 1. 0 <= number < 1
--- This means total width as a percentage. --- 2. 1 <= number
@@ -196,7 +216,10 @@ end --- 3. function
--- Must have signature: --- function(self, max_columns, max_lines): number ---- 4. table of the form: {padding = `foo`}
+--- 4. table of the form: { val, max = ..., min = ... }
+--- val has to be in the first form 0 <= val < 1 and only one is given, +--- `min` or `max` as fixed number +--- 5. table of the form: {padding = `foo`}
--- where `foo` has one of the previous three forms.
--- The width is then set to be the remaining space after padding. --- For example, if the window has width 100, and the input is {padding = 5}, diff --git a/lua/tests/automated/resolver_spec.lua b/lua/tests/automated/resolver_spec.lua index 0251ec0..f30a323 100644 --- a/lua/tests/automated/resolver_spec.lua +++ b/lua/tests/automated/resolver_spec.lua @@ -75,6 +75,14 @@ describe("telescope.config.resolve", function() end end) + it("should handle percentages with min/max boundary", function() + eq(20, resolve.resolve_width { 0.1, min = 20 }(nil, 40, 120)) + eq(30, resolve.resolve_height { 0.1, min = 20 }(nil, 40, 300)) + + eq(24, resolve.resolve_width { 0.4, max = 80 }(nil, 60, 60)) + eq(80, resolve.resolve_height { 0.4, max = 80 }(nil, 60, 300)) + end) + it("should handle fixed size", function() local fixed = { 5, 8, 13, 21, 34 } for _, s in ipairs(test_sizes) do From 4ef490defaca6343bd6e5c24f20ba8da50e66341 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Thu, 30 Jun 2022 13:59:16 +0200 Subject: [PATCH 23/35] fix: Inconsistent Color highlighting inside Git File Diff Preview fix #1098 --- lua/telescope/previewers/buffer_previewer.lua | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lua/telescope/previewers/buffer_previewer.lua b/lua/telescope/previewers/buffer_previewer.lua index 1c3ca8a..3ed13de 100644 --- a/lua/telescope/previewers/buffer_previewer.lua +++ b/lua/telescope/previewers/buffer_previewer.lua @@ -715,8 +715,12 @@ previewers.git_stash_diff = defaulter(function(opts) value = entry.value, bufname = self.state.bufname, cwd = opts.cwd, + callback = function(bufnr) + if vim.api.nvim_buf_is_valid(bufnr) then + putils.regex_highlighter(bufnr, "diff") + end + end, }) - putils.regex_highlighter(self.state.bufnr, "diff") end, } end, {}) @@ -741,10 +745,12 @@ previewers.git_commit_diff_to_parent = defaulter(function(opts) bufname = self.state.bufname, cwd = opts.cwd, callback = function(bufnr) - search_cb_jump(self, bufnr, opts.current_line) + if vim.api.nvim_buf_is_valid(bufnr) then + search_cb_jump(self, bufnr, opts.current_line) + putils.regex_highlighter(bufnr, "diff") + end end, }) - putils.regex_highlighter(self.state.bufnr, "diff") end, } end, {}) @@ -770,10 +776,12 @@ previewers.git_commit_diff_to_head = defaulter(function(opts) bufname = self.state.bufname, cwd = opts.cwd, callback = function(bufnr) - search_cb_jump(self, bufnr, opts.current_line) + if vim.api.nvim_buf_is_valid(bufnr) then + search_cb_jump(self, bufnr, opts.current_line) + putils.regex_highlighter(bufnr, "diff") + end end, }) - putils.regex_highlighter(self.state.bufnr, "diff") end, } end, {}) @@ -799,10 +807,12 @@ previewers.git_commit_diff_as_was = defaulter(function(opts) bufname = self.state.bufname, cwd = opts.cwd, callback = function(bufnr) - search_cb_jump(self, bufnr, opts.current_line) + if vim.api.nvim_buf_is_valid(bufnr) then + search_cb_jump(self, bufnr, opts.current_line) + putils.regex_highlighter(bufnr, ft) + end end, }) - putils.highlighter(self.state.bufnr, ft) end, } end, {}) @@ -864,8 +874,12 @@ previewers.git_file_diff = defaulter(function(opts) value = entry.value, bufname = self.state.bufname, cwd = opts.cwd, + callback = function(bufnr) + if vim.api.nvim_buf_is_valid(bufnr) then + putils.regex_highlighter(bufnr, "diff") + end + end, }) - putils.regex_highlighter(self.state.bufnr, "diff") end end, } From 1ba967f84e8416de9a3423bd693ec77744df8bff Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Thu, 30 Jun 2022 14:29:46 +0200 Subject: [PATCH 24/35] fix: truncate for builtin.buffers fix #2022 --- lua/telescope/make_entry.lua | 3 ++- lua/telescope/utils.lua | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index efeb750..8e9f84a 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -484,8 +484,9 @@ function make_entry.gen_from_buffer(opts) local cwd = vim.fn.expand(opts.cwd or vim.loop.cwd()) local make_display = function(entry) + -- bufnr_width + modes + icon + 3 spaces + : + lnum + opts.__prefix = opts.bufnr_width + 4 + icon_width + 3 + 1 + #tostring(entry.lnum) local display_bufname = utils.transform_path(opts, entry.filename) - local icon, hl_group = utils.get_devicons(entry.filename, disable_devicons) return displayer { diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 07800b2..356d102 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -276,7 +276,10 @@ utils.transform_path = function(opts, path) if opts.__length == nil then opts.__length = calc_result_length(path_display.truncate) end - transformed_path = truncate(transformed_path, opts.__length, nil, -1) + if opts.__prefix == nil then + opts.__prefix = 0 + end + transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1) end end From a50352eb2435a75f1d0c7af2e80133e3945fa20a Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Thu, 30 Jun 2022 14:36:41 +0200 Subject: [PATCH 25/35] docs: document limitation of action close #1994 --- doc/telescope.txt | 2 ++ lua/telescope/actions/init.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/doc/telescope.txt b/doc/telescope.txt index a12bb09..9903ac2 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -2380,6 +2380,8 @@ actions.edit_register({prompt_bufnr}) *telescope.actions.edit_register()* actions.paste_register({prompt_bufnr}) *telescope.actions.paste_register()* Paste the selected register into the buffer + Note: only meant to be used inside builtin.registers + Parameters: ~ {prompt_bufnr} (number) The prompt bufnr diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 0382014..21b651d 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -431,6 +431,8 @@ actions.edit_register = function(prompt_bufnr) end --- Paste the selected register into the buffer +--- +--- Note: only meant to be used inside builtin.registers ---@param prompt_bufnr number: The prompt bufnr actions.paste_register = function(prompt_bufnr) local selection = action_state.get_selected_entry() From 546947d442c9684c0dd97bcc6aa75dd5f947f86c Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Thu, 30 Jun 2022 14:56:49 +0200 Subject: [PATCH 26/35] fix: spell_suggest if cursor is at last char of word fix #1977 --- lua/telescope/builtin/internal.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 4519b93..8d644fb 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -1233,6 +1233,7 @@ internal.spell_suggest = function(opts) return end + action_state.get_current_picker(prompt_bufnr)._original_mode = "i" actions.close(prompt_bufnr) vim.cmd("normal! ciw" .. selection[1]) vim.cmd "stopinsert" From 8f56fede21f6bb2a2e5e600d78d75509dff821ca Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 19 Nov 2021 12:30:58 -0500 Subject: [PATCH 27/35] feat: Add entry_index for entry_makers cleanup --- lua/telescope/builtin/git.lua | 2 +- lua/telescope/builtin/internal.lua | 26 +++-- lua/telescope/make_entry.lua | 155 +++++++++++++++++++---------- 3 files changed, 115 insertions(+), 68 deletions(-) diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index 71203bb..7db45ef 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -281,7 +281,7 @@ git.branches = function(opts) entry.value = entry.name entry.ordinal = entry.name entry.display = make_display - return entry + return make_entry.set_default_entry_mt(entry, opts) end, }, previewer = previewers.git_branch_log.new(opts), diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 8d644fb..2cae23f 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -70,13 +70,13 @@ internal.builtin = function(opts) finder = finders.new_table { results = objs, entry_maker = function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry, text = entry.text, display = entry.text, ordinal = entry.text, filename = entry.filename, - } + }, opts) end, }, previewer = previewers.builtin.new(opts), @@ -221,11 +221,11 @@ internal.planets = function(opts) finder = finders.new_table { results = acceptable_files, entry_maker = function(line) - return { + return make_entry.set_default_entry_mt({ ordinal = line, display = line, filename = base_directory .. "/data/memes/planets/" .. line, - } + }, opts) end, }, previewer = previewers.cat.new(opts), @@ -298,11 +298,11 @@ internal.symbols = function(opts) finder = finders.new_table { results = results, entry_maker = function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry, ordinal = entry[1] .. " " .. entry[2], display = entry[1] .. " " .. entry[2], - } + }, opts) end, }, sorter = conf.generic_sorter(opts), @@ -399,14 +399,14 @@ internal.quickfixhistory = function(opts) end local entry_maker = opts.make_entry or function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry.title or "Untitled", ordinal = entry.title or "Untitled", display = entry.title or "Untitled", nr = entry.nr, id = entry.id, items = entry.items, - } + }, opts) end local qf_entry_maker = make_entry.gen_from_quickfix(opts) pickers.new(opts, { @@ -690,13 +690,13 @@ internal.help_tags = function(opts) finder = finders.new_table { results = tags, entry_maker = function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry.name .. "@" .. entry.lang, display = entry.name, ordinal = entry.name, filename = entry.filename, cmd = entry.cmd, - } + }, opts) end, }, previewer = previewers.help.new(opts), @@ -1189,10 +1189,8 @@ internal.autocommands = function(opts) return false end local val = selection.value - local output = vim.fn.execute( - "verb autocmd " .. val.group_name .. " " .. val.event .. " " .. val.pattern, - "silent" - ) + local group_name = val.group_name ~= "" or "" + local output = vim.fn.execute("verb autocmd " .. group_name .. " " .. val.event .. " " .. val.pattern, "silent") for line in output:gmatch "[^\r\n]+" do local source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$" if source_file and source_file ~= "Lua" then diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 8e9f84a..e8f2509 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -41,8 +41,40 @@ local get_filename_fn = function() end end +local handle_entry_index = function(opts, t, k) + local override = ((opts or {}).entry_index or {})[k] + if not override then + return + end + + local val, save = override(t, opts) + if save then + rawset(t, k, val) + end + return val +end + local make_entry = {} +make_entry.set_default_entry_mt = function(tbl, opts) + return setmetatable({}, { + __index = function(t, k) + local override = handle_entry_index(opts, t, k) + if override then + return override + end + + -- Only hit tbl once + local val = tbl[k] + if val then + rawset(t, k, val) + end + + return val + end, + }) +end + do local lookup_keys = { display = 1, @@ -50,13 +82,18 @@ do value = 1, } - local mt_string_entry = { - __index = function(t, k) - return rawget(t, rawget(lookup_keys, k)) - end, - } + function make_entry.gen_from_string(opts) + local mt_string_entry = { + __index = function(t, k) + local override = handle_entry_index(opts, t, k) + if override then + return override + end + + return rawget(t, rawget(lookup_keys, k)) + end, + } - function make_entry.gen_from_string() return function(line) return setmetatable({ line, @@ -97,6 +134,11 @@ do end mt_file_entry.__index = function(t, k) + local override = handle_entry_index(opts, t, k) + if override then + return override + end + local raw = rawget(mt_file_entry, k) if raw then return raw @@ -220,6 +262,11 @@ do end, __index = function(t, k) + local override = handle_entry_index(opts, t, k) + if override then + return override + end + local raw = rawget(mt_vimgrep_entry, k) if raw then return raw @@ -272,13 +319,13 @@ function make_entry.gen_from_git_stash(opts) local _, branch_name = string.match(splitted[2], "^([WIP on|On]+) (.+)") local commit_info = splitted[3] - return { + return make_entry.set_default_entry_mt({ value = stash_idx, ordinal = commit_info, branch_name = branch_name, commit_info = commit_info, display = make_display, - } + }, opts) end end @@ -312,13 +359,13 @@ function make_entry.gen_from_git_commits(opts) msg = "" end - return { + return make_entry.set_default_entry_mt({ value = sha, ordinal = sha .. " " .. msg, msg = msg, display = make_display, current_file = opts.current_file, - } + }, opts) end end @@ -364,7 +411,7 @@ function make_entry.gen_from_quickfix(opts) return function(entry) local filename = vim.F.if_nil(entry.filename, get_filename(entry.bufnr)) - return { + return make_entry.set_default_entry_mt({ value = entry, ordinal = (not hidden and filename or "") .. " " .. entry.text, display = make_display, @@ -376,7 +423,7 @@ function make_entry.gen_from_quickfix(opts) text = entry.text, start = entry.start, finish = entry.finish, - } + }, opts) end end @@ -443,8 +490,7 @@ function make_entry.gen_from_lsp_symbols(opts) ordinal = filename .. " " end ordinal = ordinal .. symbol_name .. " " .. (symbol_type or "unknown") - - return { + return make_entry.set_default_entry_mt({ value = entry, ordinal = ordinal, display = make_display, @@ -456,7 +502,7 @@ function make_entry.gen_from_lsp_symbols(opts) symbol_type = symbol_type, start = entry.start, finish = entry.finish, - } + }, opts) end end @@ -508,7 +554,7 @@ function make_entry.gen_from_buffer(opts) local indicator = entry.flag .. hidden .. readonly .. changed local line_count = vim.api.nvim_buf_line_count(entry.bufnr) - return { + return make_entry.set_default_entry_mt({ value = bufname, ordinal = entry.bufnr .. " : " .. bufname, display = make_display, @@ -518,7 +564,7 @@ function make_entry.gen_from_buffer(opts) -- account for potentially stale lnum as getbufinfo might not be updated or from resuming buffers picker lnum = entry.info.lnum ~= 0 and math.max(math.min(entry.info.lnum, line_count), 1) or 1, indicator = indicator, - } + }, opts) end end @@ -565,7 +611,7 @@ function make_entry.gen_from_treesitter(opts) local ts_utils = require "nvim-treesitter.ts_utils" local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node) local node_text = vim.treesitter.get_node_text(entry.node, bufnr) - return { + return make_entry.set_default_entry_mt({ value = entry.node, kind = entry.kind, ordinal = node_text .. " " .. (entry.kind or "unknown"), @@ -580,7 +626,7 @@ function make_entry.gen_from_treesitter(opts) text = node_text, start = start_row, finish = end_row, - } + }, opts) end end @@ -595,14 +641,12 @@ function make_entry.gen_from_packages(opts) end return function(module_name) - local entry = { + return make_entry.set_default_entry_mt({ valid = module_name ~= "", value = module_name, ordinal = module_name, - } - entry.display = make_display(module_name) - - return entry + display = make_display(module_name), + }, opts) end end @@ -644,21 +688,21 @@ function make_entry.gen_from_apropos(opts) cmd = vim.split(cmd, ",")[1] return keyword and sections[section] - and { + and make_entry.set_default_entry_mt({ value = cmd, description = desc, ordinal = cmd, display = make_display, section = section, keyword = keyword, - } + }, opts) or nil end end -function make_entry.gen_from_marks(_) +function make_entry.gen_from_marks(opts) return function(item) - return { + return make_entry.set_default_entry_mt({ value = item.line, ordinal = item.line, display = item.line, @@ -666,11 +710,11 @@ function make_entry.gen_from_marks(_) col = item.col, start = item.lnum, filename = item.filename, - } + }, opts) end end -function make_entry.gen_from_registers(_) +function make_entry.gen_from_registers(opts) local displayer = entry_display.create { separator = " ", hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" }, @@ -689,12 +733,12 @@ function make_entry.gen_from_registers(_) end return function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry, ordinal = entry, content = vim.fn.getreg(entry), display = make_display, - } + }, opts) end end @@ -727,7 +771,7 @@ function make_entry.gen_from_keymaps(opts) end return function(entry) - return { + return make_entry.set_default_entry_mt({ mode = entry.mode, lhs = get_lhs(entry), desc = get_desc(entry), @@ -736,22 +780,22 @@ function make_entry.gen_from_keymaps(opts) value = entry, ordinal = entry.mode .. " " .. get_lhs(entry) .. " " .. get_desc(entry), display = make_display, - } + }, opts) end end -function make_entry.gen_from_highlights() +function make_entry.gen_from_highlights(opts) local make_display = function(entry) local display = entry.value return display, { { { 0, #display }, display } } end return function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry, display = make_display, ordinal = entry, - } + }, opts) end end @@ -772,12 +816,12 @@ function make_entry.gen_from_picker(opts) end return function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry, text = entry.prompt_title, ordinal = string.format("%s %s", entry.prompt_title, vim.F.if_nil(entry.default_text, "")), display = make_display, - } + }, opts) end end @@ -820,17 +864,17 @@ function make_entry.gen_from_buffer_lines(opts) return end - return { + return make_entry.set_default_entry_mt({ ordinal = entry.text, display = make_display, filename = entry.filename, lnum = entry.lnum, text = entry.text, - } + }, opts) end end -function make_entry.gen_from_vimoptions() +function make_entry.gen_from_vimoptions(opts) local displayer = entry_display.create { separator = "", hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" }, @@ -871,7 +915,7 @@ function make_entry.gen_from_vimoptions() entry.ordinal = entry.ordinal .. " " .. utils.display_termcodes(tostring(o.default)) end - return entry + return make_entry.set_default_entry_mt(entry, opts) end end @@ -927,6 +971,11 @@ function make_entry.gen_from_ctags(opts) local mt = {} mt.__index = function(t, k) + local override = handle_entry_index(opts, t, k) + if override then + return override + end + if k == "path" then local retpath = Path:new({ t.filename }):absolute() if not vim.loop.fs_access(retpath, "R", nil) then @@ -1036,7 +1085,7 @@ function make_entry.gen_from_diagnostics(opts) end return function(entry) - return { + return make_entry.set_default_entry_mt({ value = entry, ordinal = ("%s %s"):format(not hidden and entry.filename or "", entry.text), display = make_display, @@ -1045,11 +1094,11 @@ function make_entry.gen_from_diagnostics(opts) lnum = entry.lnum, col = entry.col, text = entry.text, - } + }, opts) end end -function make_entry.gen_from_autocommands(_) +function make_entry.gen_from_autocommands(opts) local displayer = entry_display.create { separator = "▏", items = { @@ -1071,7 +1120,7 @@ function make_entry.gen_from_autocommands(_) return function(entry) local group_name = vim.F.if_nil(entry.group_name, "") - return { + return make_entry.set_default_entry_mt({ value = { event = entry.event, group_name = group_name, @@ -1081,11 +1130,11 @@ function make_entry.gen_from_autocommands(_) -- ordinal = entry.event .. " " .. group_name .. " " .. entry.pattern .. " " .. entry.command, display = make_display, - } + }, opts) end end -function make_entry.gen_from_commands(_) +function make_entry.gen_from_commands(opts) local displayer = entry_display.create { separator = "▏", items = { @@ -1118,7 +1167,7 @@ function make_entry.gen_from_commands(_) end return function(entry) - return { + return make_entry.set_default_entry_mt({ name = entry.name, bang = entry.bang, nargs = entry.nargs, @@ -1128,7 +1177,7 @@ function make_entry.gen_from_commands(_) value = entry, ordinal = entry.name, display = make_display, - } + }, opts) end end @@ -1187,13 +1236,13 @@ function make_entry.gen_from_git_status(opts) end local mod, file = string.match(entry, "(..).*%s[->%s]?(.+)") - return { + return setmetatable({ value = file, status = mod, ordinal = entry, display = make_display, path = Path:new({ opts.cwd, file }):absolute(), - } + }, opts) end end From a0a038170dbb5e4b69a50f648a8cf5cae6a910a3 Mon Sep 17 00:00:00 2001 From: julianf Date: Thu, 30 Jun 2022 16:03:55 +0200 Subject: [PATCH 28/35] docs: `make_entry` and `entry_display` --- doc/telescope.txt | 95 +++++++++++++++++++++++++ lua/telescope/make_entry.lua | 42 +++++++++-- lua/telescope/pickers/entry_display.lua | 60 ++++++++++++++++ scripts/gendocs.lua | 2 + 4 files changed, 194 insertions(+), 5 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 9903ac2..a736d18 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -2006,6 +2006,101 @@ resolver.resolve_anchor_pos() *telescope.resolve.resolve_anchor_pos()* +================================================================================ + *telescope.make_entry* + +Each picker has a finder made up of two parts, the results which are the data +to be displayed, and the entry_maker. These entry_makers are functions returned +from make_entry functions. These will be referrd to as entry_makers in the +following documentation. + +Every entry maker returns a function which accepts the data to be used for an +entry. This function will return an entry table (or nil, meaning skip this +entry) which contains of the - following important keys: +- value any: value key can be anything but still required +- valid bool: is an optional key because it defaults to true but if the key is + set to false it will not be displayed by the picker. (optional) +- ordinal string: is the text that is used for filtering (required) +- display string|function: is either a string of the text that is being + displayed or a function receiving the entry at a later stage, when the entry + is actually being displayed. A function can be useful here if complex + calculation have to be done. `make_entry` can also return a second value a + highlight array which will then apply to the line. Highlight entry in this + array has the following signature `{ { start_col, end_col }, hl_group }` + (required). +- filename string: will be interpreted by the default `` action as open + this file (optional) +- bufnr number: will be interpreted by the default `` action as open this + buffer (optional) +- lnum number: lnum value which will be interpreted by the default `` + action as a jump to this line (optional) +- col number: col value which will be interpreted by the default `` action + as a jump to this column (optional) + +More information on easier displaying, see |telescope.pickers.entry_display| + +TODO: Document something we call `entry_index` + + +================================================================================ + *telescope.pickers.entry_display* + +Entry Display is used to format each entry shown in the result panel. + +Entry Display create() will give us a function based on the configuration of +column widths we pass into it. We then can use this function n times to return +a string based on structured input. + +Note that if you call `create()` inside `make_display` it will be called for +every single entry. So it is suggested to do this outside of `make_display` for +the best performance. + +The create function will use the column widths passed to it in +configaration.items. Each item in that table is the number of characters in the +column. It's also possible for the final column to not have a fixed width, this +will be shown in the configuartion as 'remaining = true'. + +An example of this configuration is shown for the buffers picker +> +local displayer = entry_display.create { + separator = " ", + items = { + { width = opts.bufnr_width }, + { width = 4 }, + { width = icon_width }, + { remaining = true }, + }, +} +< + +This shows 4 columns, the first is defined in the opts as the width we'll use +when display_string the number of the buffer. The second has a fixed width of 4 +and the 3rd column's widht will be decided by the width of the icons we use. +The fourth column will use the remaining space. Finally we have also defined +the seperator between each column will be the space " ". + +An example of how the display reference will be used is shown, again for the +buffers picker: +> +return displayer { + { entry.bufnr, "TelescopeResultsNumber" }, + { entry.indicator, "TelescopeResultsComment" }, + { icon, hl_group }, + display_bufname .. ":" .. entry.lnum, +} +< + +There are two types of values each column can have. Either a simple String or a +table containing the String as well as the hl_group. + +The displayer can return values, string and an optional highlights. String is +all the text to be displayed for this entry as a single string. If parts of the +string are to be highlighted they will be described in the highlights table. + +For better understanding of how create() and displayer are used it's best to +look at the code in make_entry.lua. + + ================================================================================ *telescope.utils* diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index e8f2509..64993df 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -1,3 +1,40 @@ +---@tag telescope.make_entry + +---@brief [[ +--- +--- Each picker has a finder made up of two parts, the results which are the +--- data to be displayed, and the entry_maker. These entry_makers are functions +--- returned from make_entry functions. These will be referrd to as +--- entry_makers in the following documentation. +--- +--- Every entry maker returns a function which accepts the data to be used for +--- an entry. This function will return an entry table (or nil, meaning skip +--- this entry) which contains of the - following important keys: +--- - value any: value key can be anything but still required +--- - valid bool: is an optional key because it defaults to true but if the key +--- is set to false it will not be displayed by the picker. (optional) +--- - ordinal string: is the text that is used for filtering (required) +--- - display string|function: is either a string of the text that is being +--- displayed or a function receiving the entry at a later stage, when the entry +--- is actually being displayed. A function can be useful here if complex +--- calculation have to be done. `make_entry` can also return a second value +--- a highlight array which will then apply to the line. Highlight entry in +--- this array has the following signature `{ { start_col, end_col }, hl_group }` +--- (required). +--- - filename string: will be interpreted by the default `` action as +--- open this file (optional) +--- - bufnr number: will be interpreted by the default `` action as open +--- this buffer (optional) +--- - lnum number: lnum value which will be interpreted by the default `` +--- action as a jump to this line (optional) +--- - col number: col value which will be interpreted by the default `` +--- action as a jump to this column (optional) +--- +--- More information on easier displaying, see |telescope.pickers.entry_display| +--- +--- TODO: Document something we call `entry_index` +---@brief ]] + local entry_display = require "telescope.pickers.entry_display" local utils = require "telescope.utils" local strings = require "plenary.strings" @@ -190,9 +227,6 @@ do return { filename, lnum, col, text } end - --- Special options: - --- - disable_coordinates: Don't show the line & row numbers - --- - only_sort_text: Only sort via the text. Ignore filename and other items function make_entry.gen_from_vimgrep(opts) local mt_vimgrep_entry @@ -919,8 +953,6 @@ function make_entry.gen_from_vimoptions(opts) end end ---- Special options: ---- - only_sort_tags: Only sort via tag name. Ignore filename and other items function make_entry.gen_from_ctags(opts) opts = opts or {} diff --git a/lua/telescope/pickers/entry_display.lua b/lua/telescope/pickers/entry_display.lua index b1a1473..6e520f4 100644 --- a/lua/telescope/pickers/entry_display.lua +++ b/lua/telescope/pickers/entry_display.lua @@ -1,3 +1,63 @@ +---@tag telescope.pickers.entry_display + +---@brief [[ +--- Entry Display is used to format each entry shown in the result panel. +--- +--- Entry Display create() will give us a function based on the configuration +--- of column widths we pass into it. We then can use this function n times to +--- return a string based on structured input. +--- +--- Note that if you call `create()` inside `make_display` it will be called for +--- every single entry. So it is suggested to do this outside of `make_display` +--- for the best performance. +--- +--- The create function will use the column widths passed to it in +--- configaration.items. Each item in that table is the number of characters in +--- the column. It's also possible for the final column to not have a fixed +--- width, this will be shown in the configuartion as 'remaining = true'. +--- +--- An example of this configuration is shown for the buffers picker +--- +--- local displayer = entry_display.create { +--- separator = " ", +--- items = { +--- { width = opts.bufnr_width }, +--- { width = 4 }, +--- { width = icon_width }, +--- { remaining = true }, +--- }, +--- } +--- +--- +--- This shows 4 columns, the first is defined in the opts as the width we'll +--- use when display_string the number of the buffer. The second has a fixed +--- width of 4 and the 3rd column's widht will be decided by the width of the +--- icons we use. The fourth column will use the remaining space. Finally we +--- have also defined the seperator between each column will be the space " ". +--- +--- An example of how the display reference will be used is shown, again for +--- the buffers picker: +--- +--- return displayer { +--- { entry.bufnr, "TelescopeResultsNumber" }, +--- { entry.indicator, "TelescopeResultsComment" }, +--- { icon, hl_group }, +--- display_bufname .. ":" .. entry.lnum, +--- } +--- +--- +--- There are two types of values each column can have. Either a simple String +--- or a table containing the String as well as the hl_group. +--- +--- The displayer can return values, string and an optional highlights. +--- String is all the text to be displayed for this entry as a single string. If +--- parts of the string are to be highlighted they will be described in the +--- highlights table. +--- +--- For better understanding of how create() and displayer are used it's best to look +--- at the code in make_entry.lua. +---@brief ]] + local strings = require "plenary.strings" local state = require "telescope.state" local resolve = require "telescope.config.resolve" diff --git a/scripts/gendocs.lua b/scripts/gendocs.lua index 524cb04..cc9f158 100644 --- a/scripts/gendocs.lua +++ b/scripts/gendocs.lua @@ -17,6 +17,8 @@ docs.test = function() "./lua/telescope/themes.lua", "./lua/telescope/pickers/layout_strategies.lua", "./lua/telescope/config/resolve.lua", + "./lua/telescope/make_entry.lua", + "./lua/telescope/pickers/entry_display.lua", "./lua/telescope/utils.lua", "./lua/telescope/actions/init.lua", "./lua/telescope/actions/state.lua", From ef9137d85c935b83ec513db23214c7d9a0bd2b45 Mon Sep 17 00:00:00 2001 From: Fabian David Schmidt Date: Fri, 13 Aug 2021 17:32:01 +0200 Subject: [PATCH 29/35] feat: refine with new_table --- lua/telescope/actions/generate.lua | 56 +++++++++++++++++++ lua/telescope/builtin/files.lua | 10 ++++ lua/telescope/builtin/lsp.lua | 15 ++++- .../finders/async_oneshot_finder.lua | 1 + lua/telescope/finders/async_static_finder.lua | 1 + lua/telescope/pickers.lua | 2 +- 6 files changed, 82 insertions(+), 3 deletions(-) diff --git a/lua/telescope/actions/generate.lua b/lua/telescope/actions/generate.lua index 2069b03..703c83d 100644 --- a/lua/telescope/actions/generate.lua +++ b/lua/telescope/actions/generate.lua @@ -24,6 +24,10 @@ ---@brief ]] local actions = require "telescope.actions" +local config = require "telescope.config" +local action_state = require "telescope.actions.state" +local finders = require "telescope.finders" + local action_generate = {} --- Display the keymaps of registered actions similar to which-key.nvim.
@@ -54,4 +58,56 @@ action_generate.which_key = function(opts) end end +action_generate.refine = function(prompt_bufnr, opts) + opts = opts or {} + opts.prompt_to_prefix = vim.F.if_nil(opts.prompt_to_prefix, false) + opts.prefix_hl_group = vim.F.if_nil(opts.prompt_hl_group, "TelescopePromptPrefix") + opts.prompt_prefix = vim.F.if_nil(opts.promt_prefix, config.values.prompt_prefix) + opts.reset_multi_selection = vim.F.if_nil(opts.reset_multi_selection, false) + opts.reset_prompt = vim.F.if_nil(opts.reset_prompt, true) + opts.sorter = vim.F.if_nil(opts.sorter, config.values.generic_sorter {}) + + local current_picker = action_state.get_current_picker(prompt_bufnr) + + -- title + if opts.prompt_title then + current_picker.prompt_border:change_title(opts.prompt_title) + end + + if opts.results_title then + current_picker.results_border:change_title(opts.results_title) + end + + local results = {} + for entry in current_picker.manager:iter() do + table.insert(results, entry) + end + + -- if opts.sorter == false, keep older sorter + if opts.sorter then + current_picker.sorter:_destroy() + current_picker.sorter = opts.sorter + current_picker.sorter:_init() + end + + local new_finder = finders.new_table { + results = results, + entry_maker = function(x) + return x + end, + } + + if not opts.reset_multi_selection and action_state.get_current_line() ~= "" then + opts.multi = current_picker._multi + end + + if opts.prompt_to_prefix then + local prompt = action_state.get_current_line() + local current_prefix = current_picker.prompt_prefix + local suffix = current_prefix ~= opts.prompt_prefix and current_prefix or "" + opts.new_prefix = suffix .. prompt .. " " .. opts.prompt_prefix + end + current_picker:refresh(new_finder, opts) +end + return action_generate diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 599dc55..94639f6 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -111,6 +111,16 @@ files.live_grep = function(opts) -- TODO: It would be cool to use `--json` output for this -- and then we could get the highlight positions directly. sorter = sorters.highlighter_only(opts), + attach_mappings = function(_, map) + map("i", "", function(prompt_bufnr) + local line = action_state.get_current_line() + require("telescope.actions.generate").refine(prompt_bufnr, { + prompt_title = "Find Word (" .. line .. ")", + sorter = conf.generic_sorter(opts), + }) + end) + return true + end, }):find() end diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 85fabb0..480d456 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -1,5 +1,6 @@ local channel = require("plenary.async.control").channel - +local action_state = require "telescope.actions.state" +local sorters = require "telescope.sorters" local conf = require("telescope.config").values local finders = require "telescope.finders" local make_entry = require "telescope.make_entry" @@ -315,7 +316,17 @@ lsp.dynamic_workspace_symbols = function(opts) fn = get_workspace_symbols_requester(opts.bufnr, opts), }, previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), + sorter = sorters.highlighter_only(opts), + attach_mappings = function(_, map) + map("i", "", function(prompt_bufnr) + local line = action_state.get_current_line() + require("telescope.actions.generate").refine(prompt_bufnr, { + prompt_title = "LSP Workspace Symbols (" .. line .. ")", + sorter = conf.generic_sorter(opts), + }) + end) + return true + end, }):find() end diff --git a/lua/telescope/finders/async_oneshot_finder.lua b/lua/telescope/finders/async_oneshot_finder.lua index c8c2957..e3bd0ad 100644 --- a/lua/telescope/finders/async_oneshot_finder.lua +++ b/lua/telescope/finders/async_oneshot_finder.lua @@ -30,6 +30,7 @@ return function(opts) end end, results = results, + entry_maker = entry_maker, }, { __call = function(_, prompt, process_result, process_complete) if not job_started then diff --git a/lua/telescope/finders/async_static_finder.lua b/lua/telescope/finders/async_static_finder.lua index 941d858..7a684f9 100644 --- a/lua/telescope/finders/async_static_finder.lua +++ b/lua/telescope/finders/async_static_finder.lua @@ -24,6 +24,7 @@ return function(opts) return setmetatable({ results = results, + entry_maker = entry_maker, close = function() end, }, { __call = function(_, _, process_result, process_complete) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 1a45cd4..82ccda9 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -911,7 +911,7 @@ function Picker:refresh(finder, opts) local handle = type(opts.new_prefix) == "table" and unpack or function(x) return x end - self:change_prompt_prefix(handle(opts.new_prefix)) + self:change_prompt_prefix(handle(opts.new_prefix), opts.prefix_hl_group) end if finder then From 21eea92e727749ca3f6a5d2f0659f2c38d784c83 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Fri, 1 Jul 2022 18:58:13 +0200 Subject: [PATCH 30/35] fix: autocommands regression --- lua/telescope/builtin/internal.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 2cae23f..4277e2e 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -1189,7 +1189,7 @@ internal.autocommands = function(opts) return false end local val = selection.value - local group_name = val.group_name ~= "" or "" + local group_name = val.group_name ~= "" and val.group_name or "" local output = vim.fn.execute("verb autocmd " .. group_name .. " " .. val.event .. " " .. val.pattern, "silent") for line in output:gmatch "[^\r\n]+" do local source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$" From 75deb22aa84760bf496427efb7ef0e2660e41bdc Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Fri, 1 Jul 2022 19:18:30 +0200 Subject: [PATCH 31/35] fix: crash in tags on enter for no results and random crash in previewer --- lua/telescope/builtin/files.lua | 3 +++ lua/telescope/previewers/buffer_previewer.lua | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 94639f6..d6fa9b4 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -458,6 +458,9 @@ files.tags = function(opts) action_set.select:enhance { post = function() local selection = action_state.get_selected_entry() + if not selection then + return + end if selection.scode then -- un-escape / then escape required diff --git a/lua/telescope/previewers/buffer_previewer.lua b/lua/telescope/previewers/buffer_previewer.lua index 3ed13de..f9e77d2 100644 --- a/lua/telescope/previewers/buffer_previewer.lua +++ b/lua/telescope/previewers/buffer_previewer.lua @@ -386,6 +386,10 @@ previewers.new_buffer_previewer = function(opts) opts.define_preview(self, entry, status) vim.schedule(function() + if not self or not self.state or not self.state.bufnr then + return + end + if vim.api.nvim_buf_is_valid(self.state.bufnr) then vim.api.nvim_buf_call(self.state.bufnr, function() vim.cmd "do User TelescopePreviewerLoaded" From bf1a25dbfe9a4368b10354cb46e4b3a0ab0a41a4 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+tobealive@users.noreply.github.com> Date: Fri, 1 Jul 2022 22:10:31 +0200 Subject: [PATCH 32/35] feat: search_file option for builtin fd command (#2029) --- doc/telescope.txt | 1 + lua/telescope/builtin/files.lua | 18 +++++++++++++++++- lua/telescope/builtin/init.lua | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index a736d18..6381b12 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -899,6 +899,7 @@ builtin.find_files({opts}) *telescope.builtin.find_files()* (default: false) {search_dirs} (table) directory/directories/files to search + {search_file} (string) specify a filename to search for builtin.fd() *telescope.builtin.fd()* diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index d6fa9b4..dddd18a 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -201,6 +201,7 @@ files.find_files = function(opts) local no_ignore_parent = opts.no_ignore_parent local follow = opts.follow local search_dirs = opts.search_dirs + local search_file = opts.search_file if search_dirs then for k, v in pairs(search_dirs) do @@ -221,8 +222,16 @@ files.find_files = function(opts) if follow then table.insert(find_command, "-L") end + if search_file then + if command == "rg" then + table.insert(find_command, "-g") + table.insert(find_command, "*" .. search_file .. "*") + else + table.insert(find_command, search_file) + end + end if search_dirs then - if command ~= "rg" then + if command ~= "rg" and not search_file then table.insert(find_command, ".") end for _, v in pairs(search_dirs) do @@ -243,6 +252,10 @@ files.find_files = function(opts) if follow then table.insert(find_command, 2, "-L") end + if search_file then + table.insert(find_command, "-name") + table.insert(find_command, "*" .. search_file .. "*") + end if search_dirs then table.remove(find_command, 2) for _, v in pairs(search_dirs) do @@ -265,6 +278,9 @@ files.find_files = function(opts) if search_dirs ~= nil then log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`." end + if search_file ~= nil then + log.warn "The `search_file` key is not available for the Windows `where` command in `find_files`." + end end if opts.cwd then diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 145338b..71cb583 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -83,6 +83,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_s ---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false) ---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false) ---@field search_dirs table: directory/directories/files to search +---@field search_file string: specify a filename to search for builtin.find_files = require_on_exported_call("telescope.builtin.files").find_files --- This is an alias for the `find_files` picker From 0621c1c6ba3e561dfb06f58a7b0aedfcd464b590 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Fri, 1 Jul 2022 22:20:12 +0200 Subject: [PATCH 33/35] break: prefix internal files and add deprecation messages (#2032) --- lua/telescope/builtin/__diagnostics.lua | 150 +++ lua/telescope/builtin/__files.lua | 522 +++++++++ lua/telescope/builtin/__git.lua | 411 +++++++ lua/telescope/builtin/__internal.lua | 1318 ++++++++++++++++++++++ lua/telescope/builtin/__lsp.lua | 389 +++++++ lua/telescope/builtin/diagnostics.lua | 163 +-- lua/telescope/builtin/files.lua | 533 +-------- lua/telescope/builtin/git.lua | 422 +------ lua/telescope/builtin/init.lua | 100 +- lua/telescope/builtin/internal.lua | 1329 +---------------------- lua/telescope/builtin/lsp.lua | 404 +------ 11 files changed, 2913 insertions(+), 2828 deletions(-) create mode 100644 lua/telescope/builtin/__diagnostics.lua create mode 100644 lua/telescope/builtin/__files.lua create mode 100644 lua/telescope/builtin/__git.lua create mode 100644 lua/telescope/builtin/__internal.lua create mode 100644 lua/telescope/builtin/__lsp.lua diff --git a/lua/telescope/builtin/__diagnostics.lua b/lua/telescope/builtin/__diagnostics.lua new file mode 100644 index 0000000..2614e36 --- /dev/null +++ b/lua/telescope/builtin/__diagnostics.lua @@ -0,0 +1,150 @@ +local conf = require("telescope.config").values +local finders = require "telescope.finders" +local make_entry = require "telescope.make_entry" +local pickers = require "telescope.pickers" +local utils = require "telescope.utils" + +local diagnostics = {} + +local convert_diagnostic_type = function(severities, severity) + -- convert from string to int + if type(severity) == "string" then + -- make sure that e.g. error is uppercased to ERROR + return severities[severity:upper()] + end + -- otherwise keep original value, incl. nil + return severity +end + +local diagnostics_to_tbl = function(opts) + opts = vim.F.if_nil(opts, {}) + local items = {} + local severities = vim.diagnostic.severity + local current_buf = vim.api.nvim_get_current_buf() + + opts.severity = convert_diagnostic_type(severities, opts.severity) + opts.severity_limit = convert_diagnostic_type(severities, opts.severity_limit) + opts.severity_bound = convert_diagnostic_type(severities, opts.severity_bound) + + local diagnosis_opts = { severity = {}, namespace = opts.namespace } + if opts.severity ~= nil then + if opts.severity_limit ~= nil or opts.severity_bound ~= nil then + utils.notify("builtin.diagnostics", { + msg = "Invalid severity parameters. Both a specific severity and a limit/bound is not allowed", + level = "ERROR", + }) + return {} + end + diagnosis_opts.severity = opts.severity + else + if opts.severity_limit ~= nil then + diagnosis_opts.severity["min"] = opts.severity_limit + end + if opts.severity_bound ~= nil then + diagnosis_opts.severity["max"] = opts.severity_bound + end + end + + opts.root_dir = opts.root_dir == true and vim.loop.cwd() or opts.root_dir + + local bufnr_name_map = {} + local filter_diag = function(diagnostic) + if bufnr_name_map[diagnostic.bufnr] == nil then + bufnr_name_map[diagnostic.bufnr] = vim.api.nvim_buf_get_name(diagnostic.bufnr) + end + + local root_dir_test = not opts.root_dir + or string.sub(bufnr_name_map[diagnostic.bufnr], 1, #opts.root_dir) == opts.root_dir + local listed_test = not opts.no_unlisted or vim.api.nvim_buf_get_option(diagnostic.bufnr, "buflisted") + + return root_dir_test and listed_test + end + + local preprocess_diag = function(diagnostic) + return { + bufnr = diagnostic.bufnr, + filename = bufnr_name_map[diagnostic.bufnr], + lnum = diagnostic.lnum + 1, + col = diagnostic.col + 1, + text = vim.trim(diagnostic.message:gsub("[\n]", "")), + type = severities[diagnostic.severity] or severities[1], + } + end + + for _, d in ipairs(vim.diagnostic.get(opts.bufnr, diagnosis_opts)) do + if filter_diag(d) then + table.insert(items, preprocess_diag(d)) + end + end + + -- sort results by bufnr (prioritize cur buf), severity, lnum + table.sort(items, function(a, b) + if a.bufnr == b.bufnr then + if a.type == b.type then + return a.lnum < b.lnum + else + return a.type < b.type + end + else + -- prioritize for current bufnr + if a.bufnr == current_buf then + return true + end + if b.bufnr == current_buf then + return false + end + return a.bufnr < b.bufnr + end + end) + + return items +end + +diagnostics.get = function(opts) + if opts.bufnr ~= 0 then + opts.bufnr = nil + end + if opts.bufnr == nil then + opts.path_display = vim.F.if_nil(opts.path_display, {}) + end + if type(opts.bufnr) == "string" then + opts.bufnr = tonumber(opts.bufnr) + end + + local locations = diagnostics_to_tbl(opts) + + if vim.tbl_isempty(locations) then + utils.notify("builtin.diagnostics", { + msg = "No diagnostics found", + level = "INFO", + }) + return + end + + opts.path_display = vim.F.if_nil(opts.path_display, "hidden") + pickers.new(opts, { + prompt_title = opts.bufnr == nil and "Workspace Diagnostics" or "Document Diagnostics", + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_diagnostics(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.prefilter_sorter { + tag = "type", + sorter = conf.generic_sorter(opts), + }, + }):find() +end + +local function apply_checks(mod) + for k, v in pairs(mod) do + mod[k] = function(opts) + opts = opts or {} + v(opts) + end + end + + return mod +end + +return apply_checks(diagnostics) diff --git a/lua/telescope/builtin/__files.lua b/lua/telescope/builtin/__files.lua new file mode 100644 index 0000000..dddd18a --- /dev/null +++ b/lua/telescope/builtin/__files.lua @@ -0,0 +1,522 @@ +local action_state = require "telescope.actions.state" +local action_set = require "telescope.actions.set" +local finders = require "telescope.finders" +local make_entry = require "telescope.make_entry" +local pickers = require "telescope.pickers" +local previewers = require "telescope.previewers" +local sorters = require "telescope.sorters" +local utils = require "telescope.utils" +local conf = require("telescope.config").values +local log = require "telescope.log" + +local Path = require "plenary.path" + +local flatten = vim.tbl_flatten +local filter = vim.tbl_filter + +local files = {} + +local escape_chars = function(string) + return string.gsub(string, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%.]", { + ["\\"] = "\\\\", + ["-"] = "\\-", + ["("] = "\\(", + [")"] = "\\)", + ["["] = "\\[", + ["]"] = "\\]", + ["{"] = "\\{", + ["}"] = "\\}", + ["?"] = "\\?", + ["+"] = "\\+", + ["*"] = "\\*", + ["^"] = "\\^", + ["$"] = "\\$", + ["."] = "\\.", + }) +end + +-- Special keys: +-- opts.search_dirs -- list of directory to search in +-- opts.grep_open_files -- boolean to restrict search to open files +files.live_grep = function(opts) + local vimgrep_arguments = opts.vimgrep_arguments or conf.vimgrep_arguments + local search_dirs = opts.search_dirs + local grep_open_files = opts.grep_open_files + opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd() + + local filelist = {} + + if grep_open_files then + local bufnrs = filter(function(b) + if 1 ~= vim.fn.buflisted(b) then + return false + end + return true + end, vim.api.nvim_list_bufs()) + if not next(bufnrs) then + return + end + + for _, bufnr in ipairs(bufnrs) do + local file = vim.api.nvim_buf_get_name(bufnr) + table.insert(filelist, Path:new(file):make_relative(opts.cwd)) + end + elseif search_dirs then + for i, path in ipairs(search_dirs) do + search_dirs[i] = vim.fn.expand(path) + end + end + + local additional_args = {} + if opts.additional_args ~= nil and type(opts.additional_args) == "function" then + additional_args = opts.additional_args(opts) + end + + if opts.type_filter then + additional_args[#additional_args + 1] = "--type=" .. opts.type_filter + end + + if type(opts.glob_pattern) == "string" then + additional_args[#additional_args + 1] = "--glob=" .. opts.glob_pattern + elseif type(opts.glob_pattern) == "table" then + for i = 1, #opts.glob_pattern do + additional_args[#additional_args + 1] = "--glob=" .. opts.glob_pattern[i] + end + end + + local live_grepper = finders.new_job(function(prompt) + -- TODO: Probably could add some options for smart case and whatever else rg offers. + + if not prompt or prompt == "" then + return nil + end + + local search_list = {} + + if search_dirs then + table.insert(search_list, search_dirs) + end + + if grep_open_files then + search_list = filelist + end + + return flatten { vimgrep_arguments, additional_args, "--", prompt, search_list } + end, opts.entry_maker or make_entry.gen_from_vimgrep(opts), opts.max_results, opts.cwd) + + pickers.new(opts, { + prompt_title = "Live Grep", + finder = live_grepper, + previewer = conf.grep_previewer(opts), + -- TODO: It would be cool to use `--json` output for this + -- and then we could get the highlight positions directly. + sorter = sorters.highlighter_only(opts), + attach_mappings = function(_, map) + map("i", "", function(prompt_bufnr) + local line = action_state.get_current_line() + require("telescope.actions.generate").refine(prompt_bufnr, { + prompt_title = "Find Word (" .. line .. ")", + sorter = conf.generic_sorter(opts), + }) + end) + return true + end, + }):find() +end + +-- Special keys: +-- opts.search -- the string to search. +-- opts.search_dirs -- list of directory to search in +-- opts.use_regex -- special characters won't be escaped +files.grep_string = function(opts) + -- TODO: This should probably check your visual selection as well, if you've got one + + local vimgrep_arguments = opts.vimgrep_arguments or conf.vimgrep_arguments + local search_dirs = opts.search_dirs + local word = opts.search or vim.fn.expand "" + local search = opts.use_regex and word or escape_chars(word) + local word_match = opts.word_match + opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts) + + local title_word = word:gsub("\n", "\\n") + + local additional_args = {} + if opts.additional_args ~= nil and type(opts.additional_args) == "function" then + additional_args = opts.additional_args(opts) + end + + local args = flatten { + vimgrep_arguments, + additional_args, + word_match, + "--", + search, + } + + if search_dirs then + for _, path in ipairs(search_dirs) do + table.insert(args, vim.fn.expand(path)) + end + end + + pickers.new(opts, { + prompt_title = "Find Word (" .. title_word .. ")", + finder = finders.new_oneshot_job(args, opts), + previewer = conf.grep_previewer(opts), + sorter = conf.generic_sorter(opts), + }):find() +end + +files.find_files = function(opts) + local find_command = (function() + if opts.find_command then + if type(opts.find_command) == "function" then + return opts.find_command(opts) + end + return opts.find_command + elseif 1 == vim.fn.executable "fd" then + return { "fd", "--type", "f" } + elseif 1 == vim.fn.executable "fdfind" then + return { "fdfind", "--type", "f" } + elseif 1 == vim.fn.executable "rg" then + return { "rg", "--files" } + elseif 1 == vim.fn.executable "find" and vim.fn.has "win32" == 0 then + return { "find", ".", "-type", "f" } + elseif 1 == vim.fn.executable "where" then + return { "where", "/r", ".", "*" } + end + end)() + + if not find_command then + utils.notify("builtin.find_files", { + msg = "You need to install either find, fd, or rg", + level = "ERROR", + }) + return + end + + local command = find_command[1] + local hidden = opts.hidden + local no_ignore = opts.no_ignore + local no_ignore_parent = opts.no_ignore_parent + local follow = opts.follow + local search_dirs = opts.search_dirs + local search_file = opts.search_file + + if search_dirs then + for k, v in pairs(search_dirs) do + search_dirs[k] = vim.fn.expand(v) + end + end + + if command == "fd" or command == "fdfind" or command == "rg" then + if hidden then + table.insert(find_command, "--hidden") + end + if no_ignore then + table.insert(find_command, "--no-ignore") + end + if no_ignore_parent then + table.insert(find_command, "--no-ignore-parent") + end + if follow then + table.insert(find_command, "-L") + end + if search_file then + if command == "rg" then + table.insert(find_command, "-g") + table.insert(find_command, "*" .. search_file .. "*") + else + table.insert(find_command, search_file) + end + end + if search_dirs then + if command ~= "rg" and not search_file then + table.insert(find_command, ".") + end + for _, v in pairs(search_dirs) do + table.insert(find_command, v) + end + end + elseif command == "find" then + if not hidden then + table.insert(find_command, { "-not", "-path", "*/.*" }) + find_command = flatten(find_command) + end + if no_ignore ~= nil then + log.warn "The `no_ignore` key is not available for the `find` command in `find_files`." + end + if no_ignore_parent ~= nil then + log.warn "The `no_ignore_parent` key is not available for the `find` command in `find_files`." + end + if follow then + table.insert(find_command, 2, "-L") + end + if search_file then + table.insert(find_command, "-name") + table.insert(find_command, "*" .. search_file .. "*") + end + if search_dirs then + table.remove(find_command, 2) + for _, v in pairs(search_dirs) do + table.insert(find_command, 2, v) + end + end + elseif command == "where" then + if hidden ~= nil then + log.warn "The `hidden` key is not available for the Windows `where` command in `find_files`." + end + if no_ignore ~= nil then + log.warn "The `no_ignore` key is not available for the Windows `where` command in `find_files`." + end + if no_ignore_parent ~= nil then + log.warn "The `no_ignore_parent` key is not available for the Windows `where` command in `find_files`." + end + if follow ~= nil then + log.warn "The `follow` key is not available for the Windows `where` command in `find_files`." + end + if search_dirs ~= nil then + log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`." + end + if search_file ~= nil then + log.warn "The `search_file` key is not available for the Windows `where` command in `find_files`." + end + end + + if opts.cwd then + opts.cwd = vim.fn.expand(opts.cwd) + end + + opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts) + + pickers.new(opts, { + prompt_title = "Find Files", + finder = finders.new_oneshot_job(find_command, opts), + previewer = conf.file_previewer(opts), + sorter = conf.file_sorter(opts), + }):find() +end + +local function prepare_match(entry, kind) + local entries = {} + + if entry.node then + table.insert(entries, entry) + else + for name, item in pairs(entry) do + vim.list_extend(entries, prepare_match(item, name)) + end + end + + return entries +end + +-- TODO: finish docs for opts.show_line +files.treesitter = function(opts) + opts.show_line = vim.F.if_nil(opts.show_line, true) + + local has_nvim_treesitter, _ = pcall(require, "nvim-treesitter") + if not has_nvim_treesitter then + utils.notify("builtin.treesitter", { + msg = "User need to install nvim-treesitter needs to be installed", + level = "ERROR", + }) + return + end + + local parsers = require "nvim-treesitter.parsers" + if not parsers.has_parser(parsers.get_buf_lang(opts.bufnr)) then + utils.notify("builtin.treesitter", { + msg = "No parser for the current buffer", + level = "ERROR", + }) + return + end + + local ts_locals = require "nvim-treesitter.locals" + local results = {} + for _, definition in ipairs(ts_locals.get_definitions(opts.bufnr)) do + local entries = prepare_match(ts_locals.get_local_nodes(definition)) + for _, entry in ipairs(entries) do + entry.kind = vim.F.if_nil(entry.kind, "") + table.insert(results, entry) + end + end + + if vim.tbl_isempty(results) then + return + end + + pickers.new(opts, { + prompt_title = "Treesitter Symbols", + finder = finders.new_table { + results = results, + entry_maker = opts.entry_maker or make_entry.gen_from_treesitter(opts), + }, + previewer = conf.grep_previewer(opts), + sorter = conf.prefilter_sorter { + tag = "kind", + sorter = conf.generic_sorter(opts), + }, + }):find() +end + +files.current_buffer_fuzzy_find = function(opts) + -- All actions are on the current buffer + local filename = vim.fn.expand(vim.api.nvim_buf_get_name(opts.bufnr)) + local filetype = vim.api.nvim_buf_get_option(opts.bufnr, "filetype") + + local lines = vim.api.nvim_buf_get_lines(opts.bufnr, 0, -1, false) + local lines_with_numbers = {} + + for lnum, line in ipairs(lines) do + table.insert(lines_with_numbers, { + lnum = lnum, + bufnr = opts.bufnr, + filename = filename, + text = line, + }) + end + + local ts_ok, ts_parsers = pcall(require, "nvim-treesitter.parsers") + if ts_ok then + filetype = ts_parsers.ft_to_lang(filetype) + end + local _, ts_configs = pcall(require, "nvim-treesitter.configs") + + local parser_ok, parser = pcall(vim.treesitter.get_parser, opts.bufnr, filetype) + local query_ok, query = pcall(vim.treesitter.get_query, filetype, "highlights") + if parser_ok and query_ok and ts_ok and ts_configs.is_enabled("highlight", filetype, opts.bufnr) then + local root = parser:parse()[1]:root() + + local highlighter = vim.treesitter.highlighter.new(parser) + local highlighter_query = highlighter:get_query(filetype) + + local line_highlights = setmetatable({}, { + __index = function(t, k) + local obj = {} + rawset(t, k, obj) + return obj + end, + }) + for id, node in query:iter_captures(root, opts.bufnr, 0, -1) do + local hl = highlighter_query:_get_hl_from_capture(id) + if hl and type(hl) ~= "number" then + local row1, col1, row2, col2 = node:range() + + if row1 == row2 then + local row = row1 + 1 + + for index = col1, col2 do + line_highlights[row][index] = hl + end + else + local row = row1 + 1 + for index = col1, #lines[row] do + line_highlights[row][index] = hl + end + + while row < row2 + 1 do + row = row + 1 + + for index = 0, #(lines[row] or {}) do + line_highlights[row][index] = hl + end + end + end + end + end + + opts.line_highlights = line_highlights + end + + pickers.new(opts, { + prompt_title = "Current Buffer Fuzzy", + finder = finders.new_table { + results = lines_with_numbers, + entry_maker = opts.entry_maker or make_entry.gen_from_buffer_lines(opts), + }, + sorter = conf.generic_sorter(opts), + previewer = conf.grep_previewer(opts), + attach_mappings = function() + action_set.select:enhance { + post = function() + local selection = action_state.get_selected_entry() + vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) + end, + } + + return true + end, + }):find() +end + +files.tags = function(opts) + local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles() + for i, ctags_file in ipairs(tagfiles) do + tagfiles[i] = vim.fn.expand(ctags_file, true) + end + if vim.tbl_isempty(tagfiles) then + utils.notify("builtin.tags", { + msg = "No tags file found. Create one with ctags -R", + level = "ERROR", + }) + return + end + opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_ctags(opts)) + + pickers.new(opts, { + prompt_title = "Tags", + finder = finders.new_oneshot_job(flatten { "cat", tagfiles }, opts), + previewer = previewers.ctags.new(opts), + sorter = conf.generic_sorter(opts), + attach_mappings = function() + action_set.select:enhance { + post = function() + local selection = action_state.get_selected_entry() + if not selection then + return + end + + if selection.scode then + -- un-escape / then escape required + -- special chars for vim.fn.search() + -- ] ~ * + local scode = selection.scode:gsub([[\/]], "/"):gsub("[%]~*]", function(x) + return "\\" .. x + end) + + vim.cmd "norm! gg" + vim.fn.search(scode) + vim.cmd "norm! zz" + else + vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) + end + end, + } + return true + end, + }):find() +end + +files.current_buffer_tags = function(opts) + return files.tags(vim.tbl_extend("force", { + prompt_title = "Current Buffer Tags", + only_current_file = true, + path_display = "hidden", + }, opts)) +end + +local function apply_checks(mod) + for k, v in pairs(mod) do + mod[k] = function(opts) + opts = opts or {} + + v(opts) + end + end + + return mod +end + +return apply_checks(files) diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua new file mode 100644 index 0000000..7db45ef --- /dev/null +++ b/lua/telescope/builtin/__git.lua @@ -0,0 +1,411 @@ +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local finders = require "telescope.finders" +local make_entry = require "telescope.make_entry" +local pickers = require "telescope.pickers" +local previewers = require "telescope.previewers" +local utils = require "telescope.utils" +local entry_display = require "telescope.pickers.entry_display" +local strings = require "plenary.strings" +local Path = require "plenary.path" + +local conf = require("telescope.config").values + +local git = {} + +git.files = function(opts) + if opts.is_bare then + utils.notify("builtin.git_files", { + msg = "This operation must be run in a work tree", + level = "ERROR", + }) + return + end + + local show_untracked = vim.F.if_nil(opts.show_untracked, false) + local recurse_submodules = vim.F.if_nil(opts.recurse_submodules, false) + if show_untracked and recurse_submodules then + utils.notify("builtin.git_files", { + msg = "Git does not support both --others and --recurse-submodules", + level = "ERROR", + }) + return + end + + -- By creating the entry maker after the cwd options, + -- we ensure the maker uses the cwd options when being created. + opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_file(opts)) + local git_command = vim.F.if_nil(opts.git_command, { "git", "ls-files", "--exclude-standard", "--cached" }) + + pickers.new(opts, { + prompt_title = "Git Files", + finder = finders.new_oneshot_job( + vim.tbl_flatten { + git_command, + show_untracked and "--others" or nil, + recurse_submodules and "--recurse-submodules" or nil, + }, + opts + ), + previewer = conf.file_previewer(opts), + sorter = conf.file_sorter(opts), + }):find() +end + +git.commits = function(opts) + opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) + local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit", "--", "." }) + + pickers.new(opts, { + prompt_title = "Git Commits", + finder = finders.new_oneshot_job(git_command, opts), + previewer = { + previewers.git_commit_diff_to_parent.new(opts), + previewers.git_commit_diff_to_head.new(opts), + previewers.git_commit_diff_as_was.new(opts), + previewers.git_commit_message.new(opts), + }, + sorter = conf.file_sorter(opts), + attach_mappings = function(_, map) + actions.select_default:replace(actions.git_checkout) + map("i", "m", actions.git_reset_mixed) + map("n", "m", actions.git_reset_mixed) + map("i", "s", actions.git_reset_soft) + map("n", "s", actions.git_reset_soft) + map("i", "h", actions.git_reset_hard) + map("n", "h", actions.git_reset_hard) + return true + end, + }):find() +end + +git.stash = function(opts) + opts.show_branch = vim.F.if_nil(opts.show_branch, true) + opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_stash(opts)) + + pickers.new(opts, { + prompt_title = "Git Stash", + finder = finders.new_oneshot_job( + vim.tbl_flatten { + "git", + "--no-pager", + "stash", + "list", + }, + opts + ), + previewer = previewers.git_stash_diff.new(opts), + sorter = conf.file_sorter(opts), + attach_mappings = function() + actions.select_default:replace(actions.git_apply_stash) + return true + end, + }):find() +end + +local get_current_buf_line = function(winnr) + local lnum = vim.api.nvim_win_get_cursor(winnr)[1] + return vim.trim(vim.api.nvim_buf_get_lines(vim.api.nvim_win_get_buf(winnr), lnum - 1, lnum, false)[1]) +end + +git.bcommits = function(opts) + opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil + opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) + opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) + local git_command = vim.F.if_nil( + opts.git_command, + { "git", "log", "--pretty=oneline", "--abbrev-commit", "--follow" } + ) + + pickers.new(opts, { + prompt_title = "Git BCommits", + finder = finders.new_oneshot_job( + vim.tbl_flatten { + git_command, + opts.current_file, + }, + opts + ), + previewer = { + previewers.git_commit_diff_to_parent.new(opts), + previewers.git_commit_diff_to_head.new(opts), + previewers.git_commit_diff_as_was.new(opts), + previewers.git_commit_message.new(opts), + }, + sorter = conf.file_sorter(opts), + attach_mappings = function() + actions.select_default:replace(actions.git_checkout_current_buffer) + local transfrom_file = function() + return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or "" + end + + local get_buffer_of_orig = function(selection) + local value = selection.value .. ":" .. transfrom_file() + local content = utils.get_os_command_output({ "git", "--no-pager", "show", value }, opts.cwd) + + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content) + vim.api.nvim_buf_set_name(bufnr, "Original") + return bufnr + end + + local vimdiff = function(selection, command) + local ft = vim.bo.filetype + vim.cmd "diffthis" + + local bufnr = get_buffer_of_orig(selection) + vim.cmd(string.format("%s %s", command, bufnr)) + vim.bo.filetype = ft + vim.cmd "diffthis" + + vim.api.nvim_create_autocmd("WinClosed", { + buffer = bufnr, + nested = true, + once = true, + callback = function() + vim.api.nvim_buf_delete(bufnr, { force = true }) + end, + }) + end + + actions.select_vertical:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vimdiff(selection, "leftabove vert sbuffer") + end) + + actions.select_horizontal:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vimdiff(selection, "belowright sbuffer") + end) + + actions.select_tab:replace(function(prompt_bufnr) + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vim.cmd("tabedit " .. transfrom_file()) + vimdiff(selection, "leftabove vert sbuffer") + end) + return true + end, + }):find() +end + +git.branches = function(opts) + local format = "%(HEAD)" + .. "%(refname)" + .. "%(authorname)" + .. "%(upstream:lstrip=2)" + .. "%(committerdate:format-local:%Y/%m/%d %H:%M:%S)" + local output = utils.get_os_command_output( + { "git", "for-each-ref", "--perl", "--format", format, opts.pattern }, + opts.cwd + ) + + local results = {} + local widths = { + name = 0, + authorname = 0, + upstream = 0, + committerdate = 0, + } + local unescape_single_quote = function(v) + return string.gsub(v, "\\([\\'])", "%1") + end + local parse_line = function(line) + local fields = vim.split(string.sub(line, 2, -2), "''", true) + local entry = { + head = fields[1], + refname = unescape_single_quote(fields[2]), + authorname = unescape_single_quote(fields[3]), + upstream = unescape_single_quote(fields[4]), + committerdate = fields[5], + } + local prefix + if vim.startswith(entry.refname, "refs/remotes/") then + prefix = "refs/remotes/" + elseif vim.startswith(entry.refname, "refs/heads/") then + prefix = "refs/heads/" + else + return + end + local index = 1 + if entry.head ~= "*" then + index = #results + 1 + end + + entry.name = string.sub(entry.refname, string.len(prefix) + 1) + for key, value in pairs(widths) do + widths[key] = math.max(value, strings.strdisplaywidth(entry[key] or "")) + end + if string.len(entry.upstream) > 0 then + widths.upstream_indicator = 2 + end + table.insert(results, index, entry) + end + for _, line in ipairs(output) do + parse_line(line) + end + if #results == 0 then + return + end + + local displayer = entry_display.create { + separator = " ", + items = { + { width = 1 }, + { width = widths.name }, + { width = widths.authorname }, + { width = widths.upstream_indicator }, + { width = widths.upstream }, + { width = widths.committerdate }, + }, + } + + local make_display = function(entry) + return displayer { + { entry.head }, + { entry.name, "TelescopeResultsIdentifier" }, + { entry.authorname }, + { string.len(entry.upstream) > 0 and "=>" or "" }, + { entry.upstream, "TelescopeResultsIdentifier" }, + { entry.committerdate }, + } + end + + pickers.new(opts, { + prompt_title = "Git Branches", + finder = finders.new_table { + results = results, + entry_maker = function(entry) + entry.value = entry.name + entry.ordinal = entry.name + entry.display = make_display + return make_entry.set_default_entry_mt(entry, opts) + end, + }, + previewer = previewers.git_branch_log.new(opts), + sorter = conf.file_sorter(opts), + attach_mappings = function(_, map) + actions.select_default:replace(actions.git_checkout) + map("i", "", actions.git_track_branch) + map("n", "", actions.git_track_branch) + + map("i", "", actions.git_rebase_branch) + map("n", "", actions.git_rebase_branch) + + map("i", "", actions.git_create_branch) + map("n", "", actions.git_create_branch) + + map("i", "", actions.git_switch_branch) + map("n", "", actions.git_switch_branch) + + map("i", "", actions.git_delete_branch) + map("n", "", actions.git_delete_branch) + + map("i", "", actions.git_merge_branch) + map("n", "", actions.git_merge_branch) + return true + end, + }):find() +end + +git.status = function(opts) + if opts.is_bare then + utils.notify("builtin.git_status", { + msg = "This operation must be run in a work tree", + level = "ERROR", + }) + return + end + + local gen_new_finder = function() + local expand_dir = vim.F.if_nil(opts.expand_dir, true) + local git_cmd = { "git", "status", "-s", "--", "." } + + if expand_dir then + table.insert(git_cmd, #git_cmd - 1, "-u") + end + + local output = utils.get_os_command_output(git_cmd, opts.cwd) + + if #output == 0 then + print "No changes found" + utils.notify("builtin.git_status", { + msg = "No changes found", + level = "WARN", + }) + return + end + + return finders.new_table { + results = output, + entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_status(opts)), + } + end + + local initial_finder = gen_new_finder() + if not initial_finder then + return + end + + pickers.new(opts, { + prompt_title = "Git Status", + finder = initial_finder, + previewer = previewers.git_file_diff.new(opts), + sorter = conf.file_sorter(opts), + attach_mappings = function(prompt_bufnr, map) + actions.git_staging_toggle:enhance { + post = function() + action_state.get_current_picker(prompt_bufnr):refresh(gen_new_finder(), { reset_prompt = true }) + end, + } + + map("i", "", actions.git_staging_toggle) + map("n", "", actions.git_staging_toggle) + return true + end, + }):find() +end + +local set_opts_cwd = function(opts) + if opts.cwd then + opts.cwd = vim.fn.expand(opts.cwd) + else + opts.cwd = vim.loop.cwd() + end + + -- Find root of git directory and remove trailing newline characters + local git_root, ret = utils.get_os_command_output({ "git", "rev-parse", "--show-toplevel" }, opts.cwd) + local use_git_root = vim.F.if_nil(opts.use_git_root, true) + + if ret ~= 0 then + local in_worktree = utils.get_os_command_output({ "git", "rev-parse", "--is-inside-work-tree" }, opts.cwd) + local in_bare = utils.get_os_command_output({ "git", "rev-parse", "--is-bare-repository" }, opts.cwd) + + if in_worktree[1] ~= "true" and in_bare[1] ~= "true" then + error(opts.cwd .. " is not a git directory") + elseif in_worktree[1] ~= "true" and in_bare[1] == "true" then + opts.is_bare = true + end + else + if use_git_root then + opts.cwd = git_root[1] + end + end +end + +local function apply_checks(mod) + for k, v in pairs(mod) do + mod[k] = function(opts) + opts = vim.F.if_nil(opts, {}) + + set_opts_cwd(opts) + v(opts) + end + end + + return mod +end + +return apply_checks(git) diff --git a/lua/telescope/builtin/__internal.lua b/lua/telescope/builtin/__internal.lua new file mode 100644 index 0000000..4277e2e --- /dev/null +++ b/lua/telescope/builtin/__internal.lua @@ -0,0 +1,1318 @@ +local actions = require "telescope.actions" +local action_set = require "telescope.actions.set" +local action_state = require "telescope.actions.state" +local finders = require "telescope.finders" +local make_entry = require "telescope.make_entry" +local Path = require "plenary.path" +local pickers = require "telescope.pickers" +local previewers = require "telescope.previewers" +local p_window = require "telescope.pickers.window" +local sorters = require "telescope.sorters" +local state = require "telescope.state" +local utils = require "telescope.utils" + +local conf = require("telescope.config").values + +local filter = vim.tbl_filter + +-- Makes sure aliased options are set correctly +local function apply_cwd_only_aliases(opts) + local has_cwd_only = opts.cwd_only ~= nil + local has_only_cwd = opts.only_cwd ~= nil + + if has_only_cwd and not has_cwd_only then + -- Internally, use cwd_only + opts.cwd_only = opts.only_cwd + opts.only_cwd = nil + end + + return opts +end + +local internal = {} + +internal.builtin = function(opts) + opts.include_extensions = vim.F.if_nil(opts.include_extensions, false) + opts.use_default_opts = vim.F.if_nil(opts.use_default_opts, false) + + local objs = {} + + for k, v in pairs(require "telescope.builtin") do + local debug_info = debug.getinfo(v) + table.insert(objs, { + filename = string.sub(debug_info.source, 2), + text = k, + }) + end + + local title = "Telescope Builtin" + + if opts.include_extensions then + title = "Telescope Pickers" + for ext, funcs in pairs(require("telescope").extensions) do + for func_name, func_obj in pairs(funcs) do + -- Only include exported functions whose name doesn't begin with an underscore + if type(func_obj) == "function" and string.sub(func_name, 0, 1) ~= "_" then + local debug_info = debug.getinfo(func_obj) + table.insert(objs, { + filename = string.sub(debug_info.source, 2), + text = string.format("%s : %s", ext, func_name), + }) + end + end + end + end + + opts.bufnr = vim.api.nvim_get_current_buf() + opts.winnr = vim.api.nvim_get_current_win() + pickers.new(opts, { + prompt_title = title, + finder = finders.new_table { + results = objs, + entry_maker = function(entry) + return make_entry.set_default_entry_mt({ + value = entry, + text = entry.text, + display = entry.text, + ordinal = entry.text, + filename = entry.filename, + }, opts) + end, + }, + previewer = previewers.builtin.new(opts), + sorter = conf.generic_sorter(opts), + attach_mappings = function(_) + actions.select_default:replace(function(_) + local selection = action_state.get_selected_entry() + if not selection then + utils.__warn_no_selection "builtin.builtin" + return + end + + -- we do this to avoid any surprises + opts.include_extensions = nil + + local picker_opts + if not opts.use_default_opts then + picker_opts = opts + end + + if string.match(selection.text, " : ") then + -- Call appropriate function from extensions + local split_string = vim.split(selection.text, " : ") + local ext = split_string[1] + local func = split_string[2] + require("telescope").extensions[ext][func](picker_opts) + else + -- Call appropriate telescope builtin + require("telescope.builtin")[selection.text](picker_opts) + end + end) + return true + end, + }):find() +end + +internal.resume = function(opts) + opts = opts or {} + opts.cache_index = vim.F.if_nil(opts.cache_index, 1) + + local cached_pickers = state.get_global_key "cached_pickers" + if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then + utils.notify("builtin.resume", { + msg = "No cached picker(s).", + level = "INFO", + }) + return + end + local picker = cached_pickers[opts.cache_index] + if picker == nil then + utils.notify("builtin.resume", { + msg = string.format("Index too large as there are only '%s' pickers cached", #cached_pickers), + level = "ERROR", + }) + return + end + -- reset layout strategy and get_window_options if default as only one is valid + -- and otherwise unclear which was actually set + if picker.layout_strategy == conf.layout_strategy then + picker.layout_strategy = nil + end + if picker.get_window_options == p_window.get_window_options then + picker.get_window_options = nil + end + picker.cache_picker.index = opts.cache_index + + -- avoid partial `opts.cache_picker` at picker creation + if opts.cache_picker ~= false then + picker.cache_picker = vim.tbl_extend("keep", opts.cache_picker or {}, picker.cache_picker) + else + picker.cache_picker.disabled = true + end + opts.cache_picker = nil + picker.previewer = picker.all_previewers + if picker.hidden_previewer then + picker.hidden_previewer = nil + opts.previewer = vim.F.if_nil(opts.previewer, false) + end + pickers.new(opts, picker):find() +end + +internal.pickers = function(opts) + local cached_pickers = state.get_global_key "cached_pickers" + if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then + utils.notify("builtin.pickers", { + msg = "No cached picker(s).", + level = "INFO", + }) + return + end + + opts = opts or {} + + -- clear cache picker for immediate pickers.new and pass option to resumed picker + if opts.cache_picker ~= nil then + opts._cache_picker = opts.cache_picker + opts.cache_picker = nil + end + + pickers.new(opts, { + prompt_title = "Pickers", + finder = finders.new_table { + results = cached_pickers, + entry_maker = make_entry.gen_from_picker(opts), + }, + previewer = previewers.pickers.new(opts), + sorter = conf.generic_sorter(opts), + cache_picker = false, + attach_mappings = function(_, map) + actions.select_default:replace(function(prompt_bufnr) + local current_picker = action_state.get_current_picker(prompt_bufnr) + local selection_index = current_picker:get_index(current_picker:get_selection_row()) + actions.close(prompt_bufnr) + opts.cache_picker = opts._cache_picker + opts["cache_index"] = selection_index + opts["initial_mode"] = cached_pickers[selection_index].initial_mode + internal.resume(opts) + end) + map("i", "", actions.remove_selected_picker) + map("n", "", actions.remove_selected_picker) + return true + end, + }):find() +end + +internal.planets = function(opts) + local show_pluto = opts.show_pluto or false + + local sourced_file = require("plenary.debug_utils").sourced_filepath() + local base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h:h") + + local globbed_files = vim.fn.globpath(base_directory .. "/data/memes/planets/", "*", true, true) + local acceptable_files = {} + for _, v in ipairs(globbed_files) do + if show_pluto or not v:find "pluto" then + table.insert(acceptable_files, vim.fn.fnamemodify(v, ":t")) + end + end + + pickers.new(opts, { + prompt_title = "Planets", + finder = finders.new_table { + results = acceptable_files, + entry_maker = function(line) + return make_entry.set_default_entry_mt({ + ordinal = line, + display = line, + filename = base_directory .. "/data/memes/planets/" .. line, + }, opts) + end, + }, + previewer = previewers.cat.new(opts), + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.planets" + return + end + + actions.close(prompt_bufnr) + print("Enjoy astronomy! You viewed:", selection.display) + end) + + return true + end, + }):find() +end + +internal.symbols = function(opts) + local initial_mode = vim.fn.mode() + local files = vim.api.nvim_get_runtime_file("data/telescope-sources/*.json", true) + local data_path = (function() + if not opts.symbol_path then + return Path:new { vim.fn.stdpath "data", "telescope", "symbols" } + else + return Path:new { opts.symbol_path } + end + end)() + if data_path:exists() then + for _, v in ipairs(require("plenary.scandir").scan_dir(data_path:absolute(), { search_pattern = "%.json$" })) do + table.insert(files, v) + end + end + + if #files == 0 then + utils.notify("builtin.symbols", { + msg = "No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim " + .. "for some prebuild symbols or how to create you own symbol source.", + level = "ERROR", + }) + return + end + + local sources = {} + if opts.sources then + for _, v in ipairs(files) do + for _, s in ipairs(opts.sources) do + if v:find(s) then + table.insert(sources, v) + end + end + end + else + sources = files + end + + local results = {} + for _, source in ipairs(sources) do + local data = vim.json.decode(Path:new(source):read()) + for _, entry in ipairs(data) do + table.insert(results, entry) + end + end + + pickers.new(opts, { + prompt_title = "Symbols", + finder = finders.new_table { + results = results, + entry_maker = function(entry) + return make_entry.set_default_entry_mt({ + value = entry, + ordinal = entry[1] .. " " .. entry[2], + display = entry[1] .. " " .. entry[2], + }, opts) + end, + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(_) + if initial_mode == "i" then + actions.select_default:replace(actions.insert_symbol_i) + else + actions.select_default:replace(actions.insert_symbol) + end + return true + end, + }):find() +end + +internal.commands = function(opts) + pickers.new(opts, { + prompt_title = "Commands", + finder = finders.new_table { + results = (function() + local command_iter = vim.api.nvim_get_commands {} + local commands = {} + + for _, cmd in pairs(command_iter) do + table.insert(commands, cmd) + end + + local need_buf_command = vim.F.if_nil(opts.show_buf_command, true) + + if need_buf_command then + local buf_command_iter = vim.api.nvim_buf_get_commands(0, {}) + buf_command_iter[true] = nil -- remove the redundant entry + for _, cmd in pairs(buf_command_iter) do + table.insert(commands, cmd) + end + end + return commands + end)(), + + entry_maker = opts.entry_maker or make_entry.gen_from_commands(opts), + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.commands" + return + end + + actions.close(prompt_bufnr) + local val = selection.value + local cmd = string.format([[:%s ]], val.name) + + if val.nargs == "0" then + vim.cmd(cmd) + else + vim.cmd [[stopinsert]] + vim.fn.feedkeys(cmd, "n") + end + end) + + return true + end, + }):find() +end + +internal.quickfix = function(opts) + local qf_identifier = opts.id or vim.F.if_nil(opts.nr, "$") + local locations = vim.fn.getqflist({ [opts.id and "id" or "nr"] = qf_identifier, items = true }).items + + if vim.tbl_isempty(locations) then + return + end + + pickers.new(opts, { + prompt_title = "Quickfix", + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + }):find() +end + +internal.quickfixhistory = function(opts) + local qflists = {} + for i = 1, 10 do -- (n)vim keeps at most 10 quickfix lists in full + -- qf weirdness: id = 0 gets id of quickfix list nr + local qflist = vim.fn.getqflist { nr = i, id = 0, title = true, items = true } + if not vim.tbl_isempty(qflist.items) then + table.insert(qflists, qflist) + end + end + local entry_maker = opts.make_entry + or function(entry) + return make_entry.set_default_entry_mt({ + value = entry.title or "Untitled", + ordinal = entry.title or "Untitled", + display = entry.title or "Untitled", + nr = entry.nr, + id = entry.id, + items = entry.items, + }, opts) + end + local qf_entry_maker = make_entry.gen_from_quickfix(opts) + pickers.new(opts, { + prompt_title = "Quickfix History", + finder = finders.new_table { + results = qflists, + entry_maker = entry_maker, + }, + previewer = previewers.new_buffer_previewer { + title = "Quickfix List Preview", + dyn_title = function(_, entry) + return entry.title + end, + + get_buffer_by_name = function(_, entry) + return "quickfixlist_" .. tostring(entry.nr) + end, + + define_preview = function(self, entry) + if self.state.bufname then + return + end + local entries = vim.tbl_map(function(i) + return qf_entry_maker(i):display() + end, entry.items) + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, entries) + end, + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(_, _) + action_set.select:replace(function(prompt_bufnr) + local nr = action_state.get_selected_entry().nr + actions.close(prompt_bufnr) + internal.quickfix { nr = nr } + end) + return true + end, + }):find() +end + +internal.loclist = function(opts) + local locations = vim.fn.getloclist(0) + local filenames = {} + for _, value in pairs(locations) do + local bufnr = value.bufnr + if filenames[bufnr] == nil then + filenames[bufnr] = vim.api.nvim_buf_get_name(bufnr) + end + value.filename = filenames[bufnr] + end + + if vim.tbl_isempty(locations) then + return + end + + pickers.new(opts, { + prompt_title = "Loclist", + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + }):find() +end + +internal.oldfiles = function(opts) + opts = apply_cwd_only_aliases(opts) + opts.include_current_session = vim.F.if_nil(opts.include_current_session, true) + + local current_buffer = vim.api.nvim_get_current_buf() + local current_file = vim.api.nvim_buf_get_name(current_buffer) + local results = {} + + if opts.include_current_session then + for _, buffer in ipairs(vim.split(vim.fn.execute ":buffers! t", "\n")) do + local match = tonumber(string.match(buffer, "%s*(%d+)")) + local open_by_lsp = string.match(buffer, "line 0$") + if match and not open_by_lsp then + local file = vim.api.nvim_buf_get_name(match) + if vim.loop.fs_stat(file) and match ~= current_buffer then + table.insert(results, file) + end + end + end + end + + for _, file in ipairs(vim.v.oldfiles) do + if vim.loop.fs_stat(file) and not vim.tbl_contains(results, file) and file ~= current_file then + table.insert(results, file) + end + end + + if opts.cwd_only then + local cwd = vim.loop.cwd() + cwd = cwd:gsub([[\]], [[\\]]) + results = vim.tbl_filter(function(file) + return vim.fn.matchstrpos(file, cwd)[2] ~= -1 + end, results) + end + + pickers.new(opts, { + prompt_title = "Oldfiles", + finder = finders.new_table { + results = results, + entry_maker = opts.entry_maker or make_entry.gen_from_file(opts), + }, + sorter = conf.file_sorter(opts), + previewer = conf.file_previewer(opts), + }):find() +end + +internal.command_history = function(opts) + local history_string = vim.fn.execute "history cmd" + local history_list = vim.split(history_string, "\n") + + local results = {} + for i = #history_list, 3, -1 do + local item = history_list[i] + local _, finish = string.find(item, "%d+ +") + table.insert(results, string.sub(item, finish + 1)) + end + + pickers.new(opts, { + prompt_title = "Command History", + finder = finders.new_table(results), + sorter = conf.generic_sorter(opts), + + attach_mappings = function(_, map) + map("i", "", actions.set_command_line) + map("n", "", actions.set_command_line) + map("n", "", actions.edit_command_line) + map("i", "", actions.edit_command_line) + + -- TODO: Find a way to insert the text... it seems hard. + -- map('i', '', actions.insert_value, { expr = true }) + + return true + end, + }):find() +end + +internal.search_history = function(opts) + local search_string = vim.fn.execute "history search" + local search_list = vim.split(search_string, "\n") + + local results = {} + for i = #search_list, 3, -1 do + local item = search_list[i] + local _, finish = string.find(item, "%d+ +") + table.insert(results, string.sub(item, finish + 1)) + end + + pickers.new(opts, { + prompt_title = "Search History", + finder = finders.new_table(results), + sorter = conf.generic_sorter(opts), + + attach_mappings = function(_, map) + map("i", "", actions.set_search_line) + map("n", "", actions.set_search_line) + map("n", "", actions.edit_search_line) + map("i", "", actions.edit_search_line) + + -- TODO: Find a way to insert the text... it seems hard. + -- map('i', '', actions.insert_value, { expr = true }) + + return true + end, + }):find() +end + +internal.vim_options = function(opts) + local res = {} + for _, v in pairs(vim.api.nvim_get_all_options_info()) do + table.insert(res, v) + end + table.sort(res, function(left, right) + return left.name < right.name + end) + + pickers.new(opts, { + prompt_title = "options", + finder = finders.new_table { + results = res, + entry_maker = opts.entry_maker or make_entry.gen_from_vimoptions(opts), + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function() + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.vim_options" + return + end + + local esc = "" + if vim.fn.mode() == "i" then + esc = vim.api.nvim_replace_termcodes("", true, false, true) + end + + vim.api.nvim_feedkeys( + string.format("%s:set %s=%s", esc, selection.value.name, selection.value.value), + "m", + true + ) + end) + + return true + end, + }):find() +end + +internal.help_tags = function(opts) + opts.lang = vim.F.if_nil(opts.lang, vim.o.helplang) + opts.fallback = vim.F.if_nil(opts.fallback, true) + opts.file_ignore_patterns = {} + + local langs = vim.split(opts.lang, ",", true) + if opts.fallback and not vim.tbl_contains(langs, "en") then + table.insert(langs, "en") + end + local langs_map = {} + for _, lang in ipairs(langs) do + langs_map[lang] = true + end + + local tag_files = {} + local function add_tag_file(lang, file) + if langs_map[lang] then + if tag_files[lang] then + table.insert(tag_files[lang], file) + else + tag_files[lang] = { file } + end + end + end + + local help_files = {} + local all_files = vim.api.nvim_get_runtime_file("doc/*", true) + for _, fullpath in ipairs(all_files) do + local file = utils.path_tail(fullpath) + if file == "tags" then + add_tag_file("en", fullpath) + elseif file:match "^tags%-..$" then + local lang = file:sub(-2) + add_tag_file(lang, fullpath) + else + help_files[file] = fullpath + end + end + + local tags = {} + local tags_map = {} + local delimiter = string.char(9) + for _, lang in ipairs(langs) do + for _, file in ipairs(tag_files[lang] or {}) do + local lines = vim.split(Path:new(file):read(), "\n", true) + for _, line in ipairs(lines) do + -- TODO: also ignore tagComment starting with ';' + if not line:match "^!_TAG_" then + local fields = vim.split(line, delimiter, true) + if #fields == 3 and not tags_map[fields[1]] then + if fields[1] ~= "help-tags" or fields[2] ~= "tags" then + table.insert(tags, { + name = fields[1], + filename = help_files[fields[2]], + cmd = fields[3], + lang = lang, + }) + tags_map[fields[1]] = true + end + end + end + end + end + end + + pickers.new(opts, { + prompt_title = "Help", + finder = finders.new_table { + results = tags, + entry_maker = function(entry) + return make_entry.set_default_entry_mt({ + value = entry.name .. "@" .. entry.lang, + display = entry.name, + ordinal = entry.name, + filename = entry.filename, + cmd = entry.cmd, + }, opts) + end, + }, + previewer = previewers.help.new(opts), + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + action_set.select:replace(function(_, cmd) + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.help_tags" + return + end + + actions.close(prompt_bufnr) + if cmd == "default" or cmd == "horizontal" then + vim.cmd("help " .. selection.value) + elseif cmd == "vertical" then + vim.cmd("vert help " .. selection.value) + elseif cmd == "tab" then + vim.cmd("tab help " .. selection.value) + end + end) + + return true + end, + }):find() +end + +internal.man_pages = function(opts) + opts.sections = vim.F.if_nil(opts.sections, { "1" }) + assert(vim.tbl_islist(opts.sections), "sections should be a list") + opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function() + local is_darwin = vim.loop.os_uname().sysname == "Darwin" + return is_darwin and { "apropos", " " } or { "apropos", "" } + end) + opts.entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts) + opts.env = { PATH = vim.env.PATH, MANPATH = vim.env.MANPATH } + + pickers.new(opts, { + prompt_title = "Man", + finder = finders.new_oneshot_job(opts.man_cmd, opts), + previewer = previewers.man.new(opts), + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + action_set.select:replace(function(_, cmd) + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.man_pages" + return + end + + local args = selection.section .. " " .. selection.value + actions.close(prompt_bufnr) + if cmd == "default" or cmd == "horizontal" then + vim.cmd("Man " .. args) + elseif cmd == "vertical" then + vim.cmd("vert Man " .. args) + elseif cmd == "tab" then + vim.cmd("tab Man " .. args) + end + end) + + return true + end, + }):find() +end + +internal.reloader = function(opts) + local package_list = vim.tbl_keys(package.loaded) + + -- filter out packages we don't want and track the longest package name + local column_len = 0 + for index, module_name in pairs(package_list) do + if + type(require(module_name)) ~= "table" + or module_name:sub(1, 1) == "_" + or package.searchpath(module_name, package.path) == nil + then + table.remove(package_list, index) + elseif #module_name > column_len then + column_len = #module_name + end + end + opts.column_len = vim.F.if_nil(opts.column_len, column_len) + + pickers.new(opts, { + prompt_title = "Packages", + finder = finders.new_table { + results = package_list, + entry_maker = opts.entry_maker or make_entry.gen_from_packages(opts), + }, + -- previewer = previewers.vim_buffer.new(opts), + sorter = conf.generic_sorter(opts), + + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.reloader" + return + end + + actions.close(prompt_bufnr) + require("plenary.reload").reload_module(selection.value) + utils.notify("builtin.reloader", { + msg = string.format("[%s] - module reloaded", selection.value), + level = "INFO", + }) + end) + + return true + end, + }):find() +end + +internal.buffers = function(opts) + opts = apply_cwd_only_aliases(opts) + local bufnrs = filter(function(b) + if 1 ~= vim.fn.buflisted(b) then + return false + end + -- only hide unloaded buffers if opts.show_all_buffers is false, keep them listed if true or nil + if opts.show_all_buffers == false and not vim.api.nvim_buf_is_loaded(b) then + return false + end + if opts.ignore_current_buffer and b == vim.api.nvim_get_current_buf() then + return false + end + if opts.cwd_only and not string.find(vim.api.nvim_buf_get_name(b), vim.loop.cwd(), 1, true) then + return false + end + return true + end, vim.api.nvim_list_bufs()) + if not next(bufnrs) then + return + end + if opts.sort_mru then + table.sort(bufnrs, function(a, b) + return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused + end) + end + + local buffers = {} + local default_selection_idx = 1 + for _, bufnr in ipairs(bufnrs) do + local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ") + + if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then + default_selection_idx = 2 + end + + local element = { + bufnr = bufnr, + flag = flag, + info = vim.fn.getbufinfo(bufnr)[1], + } + + if opts.sort_lastused and (flag == "#" or flag == "%") then + local idx = ((buffers[1] ~= nil and buffers[1].flag == "%") and 2 or 1) + table.insert(buffers, idx, element) + else + table.insert(buffers, element) + end + end + + if not opts.bufnr_width then + local max_bufnr = math.max(unpack(bufnrs)) + opts.bufnr_width = #tostring(max_bufnr) + end + + pickers.new(opts, { + prompt_title = "Buffers", + finder = finders.new_table { + results = buffers, + entry_maker = opts.entry_maker or make_entry.gen_from_buffer(opts), + }, + previewer = conf.grep_previewer(opts), + sorter = conf.generic_sorter(opts), + default_selection_index = default_selection_idx, + }):find() +end + +internal.colorscheme = function(opts) + local before_background = vim.o.background + local before_color = vim.api.nvim_exec("colorscheme", true) + local need_restore = true + + local colors = opts.colors or { before_color } + if not vim.tbl_contains(colors, before_color) then + table.insert(colors, 1, before_color) + end + + colors = vim.list_extend( + colors, + vim.tbl_filter(function(color) + return color ~= before_color + end, vim.fn.getcompletion("", "color")) + ) + + local previewer + if opts.enable_preview then + -- define previewer + local bufnr = vim.api.nvim_get_current_buf() + local p = vim.api.nvim_buf_get_name(bufnr) + + -- don't need previewer + if vim.fn.buflisted(bufnr) ~= 1 then + local deleted = false + local function del_win(win_id) + if win_id and vim.api.nvim_win_is_valid(win_id) then + utils.buf_delete(vim.api.nvim_win_get_buf(win_id)) + pcall(vim.api.nvim_win_close, win_id, true) + end + end + + previewer = previewers.new { + preview_fn = function(_, entry, status) + if not deleted then + deleted = true + del_win(status.preview_win) + del_win(status.preview_border_win) + end + vim.cmd("colorscheme " .. entry.value) + end, + } + else + -- show current buffer content in previewer + previewer = previewers.new_buffer_previewer { + get_buffer_by_name = function() + return p + end, + define_preview = function(self, entry) + if vim.loop.fs_stat(p) then + conf.buffer_previewer_maker(p, self.state.bufnr, { bufname = self.state.bufname }) + else + local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) + end + vim.cmd("colorscheme " .. entry.value) + end, + } + end + end + + local picker = pickers.new(opts, { + prompt_title = "Change Colorscheme", + finder = finders.new_table { + results = colors, + }, + sorter = conf.generic_sorter(opts), + previewer = previewer, + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.colorscheme" + return + end + + actions.close(prompt_bufnr) + need_restore = false + vim.cmd("colorscheme " .. selection.value) + end) + + return true + end, + }) + + if opts.enable_preview then + -- rewrite picker.close_windows. restore color if needed + local close_windows = picker.close_windows + picker.close_windows = function(status) + close_windows(status) + if need_restore then + vim.o.background = before_background + vim.cmd("colorscheme " .. before_color) + end + end + end + + picker:find() +end + +internal.marks = function(opts) + local local_marks = { + items = vim.fn.getmarklist(opts.bufnr), + name_func = function(_, line) + return vim.api.nvim_buf_get_lines(opts.bufnr, line - 1, line, false)[1] + end, + } + local global_marks = { + items = vim.fn.getmarklist(), + name_func = function(mark, _) + -- get buffer name if it is opened, otherwise get file name + return vim.api.nvim_get_mark(mark, {})[4] + end, + } + local marks_table = {} + local marks_others = {} + local bufname = vim.api.nvim_buf_get_name(opts.bufnr) + for _, cnf in ipairs { local_marks, global_marks } do + for _, v in ipairs(cnf.items) do + -- strip the first single quote character + local mark = string.sub(v.mark, 2, 3) + local _, lnum, col, _ = unpack(v.pos) + local name = cnf.name_func(mark, lnum) + -- same format to :marks command + local line = string.format("%s %6d %4d %s", mark, lnum, col - 1, name) + local row = { + line = line, + lnum = lnum, + col = col, + filename = v.file or bufname, + } + -- non alphanumeric marks goes to last + if mark:match "%w" then + table.insert(marks_table, row) + else + table.insert(marks_others, row) + end + end + end + marks_table = vim.fn.extend(marks_table, marks_others) + + pickers.new(opts, { + prompt_title = "Marks", + finder = finders.new_table { + results = marks_table, + entry_maker = opts.entry_maker or make_entry.gen_from_marks(opts), + }, + previewer = conf.grep_previewer(opts), + sorter = conf.generic_sorter(opts), + push_cursor_on_edit = true, + push_tagstack_on_edit = true, + }):find() +end + +internal.registers = function(opts) + local registers_table = { '"', "_", "#", "=", "_", "/", "*", "+", ":", ".", "%" } + + -- named + for i = 0, 9 do + table.insert(registers_table, tostring(i)) + end + + -- alphabetical + for i = 65, 90 do + table.insert(registers_table, string.char(i)) + end + + pickers.new(opts, { + prompt_title = "Registers", + finder = finders.new_table { + results = registers_table, + entry_maker = opts.entry_maker or make_entry.gen_from_registers(opts), + }, + -- use levenshtein as n-gram doesn't support <2 char matches + sorter = sorters.get_levenshtein_sorter(), + attach_mappings = function(_, map) + actions.select_default:replace(actions.paste_register) + map("i", "", actions.edit_register) + + return true + end, + }):find() +end + +-- TODO: make filtering include the mapping and the action +internal.keymaps = function(opts) + opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" }) + opts.show_plug = vim.F.if_nil(opts.show_plug, true) + + local keymap_encountered = {} -- used to make sure no duplicates are inserted into keymaps_table + local keymaps_table = {} + local max_len_lhs = 0 + + -- helper function to populate keymaps_table and determine max_len_lhs + local function extract_keymaps(keymaps) + for _, keymap in pairs(keymaps) do + local keymap_key = keymap.buffer .. keymap.mode .. keymap.lhs -- should be distinct for every keymap + if not keymap_encountered[keymap_key] then + keymap_encountered[keymap_key] = true + if opts.show_plug or not string.find(keymap.lhs, "") then + table.insert(keymaps_table, keymap) + max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs)) + end + end + end + end + + for _, mode in pairs(opts.modes) do + local global = vim.api.nvim_get_keymap(mode) + local buf_local = vim.api.nvim_buf_get_keymap(0, mode) + extract_keymaps(global) + extract_keymaps(buf_local) + end + opts.width_lhs = max_len_lhs + 1 + + pickers.new(opts, { + prompt_title = "Key Maps", + finder = finders.new_table { + results = keymaps_table, + entry_maker = opts.entry_maker or make_entry.gen_from_keymaps(opts), + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.keymaps" + return + end + + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true), "t", true) + return actions.close(prompt_bufnr) + end) + return true + end, + }):find() +end + +internal.filetypes = function(opts) + local filetypes = vim.fn.getcompletion("", "filetype") + + pickers.new(opts, { + prompt_title = "Filetypes", + finder = finders.new_table { + results = filetypes, + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + print "[telescope] Nothing currently selected" + return + end + + actions.close(prompt_bufnr) + vim.cmd("setfiletype " .. selection[1]) + end) + return true + end, + }):find() +end + +internal.highlights = function(opts) + local highlights = vim.fn.getcompletion("", "highlight") + + pickers.new(opts, { + prompt_title = "Highlights", + finder = finders.new_table { + results = highlights, + entry_maker = opts.entry_maker or make_entry.gen_from_highlights(opts), + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.highlights" + return + end + + actions.close(prompt_bufnr) + vim.cmd("hi " .. selection.value) + end) + return true + end, + previewer = previewers.highlights.new(opts), + }):find() +end + +internal.autocommands = function(opts) + local autocmds = vim.api.nvim_get_autocmds {} + table.sort(autocmds, function(lhs, rhs) + return lhs.event < rhs.event + end) + pickers.new(opts, { + prompt_title = "autocommands", + finder = finders.new_table { + results = autocmds, + entry_maker = opts.entry_maker or make_entry.gen_from_autocommands(opts), + }, + previewer = previewers.autocommands.new(opts), + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + action_set.select:replace_if(function() + local selection = action_state.get_selected_entry() + if selection == nil then + return false + end + local val = selection.value + local group_name = val.group_name ~= "" and val.group_name or "" + local output = vim.fn.execute("verb autocmd " .. group_name .. " " .. val.event .. " " .. val.pattern, "silent") + for line in output:gmatch "[^\r\n]+" do + local source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$" + if source_file and source_file ~= "Lua" then + selection.filename = source_file + local source_lnum = line:match "line (%d*)$" or "1" + selection.lnum = tonumber(source_lnum) + selection.col = 1 + return false + end + end + return true + end, function() + local selection = action_state.get_selected_entry() + actions.close(prompt_bufnr) + print("You selected autocmd: " .. vim.inspect(selection.value)) + end) + + return true + end, + }):find() +end + +internal.spell_suggest = function(opts) + local cursor_word = vim.fn.expand "" + local suggestions = vim.fn.spellsuggest(cursor_word) + + pickers.new(opts, { + prompt_title = "Spelling Suggestions", + finder = finders.new_table { + results = suggestions, + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection "builtin.spell_suggest" + return + end + + action_state.get_current_picker(prompt_bufnr)._original_mode = "i" + actions.close(prompt_bufnr) + vim.cmd("normal! ciw" .. selection[1]) + vim.cmd "stopinsert" + end) + return true + end, + }):find() +end + +internal.tagstack = function(opts) + opts = opts or {} + local tagstack = vim.fn.gettagstack().items + + local tags = {} + for i = #tagstack, 1, -1 do + local tag = tagstack[i] + tag.bufnr = tag.from[1] + if vim.api.nvim_buf_is_valid(tag.bufnr) then + tags[#tags + 1] = tag + tag.filename = vim.fn.bufname(tag.bufnr) + tag.lnum = tag.from[2] + tag.col = tag.from[3] + + tag.text = vim.api.nvim_buf_get_lines(tag.bufnr, tag.lnum - 1, tag.lnum, false)[1] or "" + end + end + + if vim.tbl_isempty(tags) then + utils.notify("builtin.tagstack", { + msg = "No tagstack available", + level = "WARN", + }) + return + end + + pickers.new(opts, { + prompt_title = "TagStack", + finder = finders.new_table { + results = tags, + entry_maker = make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + }):find() +end + +internal.jumplist = function(opts) + opts = opts or {} + local jumplist = vim.fn.getjumplist()[1] + + -- reverse the list + local sorted_jumplist = {} + for i = #jumplist, 1, -1 do + if vim.api.nvim_buf_is_valid(jumplist[i].bufnr) then + jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum, jumplist[i].lnum + 1, false)[1] + or "" + table.insert(sorted_jumplist, jumplist[i]) + end + end + + pickers.new(opts, { + prompt_title = "Jumplist", + finder = finders.new_table { + results = sorted_jumplist, + entry_maker = make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + }):find() +end + +local function apply_checks(mod) + for k, v in pairs(mod) do + mod[k] = function(opts) + opts = opts or {} + + v(opts) + end + end + + return mod +end + +return apply_checks(internal) diff --git a/lua/telescope/builtin/__lsp.lua b/lua/telescope/builtin/__lsp.lua new file mode 100644 index 0000000..480d456 --- /dev/null +++ b/lua/telescope/builtin/__lsp.lua @@ -0,0 +1,389 @@ +local channel = require("plenary.async.control").channel +local action_state = require "telescope.actions.state" +local sorters = require "telescope.sorters" +local conf = require("telescope.config").values +local finders = require "telescope.finders" +local make_entry = require "telescope.make_entry" +local pickers = require "telescope.pickers" +local utils = require "telescope.utils" + +local lsp = {} + +lsp.references = function(opts) + local filepath = vim.api.nvim_buf_get_name(opts.bufnr) + local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1] + local params = vim.lsp.util.make_position_params(opts.winnr) + local include_current_line = vim.F.if_nil(opts.include_current_line, false) + params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) } + + vim.lsp.buf_request(opts.bufnr, "textDocument/references", params, function(err, result, ctx, _) + if err then + vim.api.nvim_err_writeln("Error when finding references: " .. err.message) + return + end + + local locations = {} + if result then + local results = vim.lsp.util.locations_to_items(result, vim.lsp.get_client_by_id(ctx.client_id).offset_encoding) + if include_current_line then + locations = vim.tbl_filter(function(v) + -- Remove current line from result + return not (v.filename == filepath and v.lnum == lnum) + end, vim.F.if_nil(results, {})) + else + locations = vim.F.if_nil(results, {}) + end + end + + if vim.tbl_isempty(locations) then + return + end + + pickers.new(opts, { + prompt_title = "LSP References", + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + push_cursor_on_edit = true, + push_tagstack_on_edit = true, + }):find() + end) +end + +local function call_hierarchy(opts, method, title, direction, item) + vim.lsp.buf_request(opts.bufnr, method, { item = item }, function(err, result) + if err then + vim.api.nvim_err_writeln("Error handling " .. title .. ": " .. err) + return + end + + if not result or vim.tbl_isempty(result) then + return + end + + local locations = {} + for _, ch_call in pairs(result) do + local ch_item = ch_call[direction] + for _, range in pairs(ch_call.fromRanges) do + table.insert(locations, { + filename = vim.uri_to_fname(ch_item.uri), + text = ch_item.name, + lnum = range.start.line + 1, + col = range.start.character + 1, + }) + end + end + + pickers.new(opts, { + prompt_title = title, + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + push_cursor_on_edit = true, + push_tagstack_on_edit = true, + }):find() + end) +end + +local function pick_call_hierarchy_item(call_hierarchy_items) + if not call_hierarchy_items then + return + end + if #call_hierarchy_items == 1 then + return call_hierarchy_items[1] + end + local items = {} + for i, item in pairs(call_hierarchy_items) do + local entry = item.detail or item.name + table.insert(items, string.format("%d. %s", i, entry)) + end + local choice = vim.fn.inputlist(items) + if choice < 1 or choice > #items then + return + end + return choice +end + +local function calls(opts, direction) + local params = vim.lsp.util.make_position_params() + vim.lsp.buf_request(opts.bufnr, "textDocument/prepareCallHierarchy", params, function(err, result) + if err then + vim.api.nvim_err_writeln("Error when preparing call hierarchy: " .. err) + return + end + + local call_hierarchy_item = pick_call_hierarchy_item(result) + if not call_hierarchy_item then + return + end + + if direction == "from" then + call_hierarchy(opts, "callHierarchy/incomingCalls", "LSP Incoming Calls", direction, call_hierarchy_item) + else + call_hierarchy(opts, "callHierarchy/outgoingCalls", "LSP Outgoing Calls", direction, call_hierarchy_item) + end + end) +end + +lsp.incoming_calls = function(opts) + calls(opts, "from") +end + +lsp.outgoing_calls = function(opts) + calls(opts, "to") +end + +local function list_or_jump(action, title, opts) + local params = vim.lsp.util.make_position_params(opts.winnr) + vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _) + if err then + vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message) + return + end + local flattened_results = {} + if result then + -- textDocument/definition can return Location or Location[] + if not vim.tbl_islist(result) then + flattened_results = { result } + end + + vim.list_extend(flattened_results, result) + end + + local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding + + if #flattened_results == 0 then + return + elseif #flattened_results == 1 and opts.jump_type ~= "never" then + if opts.jump_type == "tab" then + vim.cmd "tabedit" + elseif opts.jump_type == "split" then + vim.cmd "new" + elseif opts.jump_type == "vsplit" then + vim.cmd "vnew" + end + vim.lsp.util.jump_to_location(flattened_results[1], offset_encoding) + else + local locations = vim.lsp.util.locations_to_items(flattened_results, offset_encoding) + pickers.new(opts, { + prompt_title = title, + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.generic_sorter(opts), + push_cursor_on_edit = true, + push_tagstack_on_edit = true, + }):find() + end + end) +end + +lsp.definitions = function(opts) + return list_or_jump("textDocument/definition", "LSP Definitions", opts) +end + +lsp.type_definitions = function(opts) + return list_or_jump("textDocument/typeDefinition", "LSP Type Definitions", opts) +end + +lsp.implementations = function(opts) + return list_or_jump("textDocument/implementation", "LSP Implementations", opts) +end + +lsp.document_symbols = function(opts) + local params = vim.lsp.util.make_position_params(opts.winnr) + vim.lsp.buf_request(opts.bufnr, "textDocument/documentSymbol", params, function(err, result, _, _) + if err then + vim.api.nvim_err_writeln("Error when finding document symbols: " .. err.message) + return + end + + if not result or vim.tbl_isempty(result) then + utils.notify("builtin.lsp_document_symbols", { + msg = "No results from textDocument/documentSymbol", + level = "INFO", + }) + return + end + + local locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr) or {} + locations = utils.filter_symbols(locations, opts) + if locations == nil then + -- error message already printed in `utils.filter_symbols` + return + end + + if vim.tbl_isempty(locations) then + utils.notify("builtin.lsp_document_symbols", { + msg = "No document_symbol locations found", + level = "INFO", + }) + return + end + + opts.path_display = { "hidden" } + pickers.new(opts, { + prompt_title = "LSP Document Symbols", + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.prefilter_sorter { + tag = "symbol_type", + sorter = conf.generic_sorter(opts), + }, + push_cursor_on_edit = true, + push_tagstack_on_edit = true, + }):find() + end) +end + +lsp.workspace_symbols = function(opts) + local params = { query = opts.query or "" } + vim.lsp.buf_request(opts.bufnr, "workspace/symbol", params, function(err, server_result, _, _) + if err then + vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err.message) + return + end + + local locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {} + locations = utils.filter_symbols(locations, opts) + if locations == nil then + -- error message already printed in `utils.filter_symbols` + return + end + + if vim.tbl_isempty(locations) then + utils.notify("builtin.lsp_workspace_symbols", { + msg = "No results from workspace/symbol. Maybe try a different query: " + .. "'Telescope lsp_workspace_symbols query=example'", + level = "INFO", + }) + return + end + + opts.ignore_filename = vim.F.if_nil(opts.ignore_filename, false) + + pickers.new(opts, { + prompt_title = "LSP Workspace Symbols", + finder = finders.new_table { + results = locations, + entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = conf.prefilter_sorter { + tag = "symbol_type", + sorter = conf.generic_sorter(opts), + }, + }):find() + end) +end + +local function get_workspace_symbols_requester(bufnr, opts) + local cancel = function() end + + return function(prompt) + local tx, rx = channel.oneshot() + cancel() + _, cancel = vim.lsp.buf_request(bufnr, "workspace/symbol", { query = prompt }, tx) + + -- Handle 0.5 / 0.5.1 handler situation + local err, res = rx() + assert(not err, err) + + local locations = vim.lsp.util.symbols_to_items(res or {}, bufnr) or {} + if not vim.tbl_isempty(locations) then + locations = utils.filter_symbols(locations, opts) or {} + end + return locations + end +end + +lsp.dynamic_workspace_symbols = function(opts) + pickers.new(opts, { + prompt_title = "LSP Dynamic Workspace Symbols", + finder = finders.new_dynamic { + entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), + fn = get_workspace_symbols_requester(opts.bufnr, opts), + }, + previewer = conf.qflist_previewer(opts), + sorter = sorters.highlighter_only(opts), + attach_mappings = function(_, map) + map("i", "", function(prompt_bufnr) + local line = action_state.get_current_line() + require("telescope.actions.generate").refine(prompt_bufnr, { + prompt_title = "LSP Workspace Symbols (" .. line .. ")", + sorter = conf.generic_sorter(opts), + }) + end) + return true + end, + }):find() +end + +local function check_capabilities(feature, bufnr) + local clients = vim.lsp.buf_get_clients(bufnr) + + local supported_client = false + for _, client in pairs(clients) do + supported_client = client.server_capabilities[feature] + if supported_client then + break + end + end + + if supported_client then + return true + else + if #clients == 0 then + utils.notify("builtin.lsp_*", { + msg = "no client attached", + level = "INFO", + }) + else + utils.notify("builtin.lsp_*", { + msg = "server does not support " .. feature, + level = "INFO", + }) + end + return false + end +end + +local feature_map = { + ["document_symbols"] = "documentSymbolProvider", + ["references"] = "referencesProvider", + ["definitions"] = "definitionProvider", + ["type_definitions"] = "typeDefinitionProvider", + ["implementations"] = "implementationProvider", + ["workspace_symbols"] = "workspaceSymbolProvider", + ["incoming_calls"] = "callHierarchyProvider", + ["outgoing_calls"] = "callHierarchyProvider", +} + +local function apply_checks(mod) + for k, v in pairs(mod) do + mod[k] = function(opts) + opts = opts or {} + + local feature_name = feature_map[k] + if feature_name and not check_capabilities(feature_name, opts.bufnr) then + return + end + v(opts) + end + end + + return mod +end + +return apply_checks(lsp) diff --git a/lua/telescope/builtin/diagnostics.lua b/lua/telescope/builtin/diagnostics.lua index 2614e36..5d8f926 100644 --- a/lua/telescope/builtin/diagnostics.lua +++ b/lua/telescope/builtin/diagnostics.lua @@ -1,150 +1,17 @@ -local conf = require("telescope.config").values -local finders = require "telescope.finders" -local make_entry = require "telescope.make_entry" -local pickers = require "telescope.pickers" -local utils = require "telescope.utils" - -local diagnostics = {} - -local convert_diagnostic_type = function(severities, severity) - -- convert from string to int - if type(severity) == "string" then - -- make sure that e.g. error is uppercased to ERROR - return severities[severity:upper()] - end - -- otherwise keep original value, incl. nil - return severity -end - -local diagnostics_to_tbl = function(opts) - opts = vim.F.if_nil(opts, {}) - local items = {} - local severities = vim.diagnostic.severity - local current_buf = vim.api.nvim_get_current_buf() - - opts.severity = convert_diagnostic_type(severities, opts.severity) - opts.severity_limit = convert_diagnostic_type(severities, opts.severity_limit) - opts.severity_bound = convert_diagnostic_type(severities, opts.severity_bound) - - local diagnosis_opts = { severity = {}, namespace = opts.namespace } - if opts.severity ~= nil then - if opts.severity_limit ~= nil or opts.severity_bound ~= nil then - utils.notify("builtin.diagnostics", { - msg = "Invalid severity parameters. Both a specific severity and a limit/bound is not allowed", - level = "ERROR", - }) - return {} - end - diagnosis_opts.severity = opts.severity - else - if opts.severity_limit ~= nil then - diagnosis_opts.severity["min"] = opts.severity_limit - end - if opts.severity_bound ~= nil then - diagnosis_opts.severity["max"] = opts.severity_bound - end - end - - opts.root_dir = opts.root_dir == true and vim.loop.cwd() or opts.root_dir - - local bufnr_name_map = {} - local filter_diag = function(diagnostic) - if bufnr_name_map[diagnostic.bufnr] == nil then - bufnr_name_map[diagnostic.bufnr] = vim.api.nvim_buf_get_name(diagnostic.bufnr) - end - - local root_dir_test = not opts.root_dir - or string.sub(bufnr_name_map[diagnostic.bufnr], 1, #opts.root_dir) == opts.root_dir - local listed_test = not opts.no_unlisted or vim.api.nvim_buf_get_option(diagnostic.bufnr, "buflisted") - - return root_dir_test and listed_test - end - - local preprocess_diag = function(diagnostic) - return { - bufnr = diagnostic.bufnr, - filename = bufnr_name_map[diagnostic.bufnr], - lnum = diagnostic.lnum + 1, - col = diagnostic.col + 1, - text = vim.trim(diagnostic.message:gsub("[\n]", "")), - type = severities[diagnostic.severity] or severities[1], - } - end - - for _, d in ipairs(vim.diagnostic.get(opts.bufnr, diagnosis_opts)) do - if filter_diag(d) then - table.insert(items, preprocess_diag(d)) - end - end - - -- sort results by bufnr (prioritize cur buf), severity, lnum - table.sort(items, function(a, b) - if a.bufnr == b.bufnr then - if a.type == b.type then - return a.lnum < b.lnum - else - return a.type < b.type - end - else - -- prioritize for current bufnr - if a.bufnr == current_buf then - return true - end - if b.bufnr == current_buf then - return false - end - return a.bufnr < b.bufnr - end - end) - - return items -end - -diagnostics.get = function(opts) - if opts.bufnr ~= 0 then - opts.bufnr = nil - end - if opts.bufnr == nil then - opts.path_display = vim.F.if_nil(opts.path_display, {}) - end - if type(opts.bufnr) == "string" then - opts.bufnr = tonumber(opts.bufnr) - end - - local locations = diagnostics_to_tbl(opts) - - if vim.tbl_isempty(locations) then - utils.notify("builtin.diagnostics", { - msg = "No diagnostics found", - level = "INFO", +local m = setmetatable({}, { + __index = function(_, k) + local utils = require "telescope.utils" + utils.notify("builtin", { + msg = string.format( + 'You are using an internal interface. Do not use `require("telescope.builtin.diagnostics").%s`,' + .. ' please use `require("telescope.builtin").diagnostics`! We will remove this endpoint soon!', + k, + k + ), + level = "ERROR", }) - return - end + return require("telescope.builtin").diagnostics + end, +}) - opts.path_display = vim.F.if_nil(opts.path_display, "hidden") - pickers.new(opts, { - prompt_title = opts.bufnr == nil and "Workspace Diagnostics" or "Document Diagnostics", - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_diagnostics(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.prefilter_sorter { - tag = "type", - sorter = conf.generic_sorter(opts), - }, - }):find() -end - -local function apply_checks(mod) - for k, v in pairs(mod) do - mod[k] = function(opts) - opts = opts or {} - v(opts) - end - end - - return mod -end - -return apply_checks(diagnostics) +return m diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index dddd18a..645fc10 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -1,522 +1,17 @@ -local action_state = require "telescope.actions.state" -local action_set = require "telescope.actions.set" -local finders = require "telescope.finders" -local make_entry = require "telescope.make_entry" -local pickers = require "telescope.pickers" -local previewers = require "telescope.previewers" -local sorters = require "telescope.sorters" -local utils = require "telescope.utils" -local conf = require("telescope.config").values -local log = require "telescope.log" - -local Path = require "plenary.path" - -local flatten = vim.tbl_flatten -local filter = vim.tbl_filter - -local files = {} - -local escape_chars = function(string) - return string.gsub(string, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%.]", { - ["\\"] = "\\\\", - ["-"] = "\\-", - ["("] = "\\(", - [")"] = "\\)", - ["["] = "\\[", - ["]"] = "\\]", - ["{"] = "\\{", - ["}"] = "\\}", - ["?"] = "\\?", - ["+"] = "\\+", - ["*"] = "\\*", - ["^"] = "\\^", - ["$"] = "\\$", - ["."] = "\\.", - }) -end - --- Special keys: --- opts.search_dirs -- list of directory to search in --- opts.grep_open_files -- boolean to restrict search to open files -files.live_grep = function(opts) - local vimgrep_arguments = opts.vimgrep_arguments or conf.vimgrep_arguments - local search_dirs = opts.search_dirs - local grep_open_files = opts.grep_open_files - opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd() - - local filelist = {} - - if grep_open_files then - local bufnrs = filter(function(b) - if 1 ~= vim.fn.buflisted(b) then - return false - end - return true - end, vim.api.nvim_list_bufs()) - if not next(bufnrs) then - return - end - - for _, bufnr in ipairs(bufnrs) do - local file = vim.api.nvim_buf_get_name(bufnr) - table.insert(filelist, Path:new(file):make_relative(opts.cwd)) - end - elseif search_dirs then - for i, path in ipairs(search_dirs) do - search_dirs[i] = vim.fn.expand(path) - end - end - - local additional_args = {} - if opts.additional_args ~= nil and type(opts.additional_args) == "function" then - additional_args = opts.additional_args(opts) - end - - if opts.type_filter then - additional_args[#additional_args + 1] = "--type=" .. opts.type_filter - end - - if type(opts.glob_pattern) == "string" then - additional_args[#additional_args + 1] = "--glob=" .. opts.glob_pattern - elseif type(opts.glob_pattern) == "table" then - for i = 1, #opts.glob_pattern do - additional_args[#additional_args + 1] = "--glob=" .. opts.glob_pattern[i] - end - end - - local live_grepper = finders.new_job(function(prompt) - -- TODO: Probably could add some options for smart case and whatever else rg offers. - - if not prompt or prompt == "" then - return nil - end - - local search_list = {} - - if search_dirs then - table.insert(search_list, search_dirs) - end - - if grep_open_files then - search_list = filelist - end - - return flatten { vimgrep_arguments, additional_args, "--", prompt, search_list } - end, opts.entry_maker or make_entry.gen_from_vimgrep(opts), opts.max_results, opts.cwd) - - pickers.new(opts, { - prompt_title = "Live Grep", - finder = live_grepper, - previewer = conf.grep_previewer(opts), - -- TODO: It would be cool to use `--json` output for this - -- and then we could get the highlight positions directly. - sorter = sorters.highlighter_only(opts), - attach_mappings = function(_, map) - map("i", "", function(prompt_bufnr) - local line = action_state.get_current_line() - require("telescope.actions.generate").refine(prompt_bufnr, { - prompt_title = "Find Word (" .. line .. ")", - sorter = conf.generic_sorter(opts), - }) - end) - return true - end, - }):find() -end - --- Special keys: --- opts.search -- the string to search. --- opts.search_dirs -- list of directory to search in --- opts.use_regex -- special characters won't be escaped -files.grep_string = function(opts) - -- TODO: This should probably check your visual selection as well, if you've got one - - local vimgrep_arguments = opts.vimgrep_arguments or conf.vimgrep_arguments - local search_dirs = opts.search_dirs - local word = opts.search or vim.fn.expand "" - local search = opts.use_regex and word or escape_chars(word) - local word_match = opts.word_match - opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts) - - local title_word = word:gsub("\n", "\\n") - - local additional_args = {} - if opts.additional_args ~= nil and type(opts.additional_args) == "function" then - additional_args = opts.additional_args(opts) - end - - local args = flatten { - vimgrep_arguments, - additional_args, - word_match, - "--", - search, - } - - if search_dirs then - for _, path in ipairs(search_dirs) do - table.insert(args, vim.fn.expand(path)) - end - end - - pickers.new(opts, { - prompt_title = "Find Word (" .. title_word .. ")", - finder = finders.new_oneshot_job(args, opts), - previewer = conf.grep_previewer(opts), - sorter = conf.generic_sorter(opts), - }):find() -end - -files.find_files = function(opts) - local find_command = (function() - if opts.find_command then - if type(opts.find_command) == "function" then - return opts.find_command(opts) - end - return opts.find_command - elseif 1 == vim.fn.executable "fd" then - return { "fd", "--type", "f" } - elseif 1 == vim.fn.executable "fdfind" then - return { "fdfind", "--type", "f" } - elseif 1 == vim.fn.executable "rg" then - return { "rg", "--files" } - elseif 1 == vim.fn.executable "find" and vim.fn.has "win32" == 0 then - return { "find", ".", "-type", "f" } - elseif 1 == vim.fn.executable "where" then - return { "where", "/r", ".", "*" } - end - end)() - - if not find_command then - utils.notify("builtin.find_files", { - msg = "You need to install either find, fd, or rg", +local m = setmetatable({}, { + __index = function(_, k) + local utils = require "telescope.utils" + utils.notify("builtin", { + msg = string.format( + 'You are using an internal interface. Do not use `require("telescope.builtin.files").%s`,' + .. ' please use `require("telescope.builtin").%s`! We will remove this endpoint soon!', + k, + k + ), level = "ERROR", }) - return - end + return require("telescope.builtin")[k] + end, +}) - local command = find_command[1] - local hidden = opts.hidden - local no_ignore = opts.no_ignore - local no_ignore_parent = opts.no_ignore_parent - local follow = opts.follow - local search_dirs = opts.search_dirs - local search_file = opts.search_file - - if search_dirs then - for k, v in pairs(search_dirs) do - search_dirs[k] = vim.fn.expand(v) - end - end - - if command == "fd" or command == "fdfind" or command == "rg" then - if hidden then - table.insert(find_command, "--hidden") - end - if no_ignore then - table.insert(find_command, "--no-ignore") - end - if no_ignore_parent then - table.insert(find_command, "--no-ignore-parent") - end - if follow then - table.insert(find_command, "-L") - end - if search_file then - if command == "rg" then - table.insert(find_command, "-g") - table.insert(find_command, "*" .. search_file .. "*") - else - table.insert(find_command, search_file) - end - end - if search_dirs then - if command ~= "rg" and not search_file then - table.insert(find_command, ".") - end - for _, v in pairs(search_dirs) do - table.insert(find_command, v) - end - end - elseif command == "find" then - if not hidden then - table.insert(find_command, { "-not", "-path", "*/.*" }) - find_command = flatten(find_command) - end - if no_ignore ~= nil then - log.warn "The `no_ignore` key is not available for the `find` command in `find_files`." - end - if no_ignore_parent ~= nil then - log.warn "The `no_ignore_parent` key is not available for the `find` command in `find_files`." - end - if follow then - table.insert(find_command, 2, "-L") - end - if search_file then - table.insert(find_command, "-name") - table.insert(find_command, "*" .. search_file .. "*") - end - if search_dirs then - table.remove(find_command, 2) - for _, v in pairs(search_dirs) do - table.insert(find_command, 2, v) - end - end - elseif command == "where" then - if hidden ~= nil then - log.warn "The `hidden` key is not available for the Windows `where` command in `find_files`." - end - if no_ignore ~= nil then - log.warn "The `no_ignore` key is not available for the Windows `where` command in `find_files`." - end - if no_ignore_parent ~= nil then - log.warn "The `no_ignore_parent` key is not available for the Windows `where` command in `find_files`." - end - if follow ~= nil then - log.warn "The `follow` key is not available for the Windows `where` command in `find_files`." - end - if search_dirs ~= nil then - log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`." - end - if search_file ~= nil then - log.warn "The `search_file` key is not available for the Windows `where` command in `find_files`." - end - end - - if opts.cwd then - opts.cwd = vim.fn.expand(opts.cwd) - end - - opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts) - - pickers.new(opts, { - prompt_title = "Find Files", - finder = finders.new_oneshot_job(find_command, opts), - previewer = conf.file_previewer(opts), - sorter = conf.file_sorter(opts), - }):find() -end - -local function prepare_match(entry, kind) - local entries = {} - - if entry.node then - table.insert(entries, entry) - else - for name, item in pairs(entry) do - vim.list_extend(entries, prepare_match(item, name)) - end - end - - return entries -end - --- TODO: finish docs for opts.show_line -files.treesitter = function(opts) - opts.show_line = vim.F.if_nil(opts.show_line, true) - - local has_nvim_treesitter, _ = pcall(require, "nvim-treesitter") - if not has_nvim_treesitter then - utils.notify("builtin.treesitter", { - msg = "User need to install nvim-treesitter needs to be installed", - level = "ERROR", - }) - return - end - - local parsers = require "nvim-treesitter.parsers" - if not parsers.has_parser(parsers.get_buf_lang(opts.bufnr)) then - utils.notify("builtin.treesitter", { - msg = "No parser for the current buffer", - level = "ERROR", - }) - return - end - - local ts_locals = require "nvim-treesitter.locals" - local results = {} - for _, definition in ipairs(ts_locals.get_definitions(opts.bufnr)) do - local entries = prepare_match(ts_locals.get_local_nodes(definition)) - for _, entry in ipairs(entries) do - entry.kind = vim.F.if_nil(entry.kind, "") - table.insert(results, entry) - end - end - - if vim.tbl_isempty(results) then - return - end - - pickers.new(opts, { - prompt_title = "Treesitter Symbols", - finder = finders.new_table { - results = results, - entry_maker = opts.entry_maker or make_entry.gen_from_treesitter(opts), - }, - previewer = conf.grep_previewer(opts), - sorter = conf.prefilter_sorter { - tag = "kind", - sorter = conf.generic_sorter(opts), - }, - }):find() -end - -files.current_buffer_fuzzy_find = function(opts) - -- All actions are on the current buffer - local filename = vim.fn.expand(vim.api.nvim_buf_get_name(opts.bufnr)) - local filetype = vim.api.nvim_buf_get_option(opts.bufnr, "filetype") - - local lines = vim.api.nvim_buf_get_lines(opts.bufnr, 0, -1, false) - local lines_with_numbers = {} - - for lnum, line in ipairs(lines) do - table.insert(lines_with_numbers, { - lnum = lnum, - bufnr = opts.bufnr, - filename = filename, - text = line, - }) - end - - local ts_ok, ts_parsers = pcall(require, "nvim-treesitter.parsers") - if ts_ok then - filetype = ts_parsers.ft_to_lang(filetype) - end - local _, ts_configs = pcall(require, "nvim-treesitter.configs") - - local parser_ok, parser = pcall(vim.treesitter.get_parser, opts.bufnr, filetype) - local query_ok, query = pcall(vim.treesitter.get_query, filetype, "highlights") - if parser_ok and query_ok and ts_ok and ts_configs.is_enabled("highlight", filetype, opts.bufnr) then - local root = parser:parse()[1]:root() - - local highlighter = vim.treesitter.highlighter.new(parser) - local highlighter_query = highlighter:get_query(filetype) - - local line_highlights = setmetatable({}, { - __index = function(t, k) - local obj = {} - rawset(t, k, obj) - return obj - end, - }) - for id, node in query:iter_captures(root, opts.bufnr, 0, -1) do - local hl = highlighter_query:_get_hl_from_capture(id) - if hl and type(hl) ~= "number" then - local row1, col1, row2, col2 = node:range() - - if row1 == row2 then - local row = row1 + 1 - - for index = col1, col2 do - line_highlights[row][index] = hl - end - else - local row = row1 + 1 - for index = col1, #lines[row] do - line_highlights[row][index] = hl - end - - while row < row2 + 1 do - row = row + 1 - - for index = 0, #(lines[row] or {}) do - line_highlights[row][index] = hl - end - end - end - end - end - - opts.line_highlights = line_highlights - end - - pickers.new(opts, { - prompt_title = "Current Buffer Fuzzy", - finder = finders.new_table { - results = lines_with_numbers, - entry_maker = opts.entry_maker or make_entry.gen_from_buffer_lines(opts), - }, - sorter = conf.generic_sorter(opts), - previewer = conf.grep_previewer(opts), - attach_mappings = function() - action_set.select:enhance { - post = function() - local selection = action_state.get_selected_entry() - vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) - end, - } - - return true - end, - }):find() -end - -files.tags = function(opts) - local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles() - for i, ctags_file in ipairs(tagfiles) do - tagfiles[i] = vim.fn.expand(ctags_file, true) - end - if vim.tbl_isempty(tagfiles) then - utils.notify("builtin.tags", { - msg = "No tags file found. Create one with ctags -R", - level = "ERROR", - }) - return - end - opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_ctags(opts)) - - pickers.new(opts, { - prompt_title = "Tags", - finder = finders.new_oneshot_job(flatten { "cat", tagfiles }, opts), - previewer = previewers.ctags.new(opts), - sorter = conf.generic_sorter(opts), - attach_mappings = function() - action_set.select:enhance { - post = function() - local selection = action_state.get_selected_entry() - if not selection then - return - end - - if selection.scode then - -- un-escape / then escape required - -- special chars for vim.fn.search() - -- ] ~ * - local scode = selection.scode:gsub([[\/]], "/"):gsub("[%]~*]", function(x) - return "\\" .. x - end) - - vim.cmd "norm! gg" - vim.fn.search(scode) - vim.cmd "norm! zz" - else - vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) - end - end, - } - return true - end, - }):find() -end - -files.current_buffer_tags = function(opts) - return files.tags(vim.tbl_extend("force", { - prompt_title = "Current Buffer Tags", - only_current_file = true, - path_display = "hidden", - }, opts)) -end - -local function apply_checks(mod) - for k, v in pairs(mod) do - mod[k] = function(opts) - opts = opts or {} - - v(opts) - end - end - - return mod -end - -return apply_checks(files) +return m diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index 7db45ef..e6da478 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -1,411 +1,17 @@ -local actions = require "telescope.actions" -local action_state = require "telescope.actions.state" -local finders = require "telescope.finders" -local make_entry = require "telescope.make_entry" -local pickers = require "telescope.pickers" -local previewers = require "telescope.previewers" -local utils = require "telescope.utils" -local entry_display = require "telescope.pickers.entry_display" -local strings = require "plenary.strings" -local Path = require "plenary.path" - -local conf = require("telescope.config").values - -local git = {} - -git.files = function(opts) - if opts.is_bare then - utils.notify("builtin.git_files", { - msg = "This operation must be run in a work tree", +local m = setmetatable({}, { + __index = function(_, k) + local utils = require "telescope.utils" + utils.notify("builtin", { + msg = string.format( + 'You are using an internal interface. Do not use `require("telescope.builtin.git").%s`,' + .. ' please use `require("telescope.builtin").git_%s`! We will remove this endpoint soon!', + k, + k + ), level = "ERROR", }) - return - end + return require("telescope.builtin")["git_" .. k] + end, +}) - local show_untracked = vim.F.if_nil(opts.show_untracked, false) - local recurse_submodules = vim.F.if_nil(opts.recurse_submodules, false) - if show_untracked and recurse_submodules then - utils.notify("builtin.git_files", { - msg = "Git does not support both --others and --recurse-submodules", - level = "ERROR", - }) - return - end - - -- By creating the entry maker after the cwd options, - -- we ensure the maker uses the cwd options when being created. - opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_file(opts)) - local git_command = vim.F.if_nil(opts.git_command, { "git", "ls-files", "--exclude-standard", "--cached" }) - - pickers.new(opts, { - prompt_title = "Git Files", - finder = finders.new_oneshot_job( - vim.tbl_flatten { - git_command, - show_untracked and "--others" or nil, - recurse_submodules and "--recurse-submodules" or nil, - }, - opts - ), - previewer = conf.file_previewer(opts), - sorter = conf.file_sorter(opts), - }):find() -end - -git.commits = function(opts) - opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) - local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit", "--", "." }) - - pickers.new(opts, { - prompt_title = "Git Commits", - finder = finders.new_oneshot_job(git_command, opts), - previewer = { - previewers.git_commit_diff_to_parent.new(opts), - previewers.git_commit_diff_to_head.new(opts), - previewers.git_commit_diff_as_was.new(opts), - previewers.git_commit_message.new(opts), - }, - sorter = conf.file_sorter(opts), - attach_mappings = function(_, map) - actions.select_default:replace(actions.git_checkout) - map("i", "m", actions.git_reset_mixed) - map("n", "m", actions.git_reset_mixed) - map("i", "s", actions.git_reset_soft) - map("n", "s", actions.git_reset_soft) - map("i", "h", actions.git_reset_hard) - map("n", "h", actions.git_reset_hard) - return true - end, - }):find() -end - -git.stash = function(opts) - opts.show_branch = vim.F.if_nil(opts.show_branch, true) - opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_stash(opts)) - - pickers.new(opts, { - prompt_title = "Git Stash", - finder = finders.new_oneshot_job( - vim.tbl_flatten { - "git", - "--no-pager", - "stash", - "list", - }, - opts - ), - previewer = previewers.git_stash_diff.new(opts), - sorter = conf.file_sorter(opts), - attach_mappings = function() - actions.select_default:replace(actions.git_apply_stash) - return true - end, - }):find() -end - -local get_current_buf_line = function(winnr) - local lnum = vim.api.nvim_win_get_cursor(winnr)[1] - return vim.trim(vim.api.nvim_buf_get_lines(vim.api.nvim_win_get_buf(winnr), lnum - 1, lnum, false)[1]) -end - -git.bcommits = function(opts) - opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil - opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) - opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) - local git_command = vim.F.if_nil( - opts.git_command, - { "git", "log", "--pretty=oneline", "--abbrev-commit", "--follow" } - ) - - pickers.new(opts, { - prompt_title = "Git BCommits", - finder = finders.new_oneshot_job( - vim.tbl_flatten { - git_command, - opts.current_file, - }, - opts - ), - previewer = { - previewers.git_commit_diff_to_parent.new(opts), - previewers.git_commit_diff_to_head.new(opts), - previewers.git_commit_diff_as_was.new(opts), - previewers.git_commit_message.new(opts), - }, - sorter = conf.file_sorter(opts), - attach_mappings = function() - actions.select_default:replace(actions.git_checkout_current_buffer) - local transfrom_file = function() - return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or "" - end - - local get_buffer_of_orig = function(selection) - local value = selection.value .. ":" .. transfrom_file() - local content = utils.get_os_command_output({ "git", "--no-pager", "show", value }, opts.cwd) - - local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content) - vim.api.nvim_buf_set_name(bufnr, "Original") - return bufnr - end - - local vimdiff = function(selection, command) - local ft = vim.bo.filetype - vim.cmd "diffthis" - - local bufnr = get_buffer_of_orig(selection) - vim.cmd(string.format("%s %s", command, bufnr)) - vim.bo.filetype = ft - vim.cmd "diffthis" - - vim.api.nvim_create_autocmd("WinClosed", { - buffer = bufnr, - nested = true, - once = true, - callback = function() - vim.api.nvim_buf_delete(bufnr, { force = true }) - end, - }) - end - - actions.select_vertical:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vimdiff(selection, "leftabove vert sbuffer") - end) - - actions.select_horizontal:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vimdiff(selection, "belowright sbuffer") - end) - - actions.select_tab:replace(function(prompt_bufnr) - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vim.cmd("tabedit " .. transfrom_file()) - vimdiff(selection, "leftabove vert sbuffer") - end) - return true - end, - }):find() -end - -git.branches = function(opts) - local format = "%(HEAD)" - .. "%(refname)" - .. "%(authorname)" - .. "%(upstream:lstrip=2)" - .. "%(committerdate:format-local:%Y/%m/%d %H:%M:%S)" - local output = utils.get_os_command_output( - { "git", "for-each-ref", "--perl", "--format", format, opts.pattern }, - opts.cwd - ) - - local results = {} - local widths = { - name = 0, - authorname = 0, - upstream = 0, - committerdate = 0, - } - local unescape_single_quote = function(v) - return string.gsub(v, "\\([\\'])", "%1") - end - local parse_line = function(line) - local fields = vim.split(string.sub(line, 2, -2), "''", true) - local entry = { - head = fields[1], - refname = unescape_single_quote(fields[2]), - authorname = unescape_single_quote(fields[3]), - upstream = unescape_single_quote(fields[4]), - committerdate = fields[5], - } - local prefix - if vim.startswith(entry.refname, "refs/remotes/") then - prefix = "refs/remotes/" - elseif vim.startswith(entry.refname, "refs/heads/") then - prefix = "refs/heads/" - else - return - end - local index = 1 - if entry.head ~= "*" then - index = #results + 1 - end - - entry.name = string.sub(entry.refname, string.len(prefix) + 1) - for key, value in pairs(widths) do - widths[key] = math.max(value, strings.strdisplaywidth(entry[key] or "")) - end - if string.len(entry.upstream) > 0 then - widths.upstream_indicator = 2 - end - table.insert(results, index, entry) - end - for _, line in ipairs(output) do - parse_line(line) - end - if #results == 0 then - return - end - - local displayer = entry_display.create { - separator = " ", - items = { - { width = 1 }, - { width = widths.name }, - { width = widths.authorname }, - { width = widths.upstream_indicator }, - { width = widths.upstream }, - { width = widths.committerdate }, - }, - } - - local make_display = function(entry) - return displayer { - { entry.head }, - { entry.name, "TelescopeResultsIdentifier" }, - { entry.authorname }, - { string.len(entry.upstream) > 0 and "=>" or "" }, - { entry.upstream, "TelescopeResultsIdentifier" }, - { entry.committerdate }, - } - end - - pickers.new(opts, { - prompt_title = "Git Branches", - finder = finders.new_table { - results = results, - entry_maker = function(entry) - entry.value = entry.name - entry.ordinal = entry.name - entry.display = make_display - return make_entry.set_default_entry_mt(entry, opts) - end, - }, - previewer = previewers.git_branch_log.new(opts), - sorter = conf.file_sorter(opts), - attach_mappings = function(_, map) - actions.select_default:replace(actions.git_checkout) - map("i", "", actions.git_track_branch) - map("n", "", actions.git_track_branch) - - map("i", "", actions.git_rebase_branch) - map("n", "", actions.git_rebase_branch) - - map("i", "", actions.git_create_branch) - map("n", "", actions.git_create_branch) - - map("i", "", actions.git_switch_branch) - map("n", "", actions.git_switch_branch) - - map("i", "", actions.git_delete_branch) - map("n", "", actions.git_delete_branch) - - map("i", "", actions.git_merge_branch) - map("n", "", actions.git_merge_branch) - return true - end, - }):find() -end - -git.status = function(opts) - if opts.is_bare then - utils.notify("builtin.git_status", { - msg = "This operation must be run in a work tree", - level = "ERROR", - }) - return - end - - local gen_new_finder = function() - local expand_dir = vim.F.if_nil(opts.expand_dir, true) - local git_cmd = { "git", "status", "-s", "--", "." } - - if expand_dir then - table.insert(git_cmd, #git_cmd - 1, "-u") - end - - local output = utils.get_os_command_output(git_cmd, opts.cwd) - - if #output == 0 then - print "No changes found" - utils.notify("builtin.git_status", { - msg = "No changes found", - level = "WARN", - }) - return - end - - return finders.new_table { - results = output, - entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_status(opts)), - } - end - - local initial_finder = gen_new_finder() - if not initial_finder then - return - end - - pickers.new(opts, { - prompt_title = "Git Status", - finder = initial_finder, - previewer = previewers.git_file_diff.new(opts), - sorter = conf.file_sorter(opts), - attach_mappings = function(prompt_bufnr, map) - actions.git_staging_toggle:enhance { - post = function() - action_state.get_current_picker(prompt_bufnr):refresh(gen_new_finder(), { reset_prompt = true }) - end, - } - - map("i", "", actions.git_staging_toggle) - map("n", "", actions.git_staging_toggle) - return true - end, - }):find() -end - -local set_opts_cwd = function(opts) - if opts.cwd then - opts.cwd = vim.fn.expand(opts.cwd) - else - opts.cwd = vim.loop.cwd() - end - - -- Find root of git directory and remove trailing newline characters - local git_root, ret = utils.get_os_command_output({ "git", "rev-parse", "--show-toplevel" }, opts.cwd) - local use_git_root = vim.F.if_nil(opts.use_git_root, true) - - if ret ~= 0 then - local in_worktree = utils.get_os_command_output({ "git", "rev-parse", "--is-inside-work-tree" }, opts.cwd) - local in_bare = utils.get_os_command_output({ "git", "rev-parse", "--is-bare-repository" }, opts.cwd) - - if in_worktree[1] ~= "true" and in_bare[1] ~= "true" then - error(opts.cwd .. " is not a git directory") - elseif in_worktree[1] ~= "true" and in_bare[1] == "true" then - opts.is_bare = true - end - else - if use_git_root then - opts.cwd = git_root[1] - end - end -end - -local function apply_checks(mod) - for k, v in pairs(mod) do - mod[k] = function(opts) - opts = vim.F.if_nil(opts, {}) - - set_opts_cwd(opts) - v(opts) - end - end - - return mod -end - -return apply_checks(git) +return m diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 71cb583..f25d059 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -60,7 +60,7 @@ end ---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on ---@field max_results number: define a upper result value ---@field disable_coordinates boolean: don't show the line & row numbers (default: false) -builtin.live_grep = require_on_exported_call("telescope.builtin.files").live_grep +builtin.live_grep = require_on_exported_call("telescope.builtin.__files").live_grep --- Searches for the string under your cursor in your current working directory ---@param opts table: options to pass to the picker @@ -72,7 +72,7 @@ builtin.live_grep = require_on_exported_call("telescope.builtin.files").live_gre ---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on ---@field disable_coordinates boolean: don't show the line and row numbers (default: false) ---@field only_sort_text boolean: only sort the text, not the file, line or row (default: false) -builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_string +builtin.grep_string = require_on_exported_call("telescope.builtin.__files").grep_string --- Search for files (respecting .gitignore) ---@param opts table: options to pass to the picker @@ -84,7 +84,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_s ---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false) ---@field search_dirs table: directory/directories/files to search ---@field search_file string: specify a filename to search for -builtin.find_files = require_on_exported_call("telescope.builtin.files").find_files +builtin.find_files = require_on_exported_call("telescope.builtin.__files").find_files --- This is an alias for the `find_files` picker builtin.fd = builtin.find_files @@ -95,12 +95,12 @@ builtin.fd = builtin.find_files ---@field show_line boolean: if true, shows the row:column that the result is found at (default: true) ---@field bufnr number: specify the buffer number where treesitter should run. (default: current buffer) ---@field symbol_highlights table: string -> string. Matches symbol with hl_group -builtin.treesitter = require_on_exported_call("telescope.builtin.files").treesitter +builtin.treesitter = require_on_exported_call("telescope.builtin.__files").treesitter --- Live fuzzy search inside of the currently open buffer ---@param opts table: options to pass to the picker ---@field skip_empty_lines boolean: if true we dont display empty lines (default: false) -builtin.current_buffer_fuzzy_find = require_on_exported_call("telescope.builtin.files").current_buffer_fuzzy_find +builtin.current_buffer_fuzzy_find = require_on_exported_call("telescope.builtin.__files").current_buffer_fuzzy_find --- Lists tags in current directory with tag location file preview (users are required to run ctags -R to generate tags --- or update when introducing new changes) @@ -110,7 +110,7 @@ builtin.current_buffer_fuzzy_find = require_on_exported_call("telescope.builtin. ---@field show_line boolean: if true, shows the content of the line the tag is found on in the picker (default: true) ---@field only_sort_tags boolean: if true we will only sort tags (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.tags = require_on_exported_call("telescope.builtin.files").tags +builtin.tags = require_on_exported_call("telescope.builtin.__files").tags --- Lists all of the tags for the currently open buffer, with a preview ---@param opts table: options to pass to the picker @@ -119,7 +119,7 @@ builtin.tags = require_on_exported_call("telescope.builtin.files").tags ---@field show_line boolean: if true, shows the content of the line the tag is found on in the picker (default: true) ---@field only_sort_tags boolean: if true we will only sort tags (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.files").current_buffer_tags +builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.__files").current_buffer_tags -- -- @@ -137,7 +137,7 @@ builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.files" ---@field show_untracked boolean: if true, adds `--others` flag to command and shows untracked files (default: false) ---@field recurse_submodules boolean: if true, adds the `--recurse-submodules` flag to command (default: false) ---@field git_command table: command that will be exectued. {"git","ls-files","--exclude-standard","--cached"} -builtin.git_files = require_on_exported_call("telescope.builtin.git").files +builtin.git_files = require_on_exported_call("telescope.builtin.__git").files --- Lists commits for current directory with diff preview --- - Default keymaps: @@ -149,7 +149,7 @@ builtin.git_files = require_on_exported_call("telescope.builtin.git").files ---@field cwd string: specify the path of the repo ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field git_command table: command that will be exectued. {"git","log","--pretty=oneline","--abbrev-commit","--","."} -builtin.git_commits = require_on_exported_call("telescope.builtin.git").commits +builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commits --- Lists commits for current buffer with diff preview --- - Default keymaps or your overriden `select_` keys: @@ -162,7 +162,7 @@ builtin.git_commits = require_on_exported_call("telescope.builtin.git").commits ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field current_file string: specify the current file that should be used for bcommits (default: current buffer) ---@field git_command table: command that will be exectued. {"git","log","--pretty=oneline","--abbrev-commit"} -builtin.git_bcommits = require_on_exported_call("telescope.builtin.git").bcommits +builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcommits --- List branches for current directory, with output from `git log --oneline` shown in the preview window --- - Default keymaps: @@ -176,7 +176,7 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.git").bcommit ---@field cwd string: specify the path of the repo ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field pattern string: specify the pattern to match all refs -builtin.git_branches = require_on_exported_call("telescope.builtin.git").branches +builtin.git_branches = require_on_exported_call("telescope.builtin.__git").branches --- Lists git status for current directory --- - Default keymaps: @@ -186,7 +186,7 @@ builtin.git_branches = require_on_exported_call("telescope.builtin.git").branche ---@field cwd string: specify the path of the repo ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field git_icons table: string -> string. Matches name with icon (see source code, make_entry.lua git_icon_defaults) -builtin.git_status = require_on_exported_call("telescope.builtin.git").status +builtin.git_status = require_on_exported_call("telescope.builtin.__git").status --- Lists stash items in current repository --- - Default keymaps: @@ -195,7 +195,7 @@ builtin.git_status = require_on_exported_call("telescope.builtin.git").status ---@field cwd string: specify the path of the repo ---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true) ---@field show_branch boolean: if we should display the branch name for git stash entries (default: true) -builtin.git_stash = require_on_exported_call("telescope.builtin.git").stash +builtin.git_stash = require_on_exported_call("telescope.builtin.__git").stash -- -- @@ -207,14 +207,14 @@ builtin.git_stash = require_on_exported_call("telescope.builtin.git").stash ---@param opts table: options to pass to the picker ---@field include_extensions boolean: if true will show the pickers of the installed extensions (default: false) ---@field use_default_opts boolean: if the selected picker should use its default options (default: false) -builtin.builtin = require_on_exported_call("telescope.builtin.internal").builtin +builtin.builtin = require_on_exported_call("telescope.builtin.__internal").builtin --- Opens the previous picker in the identical state (incl. multi selections) --- - Notes: --- - Requires `cache_picker` in setup or when having invoked pickers, see |telescope.defaults.cache_picker| ---@param opts table: options to pass to the picker ---@field cache_index number: what picker to resume, where 1 denotes most recent (default: 1) -builtin.resume = require_on_exported_call("telescope.builtin.internal").resume +builtin.resume = require_on_exported_call("telescope.builtin.__internal").resume --- Opens a picker over previously cached pickers in their preserved states (incl. multi selections) --- - Default keymaps: @@ -222,12 +222,12 @@ builtin.resume = require_on_exported_call("telescope.builtin.internal").resume --- - Notes: --- - Requires `cache_picker` in setup or when having invoked pickers, see |telescope.defaults.cache_picker| ---@param opts table: options to pass to the picker -builtin.pickers = require_on_exported_call("telescope.builtin.internal").pickers +builtin.pickers = require_on_exported_call("telescope.builtin.__internal").pickers --- Use the telescope... ---@param opts table: options to pass to the picker ---@field show_pluto boolean: we love pluto (default: false, because its a hidden feature) -builtin.planets = require_on_exported_call("telescope.builtin.internal").planets +builtin.planets = require_on_exported_call("telescope.builtin.__internal").planets --- Lists symbols inside of `data/telescope-sources/*.json` found in your runtime path --- or found in `stdpath("data")/telescope/symbols/*.json`. The second path can be customized. @@ -237,12 +237,12 @@ builtin.planets = require_on_exported_call("telescope.builtin.internal").planets ---@param opts table: options to pass to the picker ---@field symbol_path string: specify the second path. Default: `stdpath("data")/telescope/symbols/*.json` ---@field sources table: specify a table of sources you want to load this time -builtin.symbols = require_on_exported_call("telescope.builtin.internal").symbols +builtin.symbols = require_on_exported_call("telescope.builtin.__internal").symbols --- Lists available plugin/user commands and runs them on `` ---@param opts table: options to pass to the picker ---@field show_buf_command boolean: show buf local command (Default: true) -builtin.commands = require_on_exported_call("telescope.builtin.internal").commands +builtin.commands = require_on_exported_call("telescope.builtin.__internal").commands --- Lists items in the quickfix list, jumps to location on `` ---@param opts table: options to pass to the picker @@ -250,58 +250,58 @@ builtin.commands = require_on_exported_call("telescope.builtin.internal").comman ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) ---@field nr number: specify the quickfix list number -builtin.quickfix = require_on_exported_call("telescope.builtin.internal").quickfix +builtin.quickfix = require_on_exported_call("telescope.builtin.__internal").quickfix --- Lists all quickfix lists in your history and open them with `builtin.quickfix`. It seems that neovim --- only keeps the full history for 10 lists ---@param opts table: options to pass to the picker -builtin.quickfixhistory = require_on_exported_call("telescope.builtin.internal").quickfixhistory +builtin.quickfixhistory = require_on_exported_call("telescope.builtin.__internal").quickfixhistory --- Lists items from the current window's location list, jumps to location on `` ---@param opts table: options to pass to the picker ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.loclist = require_on_exported_call("telescope.builtin.internal").loclist +builtin.loclist = require_on_exported_call("telescope.builtin.__internal").loclist --- Lists previously open files, opens on `` ---@param opts table: options to pass to the picker ---@field only_cwd boolean: show only files in the cwd (default: false) ---@field cwd_only boolean: alias for only_cwd -builtin.oldfiles = require_on_exported_call("telescope.builtin.internal").oldfiles +builtin.oldfiles = require_on_exported_call("telescope.builtin.__internal").oldfiles --- Lists commands that were executed recently, and reruns them on `` --- - Default keymaps: --- - ``: open the command line with the text of the currently selected result populated in it ---@param opts table: options to pass to the picker -builtin.command_history = require_on_exported_call("telescope.builtin.internal").command_history +builtin.command_history = require_on_exported_call("telescope.builtin.__internal").command_history --- Lists searches that were executed recently, and reruns them on `` --- - Default keymaps: --- - ``: open a search window with the text of the currently selected search result populated in it ---@param opts table: options to pass to the picker -builtin.search_history = require_on_exported_call("telescope.builtin.internal").search_history +builtin.search_history = require_on_exported_call("telescope.builtin.__internal").search_history --- Lists vim options, allows you to edit the current value on `` ---@param opts table: options to pass to the picker -builtin.vim_options = require_on_exported_call("telescope.builtin.internal").vim_options +builtin.vim_options = require_on_exported_call("telescope.builtin.__internal").vim_options --- Lists available help tags and opens a new window with the relevant help info on `` ---@param opts table: options to pass to the picker ---@field lang string: specify language (default: vim.o.helplang) ---@field fallback boolean: fallback to en if language isn't installed (default: true) -builtin.help_tags = require_on_exported_call("telescope.builtin.internal").help_tags +builtin.help_tags = require_on_exported_call("telescope.builtin.__internal").help_tags --- Lists manpage entries, opens them in a help window on `` ---@param opts table: options to pass to the picker ---@field sections table: a list of sections to search, use `{ "ALL" }` to search in all sections (default: { "1" }) ---@field man_cmd function: that returns the man command. (Default: `apropos ""` on linux, `apropos " "` on macos) -builtin.man_pages = require_on_exported_call("telescope.builtin.internal").man_pages +builtin.man_pages = require_on_exported_call("telescope.builtin.__internal").man_pages --- Lists lua modules and reloads them on `` ---@param opts table: options to pass to the picker ---@field column_len number: define the max column len for the module name (default: dynamic, longest module name) -builtin.reloader = require_on_exported_call("telescope.builtin.internal").reloader +builtin.reloader = require_on_exported_call("telescope.builtin.__internal").reloader --- Lists open buffers in current neovim instance, opens selected buffer on `` ---@param opts table: options to pass to the picker @@ -312,58 +312,58 @@ builtin.reloader = require_on_exported_call("telescope.builtin.internal").reload ---@field sort_lastused boolean: Sorts current and last buffer to the top and selects the lastused (default: false) ---@field sort_mru boolean: Sorts all buffers after most recent used. Not just the current and last one (default: false) ---@field bufnr_width number: Defines the width of the buffer numbers in front of the filenames (default: dynamic) -builtin.buffers = require_on_exported_call("telescope.builtin.internal").buffers +builtin.buffers = require_on_exported_call("telescope.builtin.__internal").buffers --- Lists available colorschemes and applies them on `` ---@param opts table: options to pass to the picker ---@field enable_preview boolean: if true, will preview the selected color -builtin.colorscheme = require_on_exported_call("telescope.builtin.internal").colorscheme +builtin.colorscheme = require_on_exported_call("telescope.builtin.__internal").colorscheme --- Lists vim marks and their value, jumps to the mark on `` ---@param opts table: options to pass to the picker -builtin.marks = require_on_exported_call("telescope.builtin.internal").marks +builtin.marks = require_on_exported_call("telescope.builtin.__internal").marks --- Lists vim registers, pastes the contents of the register on `` --- - Default keymaps: --- - ``: edit the contents of the currently selected register ---@param opts table: options to pass to the picker -builtin.registers = require_on_exported_call("telescope.builtin.internal").registers +builtin.registers = require_on_exported_call("telescope.builtin.__internal").registers --- Lists normal mode keymappings, runs the selected keymap on `` ---@param opts table: options to pass to the picker ---@field modes table: a list of short-named keymap modes to search (default: { "n", "i", "c", "x" }) ---@field show_plug boolean: if true, the keymaps for which the lhs contains "" are also shown (default: true) -builtin.keymaps = require_on_exported_call("telescope.builtin.internal").keymaps +builtin.keymaps = require_on_exported_call("telescope.builtin.__internal").keymaps --- Lists all available filetypes, sets currently open buffer's filetype to selected filetype in Telescope on `` ---@param opts table: options to pass to the picker -builtin.filetypes = require_on_exported_call("telescope.builtin.internal").filetypes +builtin.filetypes = require_on_exported_call("telescope.builtin.__internal").filetypes --- Lists all available highlights ---@param opts table: options to pass to the picker -builtin.highlights = require_on_exported_call("telescope.builtin.internal").highlights +builtin.highlights = require_on_exported_call("telescope.builtin.__internal").highlights --- Lists vim autocommands and goes to their declaration on `` ---@param opts table: options to pass to the picker -builtin.autocommands = require_on_exported_call("telescope.builtin.internal").autocommands +builtin.autocommands = require_on_exported_call("telescope.builtin.__internal").autocommands --- Lists spelling suggestions for the current word under the cursor, replaces word with selected suggestion on `` ---@param opts table: options to pass to the picker -builtin.spell_suggest = require_on_exported_call("telescope.builtin.internal").spell_suggest +builtin.spell_suggest = require_on_exported_call("telescope.builtin.__internal").spell_suggest --- Lists the tag stack for the current window, jumps to tag on `` ---@param opts table: options to pass to the picker ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.tagstack = require_on_exported_call("telescope.builtin.internal").tagstack +builtin.tagstack = require_on_exported_call("telescope.builtin.__internal").tagstack --- Lists items from Vim's jumplist, jumps to location on `` ---@param opts table: options to pass to the picker ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumplist +builtin.jumplist = require_on_exported_call("telescope.builtin.__internal").jumplist -- -- @@ -377,19 +377,19 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumpli ---@field include_current_line boolean: include current line (default: false) ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.lsp_references = require_on_exported_call("telescope.builtin.lsp").references +builtin.lsp_references = require_on_exported_call("telescope.builtin.__lsp").references --- Lists LSP incoming calls for word under the cursor, jumps to reference on `` ---@param opts table: options to pass to the picker ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) -builtin.lsp_incoming_calls = require_on_exported_call("telescope.builtin.lsp").incoming_calls +builtin.lsp_incoming_calls = require_on_exported_call("telescope.builtin.__lsp").incoming_calls --- Lists LSP outgoing calls for word under the cursor, jumps to reference on `` ---@param opts table: options to pass to the picker ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) -builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.lsp").outgoing_calls +builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.__lsp").outgoing_calls --- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope ---@param opts table: options to pass to the picker @@ -397,7 +397,7 @@ builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.lsp").o ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").definitions +builtin.lsp_definitions = require_on_exported_call("telescope.builtin.__lsp").definitions --- Goto the definition of the type of the word under the cursor, if there's only one, --- otherwise show all options in Telescope @@ -406,7 +406,7 @@ builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").defi ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions +builtin.lsp_type_definitions = require("telescope.builtin.__lsp").type_definitions --- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope ---@param opts table: options to pass to the picker @@ -414,7 +414,7 @@ builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field fname_width number: defines the width of the filename section (default: 30) -builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp").implementations +builtin.lsp_implementations = require_on_exported_call("telescope.builtin.__lsp").implementations --- Lists LSP document symbols in the current buffer --- - Default keymaps: @@ -424,7 +424,7 @@ builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp"). ---@field symbols string|table: filter results by symbol kind(s) ---@field ignore_symbols string|table: list of symbols to ignore ---@field symbol_highlights table: string -> string. Matches symbol with hl_group -builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.lsp").document_symbols +builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.__lsp").document_symbols --- Lists LSP document symbols in the current workspace --- - Default keymaps: @@ -435,7 +435,7 @@ builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.lsp") ---@field symbols string|table: filter results by symbol kind(s) ---@field ignore_symbols string|table: list of symbols to ignore ---@field symbol_highlights table: string -> string. Matches symbol with hl_group -builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.lsp").workspace_symbols +builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.__lsp").workspace_symbols --- Dynamically lists LSP for all workspace symbols --- - Default keymaps: @@ -445,7 +445,7 @@ builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.lsp" ---@field symbols string|table: filter results by symbol kind(s) ---@field ignore_symbols string|table: list of symbols to ignore ---@field symbol_highlights table: string -> string. Matches symbol with hl_group -builtin.lsp_dynamic_workspace_symbols = require_on_exported_call("telescope.builtin.lsp").dynamic_workspace_symbols +builtin.lsp_dynamic_workspace_symbols = require_on_exported_call("telescope.builtin.__lsp").dynamic_workspace_symbols -- -- @@ -468,7 +468,7 @@ builtin.lsp_dynamic_workspace_symbols = require_on_exported_call("telescope.buil ---@field no_sign boolean: hide DiagnosticSigns from Results (default: false) ---@field line_width number: set length of diagnostic entry text in Results ---@field namespace number: limit your diagnostics to a specific namespace -builtin.diagnostics = require_on_exported_call("telescope.builtin.diagnostics").get +builtin.diagnostics = require_on_exported_call("telescope.builtin.__diagnostics").get local apply_config = function(mod) local pickers_conf = require("telescope.config").pickers diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 4277e2e..b4d4197 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -1,1318 +1,17 @@ -local actions = require "telescope.actions" -local action_set = require "telescope.actions.set" -local action_state = require "telescope.actions.state" -local finders = require "telescope.finders" -local make_entry = require "telescope.make_entry" -local Path = require "plenary.path" -local pickers = require "telescope.pickers" -local previewers = require "telescope.previewers" -local p_window = require "telescope.pickers.window" -local sorters = require "telescope.sorters" -local state = require "telescope.state" -local utils = require "telescope.utils" - -local conf = require("telescope.config").values - -local filter = vim.tbl_filter - --- Makes sure aliased options are set correctly -local function apply_cwd_only_aliases(opts) - local has_cwd_only = opts.cwd_only ~= nil - local has_only_cwd = opts.only_cwd ~= nil - - if has_only_cwd and not has_cwd_only then - -- Internally, use cwd_only - opts.cwd_only = opts.only_cwd - opts.only_cwd = nil - end - - return opts -end - -local internal = {} - -internal.builtin = function(opts) - opts.include_extensions = vim.F.if_nil(opts.include_extensions, false) - opts.use_default_opts = vim.F.if_nil(opts.use_default_opts, false) - - local objs = {} - - for k, v in pairs(require "telescope.builtin") do - local debug_info = debug.getinfo(v) - table.insert(objs, { - filename = string.sub(debug_info.source, 2), - text = k, - }) - end - - local title = "Telescope Builtin" - - if opts.include_extensions then - title = "Telescope Pickers" - for ext, funcs in pairs(require("telescope").extensions) do - for func_name, func_obj in pairs(funcs) do - -- Only include exported functions whose name doesn't begin with an underscore - if type(func_obj) == "function" and string.sub(func_name, 0, 1) ~= "_" then - local debug_info = debug.getinfo(func_obj) - table.insert(objs, { - filename = string.sub(debug_info.source, 2), - text = string.format("%s : %s", ext, func_name), - }) - end - end - end - end - - opts.bufnr = vim.api.nvim_get_current_buf() - opts.winnr = vim.api.nvim_get_current_win() - pickers.new(opts, { - prompt_title = title, - finder = finders.new_table { - results = objs, - entry_maker = function(entry) - return make_entry.set_default_entry_mt({ - value = entry, - text = entry.text, - display = entry.text, - ordinal = entry.text, - filename = entry.filename, - }, opts) - end, - }, - previewer = previewers.builtin.new(opts), - sorter = conf.generic_sorter(opts), - attach_mappings = function(_) - actions.select_default:replace(function(_) - local selection = action_state.get_selected_entry() - if not selection then - utils.__warn_no_selection "builtin.builtin" - return - end - - -- we do this to avoid any surprises - opts.include_extensions = nil - - local picker_opts - if not opts.use_default_opts then - picker_opts = opts - end - - if string.match(selection.text, " : ") then - -- Call appropriate function from extensions - local split_string = vim.split(selection.text, " : ") - local ext = split_string[1] - local func = split_string[2] - require("telescope").extensions[ext][func](picker_opts) - else - -- Call appropriate telescope builtin - require("telescope.builtin")[selection.text](picker_opts) - end - end) - return true - end, - }):find() -end - -internal.resume = function(opts) - opts = opts or {} - opts.cache_index = vim.F.if_nil(opts.cache_index, 1) - - local cached_pickers = state.get_global_key "cached_pickers" - if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then - utils.notify("builtin.resume", { - msg = "No cached picker(s).", - level = "INFO", - }) - return - end - local picker = cached_pickers[opts.cache_index] - if picker == nil then - utils.notify("builtin.resume", { - msg = string.format("Index too large as there are only '%s' pickers cached", #cached_pickers), +local m = setmetatable({}, { + __index = function(_, k) + local utils = require "telescope.utils" + utils.notify("builtin", { + msg = string.format( + 'You are using an internal interface. Do not use `require("telescope.builtin.internal").%s`,' + .. ' please use `require("telescope.builtin").%s`! We will remove this endpoint soon!', + k, + k + ), level = "ERROR", }) - return - end - -- reset layout strategy and get_window_options if default as only one is valid - -- and otherwise unclear which was actually set - if picker.layout_strategy == conf.layout_strategy then - picker.layout_strategy = nil - end - if picker.get_window_options == p_window.get_window_options then - picker.get_window_options = nil - end - picker.cache_picker.index = opts.cache_index + return require("telescope.builtin")[k] + end, +}) - -- avoid partial `opts.cache_picker` at picker creation - if opts.cache_picker ~= false then - picker.cache_picker = vim.tbl_extend("keep", opts.cache_picker or {}, picker.cache_picker) - else - picker.cache_picker.disabled = true - end - opts.cache_picker = nil - picker.previewer = picker.all_previewers - if picker.hidden_previewer then - picker.hidden_previewer = nil - opts.previewer = vim.F.if_nil(opts.previewer, false) - end - pickers.new(opts, picker):find() -end - -internal.pickers = function(opts) - local cached_pickers = state.get_global_key "cached_pickers" - if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then - utils.notify("builtin.pickers", { - msg = "No cached picker(s).", - level = "INFO", - }) - return - end - - opts = opts or {} - - -- clear cache picker for immediate pickers.new and pass option to resumed picker - if opts.cache_picker ~= nil then - opts._cache_picker = opts.cache_picker - opts.cache_picker = nil - end - - pickers.new(opts, { - prompt_title = "Pickers", - finder = finders.new_table { - results = cached_pickers, - entry_maker = make_entry.gen_from_picker(opts), - }, - previewer = previewers.pickers.new(opts), - sorter = conf.generic_sorter(opts), - cache_picker = false, - attach_mappings = function(_, map) - actions.select_default:replace(function(prompt_bufnr) - local current_picker = action_state.get_current_picker(prompt_bufnr) - local selection_index = current_picker:get_index(current_picker:get_selection_row()) - actions.close(prompt_bufnr) - opts.cache_picker = opts._cache_picker - opts["cache_index"] = selection_index - opts["initial_mode"] = cached_pickers[selection_index].initial_mode - internal.resume(opts) - end) - map("i", "", actions.remove_selected_picker) - map("n", "", actions.remove_selected_picker) - return true - end, - }):find() -end - -internal.planets = function(opts) - local show_pluto = opts.show_pluto or false - - local sourced_file = require("plenary.debug_utils").sourced_filepath() - local base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h:h") - - local globbed_files = vim.fn.globpath(base_directory .. "/data/memes/planets/", "*", true, true) - local acceptable_files = {} - for _, v in ipairs(globbed_files) do - if show_pluto or not v:find "pluto" then - table.insert(acceptable_files, vim.fn.fnamemodify(v, ":t")) - end - end - - pickers.new(opts, { - prompt_title = "Planets", - finder = finders.new_table { - results = acceptable_files, - entry_maker = function(line) - return make_entry.set_default_entry_mt({ - ordinal = line, - display = line, - filename = base_directory .. "/data/memes/planets/" .. line, - }, opts) - end, - }, - previewer = previewers.cat.new(opts), - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.planets" - return - end - - actions.close(prompt_bufnr) - print("Enjoy astronomy! You viewed:", selection.display) - end) - - return true - end, - }):find() -end - -internal.symbols = function(opts) - local initial_mode = vim.fn.mode() - local files = vim.api.nvim_get_runtime_file("data/telescope-sources/*.json", true) - local data_path = (function() - if not opts.symbol_path then - return Path:new { vim.fn.stdpath "data", "telescope", "symbols" } - else - return Path:new { opts.symbol_path } - end - end)() - if data_path:exists() then - for _, v in ipairs(require("plenary.scandir").scan_dir(data_path:absolute(), { search_pattern = "%.json$" })) do - table.insert(files, v) - end - end - - if #files == 0 then - utils.notify("builtin.symbols", { - msg = "No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim " - .. "for some prebuild symbols or how to create you own symbol source.", - level = "ERROR", - }) - return - end - - local sources = {} - if opts.sources then - for _, v in ipairs(files) do - for _, s in ipairs(opts.sources) do - if v:find(s) then - table.insert(sources, v) - end - end - end - else - sources = files - end - - local results = {} - for _, source in ipairs(sources) do - local data = vim.json.decode(Path:new(source):read()) - for _, entry in ipairs(data) do - table.insert(results, entry) - end - end - - pickers.new(opts, { - prompt_title = "Symbols", - finder = finders.new_table { - results = results, - entry_maker = function(entry) - return make_entry.set_default_entry_mt({ - value = entry, - ordinal = entry[1] .. " " .. entry[2], - display = entry[1] .. " " .. entry[2], - }, opts) - end, - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(_) - if initial_mode == "i" then - actions.select_default:replace(actions.insert_symbol_i) - else - actions.select_default:replace(actions.insert_symbol) - end - return true - end, - }):find() -end - -internal.commands = function(opts) - pickers.new(opts, { - prompt_title = "Commands", - finder = finders.new_table { - results = (function() - local command_iter = vim.api.nvim_get_commands {} - local commands = {} - - for _, cmd in pairs(command_iter) do - table.insert(commands, cmd) - end - - local need_buf_command = vim.F.if_nil(opts.show_buf_command, true) - - if need_buf_command then - local buf_command_iter = vim.api.nvim_buf_get_commands(0, {}) - buf_command_iter[true] = nil -- remove the redundant entry - for _, cmd in pairs(buf_command_iter) do - table.insert(commands, cmd) - end - end - return commands - end)(), - - entry_maker = opts.entry_maker or make_entry.gen_from_commands(opts), - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.commands" - return - end - - actions.close(prompt_bufnr) - local val = selection.value - local cmd = string.format([[:%s ]], val.name) - - if val.nargs == "0" then - vim.cmd(cmd) - else - vim.cmd [[stopinsert]] - vim.fn.feedkeys(cmd, "n") - end - end) - - return true - end, - }):find() -end - -internal.quickfix = function(opts) - local qf_identifier = opts.id or vim.F.if_nil(opts.nr, "$") - local locations = vim.fn.getqflist({ [opts.id and "id" or "nr"] = qf_identifier, items = true }).items - - if vim.tbl_isempty(locations) then - return - end - - pickers.new(opts, { - prompt_title = "Quickfix", - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - }):find() -end - -internal.quickfixhistory = function(opts) - local qflists = {} - for i = 1, 10 do -- (n)vim keeps at most 10 quickfix lists in full - -- qf weirdness: id = 0 gets id of quickfix list nr - local qflist = vim.fn.getqflist { nr = i, id = 0, title = true, items = true } - if not vim.tbl_isempty(qflist.items) then - table.insert(qflists, qflist) - end - end - local entry_maker = opts.make_entry - or function(entry) - return make_entry.set_default_entry_mt({ - value = entry.title or "Untitled", - ordinal = entry.title or "Untitled", - display = entry.title or "Untitled", - nr = entry.nr, - id = entry.id, - items = entry.items, - }, opts) - end - local qf_entry_maker = make_entry.gen_from_quickfix(opts) - pickers.new(opts, { - prompt_title = "Quickfix History", - finder = finders.new_table { - results = qflists, - entry_maker = entry_maker, - }, - previewer = previewers.new_buffer_previewer { - title = "Quickfix List Preview", - dyn_title = function(_, entry) - return entry.title - end, - - get_buffer_by_name = function(_, entry) - return "quickfixlist_" .. tostring(entry.nr) - end, - - define_preview = function(self, entry) - if self.state.bufname then - return - end - local entries = vim.tbl_map(function(i) - return qf_entry_maker(i):display() - end, entry.items) - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, entries) - end, - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(_, _) - action_set.select:replace(function(prompt_bufnr) - local nr = action_state.get_selected_entry().nr - actions.close(prompt_bufnr) - internal.quickfix { nr = nr } - end) - return true - end, - }):find() -end - -internal.loclist = function(opts) - local locations = vim.fn.getloclist(0) - local filenames = {} - for _, value in pairs(locations) do - local bufnr = value.bufnr - if filenames[bufnr] == nil then - filenames[bufnr] = vim.api.nvim_buf_get_name(bufnr) - end - value.filename = filenames[bufnr] - end - - if vim.tbl_isempty(locations) then - return - end - - pickers.new(opts, { - prompt_title = "Loclist", - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - }):find() -end - -internal.oldfiles = function(opts) - opts = apply_cwd_only_aliases(opts) - opts.include_current_session = vim.F.if_nil(opts.include_current_session, true) - - local current_buffer = vim.api.nvim_get_current_buf() - local current_file = vim.api.nvim_buf_get_name(current_buffer) - local results = {} - - if opts.include_current_session then - for _, buffer in ipairs(vim.split(vim.fn.execute ":buffers! t", "\n")) do - local match = tonumber(string.match(buffer, "%s*(%d+)")) - local open_by_lsp = string.match(buffer, "line 0$") - if match and not open_by_lsp then - local file = vim.api.nvim_buf_get_name(match) - if vim.loop.fs_stat(file) and match ~= current_buffer then - table.insert(results, file) - end - end - end - end - - for _, file in ipairs(vim.v.oldfiles) do - if vim.loop.fs_stat(file) and not vim.tbl_contains(results, file) and file ~= current_file then - table.insert(results, file) - end - end - - if opts.cwd_only then - local cwd = vim.loop.cwd() - cwd = cwd:gsub([[\]], [[\\]]) - results = vim.tbl_filter(function(file) - return vim.fn.matchstrpos(file, cwd)[2] ~= -1 - end, results) - end - - pickers.new(opts, { - prompt_title = "Oldfiles", - finder = finders.new_table { - results = results, - entry_maker = opts.entry_maker or make_entry.gen_from_file(opts), - }, - sorter = conf.file_sorter(opts), - previewer = conf.file_previewer(opts), - }):find() -end - -internal.command_history = function(opts) - local history_string = vim.fn.execute "history cmd" - local history_list = vim.split(history_string, "\n") - - local results = {} - for i = #history_list, 3, -1 do - local item = history_list[i] - local _, finish = string.find(item, "%d+ +") - table.insert(results, string.sub(item, finish + 1)) - end - - pickers.new(opts, { - prompt_title = "Command History", - finder = finders.new_table(results), - sorter = conf.generic_sorter(opts), - - attach_mappings = function(_, map) - map("i", "", actions.set_command_line) - map("n", "", actions.set_command_line) - map("n", "", actions.edit_command_line) - map("i", "", actions.edit_command_line) - - -- TODO: Find a way to insert the text... it seems hard. - -- map('i', '', actions.insert_value, { expr = true }) - - return true - end, - }):find() -end - -internal.search_history = function(opts) - local search_string = vim.fn.execute "history search" - local search_list = vim.split(search_string, "\n") - - local results = {} - for i = #search_list, 3, -1 do - local item = search_list[i] - local _, finish = string.find(item, "%d+ +") - table.insert(results, string.sub(item, finish + 1)) - end - - pickers.new(opts, { - prompt_title = "Search History", - finder = finders.new_table(results), - sorter = conf.generic_sorter(opts), - - attach_mappings = function(_, map) - map("i", "", actions.set_search_line) - map("n", "", actions.set_search_line) - map("n", "", actions.edit_search_line) - map("i", "", actions.edit_search_line) - - -- TODO: Find a way to insert the text... it seems hard. - -- map('i', '', actions.insert_value, { expr = true }) - - return true - end, - }):find() -end - -internal.vim_options = function(opts) - local res = {} - for _, v in pairs(vim.api.nvim_get_all_options_info()) do - table.insert(res, v) - end - table.sort(res, function(left, right) - return left.name < right.name - end) - - pickers.new(opts, { - prompt_title = "options", - finder = finders.new_table { - results = res, - entry_maker = opts.entry_maker or make_entry.gen_from_vimoptions(opts), - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function() - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.vim_options" - return - end - - local esc = "" - if vim.fn.mode() == "i" then - esc = vim.api.nvim_replace_termcodes("", true, false, true) - end - - vim.api.nvim_feedkeys( - string.format("%s:set %s=%s", esc, selection.value.name, selection.value.value), - "m", - true - ) - end) - - return true - end, - }):find() -end - -internal.help_tags = function(opts) - opts.lang = vim.F.if_nil(opts.lang, vim.o.helplang) - opts.fallback = vim.F.if_nil(opts.fallback, true) - opts.file_ignore_patterns = {} - - local langs = vim.split(opts.lang, ",", true) - if opts.fallback and not vim.tbl_contains(langs, "en") then - table.insert(langs, "en") - end - local langs_map = {} - for _, lang in ipairs(langs) do - langs_map[lang] = true - end - - local tag_files = {} - local function add_tag_file(lang, file) - if langs_map[lang] then - if tag_files[lang] then - table.insert(tag_files[lang], file) - else - tag_files[lang] = { file } - end - end - end - - local help_files = {} - local all_files = vim.api.nvim_get_runtime_file("doc/*", true) - for _, fullpath in ipairs(all_files) do - local file = utils.path_tail(fullpath) - if file == "tags" then - add_tag_file("en", fullpath) - elseif file:match "^tags%-..$" then - local lang = file:sub(-2) - add_tag_file(lang, fullpath) - else - help_files[file] = fullpath - end - end - - local tags = {} - local tags_map = {} - local delimiter = string.char(9) - for _, lang in ipairs(langs) do - for _, file in ipairs(tag_files[lang] or {}) do - local lines = vim.split(Path:new(file):read(), "\n", true) - for _, line in ipairs(lines) do - -- TODO: also ignore tagComment starting with ';' - if not line:match "^!_TAG_" then - local fields = vim.split(line, delimiter, true) - if #fields == 3 and not tags_map[fields[1]] then - if fields[1] ~= "help-tags" or fields[2] ~= "tags" then - table.insert(tags, { - name = fields[1], - filename = help_files[fields[2]], - cmd = fields[3], - lang = lang, - }) - tags_map[fields[1]] = true - end - end - end - end - end - end - - pickers.new(opts, { - prompt_title = "Help", - finder = finders.new_table { - results = tags, - entry_maker = function(entry) - return make_entry.set_default_entry_mt({ - value = entry.name .. "@" .. entry.lang, - display = entry.name, - ordinal = entry.name, - filename = entry.filename, - cmd = entry.cmd, - }, opts) - end, - }, - previewer = previewers.help.new(opts), - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - action_set.select:replace(function(_, cmd) - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.help_tags" - return - end - - actions.close(prompt_bufnr) - if cmd == "default" or cmd == "horizontal" then - vim.cmd("help " .. selection.value) - elseif cmd == "vertical" then - vim.cmd("vert help " .. selection.value) - elseif cmd == "tab" then - vim.cmd("tab help " .. selection.value) - end - end) - - return true - end, - }):find() -end - -internal.man_pages = function(opts) - opts.sections = vim.F.if_nil(opts.sections, { "1" }) - assert(vim.tbl_islist(opts.sections), "sections should be a list") - opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function() - local is_darwin = vim.loop.os_uname().sysname == "Darwin" - return is_darwin and { "apropos", " " } or { "apropos", "" } - end) - opts.entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts) - opts.env = { PATH = vim.env.PATH, MANPATH = vim.env.MANPATH } - - pickers.new(opts, { - prompt_title = "Man", - finder = finders.new_oneshot_job(opts.man_cmd, opts), - previewer = previewers.man.new(opts), - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - action_set.select:replace(function(_, cmd) - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.man_pages" - return - end - - local args = selection.section .. " " .. selection.value - actions.close(prompt_bufnr) - if cmd == "default" or cmd == "horizontal" then - vim.cmd("Man " .. args) - elseif cmd == "vertical" then - vim.cmd("vert Man " .. args) - elseif cmd == "tab" then - vim.cmd("tab Man " .. args) - end - end) - - return true - end, - }):find() -end - -internal.reloader = function(opts) - local package_list = vim.tbl_keys(package.loaded) - - -- filter out packages we don't want and track the longest package name - local column_len = 0 - for index, module_name in pairs(package_list) do - if - type(require(module_name)) ~= "table" - or module_name:sub(1, 1) == "_" - or package.searchpath(module_name, package.path) == nil - then - table.remove(package_list, index) - elseif #module_name > column_len then - column_len = #module_name - end - end - opts.column_len = vim.F.if_nil(opts.column_len, column_len) - - pickers.new(opts, { - prompt_title = "Packages", - finder = finders.new_table { - results = package_list, - entry_maker = opts.entry_maker or make_entry.gen_from_packages(opts), - }, - -- previewer = previewers.vim_buffer.new(opts), - sorter = conf.generic_sorter(opts), - - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.reloader" - return - end - - actions.close(prompt_bufnr) - require("plenary.reload").reload_module(selection.value) - utils.notify("builtin.reloader", { - msg = string.format("[%s] - module reloaded", selection.value), - level = "INFO", - }) - end) - - return true - end, - }):find() -end - -internal.buffers = function(opts) - opts = apply_cwd_only_aliases(opts) - local bufnrs = filter(function(b) - if 1 ~= vim.fn.buflisted(b) then - return false - end - -- only hide unloaded buffers if opts.show_all_buffers is false, keep them listed if true or nil - if opts.show_all_buffers == false and not vim.api.nvim_buf_is_loaded(b) then - return false - end - if opts.ignore_current_buffer and b == vim.api.nvim_get_current_buf() then - return false - end - if opts.cwd_only and not string.find(vim.api.nvim_buf_get_name(b), vim.loop.cwd(), 1, true) then - return false - end - return true - end, vim.api.nvim_list_bufs()) - if not next(bufnrs) then - return - end - if opts.sort_mru then - table.sort(bufnrs, function(a, b) - return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused - end) - end - - local buffers = {} - local default_selection_idx = 1 - for _, bufnr in ipairs(bufnrs) do - local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ") - - if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then - default_selection_idx = 2 - end - - local element = { - bufnr = bufnr, - flag = flag, - info = vim.fn.getbufinfo(bufnr)[1], - } - - if opts.sort_lastused and (flag == "#" or flag == "%") then - local idx = ((buffers[1] ~= nil and buffers[1].flag == "%") and 2 or 1) - table.insert(buffers, idx, element) - else - table.insert(buffers, element) - end - end - - if not opts.bufnr_width then - local max_bufnr = math.max(unpack(bufnrs)) - opts.bufnr_width = #tostring(max_bufnr) - end - - pickers.new(opts, { - prompt_title = "Buffers", - finder = finders.new_table { - results = buffers, - entry_maker = opts.entry_maker or make_entry.gen_from_buffer(opts), - }, - previewer = conf.grep_previewer(opts), - sorter = conf.generic_sorter(opts), - default_selection_index = default_selection_idx, - }):find() -end - -internal.colorscheme = function(opts) - local before_background = vim.o.background - local before_color = vim.api.nvim_exec("colorscheme", true) - local need_restore = true - - local colors = opts.colors or { before_color } - if not vim.tbl_contains(colors, before_color) then - table.insert(colors, 1, before_color) - end - - colors = vim.list_extend( - colors, - vim.tbl_filter(function(color) - return color ~= before_color - end, vim.fn.getcompletion("", "color")) - ) - - local previewer - if opts.enable_preview then - -- define previewer - local bufnr = vim.api.nvim_get_current_buf() - local p = vim.api.nvim_buf_get_name(bufnr) - - -- don't need previewer - if vim.fn.buflisted(bufnr) ~= 1 then - local deleted = false - local function del_win(win_id) - if win_id and vim.api.nvim_win_is_valid(win_id) then - utils.buf_delete(vim.api.nvim_win_get_buf(win_id)) - pcall(vim.api.nvim_win_close, win_id, true) - end - end - - previewer = previewers.new { - preview_fn = function(_, entry, status) - if not deleted then - deleted = true - del_win(status.preview_win) - del_win(status.preview_border_win) - end - vim.cmd("colorscheme " .. entry.value) - end, - } - else - -- show current buffer content in previewer - previewer = previewers.new_buffer_previewer { - get_buffer_by_name = function() - return p - end, - define_preview = function(self, entry) - if vim.loop.fs_stat(p) then - conf.buffer_previewer_maker(p, self.state.bufnr, { bufname = self.state.bufname }) - else - local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) - end - vim.cmd("colorscheme " .. entry.value) - end, - } - end - end - - local picker = pickers.new(opts, { - prompt_title = "Change Colorscheme", - finder = finders.new_table { - results = colors, - }, - sorter = conf.generic_sorter(opts), - previewer = previewer, - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.colorscheme" - return - end - - actions.close(prompt_bufnr) - need_restore = false - vim.cmd("colorscheme " .. selection.value) - end) - - return true - end, - }) - - if opts.enable_preview then - -- rewrite picker.close_windows. restore color if needed - local close_windows = picker.close_windows - picker.close_windows = function(status) - close_windows(status) - if need_restore then - vim.o.background = before_background - vim.cmd("colorscheme " .. before_color) - end - end - end - - picker:find() -end - -internal.marks = function(opts) - local local_marks = { - items = vim.fn.getmarklist(opts.bufnr), - name_func = function(_, line) - return vim.api.nvim_buf_get_lines(opts.bufnr, line - 1, line, false)[1] - end, - } - local global_marks = { - items = vim.fn.getmarklist(), - name_func = function(mark, _) - -- get buffer name if it is opened, otherwise get file name - return vim.api.nvim_get_mark(mark, {})[4] - end, - } - local marks_table = {} - local marks_others = {} - local bufname = vim.api.nvim_buf_get_name(opts.bufnr) - for _, cnf in ipairs { local_marks, global_marks } do - for _, v in ipairs(cnf.items) do - -- strip the first single quote character - local mark = string.sub(v.mark, 2, 3) - local _, lnum, col, _ = unpack(v.pos) - local name = cnf.name_func(mark, lnum) - -- same format to :marks command - local line = string.format("%s %6d %4d %s", mark, lnum, col - 1, name) - local row = { - line = line, - lnum = lnum, - col = col, - filename = v.file or bufname, - } - -- non alphanumeric marks goes to last - if mark:match "%w" then - table.insert(marks_table, row) - else - table.insert(marks_others, row) - end - end - end - marks_table = vim.fn.extend(marks_table, marks_others) - - pickers.new(opts, { - prompt_title = "Marks", - finder = finders.new_table { - results = marks_table, - entry_maker = opts.entry_maker or make_entry.gen_from_marks(opts), - }, - previewer = conf.grep_previewer(opts), - sorter = conf.generic_sorter(opts), - push_cursor_on_edit = true, - push_tagstack_on_edit = true, - }):find() -end - -internal.registers = function(opts) - local registers_table = { '"', "_", "#", "=", "_", "/", "*", "+", ":", ".", "%" } - - -- named - for i = 0, 9 do - table.insert(registers_table, tostring(i)) - end - - -- alphabetical - for i = 65, 90 do - table.insert(registers_table, string.char(i)) - end - - pickers.new(opts, { - prompt_title = "Registers", - finder = finders.new_table { - results = registers_table, - entry_maker = opts.entry_maker or make_entry.gen_from_registers(opts), - }, - -- use levenshtein as n-gram doesn't support <2 char matches - sorter = sorters.get_levenshtein_sorter(), - attach_mappings = function(_, map) - actions.select_default:replace(actions.paste_register) - map("i", "", actions.edit_register) - - return true - end, - }):find() -end - --- TODO: make filtering include the mapping and the action -internal.keymaps = function(opts) - opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" }) - opts.show_plug = vim.F.if_nil(opts.show_plug, true) - - local keymap_encountered = {} -- used to make sure no duplicates are inserted into keymaps_table - local keymaps_table = {} - local max_len_lhs = 0 - - -- helper function to populate keymaps_table and determine max_len_lhs - local function extract_keymaps(keymaps) - for _, keymap in pairs(keymaps) do - local keymap_key = keymap.buffer .. keymap.mode .. keymap.lhs -- should be distinct for every keymap - if not keymap_encountered[keymap_key] then - keymap_encountered[keymap_key] = true - if opts.show_plug or not string.find(keymap.lhs, "") then - table.insert(keymaps_table, keymap) - max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs)) - end - end - end - end - - for _, mode in pairs(opts.modes) do - local global = vim.api.nvim_get_keymap(mode) - local buf_local = vim.api.nvim_buf_get_keymap(0, mode) - extract_keymaps(global) - extract_keymaps(buf_local) - end - opts.width_lhs = max_len_lhs + 1 - - pickers.new(opts, { - prompt_title = "Key Maps", - finder = finders.new_table { - results = keymaps_table, - entry_maker = opts.entry_maker or make_entry.gen_from_keymaps(opts), - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.keymaps" - return - end - - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true), "t", true) - return actions.close(prompt_bufnr) - end) - return true - end, - }):find() -end - -internal.filetypes = function(opts) - local filetypes = vim.fn.getcompletion("", "filetype") - - pickers.new(opts, { - prompt_title = "Filetypes", - finder = finders.new_table { - results = filetypes, - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - print "[telescope] Nothing currently selected" - return - end - - actions.close(prompt_bufnr) - vim.cmd("setfiletype " .. selection[1]) - end) - return true - end, - }):find() -end - -internal.highlights = function(opts) - local highlights = vim.fn.getcompletion("", "highlight") - - pickers.new(opts, { - prompt_title = "Highlights", - finder = finders.new_table { - results = highlights, - entry_maker = opts.entry_maker or make_entry.gen_from_highlights(opts), - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.highlights" - return - end - - actions.close(prompt_bufnr) - vim.cmd("hi " .. selection.value) - end) - return true - end, - previewer = previewers.highlights.new(opts), - }):find() -end - -internal.autocommands = function(opts) - local autocmds = vim.api.nvim_get_autocmds {} - table.sort(autocmds, function(lhs, rhs) - return lhs.event < rhs.event - end) - pickers.new(opts, { - prompt_title = "autocommands", - finder = finders.new_table { - results = autocmds, - entry_maker = opts.entry_maker or make_entry.gen_from_autocommands(opts), - }, - previewer = previewers.autocommands.new(opts), - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - action_set.select:replace_if(function() - local selection = action_state.get_selected_entry() - if selection == nil then - return false - end - local val = selection.value - local group_name = val.group_name ~= "" and val.group_name or "" - local output = vim.fn.execute("verb autocmd " .. group_name .. " " .. val.event .. " " .. val.pattern, "silent") - for line in output:gmatch "[^\r\n]+" do - local source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$" - if source_file and source_file ~= "Lua" then - selection.filename = source_file - local source_lnum = line:match "line (%d*)$" or "1" - selection.lnum = tonumber(source_lnum) - selection.col = 1 - return false - end - end - return true - end, function() - local selection = action_state.get_selected_entry() - actions.close(prompt_bufnr) - print("You selected autocmd: " .. vim.inspect(selection.value)) - end) - - return true - end, - }):find() -end - -internal.spell_suggest = function(opts) - local cursor_word = vim.fn.expand "" - local suggestions = vim.fn.spellsuggest(cursor_word) - - pickers.new(opts, { - prompt_title = "Spelling Suggestions", - finder = finders.new_table { - results = suggestions, - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local selection = action_state.get_selected_entry() - if selection == nil then - utils.__warn_no_selection "builtin.spell_suggest" - return - end - - action_state.get_current_picker(prompt_bufnr)._original_mode = "i" - actions.close(prompt_bufnr) - vim.cmd("normal! ciw" .. selection[1]) - vim.cmd "stopinsert" - end) - return true - end, - }):find() -end - -internal.tagstack = function(opts) - opts = opts or {} - local tagstack = vim.fn.gettagstack().items - - local tags = {} - for i = #tagstack, 1, -1 do - local tag = tagstack[i] - tag.bufnr = tag.from[1] - if vim.api.nvim_buf_is_valid(tag.bufnr) then - tags[#tags + 1] = tag - tag.filename = vim.fn.bufname(tag.bufnr) - tag.lnum = tag.from[2] - tag.col = tag.from[3] - - tag.text = vim.api.nvim_buf_get_lines(tag.bufnr, tag.lnum - 1, tag.lnum, false)[1] or "" - end - end - - if vim.tbl_isempty(tags) then - utils.notify("builtin.tagstack", { - msg = "No tagstack available", - level = "WARN", - }) - return - end - - pickers.new(opts, { - prompt_title = "TagStack", - finder = finders.new_table { - results = tags, - entry_maker = make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - }):find() -end - -internal.jumplist = function(opts) - opts = opts or {} - local jumplist = vim.fn.getjumplist()[1] - - -- reverse the list - local sorted_jumplist = {} - for i = #jumplist, 1, -1 do - if vim.api.nvim_buf_is_valid(jumplist[i].bufnr) then - jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum, jumplist[i].lnum + 1, false)[1] - or "" - table.insert(sorted_jumplist, jumplist[i]) - end - end - - pickers.new(opts, { - prompt_title = "Jumplist", - finder = finders.new_table { - results = sorted_jumplist, - entry_maker = make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - }):find() -end - -local function apply_checks(mod) - for k, v in pairs(mod) do - mod[k] = function(opts) - opts = opts or {} - - v(opts) - end - end - - return mod -end - -return apply_checks(internal) +return m diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 480d456..8c297dc 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -1,389 +1,17 @@ -local channel = require("plenary.async.control").channel -local action_state = require "telescope.actions.state" -local sorters = require "telescope.sorters" -local conf = require("telescope.config").values -local finders = require "telescope.finders" -local make_entry = require "telescope.make_entry" -local pickers = require "telescope.pickers" -local utils = require "telescope.utils" +local m = setmetatable({}, { + __index = function(_, k) + local utils = require "telescope.utils" + utils.notify("builtin", { + msg = string.format( + 'You are using an internal interface. Do not use `require("telescope.builtin.lsp").%s`,' + .. ' please use `require("telescope.builtin").lsp_%s`! We will remove this endpoint soon!', + k, + k + ), + level = "ERROR", + }) + return require("telescope.builtin")["lsp_" .. k] + end, +}) -local lsp = {} - -lsp.references = function(opts) - local filepath = vim.api.nvim_buf_get_name(opts.bufnr) - local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1] - local params = vim.lsp.util.make_position_params(opts.winnr) - local include_current_line = vim.F.if_nil(opts.include_current_line, false) - params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) } - - vim.lsp.buf_request(opts.bufnr, "textDocument/references", params, function(err, result, ctx, _) - if err then - vim.api.nvim_err_writeln("Error when finding references: " .. err.message) - return - end - - local locations = {} - if result then - local results = vim.lsp.util.locations_to_items(result, vim.lsp.get_client_by_id(ctx.client_id).offset_encoding) - if include_current_line then - locations = vim.tbl_filter(function(v) - -- Remove current line from result - return not (v.filename == filepath and v.lnum == lnum) - end, vim.F.if_nil(results, {})) - else - locations = vim.F.if_nil(results, {}) - end - end - - if vim.tbl_isempty(locations) then - return - end - - pickers.new(opts, { - prompt_title = "LSP References", - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - push_cursor_on_edit = true, - push_tagstack_on_edit = true, - }):find() - end) -end - -local function call_hierarchy(opts, method, title, direction, item) - vim.lsp.buf_request(opts.bufnr, method, { item = item }, function(err, result) - if err then - vim.api.nvim_err_writeln("Error handling " .. title .. ": " .. err) - return - end - - if not result or vim.tbl_isempty(result) then - return - end - - local locations = {} - for _, ch_call in pairs(result) do - local ch_item = ch_call[direction] - for _, range in pairs(ch_call.fromRanges) do - table.insert(locations, { - filename = vim.uri_to_fname(ch_item.uri), - text = ch_item.name, - lnum = range.start.line + 1, - col = range.start.character + 1, - }) - end - end - - pickers.new(opts, { - prompt_title = title, - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - push_cursor_on_edit = true, - push_tagstack_on_edit = true, - }):find() - end) -end - -local function pick_call_hierarchy_item(call_hierarchy_items) - if not call_hierarchy_items then - return - end - if #call_hierarchy_items == 1 then - return call_hierarchy_items[1] - end - local items = {} - for i, item in pairs(call_hierarchy_items) do - local entry = item.detail or item.name - table.insert(items, string.format("%d. %s", i, entry)) - end - local choice = vim.fn.inputlist(items) - if choice < 1 or choice > #items then - return - end - return choice -end - -local function calls(opts, direction) - local params = vim.lsp.util.make_position_params() - vim.lsp.buf_request(opts.bufnr, "textDocument/prepareCallHierarchy", params, function(err, result) - if err then - vim.api.nvim_err_writeln("Error when preparing call hierarchy: " .. err) - return - end - - local call_hierarchy_item = pick_call_hierarchy_item(result) - if not call_hierarchy_item then - return - end - - if direction == "from" then - call_hierarchy(opts, "callHierarchy/incomingCalls", "LSP Incoming Calls", direction, call_hierarchy_item) - else - call_hierarchy(opts, "callHierarchy/outgoingCalls", "LSP Outgoing Calls", direction, call_hierarchy_item) - end - end) -end - -lsp.incoming_calls = function(opts) - calls(opts, "from") -end - -lsp.outgoing_calls = function(opts) - calls(opts, "to") -end - -local function list_or_jump(action, title, opts) - local params = vim.lsp.util.make_position_params(opts.winnr) - vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _) - if err then - vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message) - return - end - local flattened_results = {} - if result then - -- textDocument/definition can return Location or Location[] - if not vim.tbl_islist(result) then - flattened_results = { result } - end - - vim.list_extend(flattened_results, result) - end - - local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding - - if #flattened_results == 0 then - return - elseif #flattened_results == 1 and opts.jump_type ~= "never" then - if opts.jump_type == "tab" then - vim.cmd "tabedit" - elseif opts.jump_type == "split" then - vim.cmd "new" - elseif opts.jump_type == "vsplit" then - vim.cmd "vnew" - end - vim.lsp.util.jump_to_location(flattened_results[1], offset_encoding) - else - local locations = vim.lsp.util.locations_to_items(flattened_results, offset_encoding) - pickers.new(opts, { - prompt_title = title, - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - push_cursor_on_edit = true, - push_tagstack_on_edit = true, - }):find() - end - end) -end - -lsp.definitions = function(opts) - return list_or_jump("textDocument/definition", "LSP Definitions", opts) -end - -lsp.type_definitions = function(opts) - return list_or_jump("textDocument/typeDefinition", "LSP Type Definitions", opts) -end - -lsp.implementations = function(opts) - return list_or_jump("textDocument/implementation", "LSP Implementations", opts) -end - -lsp.document_symbols = function(opts) - local params = vim.lsp.util.make_position_params(opts.winnr) - vim.lsp.buf_request(opts.bufnr, "textDocument/documentSymbol", params, function(err, result, _, _) - if err then - vim.api.nvim_err_writeln("Error when finding document symbols: " .. err.message) - return - end - - if not result or vim.tbl_isempty(result) then - utils.notify("builtin.lsp_document_symbols", { - msg = "No results from textDocument/documentSymbol", - level = "INFO", - }) - return - end - - local locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr) or {} - locations = utils.filter_symbols(locations, opts) - if locations == nil then - -- error message already printed in `utils.filter_symbols` - return - end - - if vim.tbl_isempty(locations) then - utils.notify("builtin.lsp_document_symbols", { - msg = "No document_symbol locations found", - level = "INFO", - }) - return - end - - opts.path_display = { "hidden" } - pickers.new(opts, { - prompt_title = "LSP Document Symbols", - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.prefilter_sorter { - tag = "symbol_type", - sorter = conf.generic_sorter(opts), - }, - push_cursor_on_edit = true, - push_tagstack_on_edit = true, - }):find() - end) -end - -lsp.workspace_symbols = function(opts) - local params = { query = opts.query or "" } - vim.lsp.buf_request(opts.bufnr, "workspace/symbol", params, function(err, server_result, _, _) - if err then - vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err.message) - return - end - - local locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {} - locations = utils.filter_symbols(locations, opts) - if locations == nil then - -- error message already printed in `utils.filter_symbols` - return - end - - if vim.tbl_isempty(locations) then - utils.notify("builtin.lsp_workspace_symbols", { - msg = "No results from workspace/symbol. Maybe try a different query: " - .. "'Telescope lsp_workspace_symbols query=example'", - level = "INFO", - }) - return - end - - opts.ignore_filename = vim.F.if_nil(opts.ignore_filename, false) - - pickers.new(opts, { - prompt_title = "LSP Workspace Symbols", - finder = finders.new_table { - results = locations, - entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.prefilter_sorter { - tag = "symbol_type", - sorter = conf.generic_sorter(opts), - }, - }):find() - end) -end - -local function get_workspace_symbols_requester(bufnr, opts) - local cancel = function() end - - return function(prompt) - local tx, rx = channel.oneshot() - cancel() - _, cancel = vim.lsp.buf_request(bufnr, "workspace/symbol", { query = prompt }, tx) - - -- Handle 0.5 / 0.5.1 handler situation - local err, res = rx() - assert(not err, err) - - local locations = vim.lsp.util.symbols_to_items(res or {}, bufnr) or {} - if not vim.tbl_isempty(locations) then - locations = utils.filter_symbols(locations, opts) or {} - end - return locations - end -end - -lsp.dynamic_workspace_symbols = function(opts) - pickers.new(opts, { - prompt_title = "LSP Dynamic Workspace Symbols", - finder = finders.new_dynamic { - entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), - fn = get_workspace_symbols_requester(opts.bufnr, opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = sorters.highlighter_only(opts), - attach_mappings = function(_, map) - map("i", "", function(prompt_bufnr) - local line = action_state.get_current_line() - require("telescope.actions.generate").refine(prompt_bufnr, { - prompt_title = "LSP Workspace Symbols (" .. line .. ")", - sorter = conf.generic_sorter(opts), - }) - end) - return true - end, - }):find() -end - -local function check_capabilities(feature, bufnr) - local clients = vim.lsp.buf_get_clients(bufnr) - - local supported_client = false - for _, client in pairs(clients) do - supported_client = client.server_capabilities[feature] - if supported_client then - break - end - end - - if supported_client then - return true - else - if #clients == 0 then - utils.notify("builtin.lsp_*", { - msg = "no client attached", - level = "INFO", - }) - else - utils.notify("builtin.lsp_*", { - msg = "server does not support " .. feature, - level = "INFO", - }) - end - return false - end -end - -local feature_map = { - ["document_symbols"] = "documentSymbolProvider", - ["references"] = "referencesProvider", - ["definitions"] = "definitionProvider", - ["type_definitions"] = "typeDefinitionProvider", - ["implementations"] = "implementationProvider", - ["workspace_symbols"] = "workspaceSymbolProvider", - ["incoming_calls"] = "callHierarchyProvider", - ["outgoing_calls"] = "callHierarchyProvider", -} - -local function apply_checks(mod) - for k, v in pairs(mod) do - mod[k] = function(opts) - opts = opts or {} - - local feature_name = feature_map[k] - if feature_name and not check_capabilities(feature_name, opts.bufnr) then - return - end - v(opts) - end - end - - return mod -end - -return apply_checks(lsp) +return m From 5dd4b5291085d0a843a43c94c5880b513fd0f484 Mon Sep 17 00:00:00 2001 From: marcel <62728887+marcelarie@users.noreply.github.com> Date: Fri, 1 Jul 2022 22:58:05 +0200 Subject: [PATCH 34/35] break: cleanup preview.treesitter language setting (#1612) this follows nvim-treesitter more closely but enable can also be a table of enabled languages The config now looks like this: ```lua defaults = { preview = { treesitter = { enable = false, -- or enable = { "c" }, -- disable can be set if enable isn't set disable = { "perl", "javascript" }, }, }, }, ``` --- doc/telescope.txt | 13 +++++++++++-- lua/telescope/config.lua | 13 +++++++++++-- lua/telescope/previewers/utils.lua | 26 ++++++++++++++++++++------ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 6381b12..4a6eb1a 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -497,8 +497,17 @@ telescope.setup({opts}) *telescope.setup()* highlighting, which falls back to regex-based highlighting. `true`: treesitter highlighting for all available filetypes `false`: regex-based highlighting for all filetypes - `table`: table of filetypes for which to attach treesitter - highlighting + `table`: following nvim-treesitters highlighting options: + It contains two keys: + - enable boolean|table: if boolean, enable all ts + highlighing with that flag, + disable still considered. + Containing a list of filetypes, + that are enabled, disabled + ignored because it doesnt make + any sense in this case. + - disable table: containing a list of filetypes + that are disabled Default: true - msg_bg_fillchar: Character to fill background of unpreviewable buffers with Default: "╱" diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index c5a9ebf..8198ee2 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -593,8 +593,17 @@ append( highlighting, which falls back to regex-based highlighting. `true`: treesitter highlighting for all available filetypes `false`: regex-based highlighting for all filetypes - `table`: table of filetypes for which to attach treesitter - highlighting + `table`: following nvim-treesitters highlighting options: + It contains two keys: + - enable boolean|table: if boolean, enable all ts + highlighing with that flag, + disable still considered. + Containing a list of filetypes, + that are enabled, disabled + ignored because it doesnt make + any sense in this case. + - disable table: containing a list of filetypes + that are disabled Default: true - msg_bg_fillchar: Character to fill background of unpreviewable buffers with Default: "╱" diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua index d250894..b1d1d5e 100644 --- a/lua/telescope/previewers/utils.lua +++ b/lua/telescope/previewers/utils.lua @@ -82,12 +82,26 @@ end utils.highlighter = function(bufnr, ft, opts) opts = opts or {} opts.preview = opts.preview or {} - opts.preview.treesitter = vim.F.if_nil( - opts.preview.treesitter, - type(conf.preview) == "table" and conf.preview.treesitter - ) - local ts_highlighting = opts.preview.treesitter == true - or type(opts.preview.treesitter) == "table" and vim.tbl_contains(opts.preview.treesitter, ft) + opts.preview.treesitter = vim.F.if_nil(opts.preview.treesitter, conf.preview.treesitter) + if type(opts.preview.treesitter) == "boolean" then + local temp = { enable = opts.preview.treesitter } + opts.preview.treesitter = temp + end + + local ts_highlighting = (function() + if type(opts.preview.treesitter.enable) == "table" then + if vim.tbl_contains(opts.preview.treesitter.enable, ft) then + return true + end + return false + end + + if vim.tbl_contains(vim.F.if_nil(opts.preview.treesitter.disable, {}), ft) then + return false + end + + return opts.preview.treesitter.enable == nil or opts.preview.treesitter.enable == true + end)() local ts_success if ts_highlighting then From e778abfdb457cc47ca47ce9b76905e043e87e598 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Fri, 1 Jul 2022 23:20:07 +0200 Subject: [PATCH 35/35] docs: changelog for dev branch, 1945 --- doc/telescope_changelog.txt | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/doc/telescope_changelog.txt b/doc/telescope_changelog.txt index a11ad84..a1a474d 100644 --- a/doc/telescope_changelog.txt +++ b/doc/telescope_changelog.txt @@ -195,5 +195,64 @@ https://github.com/stevearc/dressing.nvim which has support for multiple different backends including telescope. + *telescope.changelog-1945* + +Date: July 01, 2022 +PR: https://github.com/nvim-telescope/telescope.nvim/pull/1945 + +This is our dev branch which contains a lot of PRs, a lot of fixes, +refactoring and general quality of life improvements. It also contains new +features, the most noteworthy are the following (mostly developed by the +community): +- feat: none strategy & control attachment (#1867) +- feat: force buffer delete for terminal and improvements for + Picker:delete_selection (#1943) +- feat(tags): process tagfiles on the fly (#1989) +- feat(builtin.lsp): implement builtin handlers for + lsp.(incoming|outgoing)_calls (#1484) +- feat: clear previewer if no item is selected (#2004) +- feat: add min max boundary to width, height resolver (#2002) +- feat: Add entry_index for entry_makers (#1850) +- feat: refine with new_table (#1115) + +The last one is one of the most existing new features, because it allows you +to go from live_grep into a fuzzy environment with the following mapping +``. It's a general interface we now implemented for `live_grep` and +`lsp_dynamic_workspace_symbols` but it could also be easily implemented for +other builtins, by us or the user. It's now available for extension developers. +We will add documentation in the next couple of days and improve it by adding +more options to configure it after the initial 0.1 release. + +But with all longer development phases, there are also some breaking changes. +This is the main reason we moved development to a separate branch, for the +past two months. We can't promise that there won't be more breaking changes, +but it is the plan that this is the last set of breaking changes prior to the +0.1 release on July, 12. We are deeply sorry for the inconvenience. The +following breaking changes are included in this PR: +- break(git_files): change `show_untracked` default to false. Can be changed + back with `:Telescope git_files show_untracked=true` +- break: deprecate `utils.get_default` `utils.if_nil`, will be removed prior + to 0.1, so if you use it in your config, please move to `vim.F.if_nil` +- break: drops `ignore_filename` option, use `path_display= { "hidden" }` + instead +- break: prefix internal interfaces with __ so + `require("telescope.builtin.files").find_files` will show a notify error but + still works for now. The error will be removed prior to 0.1! You should use + `require("telescope.builtin").find_files` because we wrap all the functions + that are exposed in this module. +- break: defaults.preview.treesitter rework that allows you to either enable a + list of languages, or enable all and disable some. Please read + `:help telescope.defaults.preview` for more information. + Something like this is now possible: + > + treesitter = { + enable = false, + -- or + enable = { "c" }, + -- disable can be set if enable isn't set + disable = { "perl", "javascript" }, + }, +< + vim:tw=78:ts=8:ft=help:norl: