aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha/scratchs/graphql_queries.lua
diff options
context:
space:
mode:
authorAriel D'Alessandro <ariel.dalessandro@auto1.com>2022-09-26 09:17:39 +0200
committerAriel D'Alessandro <ariel.dalessandro@auto1.com>2022-09-26 09:18:14 +0200
commitb2ea5bb4976ad786a104d5539d47645ddef237a9 (patch)
tree63ced30c20f1ca65c23a009d316e5d5cbfdef3c4 /lua/alpha/scratchs/graphql_queries.lua
parent4457e657255ba071497b30356676a42f6f184cdf (diff)
downloadnvim-conf-b2ea5bb4976ad786a104d5539d47645ddef237a9.tar.gz
nvim-conf-b2ea5bb4976ad786a104d5539d47645ddef237a9.zip
Add gateway graphql queries search
Diffstat (limited to 'lua/alpha/scratchs/graphql_queries.lua')
-rw-r--r--lua/alpha/scratchs/graphql_queries.lua75
1 files changed, 0 insertions, 75 deletions
diff --git a/lua/alpha/scratchs/graphql_queries.lua b/lua/alpha/scratchs/graphql_queries.lua
deleted file mode 100644
index 3997d86..0000000
--- a/lua/alpha/scratchs/graphql_queries.lua
+++ /dev/null
@@ -1,75 +0,0 @@
-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