From 30f2a367f2d9dbf1a9aaf4eb447523d8fa56d9d8 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Wed, 6 Jul 2022 20:38:51 +0200 Subject: feat(grep_string): invert_match for search="", removing empty lines (#2040) --- lua/telescope/make_entry.lua | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'lua/telescope/make_entry.lua') diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 43810f2..805218e 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -205,7 +205,7 @@ do } -- Gets called only once to parse everything out for the vimgrep, after that looks up directly. - local parse = function(t) + local parse_with_col = function(t) local _, _, filename, lnum, col, text = string.find(t.value, [[(..-):(%d+):(%d+):(.*)]]) local ok @@ -227,11 +227,32 @@ do return { filename, lnum, col, text } end - function make_entry.gen_from_vimgrep(opts) - local mt_vimgrep_entry + local parse_without_col = function(t) + local _, _, filename, lnum, text = string.find(t.value, [[(..-):(%d+):(.*)]]) + + local ok + ok, lnum = pcall(tonumber, lnum) + if not ok then + lnum = nil + end + t.filename = filename + t.lnum = lnum + t.col = nil + t.text = text + + return { filename, lnum, nil, text } + end + + function make_entry.gen_from_vimgrep(opts) opts = opts or {} + local mt_vimgrep_entry + local parse = parse_with_col + if opts.__inverted == true then + parse = parse_without_col + end + local disable_devicons = opts.disable_devicons local disable_coordinates = opts.disable_coordinates local only_sort_text = opts.only_sort_text @@ -279,7 +300,11 @@ do local coordinates = "" if not disable_coordinates then - coordinates = string.format("%s:%s:", entry.lnum, entry.col) + if entry.col then + coordinates = string.format("%s:%s:", entry.lnum, entry.col) + else + coordinates = string.format("%s:", entry.lnum) + end end local display, hl_group = utils.transform_devicons( -- cgit v1.2.3