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 12, 2024
1 parent 16ab1b2 commit 3d52a8e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 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
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

0 comments on commit 3d52a8e

Please sign in to comment.