[
  {
    "path": ".github/workflows/panvimdoc.yml",
    "content": "name: panvimdoc\n\non:\n  workflow_dispatch:\n  push:\n    paths:\n      - \"README.md\"\n      - \"**.yml\"\n\njobs:\n  docs:\n    runs-on: ubuntu-latest\n    name: pandoc to vimdoc\n    permissions:\n      contents: write\n    steps:\n      - uses: actions/checkout@v3\n      - name: panvimdoc\n        uses: kdheepak/panvimdoc@main\n        with:\n          vimdoc: jqx\n          version: \"Neovim >= 0.8.0\"\n          demojify: true\n          treesitter: true\n      - uses: stefanzweifel/git-auto-commit-action@v4\n        with:\n          commit_message: \"Auto generate docs\"\n          branch: ${{ github.head_ref }}\n"
  },
  {
    "path": ".github/workflows/release.yml",
    "content": "name: release\n\non:\n  workflow_dispatch:\n  push:\n    tags:\n      - \"v*.*.*\"\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v3\n      - name: Release\n        uses: softprops/action-gh-release@v1\n\n  luarocks-release:\n    runs-on: ubuntu-latest\n    name: LuaRocks upload\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v3\n      - name: LuaRocks Upload\n        uses: nvim-neorocks/luarocks-tag-release@v2.1.0\n        env:\n          LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}\n        with:\n          copy_directories: |\n            doc\n          license: \"MIT\"\n"
  },
  {
    "path": ".gitignore",
    "content": "/plugin/reload.vim\n"
  },
  {
    "path": ".pre-commit-config.yaml",
    "content": "repos:\n- repo: https://github.com/JohnnyMorganz/StyLua\n  rev: v0.14.3\n  hooks:\n    - id: stylua\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2023 Gennaro Tedesco\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<h1 align=\"center\">\n  <br>\n  <img width=\"350\" height=\"300\" src=\"examples/logo.png\">\n  <br>\n  nvim-jqx\n  <br>\n</h1>\n\n<h2 align=\"center\">\n  <a href=\"https://luarocks.org/modules/gennaro-tedesco/nvim-jqx\">\n    <img alt=\"luarocks\" src=\"https://img.shields.io/luarocks/v/gennaro-tedesco/nvim-jqx?logo=lua&color=2aa198&style=for-the-badge\"/>\n  </a>\n  <a href=\"https://github.com/gennaro-tedesco/nvim-jqx/releases\">\n    <img alt=\"releases\" src=\"https://img.shields.io/github/release/gennaro-tedesco/nvim-jqx?logo=neovim&color=2aa198&style=for-the-badge\"/>\n  </a>\n</h2>\n\n<h4 align=\"center\">Populate the quickfix with json entries</h4>\n\n<h3 align=\"center\">\n  <a href=\"#Installation\">Installation</a> •\n  <a href=\"#Usage\">Usage</a> •\n  <a href=\"#Customisation\">Customisation</a> •\n  <a href=\"#Feedback\">Feedback</a>\n</h3>\n\nIf only one could easily browse and preview json files in neovim. Oh wait, `nvim-jqx` does just that!\n\n## Installation\n\nInstall it using your favourite plugin manager: for instance\n\n- with [lazy.nvim](https://github.com/folke/lazy.nvim)\n\n```lua\n{\n  \"gennaro-tedesco/nvim-jqx\",\n  event = {\"BufReadPost\"},\n  ft = { \"json\", \"yaml\" },\n},\n```\n\nNotice that `jq` is a prerequisite, as this plugin executes `jq` queries internally.\n\n## Usage\n\n`nvim-jqx` exposes two commands: `JqxList` and `JqxQuery`.\nOpen a json file and issue `JqxList`: the json is prettified and the quickfix window is populated with the first level keys. Press `X` on a key to query its values and show the results in a floating window; alternatively `<CR>` takes you to its location in the file.\n\n![JqxListdemo](https://user-images.githubusercontent.com/15387611/113495463-4bd24500-94f2-11eb-88b5-64c1ee965886.gif)\n\n`JqxList` also accepts an optional argument representing the json type you want to subselect: for example `JqxList number` populates the quickfix with entries of type number only, so do `JqxList string`, `JqxList boolean` and so forth, respectively: this is quite useful for big files where you want to have a quick peek at, say, some numerical values only or similar. For a full list of available types see `h: jqx-usage` or simply hit `<Tab>` to show the autocomplete for available types.\n\nTo execute more complicated and generic `jq` commands use `JqxQuery` instead; the prompt helps autocomplete with the file keys for easy typing. Open a json file `test.json` and issue `JqxQuery <my-query>`: this translates into `jq \".<my-query>\" test.json` as shown below\n\n```\n# JqxQuery grammar\nJqxQuery friends[2].name\n\"Michael Marquez\"\n\n# jq equivalent\njq '.friends[2].name' test.json\n\"Michael Marquez\"\n```\n\n![JqxQuerydemo](https://user-images.githubusercontent.com/15387611/113495732-ab7d2000-94f3-11eb-8781-0497771b60a1.gif)\n\nDefault commands\n\n| command          | description                                       |\n| :--------------- | :------------------------------------------------ |\n| `JqxList`        | populate the quickfix window with json keys       |\n| `JqxList string` | populate the quickfix window with string values   |\n| `JqxQuery`       | executes a generic `jq` query in the current file |\n| `<CR>`           | go to key location in file                        |\n| X                | query values of key under cursor                  |\n| `<Esc>`          | close floating window                             |\n\nTry it out directly with `nvim examples/test.json -c JqxList`.\n\nFor more in-depth description and explanations check the documentation `:h nvim-jqx` and links therein.\n\n### Yaml files\n\n`nvim-jqx` works on `yaml` files too. It requires, however, to install [yq](https://github.com/kislyuk/yq). Try it out directly with `nvim examples/test.yaml -c JqxList`, or execute `JqxQuery` on a `yaml` file.\n\n> ⚠️ this plugin works with the Python implementation of yq by @kislyuk, not to be confused\n> with the Go implementation of yq by @mikefarah.\n\n## Customisation\n\nIf you prefer key-mappings rather than commands simply bind\n\n```\nnmap ... <Plug>JqxList\n```\n\nThe configurable options are exposed in [nvim-jqx/config.lua](https://github.com/gennaro-tedesco/nvim-jqx/blob/master/lua/nvim-jqx/config.lua) and can be overridden at will. For example, with `lazy.nvim` you can configure them as\n\n```lua\n{\n    \"gennaro-tedesco/nvim-jqx\",\n    ...\n    init = function()\n        local jqx = require(\"nvim-jqx.config\")\n        jqx.geometry.border = \"single\"\n        jqx.geometry.width = 0.7\n        ...\n\n        jqx.query_key = \"X\"         -- keypress to query jq on keys\n        jqx.sort = false            -- show the json keys as they appear instead of sorting them alphabetically\n        jqx.show_legend = true      -- show key queried as first line in the jqx floating window\n        jqx.use_quickfix = false    -- if you prefer the location list\n    end,\n}\n```\n\nWhy not automatically formatting your `json` files as you open them? Set up the autogroup\n\n```lua\n\nlocal jqx = vim.api.nvim_create_augroup(\"Jqx\", {})\nvim.api.nvim_clear_autocmds({ group = jqx })\nvim.api.nvim_create_autocmd(\"BufWinEnter\", {\n\tpattern = { \"*.json\", \"*.yaml\" },\n\tdesc = \"preview json and yaml files on open\",\n\tgroup = jqx,\n\tcallback = function()\n\t\tvim.cmd.JqxList()\n\tend,\n})\n```\n\n## Feedback\n\nIf you find this plugin useful consider awarding it a ⭐, it is a great way to give feedback! Otherwise, any additional suggestions or merge request is warmly welcome!\n"
  },
  {
    "path": "doc/jqx.txt",
    "content": "*jqx.txt*             For Neovim >= 0.8.0             Last change: 2024 May 31\n\n==============================================================================\nTable of Contents                                      *jqx-table-of-contents*\n\n  - Installation                                            |jqx-installation|\n  - Usage                                                          |jqx-usage|\n  - Customisation                                          |jqx-customisation|\n  - Feedback                                                    |jqx-feedback|\n1. Links                                                           |jqx-links|\n\n\n\nnvim-jqx\n\n\n\n\n\nPopulate the quickfix with json entriesInstallation •\nUsage •\nCustomisation •\nFeedbackIf only one could easily browse and preview json files in neovim. Oh wait,\n`nvim-jqx` does just that!\n\n\nINSTALLATION                                                *jqx-installation*\n\nInstall it using your favourite plugin manager: for instance\n\n- with lazy.nvim <https://github.com/folke/lazy.nvim>\n\n>lua\n    {\n      \"gennaro-tedesco/nvim-jqx\",\n      event = {\"BufReadPost\"},\n      ft = { \"json\", \"yaml\" },\n    },\n<\n\nNotice that `jq` is a prerequisite, as this plugin executes `jq` queries\ninternally.\n\n\nUSAGE                                                              *jqx-usage*\n\n`nvim-jqx` exposes two commands: `JqxList` and `JqxQuery`. Open a json file and\nissue `JqxList`the json is prettified and the quickfix window is populated with\nthe first level keys. Press `X` on a key to query its values and show the\nresults in a floating window; alternatively `<CR>` takes you to its location in\nthe file.\n\n`JqxList` also accepts an optional argument representing the json type you want\nto subselect: for example `JqxList number` populates the quickfix with entries\nof type number only, so do `JqxList string`, `JqxList boolean` and so forth,\nrespectively: this is quite useful for big files where you want to have a quick\npeek at, say, some numerical values only or similar. For a full list of\navailable types see `h: jqx-usage` or simply hit `<Tab>` to show the\nautocomplete for available types.\n\nTo execute more complicated and generic `jq` commands use `JqxQuery` instead;\nthe prompt helps autocomplete with the file keys for easy typing. Open a json\nfile `test.json` and issue `JqxQuery <my-query>`this translates into `jq\n\".<my-query>\" test.json` as shown below\n\n>\n    # JqxQuery grammar\n    JqxQuery friends[2].name\n    \"Michael Marquez\"\n    \n    # jq equivalent\n    jq '.friends[2].name' test.json\n    \"Michael Marquez\"\n<\n\nDefault commands\n\n  command          description\n  ---------------- -------------------------------------------------\n  JqxList          populate the quickfix window with json keys\n  JqxList string   populate the quickfix window with string values\n  JqxQuery         executes a generic jq query in the current file\n  <CR>             go to key location in file\n  X                query values of key under cursor\n  <Esc>            close floating window\nTry it out directly with `nvim examples/test.json -c JqxList`.\n\nFor more in-depth description and explanations check the documentation\n|nvim-jqx| and links therein.\n\n\nYAML FILES ~\n\n`nvim-jqx` works on `yaml` files too. It requires, however, to install yq\n<https://github.com/kislyuk/yq>. Try it out directly with `nvim\nexamples/test.yaml -c JqxList`, or execute `JqxQuery` on a `yaml` file.\n\n\n  this plugin works with the Python implementation of yq by @kislyuk, not to be\n  confused with the Go implementation of yq by @mikefarah.\n\nCUSTOMISATION                                              *jqx-customisation*\n\nIf you prefer key-mappings rather than commands simply bind\n\n>\n    nmap ... <Plug>JqxList\n<\n\nThe configurable options are exposed in nvim-jqx/config.lua\n<https://github.com/gennaro-tedesco/nvim-jqx/blob/master/lua/nvim-jqx/config.lua>\nand can be overridden at will. For example, with `lazy.nvim` you can configure\nthem as\n\n>lua\n    {\n        \"gennaro-tedesco/nvim-jqx\",\n        ...\n        init = function()\n            local jqx = require(\"nvim-jqx.config\")\n            jqx.geometry.border = \"single\"\n            jqx.geometry.width = 0.7\n            ...\n    \n            jqx.query_key = \"X\"         -- keypress to query jq on keys\n            jqx.sort = false            -- show the json keys as they appear instead of sorting them alphabetically\n            jqx.show_legend = true      -- show key queried as first line in the jqx floating window\n            jqx.use_quickfix = false    -- if you prefer the location list\n        end,\n    }\n<\n\nWhy not automatically formatting your `json` files as you open them? Set up the\nautogroup\n\n>lua\n    \n    local jqx = vim.api.nvim_create_augroup(\"Jqx\", {})\n    vim.api.nvim_clear_autocmds({ group = jqx })\n    vim.api.nvim_create_autocmd(\"BufWinEnter\", {\n        pattern = { \"*.json\", \"*.yaml\" },\n        desc = \"preview json and yaml files on open\",\n        group = jqx,\n        callback = function()\n            vim.cmd.JqxList()\n        end,\n    })\n<\n\n\nFEEDBACK                                                        *jqx-feedback*\n\nIf you find this plugin useful consider awarding it a , it is a great way to\ngive feedback! Otherwise, any additional suggestions or merge request is warmly\nwelcome!\n\n==============================================================================\n1. Links                                                           *jqx-links*\n\n1. *JqxListdemo*: https://user-images.githubusercontent.com/15387611/113495463-4bd24500-94f2-11eb-88b5-64c1ee965886.gif\n2. *JqxQuerydemo*: https://user-images.githubusercontent.com/15387611/113495732-ab7d2000-94f3-11eb-8781-0497771b60a1.gif\n3. *@kislyuk*: \n4. *@mikefarah*: \n\nGenerated by panvimdoc <https://github.com/kdheepak/panvimdoc>\n\nvim:tw=78:ts=8:noet:ft=help:norl:\n"
  },
  {
    "path": "doc/tags",
    "content": "JqxList\tjqx.txt\t/*JqxList*\nJqxQuery\tjqx.txt\t/*JqxQuery*\njqx-commands\tjqx.txt\t/*jqx-commands*\njqx-contents\tjqx.txt\t/*jqx-contents*\njqx-customisation\tjqx.txt\t/*jqx-customisation*\njqx-introduction\tjqx.txt\t/*jqx-introduction*\njqx-usage\tjqx.txt\t/*jqx-usage*\nnvim-jqx\tjqx.txt\t/*nvim-jqx*\n"
  },
  {
    "path": "examples/test.json",
    "content": "{ \"_id\": \"60411184f69184d7cbdbe207\", \"index\": 0, \"guid\": \"ac11be49-d7e5-4716-b95b-08bd7f04c631\", \"is active\": true, \"balance\": \"$1,620.45\", \"picture\": \"http://placehold.it/32x32\", \"age\": 32, \"eyeColor\": \"brown\", \"name\": \"Dianna Rowland\", \"gender\": \"female\", \"company\": \"MEGALL\", \"email\": \"diannarowland@megall.com\", \"phone\": \"+1 (989) 506-3197\", \"address\": \"587 Thatford Avenue, Brookfield, Idaho, 8295\", \"about\": \"Commodo laborum tempor et laborum sint. Id ut labore labore do ad duis fugiat sint. Id ut laborum ullamco reprehenderit Lorem fugiat nostrud aliqua aute non magna aliquip.\\r\\n\", \"registered\": \"2019-06-20T06:41:43 -02:00\", \"latitude\": 82.560783, \"longitude\": 147.725325, \"tags\": [ \"laboris\", \"cillum\", \"ullamco\", \"consectetur\", \"labore\", \"sunt\", \"occaecat\" ], \"friends\": [ { \"id\": 0, \"name\": \"Black Schroeder\" }, { \"id\": 1, \"name\": \"Sellers Garza\" }, { \"id\": 2, \"name\": \"Michael Marquez\" } ], \"morning greeting\": \"Hello, Dianna Rowland! You have 6 unread messages.\", \"favoriteFruit\": \"strawberry\" }\n"
  },
  {
    "path": "examples/test.yaml",
    "content": "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: octopus-deployment\n  labels:\n    app: web\nspec:\n  selector:\n    matchLabels:\n      octopusexport: OctopusExport\n  replicas: 1\n  strategy:\n    type: RollingUpdate\n  template:\n    metadata:\n      labels:\n        app: web\n        octopusexport: OctopusExport\n    spec:\n      containers:\n        - name: nginx\n          image: nginx\n          ports:\n            - containerPort: 80\n      affinity:\n        podAntiAffinity:\n          preferredDuringSchedulingIgnoredDuringExecution:\n            - weight: 100\n              podAffinityTerm:\n                labelSelector:\n                  matchExpressions:\n                    - key: app\n                      operator: In\n                      values:\n                        - web\n                topologyKey: kubernetes.io/hostname\n"
  },
  {
    "path": "lua/nvim-jqx/config.lua",
    "content": "local geometry = {\n\twidth = 0.4,\n\theight = 0.3,\n\twrap = true,\n\tborder = \"rounded\",\n}\n\nlocal query_key = \"X\"\n\nlocal sort = true\n\nlocal close_window_key = \"<ESC>\"\n\nlocal use_quickfix = true\n\nlocal show_legend = false\n\nreturn {\n\tgeometry = geometry,\n\tquery_key = query_key,\n\tsort = sort,\n\tclose_window_key = close_window_key,\n\tuse_quickfix = use_quickfix,\n\tshow_legend = show_legend,\n}\n"
  },
  {
    "path": "lua/nvim-jqx/floating.lua",
    "content": "local config = require(\"nvim-jqx.config\")\n\nlocal function centre_string(s)\n\tlocal shift = math.floor((vim.api.nvim_win_get_width(0) - #s) / 2)\n\treturn string.rep(\" \", shift) .. s\nend\n\nlocal function floating_window(geometry)\n\tlocal total_width = vim.api.nvim_get_option_value(\"columns\", {})\n\tlocal total_height = vim.api.nvim_get_option_value(\"lines\", {})\n\tlocal win_width = geometry.width <= 1 and math.ceil(total_width * geometry.width) or total_width\n\tlocal win_height = geometry.height <= 1 and math.ceil(total_height * geometry.height) or total_height\n\tlocal win_opts = {\n\t\trelative = \"editor\",\n\t\twidth = win_width,\n\t\theight = win_height,\n\t\trow = math.ceil((total_height - win_height) / 2 - 1),\n\t\tcol = math.ceil(total_width - win_width) / 2,\n\t\tfocusable = true,\n\t\tstyle = \"minimal\",\n\t\tborder = config.geometry.border,\n\t}\n\tlocal buf = vim.api.nvim_create_buf(false, true)\n\n\tvim.api.nvim_open_win(buf, true, win_opts)\n\tvim.api.nvim_set_option_value(\"wrap\", config.geometry.wrap, { win = 0 })\n\treturn buf\nend\n\nlocal function set_fw_opts(buf)\n\tvim.api.nvim_set_option_value(\"filetype\", \"jqx\", { buf = buf })\n\tvim.api.nvim_set_option_value(\"bufhidden\", \"wipe\", { buf = buf })\n\tvim.api.nvim_set_option_value(\"modifiable\", false, { buf = buf })\n\tvim.api.nvim_set_option_value(\"readonly\", true, { buf = buf })\n\tvim.api.nvim_buf_set_keymap(\n\t\tbuf,\n\t\t\"n\",\n\t\tconfig.close_window_key,\n\t\t\":q<CR> <C-w>j\",\n\t\t{ nowait = true, noremap = true, silent = true }\n\t)\n\tvim.treesitter.start(buf, \"json\")\nend\n\nreturn {\n\tfloating_window = floating_window,\n\tset_fw_opts = set_fw_opts,\n\tcentre_string = centre_string,\n}\n"
  },
  {
    "path": "lua/nvim-jqx/init.lua",
    "content": "--[[ this module exposes the main interface and\nuser commands that are defined in /plugin/nvim-jqx.vim ]]\n\nlocal jqx = require(\"nvim-jqx.jqx\")\nlocal config = require(\"nvim-jqx.config\")\nlocal fw = require(\"nvim-jqx.floating\")\n\n---@returns boolean\nlocal function is_valid_ft(ft)\n\tif not (ft == \"json\" or ft == \"yaml\") then\n\t\tprint(\"only json or yaml files\")\n\t\treturn false\n\tend\n\n\tif ft == \"json\" then\n\t\tif vim.fn.executable(\"jq\") == 0 then\n\t\t\tprint(\"please install jq\")\n\t\t\treturn false\n\t\tend\n\tend\n\n\tif ft == \"yaml\" then\n\t\tif vim.fn.executable(\"yq\") == 0 then\n\t\t\tprint(\"please install yq\")\n\t\t\treturn false\n\t\tend\n\tend\n\n\treturn true\nend\n\n---set keymaps in the qf to query entry on keypress\nlocal function set_qf_maps(ft)\n\tvim.api.nvim_exec2(\n\t\t[[autocmd FileType qf nnoremap <buffer> ]]\n\t\t\t.. config.query_key\n\t\t\t.. [[ :lua require(\"nvim-jqx.jqx\").on_keystroke(\"]]\n\t\t\t.. ft\n\t\t\t.. [[\")<CR> ]],\n\t\t{ output = false }\n\t)\nend\n\n---main function interface that populates the quickfix list on invocation\n---invoke set_qf_maps and jqx.populate_qf\n---@param type string variable type to fetch if given\nlocal function jqx_open(type)\n\tlocal ft = vim.bo.filetype\n\tif not is_valid_ft(ft) then\n\t\treturn nil\n\tend\n\tif ft == \"json\" then\n\t\tvim.cmd(\"%! jq .\")\n\tend\n\n\tset_qf_maps(ft)\n\tjqx.populate_qf(ft, type, config.sort)\nend\n\n---execute jq query from user input\n---@param q string user query\nlocal function query_jq(q)\n\tlocal ft = vim.bo.filetype\n\tif not is_valid_ft(ft) then\n\t\treturn nil\n\tend\n\n\t-- reads the query from user input\n\tvim.fn.inputsave()\n\tlocal input_query = q == \"\" and vim.fn.input(\"enter query: \") or q\n\tif input_query == \"\" then\n\t\tvim.cmd(\"redraw\")\n\t\tprint(\" \")\n\t\treturn nil\n\tend\n\tlocal cur_file = vim.fn.getreg(\"%\")\n\tlocal user_query = ft == \"json\" and \"jq '.\" .. input_query .. \"' \" .. cur_file\n\t\tor \"yq '.\" .. input_query .. \"' \" .. cur_file\n\tvim.fn.inputrestore()\n\n\t-- parsing query results\n\tlocal query_results = {}\n\tfor s in vim.fn.system(user_query):gmatch(\"[^\\r\\n]+\") do\n\t\ttable.insert(query_results, s)\n\tend\n\tvim.cmd(\"redraw\")\n\tprint(\" \")\n\tlocal floating_buf = fw.floating_window(config.geometry)\n\n\ttable.insert(query_results, 1, fw.centre_string(user_query))\n\ttable.insert(query_results, 2, \"\")\n\tvim.api.nvim_buf_set_lines(floating_buf, 0, -1, true, query_results)\n\tfw.set_fw_opts(floating_buf)\n\tvim.cmd('execute \"normal! gg\"')\nend\n\nreturn {\n\tjqx_open = jqx_open,\n\tquery_jq = query_jq,\n}\n"
  },
  {
    "path": "lua/nvim-jqx/jqx.lua",
    "content": "local fw = require(\"nvim-jqx.floating\")\nlocal config = require(\"nvim-jqx.config\")\n\nlocal function has_value(tab, val)\n\tfor _, value in ipairs(tab) do\n\t\tif value == val then\n\t\t\treturn true\n\t\tend\n\tend\n\treturn false\nend\n\n---remove vim special characters from json keys\n---@param key string\n---@return string \"parsed key\"\nlocal function parse_key(key)\n\treturn (key:gsub(\"/\", \"\\\\/\"))\nend\n\n---return location of key in buffer\n---@param key string\n---@param ft string\n---@return table\nlocal function get_key_location(key, ft)\n\tif ft == \"json\" then\n\t\treturn {\n\t\t\trow = vim.api.nvim_exec2([[g/^\\s*\"]] .. parse_key(key) .. [[\"/echo line('.')]], { output = true }).output,\n\t\t\tcol = vim.api.nvim_exec2(\n\t\t\t\t[[g/^\\s*\"]] .. parse_key(key) .. [[\"/execute \"normal! ^\" | echo col('.')-1]],\n\t\t\t\t{ output = true }\n\t\t\t).output,\n\t\t}\n\telseif ft == \"yaml\" then\n\t\treturn {\n\t\t\trow = vim.api.nvim_exec2([[g/^]] .. parse_key(key) .. [[/echo line('.')]], { output = true }).output,\n\t\t\tcol = vim.api.nvim_exec2(\n\t\t\t\t[[g/^]] .. parse_key(key) .. [[/execute \"normal! ^\" | echo col('.')]],\n\t\t\t\t{ output = true }\n\t\t\t).output,\n\t\t}\n\telse\n\t\treturn {}\n\tend\nend\n\n---fetch json keys for cur buf and populate qf list\n---@param ft string\n---@param type string variable type to fetch if given\n---@param sort boolean sort list alphabetically\nlocal function populate_qf(ft, type, sort)\n\tlocal cmd_lines = {}\n\tlocal cur_file = vim.fn.getreg(\"%\")\n\tif ft == \"json\" then\n\t\tlocal json_types = { \"string\", \"number\", \"boolean\", \"array\", \"object\", \"null\" }\n\t\tif has_value(json_types, type) then\n\t\t\tfor s in\n\t\t\t\tvim.fn\n\t\t\t\t\t.system(\n\t\t\t\t\t\t\"jq -c 'to_entries[] | if (.value|type == \\\"\"\n\t\t\t\t\t\t\t.. type\n\t\t\t\t\t\t\t.. \"\\\") then .key else empty end' \"\n\t\t\t\t\t\t\t.. cur_file\n\t\t\t\t\t)\n\t\t\t\t\t:gmatch(\"[^\\r\\n]+\")\n\t\t\tdo\n\t\t\t\tlocal key = s:gsub('%\"', \"\"):gsub(\"^%s*(.-)%s*$\", \"%1\"):gsub(\",\", \"\")\n\t\t\t\ttable.insert(cmd_lines, key)\n\t\t\tend\n\t\telse\n\t\t\tlocal get_keys = sort and \"jq 'keys[]' \" .. cur_file or \"jq 'keys_unsorted[]' \" .. cur_file\n\t\t\tfor s in vim.fn.system(get_keys):gmatch(\"[^\\r\\n]+\") do\n\t\t\t\tlocal key = s:gsub('%\"', \"\"):gsub(\"^%s*(.-)%s*$\", \"%1\"):gsub(\",\", \"\")\n\t\t\t\ttable.insert(cmd_lines, key)\n\t\t\tend\n\t\tend\n\telseif ft == \"yaml\" then\n\t\tfor s in vim.fn.system(\"yq 'keys[]' \" .. cur_file):gmatch(\"[^\\r\\n]+\") do\n\t\t\tlocal key = s:gsub(\"^-%s+\", \"\"):gsub('\"', \"\")\n\t\t\ttable.insert(cmd_lines, key)\n\t\tend\n\tend\n\n\tlocal qf_list = {}\n\tfor _, v in pairs(cmd_lines) do\n\t\ttable.insert(\n\t\t\tqf_list,\n\t\t\t{ filename = cur_file, lnum = get_key_location(v, ft).row, col = get_key_location(v, ft).col, text = v }\n\t\t)\n\tend\n\n\tif config.use_quickfix then\n\t\tvim.fn.setqflist(qf_list, \" \")\n\t\tvim.cmd(\"copen\")\n\telse\n\t\tvim.fn.setloclist(0, qf_list, \" \")\n\t\tvim.cmd(\"lopen\")\n\tend\nend\n\nlocal function parse_jq_query(key, cur_file, ft)\n\tlocal parsed_lines = {}\n\tif ft == \"json\" then\n\t\tlocal jq_query = tonumber(key) ~= nil and \"jq '.[\" .. key .. \"]' \" .. cur_file\n\t\t\tor \"jq '.\\\"\" .. key .. \"\\\"' \" .. cur_file\n\n\t\tfor s in vim.fn.system(jq_query):gmatch(\"[^\\r\\n]+\") do\n\t\t\ttable.insert(parsed_lines, s)\n\t\tend\n\telseif ft == \"yaml\" then\n\t\tlocal yq_query = \"yq '.\\\"\" .. key .. \"\\\"' \" .. cur_file\n\t\tfor s in vim.fn.system(yq_query):gmatch(\"[^\\r\\n]+\") do\n\t\t\ttable.insert(parsed_lines, s)\n\t\tend\n\tend\n\treturn parsed_lines\nend\n\nlocal function on_keystroke(ft)\n\tlocal line = vim.api.nvim_get_current_line()\n\tlocal words = {}\n\tfor word in line:gmatch(\"[^|]+\") do\n\t\ttable.insert(words, word:match(\"^%s*(.+)\"))\n\tend\n\tlocal key, cur_file = words[#words], words[1]\n\tlocal results = parse_jq_query(key, cur_file, ft)\n\tlocal floating_buf = fw.floating_window(config.geometry)\n\n\tif config.show_legend then\n\t\ttable.insert(results, 1, fw.centre_string(key))\n\t\ttable.insert(results, 2, \"\")\n\tend\n\tvim.api.nvim_buf_set_lines(floating_buf, 0, -1, true, results)\n\tfw.set_fw_opts(floating_buf)\n\tvim.cmd('execute \"normal! gg\"')\nend\n\nreturn {\n\tpopulate_qf = populate_qf,\n\ton_keystroke = on_keystroke,\n}\n"
  },
  {
    "path": "plugin/nvim-jqx.vim",
    "content": "if exists(\"g:loaded_jqx\")\n\tfinish\nendif\n\nnnoremap <Plug>JqxList :lua require('nvim-jqx').jqx_open()<CR>\ncommand! -complete=customlist,TypeKeys -nargs=? JqxList execute 'lua require(\"nvim-jqx\").jqx_open(\"'..<q-args>..'\")'\n\ncommand! -complete=customlist,FileKeys -nargs=? JqxQuery execute 'lua require(\"nvim-jqx\").query_jq(\"'..<q-args>..'\")<CR>'\n\nfunction! TypeKeys(A, L, P) abort\n\tif &filetype ==# 'json'\n\t\treturn ['string', 'number', 'boolean', 'array', 'object', 'null']\n\tendif\nendfunction\n\nfunction! FileKeys(A, L, P) abort\n\tif &filetype ==# 'json'\n\t\tlet a = split(system(\"jq 'keys' \" . getreg(\"%\") . \" | sed 's/,*$//g' | sed '1d;$d' \"), \"\\n\")\n\t\tcall map(a, {idx, val -> substitute(trim(val), '\\\"', '', 'g')})\n\telseif &filetype == 'yaml'\n\t\tlet a = split(system(\"yq 'keys[]' \" . getreg(\"%\")), \"\\n\")\n\t\tcall map(a, {idx, val -> substitute(trim(val), '\\\"', '', 'g')})\n\tendif\n\treturn filter(a, 'v:val =~ ''\\V\\^''.a:A')\nendfunction\n\naugroup JqxAutoClose\n\tautocmd!\n\tautocmd WinLeave * call s:JqxClose()\naugroup END\n\nfunction s:JqxClose() abort\n\tfor i in range(1, winnr('$'))\n        if getbufvar(winbufnr(i), '&filetype') ==? 'jqx'\n\t\t\tclose\n\t\tendif\n    endfor\nendfunction\n\nlet g:loaded_jqx = 1\n"
  }
]