From 669561e21073e6efafddda25ba3ace69fb43819e Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Tue, 31 Jan 2023 09:44:13 +0100 Subject: feat: apply stylua --- lua/alpha/completition/init.lua | 210 ++++++++++++------------- lua/alpha/dap.lua | 272 ++++++++++++++++---------------- lua/alpha/database.lua | 66 ++++---- lua/alpha/globals.lua | 16 +- lua/alpha/harpoon.lua | 51 +++--- lua/alpha/laravel-tinker.lua | 99 ++++++------ lua/alpha/lsp/attach.lua | 49 +++--- lua/alpha/lsp/init.lua | 18 +-- lua/alpha/lsp/mason.lua | 16 +- lua/alpha/lsp/null-ls.lua | 55 +++---- lua/alpha/lsp/servers.lua | 22 +-- lua/alpha/lsp/setups.lua | 134 ++++++++-------- lua/alpha/lsp/tools.lua | 4 +- lua/alpha/php/gateway.lua | 198 +++++++++++------------ lua/alpha/php/lsp.lua | 197 ++++++++++++----------- lua/alpha/php/servers.lua | 42 +++-- lua/alpha/scratchs/behat-test.lua | 111 +++++++------ lua/alpha/scratchs/laravel.lua | 2 +- lua/alpha/scratchs/sample.lua | 36 ++--- lua/alpha/snips/ft/cucumber.lua | 7 +- lua/alpha/snips/ft/go.lua | 190 +++++++++++----------- lua/alpha/snips/ft/lua.lua | 82 +++++----- lua/alpha/snips/ft/php.lua | 198 +++++++++++------------ lua/alpha/snips/ft/yaml.lua | 258 +++++++++++++++--------------- lua/alpha/telescope/actions.lua | 230 +++++++++++++-------------- lua/alpha/telescope/init.lua | 210 ++++++++++++------------- lua/alpha/telescope/mappings.lua | 24 +-- lua/alpha/telescope/setup.lua | 320 +++++++++++++++++++------------------- lua/alpha/utils.lua | 30 ++-- lua/config/autocmds.lua | 10 +- lua/config/diagnostic.lua | 10 +- lua/config/init.lua | 18 +-- lua/config/keymaps.lua | 2 +- lua/config/lazy.lua | 66 ++++---- lua/config/options.lua | 4 +- lua/plugins/autopairs.lua | 6 +- lua/plugins/colorscheme.lua | 18 +-- lua/plugins/comment.lua | 6 +- lua/plugins/completition.lua | 36 ++--- lua/plugins/composer.lua | 4 +- lua/plugins/dap.lua | 54 +++---- lua/plugins/database.lua | 20 +-- lua/plugins/dressing.lua | 310 ++++++++++++++++++------------------ lua/plugins/easy-align.lua | 4 +- lua/plugins/fugitive.lua | 18 +-- lua/plugins/gitsigns.lua | 38 ++--- lua/plugins/harpoon.lua | 18 +-- lua/plugins/icon-picker.lua | 14 +- lua/plugins/indent-blankline.lua | 4 +- lua/plugins/init.lua | 20 +-- lua/plugins/laravel.lua | 28 ++-- lua/plugins/lazygit.lua | 4 +- lua/plugins/lsp.lua | 48 +++--- lua/plugins/lualine.lua | 89 ++++++----- lua/plugins/mind.lua | 26 ++-- lua/plugins/neogen.lua | 12 +- lua/plugins/neotest.lua | 110 ++++++------- lua/plugins/notify.lua | 16 +- lua/plugins/project-config.lua | 4 +- lua/plugins/refactoring.lua | 28 ++-- lua/plugins/rest.lua | 77 ++++----- lua/plugins/snippets.lua | 233 ++++++++++++++------------- lua/plugins/telescope.lua | 50 +++--- lua/plugins/test.lua | 68 ++++---- lua/plugins/todo-comments.lua | 38 ++--- lua/plugins/transparent.lua | 34 ++-- lua/plugins/treesitter.lua | 152 ++++++++++-------- lua/plugins/trouble.lua | 8 +- lua/plugins/worktree.lua | 26 +++- 69 files changed, 2454 insertions(+), 2424 deletions(-) (limited to 'lua') diff --git a/lua/alpha/completition/init.lua b/lua/alpha/completition/init.lua index 2951608..9955d4e 100644 --- a/lua/alpha/completition/init.lua +++ b/lua/alpha/completition/init.lua @@ -1,127 +1,127 @@ -local cmp = require("cmp") -local lspkind = require("lspkind") -local luasnip = require("luasnip") -local cmp_autopairs = require("nvim-autopairs.completion.cmp") -local compare = require('cmp.config.compare') +local cmp = require "cmp" +local lspkind = require "lspkind" +local luasnip = require "luasnip" +local cmp_autopairs = require "nvim-autopairs.completion.cmp" +local compare = require "cmp.config.compare" -cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } })) +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } }) -cmp.setup({ - mapping = { - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.close() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.choice_active() then - luasnip.change_choice(1) - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }), - [""] = cmp.mapping.complete(), - }, - sources = { - { name = "nvim_lua" }, - { name = "nvim_lsp" }, - { name = "path" }, - { name = "luasnip" }, - { name = 'nvim_lsp_signature_help' }, - { - name = "buffer", - keyword_length = 4, - option = { - get_bufnrs = function() - local bufs = {} - for _, win in ipairs(vim.api.nvim_list_wins()) do - bufs[vim.api.nvim_win_get_buf(win)] = true - end - return vim.tbl_keys(bufs) - end, - }, - }, - }, +cmp.setup { + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + [""] = cmp.mapping.complete(), + }, + sources = { + { name = "nvim_lua" }, + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "nvim_lsp_signature_help" }, + { + name = "buffer", + keyword_length = 4, + option = { + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + bufs[vim.api.nvim_win_get_buf(win)] = true + end + return vim.tbl_keys(bufs) + end, + }, + }, + }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, - formatting = { - format = lspkind.cmp_format({ - with_text = true, - menu = { - buffer = "[buf]", - nvim_lsp = "[LSP]", - nvim_lua = "[api]", - path = "[path]", - luasnip = "[snip]", - ["vim-dadbod-completion"] = "[DB]", - }, - }), - }, + formatting = { + format = lspkind.cmp_format { + with_text = true, + menu = { + buffer = "[buf]", + nvim_lsp = "[LSP]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + ["vim-dadbod-completion"] = "[DB]", + }, + }, + }, - sorting = { - priority_weight = 2, - comparators = { - compare.kind, - compare.sort_text, - } - }, + sorting = { + priority_weight = 2, + comparators = { + compare.kind, + compare.sort_text, + }, + }, - experimental = { - native_menu = false, + experimental = { + native_menu = false, - ghost_text = true, - }, -}) + ghost_text = true, + }, +} -- Set configuration for specific filetype. cmp.setup.filetype("gitcommit", { - sources = cmp.config.sources({ - { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = "buffer" }, - }), + sources = cmp.config.sources({ + { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = "buffer" }, + }), }) -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline("/", { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer" }, - }, + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "path" }, - }, { - { name = "cmdline" }, - }), + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), }) cmp.setup.filetype({ "sql", "mysql", "plsql" }, { - sources = cmp.config.sources({ - { name = "vim-dadbod-completion" }, - }, { - { name = "buffer" }, - }), + sources = cmp.config.sources({ + { name = "vim-dadbod-completion" }, + }, { + { name = "buffer" }, + }), }) diff --git a/lua/alpha/dap.lua b/lua/alpha/dap.lua index ee53443..a89d72e 100644 --- a/lua/alpha/dap.lua +++ b/lua/alpha/dap.lua @@ -1,33 +1,33 @@ -local dap, dapui, dap_go = require("dap"), require("dapui"), require("dap-go") +local dap, dapui, dap_go = require "dap", require "dapui", require "dap-go" -require("nvim-dap-virtual-text").setup({}) +require("nvim-dap-virtual-text").setup {} -- dap.set_log_level('TRACE') dap_go.setup() -dapui.setup({ - icons = { expanded = "▾", collapsed = "▸" }, - layouts = { - { - elements = { - "scopes", - "breakpoints", - "stacks", - "watches", - }, - size = 80, - position = "left", - }, - { - elements = { - "repl", - "console", - }, - size = 10, - position = "bottom", - }, - }, -}) +dapui.setup { + icons = { expanded = "▾", collapsed = "▸" }, + layouts = { + { + elements = { + "scopes", + "breakpoints", + "stacks", + "watches", + }, + size = 80, + position = "left", + }, + { + elements = { + "repl", + "console", + }, + size = 10, + position = "bottom", + }, + }, +} vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" }) vim.fn.sign_define("DapStopped", { text = "▶", texthl = "", linehl = "", numhl = "" }) @@ -36,83 +36,83 @@ vim.fn.sign_define("DapBreakpointCondition", { text = "❓", texthl = "", linehl vim.fn.sign_define("DapLogPoint", { text = "💬", texthl = "", linehl = "", numhl = "" }) dap.adapters.php = { - type = "executable", - command = "php-debug-adapter", + type = "executable", + command = "php-debug-adapter", } dap.configurations.php = { - { - type = "php", - request = "launch", - name = "Laravel", - port = 9003, - pathMappings = { - ["/var/www/html"] = "${workspaceFolder}", - }, - }, - { - type = "php", - request = "launch", - name = "Symfony", - port = 9003, - pathMappings = { - ["/app"] = "${workspaceFolder}", - }, - }, + { + type = "php", + request = "launch", + name = "Laravel", + port = 9003, + pathMappings = { + ["/var/www/html"] = "${workspaceFolder}", + }, + }, + { + type = "php", + request = "launch", + name = "Symfony", + port = 9003, + pathMappings = { + ["/app"] = "${workspaceFolder}", + }, + }, } -require("dap-vscode-js").setup({ - debugger_cmd = { "js-debug-adapter" }, - adapters = { "pwa-node", "pwa-chrome", "node-terminal" }, -}) +require("dap-vscode-js").setup { + debugger_cmd = { "js-debug-adapter" }, + adapters = { "pwa-node", "pwa-chrome", "node-terminal" }, +} -for _, language in ipairs({ "typescript", "javascript" }) do - require("dap").configurations[language] = { - { - type = "pwa-node", - request = "launch", - name = "Launch file", - program = "${file}", - cwd = "${workspaceFolder}", - }, - { - type = "pwa-node", - request = "attach", - name = "Attach", - processId = require("dap.utils").pick_process, - cwd = "${workspaceFolder}", - }, - } +for _, language in ipairs { "typescript", "javascript" } do + require("dap").configurations[language] = { + { + type = "pwa-node", + request = "launch", + name = "Launch file", + program = "${file}", + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "attach", + name = "Attach", + processId = require("dap.utils").pick_process, + cwd = "${workspaceFolder}", + }, + } end -for _, language in ipairs({ "typescriptreact", "javascriptreact" }) do - require("dap").configurations[language] = { - { - type = "pwa-chrome", - name = "Attach - Remote Debugging", - request = "attach", - program = "${file}", - cwd = vim.fn.getcwd(), - sourceMaps = true, - protocol = "inspector", - port = 9222, - webRoot = "${workspaceFolder}", - }, - { - type = "pwa-chrome", - name = "Launch Chrome", - request = "launch", - url = "http://localhost:3000", - }, - } +for _, language in ipairs { "typescriptreact", "javascriptreact" } do + require("dap").configurations[language] = { + { + type = "pwa-chrome", + name = "Attach - Remote Debugging", + request = "attach", + program = "${file}", + cwd = vim.fn.getcwd(), + sourceMaps = true, + protocol = "inspector", + port = 9222, + webRoot = "${workspaceFolder}", + }, + { + type = "pwa-chrome", + name = "Launch Chrome", + request = "launch", + url = "http://localhost:3000", + }, + } end -- Events Listeners dap.listeners.after.event_initialized["dapui_config"] = function() - dapui.open({}) + dapui.open {} end -local hydra = require("hydra") +local hydra = require "hydra" local hint = [[ Nvim DAP _d_: Start/Continue _j_: StepOver _k_: StepOut _l_: StepInto ^ @@ -124,52 +124,52 @@ local hint = [[ ^^ __ ]] -hydra({ - name = "dap", - hint = hint, - mode = "n", - config = { - color = "blue", - invoke_on_body = true, - hint = { - border = "rounded", - position = "bottom", - }, - }, - body = "d", - heads = { - { "d", dap.continue }, - { "bp", dap.toggle_breakpoint }, - { "l", dap.step_into }, - { "j", dap.step_over }, - { "k", dap.step_out }, - { "h", dapui.eval }, - { "c", dap.run_to_cursor }, - { - "bc", - function() - vim.ui.input({ prompt = "Condition: " }, function(condition) - dap.set_breakpoint(condition) - end) - end, - }, - { - "?", - function() - vim.ui.input({ prompt = "Log: " }, function(log) - dap.set_breakpoint(nil, nil, log) - end) - end, - }, - { - "x", - function() - dap.terminate() - dapui.close({}) - dap.clear_breakpoints() - end, - }, +hydra { + name = "dap", + hint = hint, + mode = "n", + config = { + color = "blue", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "d", + heads = { + { "d", dap.continue }, + { "bp", dap.toggle_breakpoint }, + { "l", dap.step_into }, + { "j", dap.step_over }, + { "k", dap.step_out }, + { "h", dapui.eval }, + { "c", dap.run_to_cursor }, + { + "bc", + function() + vim.ui.input({ prompt = "Condition: " }, function(condition) + dap.set_breakpoint(condition) + end) + end, + }, + { + "?", + function() + vim.ui.input({ prompt = "Log: " }, function(log) + dap.set_breakpoint(nil, nil, log) + end) + end, + }, + { + "x", + function() + dap.terminate() + dapui.close {} + dap.clear_breakpoints() + end, + }, - { "", nil, { exit = true } }, - }, -}) + { "", nil, { exit = true } }, + }, +} diff --git a/lua/alpha/database.lua b/lua/alpha/database.lua index 32121eb..39e9769 100644 --- a/lua/alpha/database.lua +++ b/lua/alpha/database.lua @@ -1,43 +1,43 @@ vim.g.db_ui_use_nerd_fonts = 1 vim.g.db_ui_show_database_icon = 1 vim.g.db_ui_force_echo_notifications = 1 -vim.g.db_ui_win_position = 'right' +vim.g.db_ui_win_position = "right" vim.g.db_ui_winwidth = 80 vim.g.db_ui_table_helpers = { - mysql = { - Count = "select count(1) from {optional_schema}{table}", - Explain = "EXPLAIN {last_query}" - }, - sqlite = { - Describe = "PRAGMA table_info({table})" - } + mysql = { + Count = "select count(1) from {optional_schema}{table}", + Explain = "EXPLAIN {last_query}", + }, + sqlite = { + Describe = "PRAGMA table_info({table})", + }, } vim.g.db_ui_icons = { - expanded = { - db = '▾ ', - buffers = '▾ ', - saved_queries = '▾ ', - schemas = '▾ ', - schema = '▾ פּ', - tables = '▾ 藺', - table = '▾ ', - }, - collapsed = { - db = '▸ ', - buffers = '▸ ', - saved_queries = '▸ ', - schemas = '▸ ', - schema = '▸ פּ', - tables = '▸ 藺', - table = '▸ ', - }, - saved_query = '', - new_query = '璘', - tables = '離', - buffers = '﬘', - add_connection = '', - connection_ok = '✓', - connection_error = '✕', + expanded = { + db = "▾ ", + buffers = "▾ ", + saved_queries = "▾ ", + schemas = "▾ ", + schema = "▾ פּ", + tables = "▾ 藺", + table = "▾ ", + }, + collapsed = { + db = "▸ ", + buffers = "▸ ", + saved_queries = "▸ ", + schemas = "▸ ", + schema = "▸ פּ", + tables = "▸ 藺", + table = "▸ ", + }, + saved_query = "", + new_query = "璘", + tables = "離", + buffers = "﬘", + add_connection = "", + connection_ok = "✓", + connection_error = "✕", } diff --git a/lua/alpha/globals.lua b/lua/alpha/globals.lua index 5fcee70..d6fd70c 100644 --- a/lua/alpha/globals.lua +++ b/lua/alpha/globals.lua @@ -1,13 +1,13 @@ -P = function (v) - print(vim.inspect(v)) - return v +P = function(v) + print(vim.inspect(v)) + return v end -RELOAD = function (...) - return require("plenary.reload").reload_module(...) +RELOAD = function(...) + return require("plenary.reload").reload_module(...) end -R = function (name) - RELOAD(name) - return require(name) +R = function(name) + RELOAD(name) + return require(name) end diff --git a/lua/alpha/harpoon.lua b/lua/alpha/harpoon.lua index 209424f..78e6e9b 100644 --- a/lua/alpha/harpoon.lua +++ b/lua/alpha/harpoon.lua @@ -1,43 +1,44 @@ -local M = {}; +local M = {} -- changing this values will require re-compile packer local terms = vim.g.harpoon_terms or 3 local quick_binds = vim.g.harpoon_quick_binds or 5 M.keymaps = { - {"ss"}, - {"sa"}, + { "ss" }, + { "sa" }, } for i = 1, terms do - table.insert(M.keymaps, {string.format("%s", i)}) + table.insert(M.keymaps, { string.format("%s", i) }) end for i = 1, quick_binds do - table.insert(M.keymaps, {string.format("%s", i)}) + table.insert(M.keymaps, { string.format("%s", i) }) end M.setup = function() - require('harpoon').setup() - - vim.keymap.set('n', 'ss', require("harpoon.ui").toggle_quick_menu, { noremap = true, silent = true, expr = false }) - vim.keymap.set('n', 'sa', require("harpoon.mark").add_file, { noremap = true, silent = true, expr = false }) - - for i = 1, terms do - vim.keymap.set('n', string.format('%s', i), function() require("harpoon.term").gotoTerminal(i) end, - { noremap = true, silent = true, expr = false }) - end - - for i = 1, quick_binds do - vim.keymap.set( - 'n', - string.format("%s", i), - function() - require("harpoon.ui").nav_file(i) - end, - { noremap = true, silent = true, expr = false } - ) - end + require("harpoon").setup() + + vim.keymap.set( + "n", + "ss", + require("harpoon.ui").toggle_quick_menu, + { noremap = true, silent = true, expr = false } + ) + vim.keymap.set("n", "sa", require("harpoon.mark").add_file, { noremap = true, silent = true, expr = false }) + + for i = 1, terms do + vim.keymap.set("n", string.format("%s", i), function() + require("harpoon.term").gotoTerminal(i) + end, { noremap = true, silent = true, expr = false }) + end + + for i = 1, quick_binds do + vim.keymap.set("n", string.format("%s", i), function() + require("harpoon.ui").nav_file(i) + end, { noremap = true, silent = true, expr = false }) + end end return M diff --git a/lua/alpha/laravel-tinker.lua b/lua/alpha/laravel-tinker.lua index fa23346..214d958 100644 --- a/lua/alpha/laravel-tinker.lua +++ b/lua/alpha/laravel-tinker.lua @@ -1,67 +1,64 @@ local M = {} +M.runCode = function() + local curBuff = vim.api.nvim_get_current_buf() -M.runCode = function () - local curBuff = vim.api.nvim_get_current_buf() + local stats = vim.api.nvim_list_uis()[1] - local stats = vim.api.nvim_list_uis()[1] + local width = stats.width + local height = stats.height - local width = stats.width - local height = stats.height + local bufh = vim.api.nvim_create_buf(false, true) + local winId = vim.api.nvim_open_win(bufh, true, { + relative = "editor", + width = width * 0.75, + height = height * 0.75, + col = 2, + row = 2, + style = "minimal", + border = "rounded", + }) - local bufh = vim.api.nvim_create_buf(false, true) - local winId = vim.api.nvim_open_win(bufh, true, { - relative = "editor", - width = width * 0.75, - height = height * 0.75, - col = 2, - row = 2, - style = "minimal", - border = "rounded", - }) + -- get the start and end lines of selection + local startLine = vim.api.nvim_buf_get_mark(curBuff, "<")[1] - 1 + local endLine = vim.api.nvim_buf_get_mark(curBuff, ">")[1] + -- print("range: ", startLine, endLine) - -- get the start and end lines of selection - local startLine = vim.api.nvim_buf_get_mark(curBuff, "<")[1] -1 - local endLine = vim.api.nvim_buf_get_mark(curBuff, ">")[1] - -- print("range: ", startLine, endLine) + local code = vim.api.nvim_buf_get_lines(curBuff, startLine, endLine, false) - local code = vim.api.nvim_buf_get_lines(curBuff, startLine, endLine, false); + -- print (vim.inspect(code)) - -- print (vim.inspect(code)) + local codeText = vim.fn.shellescape(table.concat(code, " ")) + -- print(codeText) - local codeText = vim.fn.shellescape(table.concat(code, " ")) - -- print(codeText) + local result = vim.fn.systemlist("php artisan tinker --execute=" .. codeText) - - local result = vim.fn.systemlist('php artisan tinker --execute=' .. codeText) - - vim.api.nvim_buf_set_text(bufh, 0, 0, 0, 0, result) + vim.api.nvim_buf_set_text(bufh, 0, 0, 0, 0, result) end -M.backTerminal = function () - local bufh = vim.api.nvim_create_buf(false, true) - local term = vim.api.nvim_open_term(bufh, {}) - - local winId = vim.api.nvim_open_win(bufh, true, { - relative = "editor", - width = 80, - height = 80, - col = 2, - row = 2, - style = "minimal", - border = "rounded", - }) - - local jobId = vim.fn.jobstart("php artisan tinker", { - on_stdout = function (err, data) - print(err, vim.inspect(data)) - vim.api.nvim_chan_send(term, table.concat(data, "\n")) - end - }) - - vim.api.nvim_chan_send(jobId, "$ub = UploadBatch::find(1);\n") - vim.api.nvim_chan_send(jobId, "dump($ub);\n") +M.backTerminal = function() + local bufh = vim.api.nvim_create_buf(false, true) + local term = vim.api.nvim_open_term(bufh, {}) + + local winId = vim.api.nvim_open_win(bufh, true, { + relative = "editor", + width = 80, + height = 80, + col = 2, + row = 2, + style = "minimal", + border = "rounded", + }) + + local jobId = vim.fn.jobstart("php artisan tinker", { + on_stdout = function(err, data) + print(err, vim.inspect(data)) + vim.api.nvim_chan_send(term, table.concat(data, "\n")) + end, + }) + + vim.api.nvim_chan_send(jobId, "$ub = UploadBatch::find(1);\n") + vim.api.nvim_chan_send(jobId, "dump($ub);\n") end - return M diff --git a/lua/alpha/lsp/attach.lua b/lua/alpha/lsp/attach.lua index ce63e02..fa67b2e 100644 --- a/lua/alpha/lsp/attach.lua +++ b/lua/alpha/lsp/attach.lua @@ -1,29 +1,34 @@ -local telescope_mapper = require("alpha.telescope.mappings") +local telescope_mapper = require "alpha.telescope.mappings" local filetype_attach = setmetatable({}, { - __index = function() - return function() end - end, + __index = function() + return function() end + end, }) -return function (client, bufnr) - local filetype = vim.api.nvim_buf_get_option(0, "filetype") - -- keymaps for lsp - vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0 }) - vim.keymap.set("n", "vrn", vim.lsp.buf.rename, { buffer = 0 }) - vim.keymap.set("i", "", vim.lsp.buf.signature_help, { buffer = 0 }) - vim.keymap.set("n", "vo", ":LspRestart", { noremap = true }) - vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, {}) - vim.keymap.set("n", "vf", function() - return vim.lsp.buf.format({ async = true }) - end, {}) +return function(client, bufnr) + local filetype = vim.api.nvim_buf_get_option(0, "filetype") + -- keymaps for lsp + vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0 }) + vim.keymap.set("n", "vrn", vim.lsp.buf.rename, { buffer = 0 }) + vim.keymap.set("i", "", vim.lsp.buf.signature_help, { buffer = 0 }) + vim.keymap.set("n", "vo", ":LspRestart", { noremap = true }) + vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, {}) + vim.keymap.set("n", "vf", function() + return vim.lsp.buf.format { + async = true, + filter = function(cli) + return cli.name ~= "sumneko_lua" + end, + } + end, {}) - telescope_mapper("gr", "lsp_references", nil, true) - telescope_mapper("pv", "find_symbol", nil, true) - telescope_mapper("pd", "lsp_document_symbols", nil, true) - telescope_mapper("", "lsp_definitions", nil, true) + telescope_mapper("gr", "lsp_references", nil, true) + telescope_mapper("pv", "find_symbol", nil, true) + telescope_mapper("pd", "lsp_document_symbols", nil, true) + telescope_mapper("", "lsp_definitions", nil, true) - vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" + vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" - -- Attach any filetype specific options to the client - filetype_attach[filetype](client, bufnr) + -- Attach any filetype specific options to the client + filetype_attach[filetype](client, bufnr) end diff --git a/lua/alpha/lsp/init.lua b/lua/alpha/lsp/init.lua index c29472d..01bb3c1 100644 --- a/lua/alpha/lsp/init.lua +++ b/lua/alpha/lsp/init.lua @@ -1,14 +1,14 @@ -- LSP configuration -- install servers and tools -require('alpha.lsp.mason') -local setups = require("alpha.lsp.setups") +require "alpha.lsp.mason" +local setups = require "alpha.lsp.setups" -local lspconfig = require('lspconfig') -require('mason-lspconfig').setup_handlers({ - function (server_name) - lspconfig[server_name].setup(setups[server_name]()) - end -}) +local lspconfig = require "lspconfig" +require("mason-lspconfig").setup_handlers { + function(server_name) + lspconfig[server_name].setup(setups[server_name]()) + end, +} -require('alpha.lsp.null-ls') +require "alpha.lsp.null-ls" diff --git a/lua/alpha/lsp/mason.lua b/lua/alpha/lsp/mason.lua index 9dab32e..345301a 100644 --- a/lua/alpha/lsp/mason.lua +++ b/lua/alpha/lsp/mason.lua @@ -1,12 +1,12 @@ -local mason = require("mason") -local mason_lspconfig = require("mason-lspconfig") +local mason = require "mason" +local mason_lspconfig = require "mason-lspconfig" mason.setup() -mason_lspconfig.setup({ - ensure_installed = require('alpha.lsp.servers'), -}) +mason_lspconfig.setup { + ensure_installed = require "alpha.lsp.servers", +} -require('mason-tool-installer').setup({ - ensure_installed = require('alpha.lsp.tools'), -}) +require("mason-tool-installer").setup { + ensure_installed = require "alpha.lsp.tools", +} diff --git a/lua/alpha/lsp/null-ls.lua b/lua/alpha/lsp/null-ls.lua index d8280a8..f80b183 100644 --- a/lua/alpha/lsp/null-ls.lua +++ b/lua/alpha/lsp/null-ls.lua @@ -1,39 +1,42 @@ -local null_ls = require("null-ls") -local composer = require("composer") -local php_actions = require("php-code-actions") +local null_ls = require "null-ls" +local composer = require "composer" +local php_actions = require "php-code-actions" -- local laravel_actions = require("laravel.code-actions") local sources = { - null_ls.builtins.code_actions.gitsigns, - null_ls.builtins.formatting.jq, - null_ls.builtins.code_actions.refactoring, - null_ls.builtins.formatting.alejandra, - null_ls.builtins.diagnostics.luacheck, - null_ls.builtins.formatting.stylua, + null_ls.builtins.code_actions.gitsigns, + null_ls.builtins.formatting.jq, + null_ls.builtins.code_actions.refactoring, + null_ls.builtins.formatting.alejandra, + null_ls.builtins.diagnostics.luacheck, + null_ls.builtins.formatting.stylua, - php_actions.getter_setter, - php_actions.file_creator, + php_actions.getter_setter, + php_actions.file_creator, - null_ls.builtins.diagnostics.phpstan.with({ - to_temp_file = false, - method = null_ls.methods.DIAGNOSTICS_ON_SAVE, - }), + null_ls.builtins.diagnostics.phpstan.with { + to_temp_file = false, + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + }, } -if composer.query({ "require", "symfony/framework-bundle" }) ~= nil then - table.insert(sources, null_ls.builtins.diagnostics.phpcs.with({ - method = null_ls.methods.DIAGNOSTICS_ON_SAVE, - })) -elseif composer.query({ "require", "laravel/framework" }) ~= nil then - table.insert(sources, null_ls.builtins.formatting.pint) - -- table.insert(sources, laravel_actions.relationships) +if composer.query { "require", "symfony/framework-bundle" } ~= nil then + table.insert( + sources, + null_ls.builtins.diagnostics.phpcs.with { + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + } + ) +elseif composer.query { "require", "laravel/framework" } ~= nil then + table.insert(sources, null_ls.builtins.formatting.pint) + -- table.insert(sources, laravel_actions.relationships) end -null_ls.setup({ - sources = sources, -}) +null_ls.setup { + sources = sources, +} vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, {}) vim.keymap.set("n", "vf", function() - return vim.lsp.buf.format({ async = true }) + return vim.lsp.buf.format { async = true } end, {}) diff --git a/lua/alpha/lsp/servers.lua b/lua/alpha/lsp/servers.lua index b3f70a0..f401510 100644 --- a/lua/alpha/lsp/servers.lua +++ b/lua/alpha/lsp/servers.lua @@ -1,13 +1,13 @@ return { - "emmet_ls", - "gopls", - "html", - "jsonls", - "marksman", - "phpactor", - "nil_ls", - "rust_analyzer", - "sumneko_lua", - "tsserver", - "volar", + "emmet_ls", + "gopls", + "html", + "jsonls", + "marksman", + "phpactor", + "nil_ls", + "rust_analyzer", + "sumneko_lua", + "tsserver", + "volar", } diff --git a/lua/alpha/lsp/setups.lua b/lua/alpha/lsp/setups.lua index 15ef064..a8bce09 100644 --- a/lua/alpha/lsp/setups.lua +++ b/lua/alpha/lsp/setups.lua @@ -1,74 +1,78 @@ -local lsp_attach = require("alpha.lsp.attach") +local lsp_attach = require "alpha.lsp.attach" local lsp_flags = { - debounce_text_changes = 150, + debounce_text_changes = 150, } return setmetatable({ - rust_analyzer = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - settings = { - ["rust-analyzer"] = { - checkOnSave = { - allFeatures = true, - overrideCommand = { - 'cargo', 'clippy', '--workspace', '--message-format=json', - '--all-targets', '--all-features' - } - } - }, + rust_analyzer = function() + return { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["rust-analyzer"] = { + checkOnSave = { + allFeatures = true, + overrideCommand = { + "cargo", + "clippy", + "--workspace", + "--message-format=json", + "--all-targets", + "--all-features", }, - } - end, - phpactor = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - filetypes = { "php", "cucumber" }, - } - end, - emmet_ls = function() - local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + }, + }, + }, + } + end, + phpactor = function() + return { + on_attach = lsp_attach, + flags = lsp_flags, + filetypes = { "php", "cucumber" }, + } + end, + emmet_ls = function() + local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) - return { - on_attach = lsp_attach, - flags = lsp_flags, - capabilities = capabilities, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, - } - end, - sumneko_lua = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - }, - diagnostics = { - globals = { "vim" }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - checkThirdParty = false, - }, - telemetry = { - enable = false, - }, - }, - }, - } - end, + return { + on_attach = lsp_attach, + flags = lsp_flags, + capabilities = capabilities, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, + } + end, + sumneko_lua = function() + return { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + }, + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + telemetry = { + enable = false, + }, + }, + }, + } + end, }, { - __index = function() - return function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - } - end - end, + __index = function() + return function() + return { + on_attach = lsp_attach, + flags = lsp_flags, + } + end + end, }) diff --git a/lua/alpha/lsp/tools.lua b/lua/alpha/lsp/tools.lua index 23ef226..68607d5 100644 --- a/lua/alpha/lsp/tools.lua +++ b/lua/alpha/lsp/tools.lua @@ -1,4 +1,4 @@ return { - "go-debug-adapter", - "php-debug-adapter", + "go-debug-adapter", + "php-debug-adapter", } diff --git a/lua/alpha/php/gateway.lua b/lua/alpha/php/gateway.lua index 9d78bf1..51f230b 100644 --- a/lua/alpha/php/gateway.lua +++ b/lua/alpha/php/gateway.lua @@ -1,58 +1,58 @@ -local pickers = require("telescope.pickers") -local finders = require("telescope.finders") +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 actions = require("telescope.actions") +local action_state = require "telescope.actions.state" +local action_set = require "telescope.actions.set" +local actions = require "telescope.actions" local get_node_text = vim.treesitter.get_node_text local gateway = {} -local get_definition_buffer = function (type) - local uri = vim.uri_from_fname(vim.fn.getcwd() .. "/config/graphql/_".. type ..".yaml") - local buff = vim.uri_to_bufnr(uri) - vim.fn.bufload(buff) +local get_definition_buffer = function(type) + local uri = vim.uri_from_fname(vim.fn.getcwd() .. "/config/graphql/_" .. type .. ".yaml") + local buff = vim.uri_to_bufnr(uri) + vim.fn.bufload(buff) - return buff + return buff end -local get_all_definitions = function () - local mutations_definitions = gateway.get_graphql_definitions(get_definition_buffer("mutation")) - local queries_definitions = gateway.get_graphql_definitions(get_definition_buffer("query")) - for _, definition in ipairs(queries_definitions) do - table.insert(mutations_definitions, definition) - end +local get_all_definitions = function() + local mutations_definitions = gateway.get_graphql_definitions(get_definition_buffer "mutation") + local queries_definitions = gateway.get_graphql_definitions(get_definition_buffer "query") + for _, definition in ipairs(queries_definitions) do + table.insert(mutations_definitions, definition) + end - return mutations_definitions + return mutations_definitions end -- "'@=mutation(\"App\\\\GraphQL\\\\Mutation\\\\ImageMutation::deleteVehicleImage\", args[\"inspectionId\"], args[\"url\"], info)'", -local open_resolver = function (resolver) - -- need to parse to get this values - local args = string.match(resolver,"'@=mutation%((.+)%)'") - if args == nil then - args = string.match(resolver,"'@=query%((.+)%)'") - end - if args == nil then - P("error resolver") - P(resolver) - return - end - - local args_tbl = vim.split(args, ', ') - local fqn = string.match(args_tbl[1], "\"(.+)\"") - fqn = string.gsub(fqn, "\\\\", "\\") - -- P(fqn) - - R("alpha.php.lsp").find(fqn, 'phpactor') +local open_resolver = function(resolver) + -- need to parse to get this values + local args = string.match(resolver, "'@=mutation%((.+)%)'") + if args == nil then + args = string.match(resolver, "'@=query%((.+)%)'") + end + if args == nil then + P "error resolver" + P(resolver) + return + end + + local args_tbl = vim.split(args, ", ") + local fqn = string.match(args_tbl[1], '"(.+)"') + fqn = string.gsub(fqn, "\\\\", "\\") + -- P(fqn) + + R("alpha.php.lsp").find(fqn, "phpactor") end --- @param bufnr integer Buff id -gateway.get_graphql_definitions = function (bufnr) - vim.treesitter.set_query( - "yaml", - "GraphQL_endpoints", - [[ +gateway.get_graphql_definitions = function(bufnr) + 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 @@ -67,71 +67,73 @@ gateway.get_graphql_definitions = function (bufnr) ))) )))) ]] - ) - - local query = vim.treesitter.get_query("yaml", "GraphQL_endpoints") - - local elements = {} - - local parsers = require("nvim-treesitter.parsers") - local parser = parsers.get_parser(bufnr) - local tree = unpack(parser:parse()) - - for id, node in query:iter_captures(tree:root(), bufnr) do - if query.captures[id] == "mutation" then - table.insert(elements, { - value = get_node_text(node, bufnr), - lnum = node:start() + 1, - buffer = bufnr, - }) - elseif query.captures[id] == "resolver" then - elements[#elements].resolver = get_node_text(node, bufnr) - end + ) + + local query = vim.treesitter.get_query("yaml", "GraphQL_endpoints") + + local elements = {} + + local parsers = require "nvim-treesitter.parsers" + local parser = parsers.get_parser(bufnr) + local tree = unpack(parser:parse()) + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "mutation" then + table.insert(elements, { + value = get_node_text(node, bufnr), + lnum = node:start() + 1, + buffer = bufnr, + }) + elseif query.captures[id] == "resolver" then + elements[#elements].resolver = get_node_text(node, bufnr) end + end - return elements + return elements end --- gets the graphql function defined on a given buffer --- @param opts table: options to pass to the picker -gateway.graphql_definitions = function (opts) - opts = opts or {} - pickers.new(opts, { - promt_title = "Queries", - finder = finders.new_table({ - results = get_all_definitions(), - entry_maker = function(entry) - -- buffer = 43, - -- lnum = 82, - -- resolver = "'@=mutation(\"App\\\\GraphQL\\\\Mutation\\\\ImageMutation::deleteVehicleImage\", args[\"inspectionId\"], args[\"url\"], info)'", - -- value = "deleteVehicleImage" - return { - value = entry, - display = entry.value, - ordinal = entry.value, - path = vim.api.nvim_buf_get_name(entry.buffer), - lnum = entry.lnum, - resolver = entry.resolver, - } - end, - }), - sorter = conf.generic_sorter(opts), - previewer = conf.grep_previewer(opts), - attach_mappings = function(prompt_bufnr, map) - action_set.select:enhance({ - post = function() - local selection = action_state.get_selected_entry() - vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) - end, - }) - map("i", "", function () - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - open_resolver(selection.resolver) - end) - return true +gateway.graphql_definitions = function(opts) + opts = opts or {} + pickers + .new(opts, { + promt_title = "Queries", + finder = finders.new_table { + results = get_all_definitions(), + entry_maker = function(entry) + -- buffer = 43, + -- lnum = 82, + -- resolver = "'@=mutation(\"App\\\\GraphQL\\\\Mutation\\\\ImageMutation::deleteVehicleImage\", args[\"inspectionId\"], args[\"url\"], info)'", + -- value = "deleteVehicleImage" + return { + value = entry, + display = entry.value, + ordinal = entry.value, + path = vim.api.nvim_buf_get_name(entry.buffer), + lnum = entry.lnum, + resolver = entry.resolver, + } end, - }):find() + }, + sorter = conf.generic_sorter(opts), + previewer = conf.grep_previewer(opts), + attach_mappings = function(prompt_bufnr, map) + action_set.select:enhance { + post = function() + local selection = action_state.get_selected_entry() + vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) + end, + } + map("i", "", function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + open_resolver(selection.resolver) + end) + return true + end, + }) + :find() end return gateway diff --git a/lua/alpha/php/lsp.lua b/lua/alpha/php/lsp.lua index 506ed40..93f18f9 100644 --- a/lua/alpha/php/lsp.lua +++ b/lua/alpha/php/lsp.lua @@ -1,4 +1,4 @@ -local Path = require("plenary.path") +local Path = require "plenary.path" local lsp = {} @@ -6,124 +6,119 @@ local lsp = {} ---@param server_name string ---@return integer|nil lsp.get_lsp_buffer = function(server_name) - local clients = vim.lsp.get_active_clients({ name = server_name }) - if #clients == 0 then - return nil - end + local clients = vim.lsp.get_active_clients { name = server_name } + if #clients == 0 then + return nil + end - local buffers = vim.lsp.get_buffers_by_client_id(clients[1].id) + local buffers = vim.lsp.get_buffers_by_client_id(clients[1].id) - if #buffers == 0 then - return nil - end + if #buffers == 0 then + return nil + end - return buffers[1] + return buffers[1] end --- @param fqn string: fully name to search Class::method lsp.find = function(fqn, client) - local search = vim.split(fqn, "::") - local fqn_class = search[1] - local method = search[2] + local search = vim.split(fqn, "::") + local fqn_class = search[1] + local method = search[2] + + local buffer = lsp.get_lsp_buffer(client) + + if buffer == nil then + -- TODO I want to not require this. + -- I can load a buffer but does not start the lsp + vim.api.nvim_err_writeln(string.format("No buffer available for client %s", client)) + return + end + + local class_parts = vim.split(fqn_class, "\\") + local class = class_parts[#class_parts] + + -- TODO phpactor does not support FQN search need to de sepparated + -- can query get the optiosn, match the full name and type class + -- I don't think gives the namespace + -- So I will get the full name, not the + -- the option is to get the class + -- open the buffer, change in the window + -- call the vim.lsp.buf_document_symbol({on_list = function (list) end}) + -- grab the information and move the cursor + -- if method does not exist show error but stay in the class + -- Can have the code extracted to work with both implementations ? + -- Potentially could have a way to create the classes if they don't exist + -- With the file creater action + vim.lsp.buf_request(buffer, "workspace/symbol", { query = class }, function(err, server_result, _, _) + if err then + vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err.message) + return + end - local buffer = lsp.get_lsp_buffer(client) + local locations = vim.lsp.util.symbols_to_items(server_result or {}, buffer) or {} + if vim.tbl_isempty(locations) then + vim.api.nvim_err_writeln("Empty response looking for class: " .. fqn_class) + return + end + local class_location = nil + for idx, location in pairs(locations) do + if location.text == string.format("[Class] %s", fqn_class) then + class_location = locations[idx] + break + end + end - if buffer == nil then - -- TODO I want to not require this. - -- I can load a buffer but does not start the lsp - vim.api.nvim_err_writeln(string.format("No buffer available for client %s", client)) - return + if class_location == nil then + P("Did not found any class: " .. class) + return end - local class_parts = vim.split(fqn_class, "\\") - local class = class_parts[#class_parts] - - -- TODO phpactor does not support FQN search need to de sepparated - -- can query get the optiosn, match the full name and type class - -- I don't think gives the namespace - -- So I will get the full name, not the - -- the option is to get the class - -- open the buffer, change in the window - -- call the vim.lsp.buf_document_symbol({on_list = function (list) end}) - -- grab the information and move the cursor - -- if method does not exist show error but stay in the class - -- Can have the code extracted to work with both implementations ? - -- Potentially could have a way to create the classes if they don't exist - -- With the file creater action - vim.lsp.buf_request(buffer, "workspace/symbol", { query = class }, function(err, server_result, _, _) - if err then - vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err.message) - return - end + local command = "edit" + local filename = class_location.filename - local locations = vim.lsp.util.symbols_to_items(server_result or {}, buffer) or {} - if vim.tbl_isempty(locations) then - vim.api.nvim_err_writeln("Empty response looking for class: " .. fqn_class) - return - end - local class_location = nil - for idx, location in pairs(locations) do - if location.text == string.format("[Class] %s", fqn_class) then - class_location = locations[idx] - break - end - end + if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then + filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) + pcall(vim.cmd, string.format("%s %s", command, filename)) + end - if class_location == nil then - P("Did not found any class: " .. class) - return - end + local params = vim.lsp.util.make_position_params(0) + vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(method_err, method_server_result, _, _) + if err then + vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. method_err.message) + return + end - local command = "edit" - local filename = class_location.filename + local method_locations = vim.lsp.util.symbols_to_items(method_server_result or {}, buffer) or {} + if vim.tbl_isempty(method_locations) then + P(string.format("empty response looking for method %s", method)) + return + end - if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then - filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) - pcall(vim.cmd, string.format("%s %s", command, filename)) + local method_location = nil + for _, value in ipairs(method_locations) do + if value.text == string.format("[Method] %s", method) then + method_location = value + break end + end - local params = vim.lsp.util.make_position_params(0) - vim.lsp.buf_request( - 0, - "textDocument/documentSymbol", - params, - function(method_err, method_server_result, _, _) - if err then - vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. method_err.message) - return - end - - local method_locations = vim.lsp.util.symbols_to_items(method_server_result or {}, buffer) or {} - if vim.tbl_isempty(method_locations) then - P(string.format("empty response looking for method %s", method)) - return - end - - local method_location = nil - for _, value in ipairs(method_locations) do - if value.text == string.format("[Method] %s", method) then - method_location = value - break - end - end - - if method_location == nil then - return - end - - local row = method_location.lnum - local col = method_location.col - 1 - - if row and col then - local ok, err_msg = pcall(vim.api.nvim_win_set_cursor, 0, { row, col }) - if not ok then - vim.api.nvim_err_writeln("error seting row and col: " .. err_msg) - end - vim.cmd("normal zt") - end - end - ) + if method_location == nil then + return + end + + local row = method_location.lnum + local col = method_location.col - 1 + + if row and col then + local ok, err_msg = pcall(vim.api.nvim_win_set_cursor, 0, { row, col }) + if not ok then + vim.api.nvim_err_writeln("error seting row and col: " .. err_msg) + end + vim.cmd "normal zt" + end end) + end) end return lsp diff --git a/lua/alpha/php/servers.lua b/lua/alpha/php/servers.lua index caab4a8..ba3680c 100644 --- a/lua/alpha/php/servers.lua +++ b/lua/alpha/php/servers.lua @@ -6,40 +6,34 @@ local phpactor = {} -- vim.lsp.start() should return the client function phpactor.findclass(buffer, fqn, callback) - local class_parts = vim.split(fqn, "\\") - local class = class_parts[#class_parts] - - vim.lsp.buf_request(buffer, "workspace/symbol", { query = class }, function(err, server_result, _, _) - if err then - callback( - nil, - "Error when finding workspace symbols: " .. err.message - ) - - return - end - - local locations = vim.lsp.util.symbols_to_items(server_result or {}, buffer) or {} - if vim.tbl_isempty(locations) then - vim.api.nvim_err_writeln("Empty response looking for class: " .. fqn) - return - end - - end) + local class_parts = vim.split(fqn, "\\") + local class = class_parts[#class_parts] + + vim.lsp.buf_request(buffer, "workspace/symbol", { query = class }, function(err, server_result, _, _) + if err then + callback(nil, "Error when finding workspace symbols: " .. err.message) + + return + end + + local locations = vim.lsp.util.symbols_to_items(server_result or {}, buffer) or {} + if vim.tbl_isempty(locations) then + vim.api.nvim_err_writeln("Empty response looking for class: " .. fqn) + return + end + end) end -- getting the config I can re use the client -- the next thing is to make the request with the client local config = require("lspconfig").phpactor config.root_dir = vim.fn.getcwd() -local client_id = vim.lsp.start( - config -); +local client_id = vim.lsp.start(config) local client = vim.lsp.get_client_by_id(client_id) P(client) -- use client.request or request_sync -- look for the direct of the symbol return { - phpactor = phpactor, + phpactor = phpactor, } diff --git a/lua/alpha/scratchs/behat-test.lua b/lua/alpha/scratchs/behat-test.lua index 0fadb43..805459f 100644 --- a/lua/alpha/scratchs/behat-test.lua +++ b/lua/alpha/scratchs/behat-test.lua @@ -8,74 +8,73 @@ -- should get current window, switch for the buffer and get back to the buffer, that is just for the initial not all the time for every save -- +local attach_to_buffer = function(output_bufnr, command) + vim.api.nvim_create_autocmd("BufWritePost", { + group = vim.api.nvim_create_augroup("behat-auto-test", { clear = true }), + pattern = { "*.php", "*.feature" }, + callback = function() + local append_data = function(_, data) + if data then + vim.api.nvim_buf_set_option(output_bufnr, "modifiable", true) + vim.api.nvim_buf_set_lines(output_bufnr, -1, -1, false, data) + vim.api.nvim_buf_set_option(output_bufnr, "modifiable", false) + end + end -local attach_to_buffer = function (output_bufnr, command) - vim.api.nvim_create_autocmd("BufWritePost", { - group = vim.api.nvim_create_augroup("behat-auto-test", {clear = true}), - pattern = {"*.php", "*.feature"}, - callback = function () - local append_data = function (_, data) - if data then - - vim.api.nvim_buf_set_option(output_bufnr, "modifiable", true) - vim.api.nvim_buf_set_lines(output_bufnr, -1, -1, false, data) - vim.api.nvim_buf_set_option(output_bufnr, "modifiable", false) - end - end - - vim.api.nvim_buf_set_option(output_bufnr, "modifiable", true) - vim.api.nvim_buf_set_lines(output_bufnr, 0, -1, false, {"Behat test output"}) - vim.api.nvim_buf_set_option(output_bufnr, "modifiable", false) - vim.fn.jobstart(command, { - stdout_buffered = true, - on_stdout = append_data, - on_stderr = append_data, - }) - end, - }) + vim.api.nvim_buf_set_option(output_bufnr, "modifiable", true) + vim.api.nvim_buf_set_lines(output_bufnr, 0, -1, false, { "Behat test output" }) + vim.api.nvim_buf_set_option(output_bufnr, "modifiable", false) + vim.fn.jobstart(command, { + stdout_buffered = true, + on_stdout = append_data, + on_stderr = append_data, + }) + end, + }) end vim.api.nvim_create_user_command("Behat", function() - local fname = vim.fn.expand("%") - local line = vim.api.nvim_win_get_cursor(0)[1] - local command = vim.split(string.format("docker-compose exec -T -u 1000:1000 php-fpm bin/behat %s:%d", fname, line), " ") - -- TODO generate dinamically - -- local output_bufnr = 214 + local fname = vim.fn.expand "%" + local line = vim.api.nvim_win_get_cursor(0)[1] + local command = + vim.split(string.format("docker-compose exec -T -u 1000:1000 php-fpm bin/behat %s:%d", fname, line), " ") + -- TODO generate dinamically + -- local output_bufnr = 214 - local current_win = vim.api.nvim_get_current_win() - vim.cmd("vsplit") - local winh = vim.api.nvim_get_current_win() - local bufh = vim.api.nvim_create_buf(true, true) - vim.api.nvim_win_set_buf(winh, bufh) - vim.api.nvim_set_current_win(current_win) - vim.api.nvim_buf_set_name(bufh, string.format("Behat %s:%s", fname, line)) - vim.api.nvim_buf_set_option(bufh, "modifiable", false) - vim.api.nvim_win_set_option(winh, "number", false) - vim.api.nvim_win_set_option(winh, "relativenumber", false) + local current_win = vim.api.nvim_get_current_win() + vim.cmd "vsplit" + local winh = vim.api.nvim_get_current_win() + local bufh = vim.api.nvim_create_buf(true, true) + vim.api.nvim_win_set_buf(winh, bufh) + vim.api.nvim_set_current_win(current_win) + vim.api.nvim_buf_set_name(bufh, string.format("Behat %s:%s", fname, line)) + vim.api.nvim_buf_set_option(bufh, "modifiable", false) + vim.api.nvim_win_set_option(winh, "number", false) + vim.api.nvim_win_set_option(winh, "relativenumber", false) - attach_to_buffer(bufh, command) + attach_to_buffer(bufh, command) end, {}) vim.api.nvim_create_user_command("BehatFile", function() - local fname = vim.fn.expand("%") - local command = vim.split(string.format("docker-compose exec -T -u 1000:1000 php-fpm bin/behat %s", fname), " ") - -- TODO generate dinamically - -- local output_bufnr = 214 + local fname = vim.fn.expand "%" + local command = vim.split(string.format("docker-compose exec -T -u 1000:1000 php-fpm bin/behat %s", fname), " ") + -- TODO generate dinamically + -- local output_bufnr = 214 - local current_win = vim.api.nvim_get_current_win() - vim.cmd("vsplit") - local winh = vim.api.nvim_get_current_win() - local bufh = vim.api.nvim_create_buf(true, true) - vim.api.nvim_win_set_buf(winh, bufh) - vim.api.nvim_set_current_win(current_win) - vim.api.nvim_buf_set_name(bufh, string.format("Behat Test")) - vim.api.nvim_buf_set_option(bufh, "modifiable", false) - vim.api.nvim_win_set_option(winh, "number", false) - vim.api.nvim_win_set_option(winh, "relativenumber", false) + local current_win = vim.api.nvim_get_current_win() + vim.cmd "vsplit" + local winh = vim.api.nvim_get_current_win() + local bufh = vim.api.nvim_create_buf(true, true) + vim.api.nvim_win_set_buf(winh, bufh) + vim.api.nvim_set_current_win(current_win) + vim.api.nvim_buf_set_name(bufh, string.format "Behat Test") + vim.api.nvim_buf_set_option(bufh, "modifiable", false) + vim.api.nvim_win_set_option(winh, "number", false) + vim.api.nvim_win_set_option(winh, "relativenumber", false) - attach_to_buffer(bufh, command) + attach_to_buffer(bufh, command) end, {}) vim.api.nvim_create_user_command("BehatStop", function() - vim.api.nvim_del_augroup_by_name("behat-auto-test") + vim.api.nvim_del_augroup_by_name "behat-auto-test" end, {}) diff --git a/lua/alpha/scratchs/laravel.lua b/lua/alpha/scratchs/laravel.lua index 3da2c69..a0f0de7 100644 --- a/lua/alpha/scratchs/laravel.lua +++ b/lua/alpha/scratchs/laravel.lua @@ -14,6 +14,6 @@ -- -- Problem when I switch project sail is runnin in another one -- -local artisan = R("laravel.artisan") +local artisan = R "laravel.artisan" P(artisan.commands(true)) diff --git a/lua/alpha/scratchs/sample.lua b/lua/alpha/scratchs/sample.lua index 415e9a2..68052f5 100644 --- a/lua/alpha/scratchs/sample.lua +++ b/lua/alpha/scratchs/sample.lua @@ -1,29 +1,29 @@ local M = {} -local action_state = require("telescope.actions.state") -local actions = require('telescope.actions') +local action_state = require "telescope.actions.state" +local actions = require "telescope.actions" M.find_config = function() - require("telescope.builtin").find_files({ - prompt_title = "< Neovim >", - cwd = "$HOME/.config/nvim/", - }) + require("telescope.builtin").find_files { + prompt_title = "< Neovim >", + cwd = "$HOME/.config/nvim/", + } end M.find_plugin = function() - require("telescope.builtin").find_files({ - prompt_title = "< Plugins >", - cwd = "$HOME/.config/nvim/lua/alpha/plugins/", - attach_mappings = function(_, map) - map("i", "", function(prompt_bufnr) - local new_plugin = action_state.get_current_line() - actions.close(prompt_bufnr) - vim.cmd(string.format("edit ~/.config/nvim/lua/alpha/plugins/%s.lua", new_plugin)) - end) + require("telescope.builtin").find_files { + prompt_title = "< Plugins >", + cwd = "$HOME/.config/nvim/lua/alpha/plugins/", + attach_mappings = function(_, map) + map("i", "", function(prompt_bufnr) + local new_plugin = action_state.get_current_line() + actions.close(prompt_bufnr) + vim.cmd(string.format("edit ~/.config/nvim/lua/alpha/plugins/%s.lua", new_plugin)) + end) - return true - end, - }) + return true + end, + } end M.find_plugin() diff --git a/lua/alpha/snips/ft/cucumber.lua b/lua/alpha/snips/ft/cucumber.lua index b6ea422..5c183b2 100644 --- a/lua/alpha/snips/ft/cucumber.lua +++ b/lua/alpha/snips/ft/cucumber.lua @@ -1,10 +1,9 @@ - -local ls = require("luasnip") +local ls = require "luasnip" local t = ls.text_node local M = { - clean = t([[Given clean stubs list]]), - all = t([[And all stubs should be matched]]), + clean = t [[Given clean stubs list]], + all = t [[And all stubs should be matched]], } return M diff --git a/lua/alpha/snips/ft/go.lua b/lua/alpha/snips/ft/go.lua index 6038d52..58c6bfc 100644 --- a/lua/alpha/snips/ft/go.lua +++ b/lua/alpha/snips/ft/go.lua @@ -1,4 +1,4 @@ -local ls = require("luasnip") +local ls = require "luasnip" local snippet_from_nodes = ls.sn local c = ls.choice_node @@ -8,15 +8,15 @@ local i = ls.insert_node local rep = require("luasnip.extras").rep local fmt = require("luasnip.extras.fmt").fmt -local ts_locals = require("nvim-treesitter.locals") -local ts_utils = require("nvim-treesitter.ts_utils") +local ts_locals = require "nvim-treesitter.locals" +local ts_utils = require "nvim-treesitter.ts_utils" local get_node_text = vim.treesitter.get_node_text vim.treesitter.set_query( - "go", - "LuaSnip_Result", - [[ + "go", + "LuaSnip_Result", + [[ [ (method_declaration result: (_) @id) (function_declaration result: (_) @id) @@ -26,107 +26,107 @@ vim.treesitter.set_query( ) local transform = function(text, info) - if text == "int" then - return t("0") - elseif text == "error" then - if info then - info.index = info.index + 1 - - return c(info.index, { - t(string.format('fmt.Errorf("%s %%w", %s)', info.func_name, info.err_name)), - t(info.err_name), - }) - else - return t