-
-
Notifications
You must be signed in to change notification settings - Fork 842
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
vimgrep entry maker using --json
#2536
base: master
Are you sure you want to change the base?
Conversation
66170f7
to
f31994a
Compare
thats awesome thank you very much. there are a couple of things i have to think about like: Another question i need to think about is if displayer is the best way to do highlighting here. But i've tested it and it already works great. Thank you very much for implementing it :) |
Yeah I'm not opposed to keeping
Yeah I don't love creating a new |
84b4301
to
c3e4a74
Compare
9a3b699
to
121a535
Compare
when this will be merged into master, I realy love this new feature |
Displayer is just a wrapper around the actual interface, i'll going to rewrite that section. I am also making this PR a Draft for the time being. I know its almost done but then we might have less ppl asking 😆 |
Note to self: vim.base64? |
function make_entry.gen_from_vimgrep_json(opts)
opts = opts or {}
local cwd = vim.fn.expand(opts.cwd or vim.loop.cwd() or "")
local function bytes_or_text_to_str(data)
if data.bytes ~= nil then
return require("telescope.algos.base64").decode(data.bytes)
else
return data.text
end
end
local mt_vimgrep_entry = {}
mt_vimgrep_entry.display = function(entry)
local display_filename = utils.transform_path(opts, entry.filename)
local coordinates = ":"
if not opts.disable_coordinates then
if entry.lnum then
if entry.col then
coordinates = string.format(":%s:%s:", entry.lnum, entry.col)
else
coordinates = string.format(":%s:", entry.lnum)
end
end
end
local file_pos, hl_group, icon = utils.transform_devicons(
entry.filename,
string.format("%s%s", display_filename, coordinates),
opts.disable_devicons
)
return file_pos .. entry.text,
(function()
if opts.__finder == "grep_string" then
return {}
end
local highlights = { { { 0, #icon }, hl_group or "" } }
local file_pos_len = #file_pos
for _, submatch in ipairs(entry.submatches) do
table.insert(
highlights,
{ { submatch["start"] + file_pos_len, submatch["end"] + file_pos_len }, "TelescopeMatching" }
)
end
return highlights
end)()
end
mt_vimgrep_entry.__index = function(t, k)
local override = handle_entry_index(opts, t, k)
if override then
return override
end
local raw = rawget(mt_vimgrep_entry, k)
if raw then
return raw
end
if k == "path" then
local path = Path:new(t.filename)
if path:is_absolute() then
return t.filename
end
return Path:new({ cwd, t.filename }):absolute()
end
if k == "text" then
return t.value
end
if k == "ordinal" then
local text = t.text
return opts.only_sort_text and text or text .. " " .. t.filename
end
end
return function(line)
local msg = vim.json.decode(line)
if msg == nil or msg.type ~= "match" then
return
end
local text = bytes_or_text_to_str(msg.data.lines):gsub("%s+$", "")
return setmetatable({
value = text,
filename = bytes_or_text_to_str(msg.data.path),
lnum = msg.data.line_number,
col = #msg.data.submatches ~= 0 and msg.data.submatches[1].start + 1 or nil,
submatches = msg.data.submatches,
}, mt_vimgrep_entry)
end
end @jamestrew this should fix it, |
21be2ee
to
889eb8b
Compare
@Marskey thanks I've incorporated your snippets. looks to be working well so far. |
return setmetatable({
value = text,
filename = bytes_or_text_to_str(msg.data.path),
lnum = msg.data.line_number,
col = #msg.data.submatches ~= 0 and msg.data.submatches[1].start + 1 or nil,
colend = #msg.data.submatches ~= 0 and msg.data.submatches[1]["end"] + 1 or nil,
submatches = msg.data.submatches,
}, mt_vimgrep_entry)
Please consider whether |
I also rebased everything. |
This fix has been working for me. Any chance we can get this merged? |
til neovim 0.10 released, or you can merged by youself if you are using pre-release version 0.10 |
9cbecff
to
c77eb92
Compare
skip-checks: true
Neovim 0.10 has already been released. Any reason this PR still can't be merged? |
I still need to review this, thats missing. |
We're still supporting 0.9 on the master branch as well. |
vimgrep entry maker using --json nvim-telescope#2536
Description
Applies
--json
to vimgrep arguments forlive_grep
andgrep_string
allowing for correct highlighting of submatches in the entry display.^notice the filename foo is not getting highlighted matching the submatch highlight directly from
rg
More specific changes:
vimgrep_arguments
now{ "rg", "--smart-case", "--json" }
gen_from_vimgrep
entry maker to support parsing of json outputrg
options, pattern and search paths generation forlive_grep
andgrep_string
Closes #2272
Closes #934
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list relevant details about your configuration
live_grep
andgrep_string
pickers using all optionstouch foo.md
echo "foo\nfoobar bar\n\tfoo" > foo.md
touch test.py
echo "def bar():\n\treturn 'foobar'" > test.py
additional_args
(notably-l
,--files-with-matches
,--files
, ie. those documented by rg to be incompatible with--json
)For
file_encoding
option:acentuação
:Telescope <picker> file_encoding=latin1
and verify previewer/entryConfiguration:
NVIM v0.10.0-dev-410+gc48f94d1f
Linux archlinux 6.3.2-arch1-1
Checklist: