feat: live_grep and grep_string function for additional opts (allow file mask) (#1017)

This commit is contained in:
Nazeeh ElDirghami
2021-08-04 03:07:04 -04:00
committed by GitHub
parent b7cd8c7699
commit ca195e32e0
3 changed files with 28 additions and 10 deletions

View File

@@ -332,11 +332,13 @@ builtin.live_grep({opts}) *builtin.live_grep()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~ Fields: ~
{grep_open_files} (boolean) if true, restrict search to open files {grep_open_files} (boolean) if true, restrict search to open files
only, mutually exclusive with only, mutually exclusive with
`search_dirs` `search_dirs`
{search_dirs} (table) directory/directories to search in, {search_dirs} (table) directory/directories to search in,
mutually exclusive with `grep_open_files` mutually exclusive with `grep_open_files`
{additional_args} (function) function(opts) which returns a table of
additional arguments to be passed on
builtin.grep_string({opts}) *builtin.grep_string()* builtin.grep_string({opts}) *builtin.grep_string()*
@@ -347,10 +349,13 @@ builtin.grep_string({opts}) *builtin.grep_string()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~ Fields: ~
{search} (string) the query to search {search} (string) the query to search
{search_dirs} (table) directory/directories to search in {search_dirs} (table) directory/directories to search in
{use_regex} (boolean) if true, special characters won't be escaped, {use_regex} (boolean) if true, special characters won't be
allows for using regex (default is false) escaped, allows for using regex (default
is false)
{additional_args} (function) function(opts) which returns a table of
additional arguments to be passed on
builtin.find_files({opts}) *builtin.find_files()* builtin.find_files({opts}) *builtin.find_files()*

View File

@@ -68,6 +68,11 @@ files.live_grep = function(opts)
end end
end end
local additional_args = {}
if opts.additional_args ~= nil and type(opts.additional_args) == "function" then
additional_args = opts.additional_args(opts)
end
local live_grepper = finders.new_job(function(prompt) local live_grepper = finders.new_job(function(prompt)
-- TODO: Probably could add some options for smart case and whatever else rg offers. -- TODO: Probably could add some options for smart case and whatever else rg offers.
@@ -89,7 +94,7 @@ files.live_grep = function(opts)
search_list = filelist search_list = filelist
end end
return flatten { vimgrep_arguments, prompt, search_list } return flatten { vimgrep_arguments, additional_args, prompt, search_list }
end, opts.entry_maker or make_entry.gen_from_vimgrep( end, opts.entry_maker or make_entry.gen_from_vimgrep(
opts opts
), opts.max_results, opts.cwd) ), opts.max_results, opts.cwd)
@@ -116,8 +121,14 @@ files.grep_string = function(opts)
local word_match = opts.word_match local word_match = opts.word_match
opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts) opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts)
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 { local args = flatten {
vimgrep_arguments, vimgrep_arguments,
additional_args,
word_match, word_match,
search, search,
} }

View File

@@ -70,6 +70,7 @@ local builtin = {}
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field grep_open_files boolean: if true, restrict search to open files only, mutually exclusive with `search_dirs` ---@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 to search in, mutually exclusive with `grep_open_files`
---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on
builtin.live_grep = require("telescope.builtin.files").live_grep builtin.live_grep = require("telescope.builtin.files").live_grep
--- Searches for the string under your cursor in your current working directory --- Searches for the string under your cursor in your current working directory
@@ -77,6 +78,7 @@ builtin.live_grep = require("telescope.builtin.files").live_grep
---@field search string: the query to search ---@field search string: the query to search
---@field search_dirs table: directory/directories to search in ---@field search_dirs table: directory/directories to search in
---@field use_regex boolean: if true, special characters won't be escaped, allows for using regex (default is false) ---@field use_regex boolean: if true, special characters won't be escaped, allows for using regex (default is false)
---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on
builtin.grep_string = require("telescope.builtin.files").grep_string builtin.grep_string = require("telescope.builtin.files").grep_string
--- Lists files in your current working directory, respects .gitignore --- Lists files in your current working directory, respects .gitignore