Skip to content

Commit

Permalink
fix: quotes highlight.
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPONG committed Jul 10, 2024
1 parent 16ab1b2 commit 717b76d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
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: 1 addition & 1 deletion lua/telescope-live-grep-args/prompt_parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ M.parse = function(prompt, autoquote)
end

frag = frag or ''

if current_arg == nil then
current_arg = frag
else
Expand Down
46 changes: 30 additions & 16 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,7 +39,11 @@ local live_grep_args = function(opts)
end
end

local cmd_generator = function(prompt)
local picker

local cmd_generator = function(_)
local prompt = picker:_get_prompt(true)

if not prompt or prompt == "" then
return nil
end
Expand All @@ -61,22 +66,31 @@ 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 = conf.generic_sorter(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_get_prompt = picker._get_prompt
picker._get_prompt = function(self, orginal)
local ret = org_get_prompt(self)
if not orginal then
ret = helpers.extract_quotes(ret)
end
return ret
end

picker:find()
end

return telescope.register_extension({
Expand Down

0 comments on commit 717b76d

Please sign in to comment.