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

support additional_args argument #86

Merged
merged 2 commits into from
Jul 28, 2024
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- `additional_args` support to `live_grep_args()`

## 1.1.0 - 2024-06-09

### Added
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ telescope.load_extension("live_grep_args")

This extension accepts the same options as `builtin.live_grep`, check out `:help live_grep` and `:help vimgrep_arguments` for more information. Additionally it also accepts `theme` and `layout_config`.

`live_grep_args` args

| Name | Type | Description | Example |
| --- | --- | --- | --- |
| `additional_args` | `function|table` | additional arguments to be passed on. Can be fn(opts) -> tbl | `{ '-tmd' }` |


### Mapping recipes:

Expand Down
11 changes: 10 additions & 1 deletion lua/telescope/_extensions/live_grep_args.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ local live_grep_args = function(opts)
opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts)
opts.cwd = opts.cwd and vim.fn.expand(opts.cwd)

local additional_args = {}
if opts.additional_args ~= nil then
if type(opts.additional_args) == "function" then
additional_args = opts.additional_args(opts)
elseif type(opts.additional_args) == "table" then
additional_args = opts.additional_args
end
end

if opts.search_dirs then
for i, path in ipairs(opts.search_dirs) do
opts.search_dirs[i] = vim.fn.expand(path)
Expand All @@ -43,7 +52,7 @@ local live_grep_args = function(opts)
return nil
end

local args = tbl_clone(opts.vimgrep_arguments)
local args = vim.tbl_flatten({ tbl_clone(opts.vimgrep_arguments), tbl_clone(additional_args) })
local prompt_parts = prompt_parser.parse(prompt, opts.auto_quoting)

local cmd = vim.tbl_flatten({ args, prompt_parts, opts.search_dirs })
Expand Down
Loading