feat: live_grep and grep_string function for additional opts (allow file mask) (#1017)
This commit is contained in:
committed by
GitHub
parent
b7cd8c7699
commit
ca195e32e0
@@ -337,6 +337,8 @@ builtin.live_grep({opts}) *builtin.live_grep()*
|
||||
`search_dirs`
|
||||
{search_dirs} (table) directory/directories to search in,
|
||||
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()*
|
||||
@@ -349,8 +351,11 @@ builtin.grep_string({opts}) *builtin.grep_string()*
|
||||
Fields: ~
|
||||
{search} (string) the query to search
|
||||
{search_dirs} (table) directory/directories to search in
|
||||
{use_regex} (boolean) if true, special characters won't be escaped,
|
||||
allows for using regex (default is false)
|
||||
{use_regex} (boolean) if true, special characters won't be
|
||||
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()*
|
||||
|
||||
@@ -68,6 +68,11 @@ files.live_grep = function(opts)
|
||||
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)
|
||||
-- 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
|
||||
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(
|
||||
opts
|
||||
), opts.max_results, opts.cwd)
|
||||
@@ -116,8 +121,14 @@ files.grep_string = function(opts)
|
||||
local word_match = opts.word_match
|
||||
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 {
|
||||
vimgrep_arguments,
|
||||
additional_args,
|
||||
word_match,
|
||||
search,
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ local builtin = {}
|
||||
---@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 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
|
||||
|
||||
--- 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_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 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
|
||||
|
||||
--- Lists files in your current working directory, respects .gitignore
|
||||
|
||||
Reference in New Issue
Block a user