Skip to content

Commit

Permalink
Merge pull request #23 from gennaro-tedesco/fix_yaml
Browse files Browse the repository at this point in the history
fixed yaml queries after latest changes in `yq`
  • Loading branch information
gennaro-tedesco authored Feb 12, 2023
2 parents 24d3e02 + 9df59f7 commit 89bf1e9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions lua/nvim-jqx/floating.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ local function set_fw_opts(buf)
":q<CR> <C-w>j",
{ nowait = true, noremap = true, silent = true }
)
vim.treesitter.start(buf, "json")
end

return {
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-jqx/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ local function query_jq(q)
end
local cur_file = vim.fn.getreg("%")
local user_query = ft == "json" and "jq '." .. input_query .. "' " .. cur_file
or "yq eval '." .. input_query .. "' " .. cur_file
or "yq '." .. input_query .. "' " .. cur_file
vim.fn.inputrestore()

-- parsing query results
Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-jqx/jqx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ local function populate_qf(ft, type, sort)
end
end
elseif ft == "yaml" then
for s in vim.fn.system("yq eval 'keys' " .. cur_file):gmatch("[^\r\n]+") do
local key = s:gsub("^-%s+", "")
for s in vim.fn.system("yq 'keys[]' " .. cur_file):gmatch("[^\r\n]+") do
local key = s:gsub("^-%s+", ""):gsub('"', "")
table.insert(cmd_lines, key)
end
end
Expand Down Expand Up @@ -81,7 +81,7 @@ local function parse_jq_query(key, cur_file, ft)
table.insert(parsed_lines, s)
end
elseif ft == "yaml" then
for s in vim.fn.system("yq eval '.\"" .. key .. "\"' " .. cur_file):gmatch("[^\r\n]+") do
for s in vim.fn.system("yq '.\"" .. key .. "\"' " .. cur_file):gmatch("[^\r\n]+") do
table.insert(parsed_lines, s)
end
end
Expand Down
4 changes: 2 additions & 2 deletions plugin/nvim-jqx.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function! FileKeys(A, L, P) abort
let a = split(system("jq 'keys' " . getreg("%") . " | sed 's/,*$//g' | sed '1d;$d' "), "\n")
call map(a, {idx, val -> substitute(trim(val), '\"', '', 'g')})
elseif &filetype == 'yaml'
let a = split(system("yq eval 'keys' " . getreg("%")), "\n")
call map(a, {idx, val -> substitute(trim(val), '-', '', 'g')})
let a = split(system("yq 'keys[]' " . getreg("%")), "\n")
call map(a, {idx, val -> substitute(trim(val), '\"', '', 'g')})
endif
return filter(a, 'v:val =~ ''\V\^''.a:A')
endfunction
Expand Down

0 comments on commit 89bf1e9

Please sign in to comment.