Skip to content

Commit

Permalink
feat(live_grep): Allow passing multiple file types for type_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh08 committed Nov 10, 2024
1 parent 85922dd commit 3cfaef1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,10 @@ builtin.live_grep({opts}) *telescope.builtin.live_grep()*
{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`
{type_filter} (string|table) comma-separated string or
string list argument to be
used with `--type`, e.g. "rust",
see `rg --type-list`
{additional_args} (function|table) additional arguments to be
passed on. Can be fn(opts) ->
tbl
Expand Down
8 changes: 7 additions & 1 deletion lua/telescope/builtin/__files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ files.live_grep = function(opts)
end

if opts.type_filter then
additional_args[#additional_args + 1] = "--type=" .. opts.type_filter
local file_types = opts.type_filter
if type(opts.type_filter) == "string" then
file_types = vim.split(opts.type_filter, ",", { trimempty = true })
end
for _, file_type in ipairs(file_types) do
additional_args[#additional_args + 1] = "--type=" .. file_type
end
end

if type(opts.glob_pattern) == "string" then
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
---@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|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 type_filter string|table: comma-separated string or string list argument to be used with `--type`, e.g. "rust", see `rg --type-list`
---@field additional_args function|table: additional arguments to be passed on. Can be fn(opts) -> tbl
---@field max_results number: define a upper result value
---@field disable_coordinates boolean: don't show the line & row numbers (default: false)
Expand Down

0 comments on commit 3cfaef1

Please sign in to comment.