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

Fix nil Assignment to frag causing errors in subsequent logic execution. #81

Open
wants to merge 4 commits 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
11 changes: 10 additions & 1 deletion lua/telescope-live-grep-args/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ M.quote = function(value, opts)
return opts.quote_char .. quoted .. opts.quote_char
end

return M
M.extract_quotes = function(input)
local match = input:match('"(.-)"')
if match then
return match
else
return input
end
end

return M
2 changes: 2 additions & 0 deletions lua/telescope-live-grep-args/prompt_parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ M.parse = function(prompt, autoquote)
frag = shift_any(str)
end

frag = frag or ''

if current_arg == nil then
current_arg = frag
else
Expand Down
43 changes: 28 additions & 15 deletions lua/telescope/_extensions/live_grep_args.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--
-- SPDX-License-Identifier: MIT

local helpers = require("telescope-live-grep-args.helpers")
local prompt_parser = require("telescope-live-grep-args.prompt_parser")

local pickers = require("telescope.pickers")
Expand Down Expand Up @@ -38,6 +39,8 @@ local live_grep_args = function(opts)
end
end

local picker

local cmd_generator = function(prompt)
if not prompt or prompt == "" then
return nil
Expand All @@ -61,22 +64,32 @@ local live_grep_args = function(opts)
end
end

pickers
.new(opts, {
prompt_title = "Live Grep (Args)",
finder = finders.new_job(cmd_generator, opts.entry_maker, opts.max_results, opts.cwd),
previewer = conf.grep_previewer(opts),
sorter = sorters.highlighter_only(opts),
attach_mappings = function(_, map)
for mode, mappings in pairs(opts.mappings) do
for key, action in pairs(mappings) do
map(mode, key, action)
end
picker = pickers.new(opts, {
prompt_title = "Live Grep (Args)",
finder = finders.new_job(cmd_generator, opts.entry_maker, opts.max_results, opts.cwd),
previewer = conf.grep_previewer(opts),
sorter = (opts.custom_sorter and opts.custom_sorter or sorters.highlighter_only(opts)),
attach_mappings = function(_, map)
for mode, mappings in pairs(opts.mappings) do
for key, action in pairs(mappings) do
map(mode, key, action)
end
return true
end,
})
:find()
end
return true
end,
})

local org_highligh_on_row = picker.highlight_one_row
picker.highlight_one_row = function(...)
local args = { ... }
assert(#args == 5, 'invalid argment declation')

args[3] = picker._get_prompt(picker)

org_highligh_on_row(table.unpack(args))
end

picker:find()
end

return telescope.register_extension({
Expand Down