Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(live_grep): Allow passing multiple file types for type_filter #3361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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