diff options
| author | Ariel D'Alessandro <ariel.dalessandro@auto1.com> | 2022-09-20 17:45:11 +0200 |
|---|---|---|
| committer | Ariel D'Alessandro <ariel.dalessandro@auto1.com> | 2022-09-20 17:45:44 +0200 |
| commit | 7701e1e3ebf73c58d2636a0707c08dca459a15ff (patch) | |
| tree | e2972ebb504088f4cc65cbbae699775c3f75c070 /lua/alpha/scratchs/graphql_queries.lua | |
| parent | 0dbf8150681d38907a29a4aa1893faa3bda4b9c6 (diff) | |
| download | nvim-conf-7701e1e3ebf73c58d2636a0707c08dca459a15ff.tar.gz nvim-conf-7701e1e3ebf73c58d2636a0707c08dca459a15ff.zip | |
disable hydra since was not working for the window as I was expecting
Diffstat (limited to 'lua/alpha/scratchs/graphql_queries.lua')
| -rw-r--r-- | lua/alpha/scratchs/graphql_queries.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/lua/alpha/scratchs/graphql_queries.lua b/lua/alpha/scratchs/graphql_queries.lua new file mode 100644 index 0000000..3997d86 --- /dev/null +++ b/lua/alpha/scratchs/graphql_queries.lua @@ -0,0 +1,75 @@ +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local conf = require("telescope.config").values +local action_state = require("telescope.actions.state") +local action_set = require("telescope.actions.set") +local get_node_text = vim.treesitter.get_node_text + +local function getElements() + vim.treesitter.set_query( + "yaml", + "GraphQL_endpoints", + [[ + (document (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @mutation + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @resolve (#eq? @resolve "resolve") + value: (flow_node) @resolver + ))) + ))) + ))) + ))) + )))) + ]] + ) + + local query = vim.treesitter.get_query("yaml", "GraphQL_endpoints") + + local elements = {} + + local parsers = require("nvim-treesitter.parsers") + local parser = parsers.get_parser(0) + local tree = unpack(parser:parse()) + + for id, node in query:iter_captures(tree:root(), 0) do + if query.captures[id] == "mutation" then + table.insert(elements, { get_node_text(node, 0), node:start() + 1 }) + end + end + + return elements +end + +function Queries(opts) + opts = opts or {} + pickers.new(opts, { + promt_title = "Queries", + finder = finders.new_table({ + results = getElements(), + entry_maker = function(entry) + return { + value = entry, + display = entry[1], + ordinal = entry[1], + path = vim.api.nvim_buf_get_name(0), + lnum = entry[2], + } + end, + }), + sorter = conf.generic_sorter(opts), + previewer = conf.grep_previewer(opts), + attach_mappings = function() + action_set.select:enhance({ + post = function() + local selection = action_state.get_selected_entry() + vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) + end, + }) + + return true + end, + }):find() +end |