diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/alpha/php_code_actions.lua | 11 | ||||
| -rw-r--r-- | lua/alpha/plugins.lua | 16 | ||||
| -rw-r--r-- | lua/alpha/scratchs/draft.lua | 144 | ||||
| -rw-r--r-- | lua/alpha/snips/ft/yaml.lua | 90 |
4 files changed, 158 insertions, 103 deletions
diff --git a/lua/alpha/php_code_actions.lua b/lua/alpha/php_code_actions.lua index f43245b..3d6b5e9 100644 --- a/lua/alpha/php_code_actions.lua +++ b/lua/alpha/php_code_actions.lua @@ -45,7 +45,9 @@ vim.treesitter.set_query( ]] ) -local php_setter_getter_actions = { +local M = {} + +M.php_setter_getter_actions = { method = null_ls.methods.CODE_ACTION, filetypes = { "php" }, generator = { @@ -86,6 +88,7 @@ local php_setter_getter_actions = { for _, match in comment_query:iter_matches(test_node, 0) do for _, subNode in pairs(match) do local type = get_node_text(subNode, 0) + P(type) if type ~= "null" then table.insert(property_types, type) else @@ -94,6 +97,7 @@ local php_setter_getter_actions = { end end + P(property_types) local getter = generator.getGetter(property_name, nullable, property_types) local setter = generator.getSetter(property_name, nullable, property_types) @@ -126,6 +130,5 @@ local php_setter_getter_actions = { end, }, } --- uncomment when not developing this -null_ls.reset_sources() -null_ls.register(php_setter_getter_actions) + +return M diff --git a/lua/alpha/plugins.lua b/lua/alpha/plugins.lua index a82dfca..b736e1b 100644 --- a/lua/alpha/plugins.lua +++ b/lua/alpha/plugins.lua @@ -95,10 +95,6 @@ return require("packer").startup(function(use) "jose-elias-alvarez/null-ls.nvim", }) - use("github/copilot.vim") - - use("kdheepak/lazygit.nvim") - use({ "nvim-telescope/telescope.nvim", requires = { @@ -127,10 +123,6 @@ return require("packer").startup(function(use) end, }) - -- use({ - -- "nvim-lualine/lualine.nvim", - -- requires = { "kyazdani42/nvim-web-devicons", opt = true }, - -- }) use("feline-nvim/feline.nvim") use({ @@ -143,13 +135,7 @@ return require("packer").startup(function(use) }, }) - use({ - "noahfrederick/vim-laravel", - requires = { - { "tpope/vim-projectionist" }, - { "noahfrederick/vim-composer" }, - }, - }) + use({ "noahfrederick/vim-composer" }) use({ "folke/trouble.nvim", diff --git a/lua/alpha/scratchs/draft.lua b/lua/alpha/scratchs/draft.lua index 32b9c8d..8954fdc 100644 --- a/lua/alpha/scratchs/draft.lua +++ b/lua/alpha/scratchs/draft.lua @@ -1,100 +1,76 @@ -local api = vim.api - -function GlobalFunction() - local position_params = vim.lsp.util.make_position_params() - P(position_params) - - vim.lsp.buf_request(0, "textDocument/completion", position_params, function(err, result) - if vim.tbl_isempty(result or {}) then return end - - local textEdit = result.items[1].additionalTextEdits; - - local bufnr = vim.api.nvim_get_current_buf() - vim.lsp.util.apply_text_edits(textEdit, bufnr) - end) -end - -local ts_locals = require "nvim-treesitter.locals" -local ts_utils = require "nvim-treesitter.ts_utils" - +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 get_root_node() - local node = ts_utils.get_node_at_cursor() - if node == nil then - error("No treesitter parser found.") - end - - local parent = node:parent() - while (parent ~= nil) do - node = parent - parent = node:parent() - end - - return node -end - --- this function allows me to retrieve all the queries or mutations --- from the yaml file --- next integrate with telescope to quick search --- actions, go to the file line --- new action open the php class on the method (lsp maybe, but the problem is not attached) -function Queries() +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) @name)) -)))))))))) - ) -) + (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 rootNode = get_root_node() - for _, node in query:iter_captures(rootNode, 0, rootNode:start(), rootNode:end_()) do - P(get_node_text(node, 0)) - P(node:start()) - P(node:end_()) + local elements = {} + + local parsers = require("nvim-treesitter.parsers") + local parser = parsers.get_parser(0) + ---@diagnostic disable-next-line: deprecated + 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 -end -local function get_visual_selection() - local s_start = vim.fn.getpos("'<") - local s_end = vim.fn.getpos("'>") - local n_lines = math.abs(s_end[2] - s_start[2]) + 1 - local lines = vim.api.nvim_buf_get_lines(0, s_start[2] - 1, s_end[2], false) - lines[1] = string.sub(lines[1], s_start[3], -1) - if n_lines == 1 then - lines[n_lines] = string.sub(lines[n_lines], 1, s_end[3] - s_start[3] + 1) - else - lines[n_lines] = string.sub(lines[n_lines], 1, s_end[3]) - end - return table.concat(lines, '\n') + return elements end -function GetPhpString() - local s_start = vim.fn.getpos("'<") - local s_end = vim.fn.getpos("'>") - local text = get_visual_selection() - P(text) - local result = vim.fn.system("php -r 'echo \"" .. text .. "\";'") - vim.api.nvim_put({result}, "", true, false) - P(result) - vim.api.nvim_buf_set_text(0, s_start[2] -1 , s_start[3] -1, s_end[2] -1, s_end[3], {result}) +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 - -vim.keymap.set('n', '<leader>rrh', GetPhpString, {}) diff --git a/lua/alpha/snips/ft/yaml.lua b/lua/alpha/snips/ft/yaml.lua new file mode 100644 index 0000000..708a67e --- /dev/null +++ b/lua/alpha/snips/ft/yaml.lua @@ -0,0 +1,90 @@ +local ls = require("luasnip") + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local f = ls.function_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt + +local M = { + str = fmt([[{}: + type: string +{}]], { + i(1, ""), + i(2, ""), + }), + bool = fmt([[{}: + type: boolean +{}]], { + i(1, ""), + i(2, ""), + }), + float = fmt([[{}: + type: number + format: float +{}]], { + i(1, ""), + i(2, "") + }), + int = fmt([[{}: + type: integer +{}]], { + i(1, ""), + i(2, "") + }), + id = fmt([[{}: + type: integer + format: int64 +{}]], { + i(1, ""), + i(2, "") + }), + class = fmt([[{}: + $ref: '#/components/schemas/{}' +{}]], { + i(1, ""), + i(2, ""), + i(3, "") + }), + date = fmt([[{}: + type: string + format: date-time +{}]], { + i(1, ""), + i(2, "") + }), + arr = fmt([[{}: + type: array + items: + {} +{}]], { + i(1, ""), + i(2, ""), + i(3, "") + }), + ref = fmt([[$ref: '#/components/schemas/{}']], {i(1, "")}), + obj = fmt([[type: object +properties: + {}]], i(1, "")), + aint = fmt([[{}: + type: array + items: + type: int + format: int64 +{}]], { + i(1, ""), + i(2, ""), + }), + astr = fmt([[{}: + type: array + items: + type: string +{}]], { + i(1, ""), + i(2, ""), + }), +} + +return M |