summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorNazeeh ElDirghami <32499832+Nazeehe@users.noreply.github.com>2021-08-04 03:07:04 -0400
committerGitHub <noreply@github.com>2021-08-04 09:07:04 +0200
commitca195e32e0d6e9238fb2dd405e2f794ab8c90819 (patch)
tree310d3766537201a5314c570679ea44eb02aef608 /lua
parentb7cd8c7699623c4b351009192dc9a03a54195e6b (diff)
feat: live_grep and grep_string function for additional opts (allow file mask) (#1017)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/files.lua13
-rw-r--r--lua/telescope/builtin/init.lua2
2 files changed, 14 insertions, 1 deletions
diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua
index 80b8125..605a874 100644
--- a/lua/telescope/builtin/files.lua
+++ b/lua/telescope/builtin/files.lua
@@ -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,
}
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index 25d59fb..1972265 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -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