diff options
Diffstat (limited to 'lua/alpha')
29 files changed, 1574 insertions, 1573 deletions
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 = { - ["<C-d>"] = cmp.mapping.scroll_docs(-4), - ["<C-f>"] = cmp.mapping.scroll_docs(4), - ["<C-e>"] = 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" }), - ["<C-n>"] = 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" }), - ["<C-p>"] = cmp.mapping.select_prev_item(), - ["<C-y>"] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }), - ["<c-space>"] = 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 = { + ["<C-d>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + ["<C-e>"] = 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" }), + ["<C-n>"] = 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" }), + ["<C-p>"] = cmp.mapping.select_prev_item(), + ["<C-y>"] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + ["<c-space>"] = 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 = [[ ^^ _<Esc>_ ]] -hydra({ - name = "dap", - hint = hint, - mode = "n", - config = { - color = "blue", - invoke_on_body = true, - hint = { - border = "rounded", - position = "bottom", - }, - }, - body = "<leader>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 = "<leader>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, + }, - { "<Esc>", nil, { exit = true } }, - }, -}) + { "<Esc>", 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 = { - {"<leader>ss"}, - {"<leader>sa"}, + { "<leader>ss" }, + { "<leader>sa" }, } for i = 1, terms do - table.insert(M.keymaps, {string.format("<leader><leader>%s", i)}) + table.insert(M.keymaps, { string.format("<leader><leader>%s", i) }) end for i = 1, quick_binds do - table.insert(M.keymaps, {string.format("<leader>%s", i)}) + table.insert(M.keymaps, { string.format("<leader>%s", i) }) end M.setup = function() - require('harpoon').setup() - - vim.keymap.set('n', '<leader>ss', require("harpoon.ui").toggle_quick_menu, { noremap = true, silent = true, expr = false }) - vim.keymap.set('n', '<leader>sa', require("harpoon.mark").add_file, { noremap = true, silent = true, expr = false }) - - for i = 1, terms do - vim.keymap.set('n', string.format('<leader><leader>%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("<leader>%s", i), - function() - require("harpoon.ui").nav_file(i) - end, - { noremap = true, silent = true, expr = false } - ) - end + require("harpoon").setup() + + vim.keymap.set( + "n", + "<leader>ss", + require("harpoon.ui").toggle_quick_menu, + { noremap = true, silent = true, expr = false } + ) + vim.keymap.set("n", "<leader>sa", require("harpoon.mark").add_file, { noremap = true, silent = true, expr = false }) + + for i = 1, terms do + vim.keymap.set("n", string.format("<leader><leader>%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("<leader>%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", "<leader>vrn", vim.lsp.buf.rename, { buffer = 0 }) - vim.keymap.set("i", "<c-h>", vim.lsp.buf.signature_help, { buffer = 0 }) - vim.keymap.set("n", "<leader>vo", ":LspRestart<cr>", { noremap = true }) - vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {}) - vim.keymap.set("n", "<leader>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", "<leader>vrn", vim.lsp.buf.rename, { buffer = 0 }) + vim.keymap.set("i", "<c-h>", vim.lsp.buf.signature_help, { buffer = 0 }) + vim.keymap.set("n", "<leader>vo", ":LspRestart<cr>", { noremap = true }) + vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {}) + vim.keymap.set("n", "<leader>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("<leader>pv", "find_symbol", nil, true) - telescope_mapper("<leader>pd", "lsp_document_symbols", nil, true) - telescope_mapper("<c-]>", "lsp_definitions", nil, true) + telescope_mapper("gr", "lsp_references", nil, true) + telescope_mapper("<leader>pv", "find_symbol", nil, true) + telescope_mapper("<leader>pd", "lsp_document_symbols", nil, true) + telescope_mapper("<c-]>", "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" }, "<leader>vca", vim.lsp.buf.code_action, {}) vim.keymap.set("n", "<leader>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", "<c-o>", 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", "<c-o>", 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", "<C-t>", 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", "<C-t>", 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("err") - end - elseif text == "bool" then - return t("false") - elseif text == "string" then - return t('""') - elseif string.find(text, "*", 1, true) then - return t("nil") - end - - return t(text) + 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 "err" + end + elseif text == "bool" then + return t "false" + elseif text == "string" then + return t '""' + elseif string.find(text, "*", 1, true) then + return t "nil" + end + + return t(text) end local handlers = { - ["parameter_list"] = function(node, info) - local result = {} - - local count = node:named_child_count() - for idx = 0, count - 1 do - table.insert(result, transform(get_node_text(node:named_child(idx), 0), info)) - if idx ~= count - 1 then - table.insert(result, t({ ", " })) - end - end - - return result - end, - - ["type_identifier"] = function(node, info) - local text = get_node_text(node, 0) - return { transform(text, info) } - end, + ["parameter_list"] = function(node, info) + local result = {} + + local count = node:named_child_count() + for idx = 0, count - 1 do + table.insert(result, transform(get_node_text(node:named_child(idx), 0), info)) + if idx ~= count - 1 then + table.insert(result, t { ", " }) + end + end + + return result + end, + + ["type_identifier"] = function(node, info) + local text = get_node_text(node, 0) + return { transform(text, info) } + end, } local function go_result_type(info) - local cursor_node = ts_utils.get_node_at_cursor() - local scope = ts_locals.get_scope_tree(cursor_node, 0) - - local function_node - for _, v in ipairs(scope) do - if v:type() == "function_declaration" or v:type() == "method_declaration" or v:type() == "func_literal" then - function_node = v - break - end - end - - local query = vim.treesitter.get_query("go", "LuaSnip_Result") - for _, node in query:iter_captures(function_node, 0) do - if handlers[node:type()] then - return handlers[node:type()](node, info) - end - end + local cursor_node = ts_utils.get_node_at_cursor() + local scope = ts_locals.get_scope_tree(cursor_node, 0) + + local function_node + for _, v in ipairs(scope) do + if v:type() == "function_declaration" or v:type() == "method_declaration" or v:type() == "func_literal" then + function_node = v + break + end + end + + local query = vim.treesitter.get_query("go", "LuaSnip_Result") + for _, node in query:iter_captures(function_node, 0) do + if handlers[node:type()] then + return handlers[node:type()](node, info) + end + end end local go_ret_vals = function(args) - local info = { index = 0, err_name = args[1][1], func_name = args[2][1] } - return snippet_from_nodes(nil, go_result_type(info)) + local info = { index = 0, err_name = args[1][1], func_name = args[2][1] } + return snippet_from_nodes(nil, go_result_type(info)) end local M = { - main = { - t({ "func main() {", "\t" }), - i(0), - t({ "", "}" }), - }, - ef = { - i(1, { "val" }), - t(", err := "), - i(2, { "f" }), - t("("), - i(3), - t(")"), - i(0), - }, - efi = { - i(1, { "val" }), - ", ", - i(2, { "err" }), - " := ", - i(3, { "f" }), - "(", - i(4), - ")", - t({ "", "if " }), - rep(2), - t({ " != nil {", "\treturn " }), - d(5, go_ret_vals, { 2, 3 }), - t({ "", "}" }), - i(0), - }, + main = { + t { "func main() {", "\t" }, + i(0), + t { "", "}" }, + }, + ef = { + i(1, { "val" }), + t ", err := ", + i(2, { "f" }), + t "(", + i(3), + t ")", + i(0), + }, + efi = { + i(1, { "val" }), + ", ", + i(2, { "err" }), + " := ", + i(3, { "f" }), + "(", + i(4), + ")", + t { "", "if " }, + rep(2), + t { " != nil {", "\treturn " }, + d(5, go_ret_vals, { 2, 3 }), + t { "", "}" }, + i(0), + }, } M.f = fmt("func {}({}) {} {{\n\t{}\n}}", { i(1, "name"), i(2), i(3), i(0) }) diff --git a/lua/alpha/snips/ft/lua.lua b/lua/alpha/snips/ft/lua.lua index 9f6b6fa..d896f3e 100644 --- a/lua/alpha/snips/ft/lua.lua +++ b/lua/alpha/snips/ft/lua.lua @@ -1,4 +1,4 @@ -local ls = require("luasnip") +local ls = require "luasnip" -- local snippet = ls.s local snippet_from_nodes = ls.sn @@ -11,57 +11,59 @@ local t = ls.text_node local fmt = require("luasnip.extras.fmt").fmt local require_var = function(args, _) - local text = args[1][1] or "" - local split = vim.split(text, ".", { plain = true }) + local text = args[1][1] or "" + local split = vim.split(text, ".", { plain = true }) - local options = {} - for len = 0, #split - 1 do - table.insert(options, t(table.concat(vim.list_slice(split, #split - len, #split), "_"))) - end + local options = {} + for len = 0, #split - 1 do + table.insert(options, t(table.concat(vim.list_slice(split, #split - len, #split), "_"))) + end - return snippet_from_nodes(nil, { - c(1, options), - }) + return snippet_from_nodes(nil, { + c(1, options), + }) end local newline = function(text) - return t({ "", text }) + return t { "", text } end return { - req = fmt([[local {} = require("{}")]], { - d(2, require_var, { 1 }), - i(1), - }), - lf = { - desc = "table function", - "local ", - i(1), - " = function(", - i(2), - ")", - newline(" "), - i(0), - newline("end"), - }, + req = fmt([[local {} = require("{}")]], { + d(2, require_var, { 1 }), + i(1), + }), + lf = { + desc = "table function", + "local ", + i(1), + " = function(", + i(2), + ")", + newline " ", + i(0), + newline "end", + }, - preq = fmt( - [[local ok, {} = pcall(require, "{}") + preq = fmt( + [[local ok, {} = pcall(require, "{}") if not ok then return end]], - { - f(function(args) - return args[1][1] - end, { 1 }), - i(1) - } - ), + { + f(function(args) + return args[1][1] + end, { 1 }), + i(1), + } + ), - plugin = fmt( -[[return {{ + plugin = fmt( + [[return {{ "{}" -}}]], { - i(1, "plugin") - }), +}}]], + { + i(1, "plugin"), + } + ), } diff --git a/lua/alpha/snips/ft/php.lua b/lua/alpha/snips/ft/php.lua index d70db2e..abfc6f7 100644 --- a/lua/alpha/snips/ft/php.lua +++ b/lua/alpha/snips/ft/php.lua @@ -1,5 +1,5 @@ -local ls = require("luasnip") -local composer = require("composer") +local ls = require "luasnip" +local composer = require "composer" local snippet_from_nodes = ls.sn local c = ls.choice_node @@ -10,72 +10,72 @@ local i = ls.insert_node local fmt = require("luasnip.extras.fmt").fmt function string.starts(String, Start) - return string.sub(String, 1, string.len(Start)) == Start + return string.sub(String, 1, string.len(Start)) == Start end local newline = function(text) - return t({ "", text }) + return t { "", text } end local visibility = function(position, default) - local possibles = { "private", "protected", "public" } - local options = {} - - for _, value in pairs(possibles) do - if value == default then - table.insert(options, 1, t(value)) - else - table.insert(options, t(value)) - end - end - - return c(position, options) + local possibles = { "private", "protected", "public" } + local options = {} + + for _, value in pairs(possibles) do + if value == default then + table.insert(options, 1, t(value)) + else + table.insert(options, t(value)) + end + end + + return c(position, options) end local namespace = function() - local dir = vim.fn.expand("%:h") - local autoloads = composer.query({ "autoload", "psr-4" }) - if autoloads == nil then - return (dir:gsub("^%l", string.upper)) - end - - local globalNamespace - for key, value in pairs(autoloads) do - if string.starts(dir, value:sub(1, -2)) then - globalNamespace = key:sub(1, -2) - dir = dir:sub(#key + 1) - break - end - end - dir = dir:gsub("/", "\\") - if dir == "" then - return globalNamespace - end - - return string.format("%s\\%s", globalNamespace, dir) + local dir = vim.fn.expand "%:h" + local autoloads = composer.query { "autoload", "psr-4" } + if autoloads == nil then + return (dir:gsub("^%l", string.upper)) + end + + local globalNamespace + for key, value in pairs(autoloads) do + if string.starts(dir, value:sub(1, -2)) then + globalNamespace = key:sub(1, -2) + dir = dir:sub(#key + 1) + break + end + end + dir = dir:gsub("/", "\\") + if dir == "" then + return globalNamespace + end + + return string.format("%s\\%s", globalNamespace, dir) end local class_name = function() - return vim.fn.expand("%:t:r") + return vim.fn.expand "%:t:r" end local M = {} M.v = fmt( - [[ + [[ /** * @var {} */ {} ${}; ]], - { - i(1, "type"), - visibility(2, "private"), - i(3, "var"), - } + { + i(1, "type"), + visibility(2, "private"), + i(3, "var"), + } ) M.class = fmt( - [[ + [[ <?php declare(strict_types=1); @@ -87,89 +87,89 @@ class {} {} }} ]], - { - f(namespace), - f(class_name), - i(0), - } + { + f(namespace), + f(class_name), + i(0), + } ) M.pro = fmt([[{} {}{} ${},]], { - visibility(1, "private"), - c(2, { - t(""), - t("readonly "), - }), - i(3, "Type"), - d(4, function(args) - return snippet_from_nodes(nil, { - i(1, args[1][1]:gsub("^%u", string.lower) or ""), - }) - end, { 3 }), + visibility(1, "private"), + c(2, { + t "", + t "readonly ", + }), + i(3, "Type"), + d(4, function(args) + return snippet_from_nodes(nil, { + i(1, args[1][1]:gsub("^%u", string.lower) or ""), + }) + end, { 3 }), }) M.arg = fmt([[{} ${}]], { - i(1, "Type"), - d(2, function(args) - return snippet_from_nodes(nil, { - i(1, args[1][1]:gsub("^%u", string.lower) or ""), - }) - end, { 1 }), + i(1, "Type"), + d(2, function(args) + return snippet_from_nodes(nil, { + i(1, args[1][1]:gsub("^%u", string.lower) or ""), + }) + end, { 1 }), }) M._c = fmt( - [[{} function __construct({}) {{ + [[{} function __construct({}) {{ {} }}]], - { - visibility(1, "public"), - i(2), - i(0), - } + { + visibility(1, "public"), + i(2), + i(0), + } ) M._p = fmt( - [[{} function __construct( + [[{} function __construct( {} ) {{ }}]], - { - visibility(1, "public"), - i(2), - } + { + visibility(1, "public"), + i(2), + } ) -M.strict = t("declare(strict_types=1);") +M.strict = t "declare(strict_types=1);" M.fn = { - visibility(1, "public"), - t(" function "), - i(2, "name"), - t("("), - i(3), - t(")"), - c(4, { - t(""), - snippet_from_nodes(nil, { - t(": "), - i(1, "void"), - }), - }), - newline("{"), - newline("\t"), - i(0, ""), - newline("}"), + visibility(1, "public"), + t " function ", + i(2, "name"), + t "(", + i(3), + t ")", + c(4, { + t "", + snippet_from_nodes(nil, { + t ": ", + i(1, "void"), + }), + }), + newline "{", + newline "\t", + i(0, ""), + newline "}", } M["then"] = fmt( - [[->then(function ({}) {{ + [[->then(function ({}) {{ {} }})]], - { i(1, ""), i(2, "") } + { i(1, ""), i(2, "") } ) M.test = fmt( - [[/** + [[/** * @test */ public function it_{}(): void @@ -177,7 +177,7 @@ public function it_{}(): void {} }} ]], - { i(1, ""), i(0, "") } + { i(1, ""), i(0, "") } ) return M diff --git a/lua/alpha/snips/ft/yaml.lua b/lua/alpha/snips/ft/yaml.lua index 796512e..3924c6f 100644 --- a/lua/alpha/snips/ft/yaml.lua +++ b/lua/alpha/snips/ft/yaml.lua @@ -1,4 +1,4 @@ -local ls = require("luasnip") +local ls = require "luasnip" local snippet_from_nodes = ls.sn local c = ls.choice_node @@ -10,149 +10,149 @@ local fmt = require("luasnip.extras.fmt").fmt local rep = require("luasnip.extras").rep local M = { - str = fmt( - [[{}: + str = fmt( + [[{}: type: string -{}]] , - { - i(1, ""), - i(2, ""), - } - ), - bool = fmt( - [[{}: +{}]], + { + i(1, ""), + i(2, ""), + } + ), + bool = fmt( + [[{}: type: boolean -{}]] , - { - i(1, ""), - i(2, ""), - } - ), - float = fmt( - [[{}: +{}]], + { + i(1, ""), + i(2, ""), + } + ), + float = fmt( + [[{}: type: number format: float -{}]] , - { - i(1, ""), - i(2, ""), - } - ), - int = fmt( - [[{}: +{}]], + { + i(1, ""), + i(2, ""), + } + ), + int = fmt( + [[{}: type: integer -{}]] , - { - i(1, ""), - i(2, ""), - } - ), - id = fmt( - [[{}: +{}]], + { + i(1, ""), + i(2, ""), + } + ), + id = fmt( + [[{}: type: integer format: int64 -{}]] , - { - i(1, ""), - i(2, ""), - } - ), - class = fmt( - [[{}: +{}]], + { + i(1, ""), + i(2, ""), + } + ), + class = fmt( + [[{}: $ref: '#/components/schemas/{}' -{}]] , - { - i(1, ""), - i(2, ""), - i(3, ""), - } - ), - date = fmt( - [[{}: +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + date = fmt( + [[{}: type: string format: date-time -{}]] , - { - i(1, ""), - i(2, ""), - } - ), - arr = fmt( - [[{}: +{}]], + { + 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 +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + ref = fmt([[$ref: '#/components/schemas/{}']], { i(1, "") }), + obj = fmt( + [[type: object properties: - {}]] , - i(1, "") - ), - aint = fmt( - [[{}: + {}]], + i(1, "") + ), + aint = fmt( + [[{}: type: array items: type: int format: int64 -{}]] , - { - i(1, ""), - i(2, ""), - } - ), - astr = fmt( - [[{}: +{}]], + { + i(1, ""), + i(2, ""), + } + ), + astr = fmt( + [[{}: type: array items: type: string -{}]] , - { - i(1, ""), - i(2, ""), - } - ), +{}]], + { + i(1, ""), + i(2, ""), + } + ), - mut = fmt( - [[{}: + mut = fmt( + [[{}: type: "{}" resolve: '@=mutation("App\\GraphQL\\Mutation\\{}::{}", {}, info)' args: {} -]] , - { - i(1, ""), - i(2, ""), - i(3, ""), - rep(1), - i(5, ""), - i(6, ""), - } - ), +]], + { + i(1, ""), + i(2, ""), + i(3, ""), + rep(1), + i(5, ""), + i(6, ""), + } + ), - input = fmt( - [[{}: + input = fmt( + [[{}: type: input-object config: fields: {} -]] , - { - i(1, ""), - i(2, ""), - } - ), - f = fmt([[{}: {{ type: "{}" }}]], { i(1, ""), i(2, "") }), +]], + { + i(1, ""), + i(2, ""), + } + ), + f = fmt([[{}: {{ type: "{}" }}]], { i(1, ""), i(2, "") }), - api = fmt( - [[openapi: 3.0.2 + api = fmt( + [[openapi: 3.0.2 info: title: {} contact: @@ -162,15 +162,17 @@ x-bundle-apis: true tags: - name: {} description: {} -]] , - { i(1, "my app"), i(2, "1.0.0"), i(3, "tag"), i(4, "tag description") } - ), - paths = fmt([[paths: +]], + { i(1, "my app"), i(2, "1.0.0"), i(3, "tag"), i(4, "tag description") } + ), + paths = fmt( + [[paths: {} ]], - {i(0, "")} - ), - param = fmt([[parameters: + { i(0, "") } + ), + param = fmt( + [[parameters: - name: {} description: {} in: path @@ -179,9 +181,10 @@ tags: type: integer format: int64 ]], - {i(1, ""), i(2, "")} - ), - get = fmt([[get: + { i(1, ""), i(2, "") } + ), + get = fmt( + [[get: operationId: {} description: {} tags: [ {} ] @@ -192,9 +195,12 @@ tags: application/json: schema: {} - ]], {i(1, "GetOperation"), i(2, "description"), i(3, "tag"), i(4, "")}), + ]], + { i(1, "GetOperation"), i(2, "description"), i(3, "tag"), i(4, "") } + ), - put = fmt([[put: + put = fmt( + [[put: operationId: {} tags: [ {} ] description: {} @@ -211,7 +217,9 @@ tags: application/json: schema: {} - ]], {i(1, "PutOperation"), i(2, "tag"), i(3, "description"), i(4, ""), i(5, "description"), i(6, "")}) + ]], + { i(1, "PutOperation"), i(2, "tag"), i(3, "description"), i(4, ""), i(5, "description"), i(6, "") } + ), } return M diff --git a/lua/alpha/telescope/actions.lua b/lua/alpha/telescope/actions.lua index a3e41ec..e4bbd8e 100644 --- a/lua/alpha/telescope/actions.lua +++ b/lua/alpha/telescope/actions.lua @@ -1,20 +1,19 @@ 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.create_plugin = function(prompt_bufnr) - local new_plugin = action_state.get_current_line() - actions.close(prompt_bufnr) - vim.cmd(string.format("edit ~/.config/nvim/lua/plugins/%s.lua", new_plugin)) + local new_plugin = action_state.get_current_line() + actions.close(prompt_bufnr) + vim.cmd(string.format("edit ~/.config/nvim/lua/plugins/%s.lua", new_plugin)) end local get_disable_stm_node = function(bufnr, tree) - - vim.treesitter.set_query( - "lua", - "alpha_plugin_is_disabled", - [[ + vim.treesitter.set_query( + "lua", + "alpha_plugin_is_disabled", + [[ (return_statement (expression_list (table_constructor @@ -26,26 +25,24 @@ local get_disable_stm_node = function(bufnr, tree) ) ) ]] - ) - - local query = vim.treesitter.get_query("lua", "alpha_plugin_is_disabled") - + ) - for id, node in query:iter_captures(tree:root(), bufnr) do - if query.captures[id] == "enabled" then + local query = vim.treesitter.get_query("lua", "alpha_plugin_is_disabled") - return node - end + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node end + end - return nil + return nil end local get_enabled_node = function(bufnr, tree) - vim.treesitter.set_query( - "lua", - "alpha_plugin_has_enable_property", - [[ + vim.treesitter.set_query( + "lua", + "alpha_plugin_has_enable_property", + [[ (return_statement (expression_list (table_constructor @@ -56,126 +53,121 @@ local get_enabled_node = function(bufnr, tree) ) ) ]] - ) - - local query = vim.treesitter.get_query("lua", "alpha_plugin_has_enable_property") - + ) - for id, node in query:iter_captures(tree:root(), bufnr) do - if query.captures[id] == "enabled" then + local query = vim.treesitter.get_query("lua", "alpha_plugin_has_enable_property") - return node - end + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node end + end - return nil + return nil end local get_return_node = function(bufnr, tree) - vim.treesitter.set_query( - "lua", - "alpha_plugin_return_table_constructor", - [[ + vim.treesitter.set_query( + "lua", + "alpha_plugin_return_table_constructor", + [[ (return_statement (expression_list (table_constructor) @table_constructor ) ) ]] - ) - - local query = vim.treesitter.get_query("lua", "alpha_plugin_return_table_constructor") - + ) - for id, node in query:iter_captures(tree:root(), bufnr) do - if query.captures[id] == "table_constructor" then + local query = vim.treesitter.get_query("lua", "alpha_plugin_return_table_constructor") - return node - end + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "table_constructor" then + return node end + end - return nil + return nil end M.disable_plugin = function(prompt_bufnr) - local entry = action_state.get_selected_entry() - local uri = vim.uri_from_fname(entry.cwd .. entry[1]) - local bufnr = vim.uri_to_bufnr(uri) - vim.fn.bufload(bufnr) - - local parsers = require("nvim-treesitter.parsers") - local parser = parsers.get_parser(bufnr) - if type(parser:parse()) ~= "table" then - vim.notify("Expected table but got something else ???", vim.log.levels.ERROR, {}) - P(parser:parse()) - return + local entry = action_state.get_selected_entry() + local uri = vim.uri_from_fname(entry.cwd .. entry[1]) + local bufnr = vim.uri_to_bufnr(uri) + vim.fn.bufload(bufnr) + + local parsers = require "nvim-treesitter.parsers" + local parser = parsers.get_parser(bufnr) + if type(parser:parse()) ~= "table" then + vim.notify("Expected table but got something else ???", vim.log.levels.ERROR, {}) + P(parser:parse()) + return + end + local tree = unpack(parser:parse()) + + local disabled_stm_node = get_disable_stm_node(bufnr, tree) + if disabled_stm_node ~= nil then + vim.notify("Plugin is already disable", vim.log.levels.WARN, {}) + return + end + + local start_line + local end_line + + local enable_node = get_enabled_node(bufnr, tree) + if enable_node == nil then + -- node does not exists need to assume line + local return_node = get_return_node(bufnr, tree) + + if return_node == nil then + vim.notify("Can determine how to diable the plugin", vim.log.levels.ERROR, {}) + return end - local tree = unpack(parser:parse()) - local disabled_stm_node = get_disable_stm_node(bufnr, tree) - if disabled_stm_node ~= nil then - vim.notify("Plugin is already disable", vim.log.levels.WARN, {}) - return - end - - local start_line - local end_line - - local enable_node = get_enabled_node(bufnr, tree) - if enable_node == nil then - -- node does not exists need to assume line - local return_node = get_return_node(bufnr, tree) - - if return_node == nil then - vim.notify("Can determine how to diable the plugin", vim.log.levels.ERROR, {}) - return - end - - start_line = return_node:start() + 2 - end_line = start_line - else - start_line = enable_node:start() - end_line = start_line + 1 - end - - - vim.api.nvim_buf_set_lines(bufnr, start_line, end_line, false, { " enabled = false," }) - vim.notify("Plugin " .. entry[1] .. " Disabled", vim.log.levels.INFO, {}) - actions.close(prompt_bufnr) - vim.api.nvim_buf_call(bufnr, function() - vim.cmd("write") - end) + start_line = return_node:start() + 2 + end_line = start_line + else + start_line = enable_node:start() + end_line = start_line + 1 + end + + vim.api.nvim_buf_set_lines(bufnr, start_line, end_line, false, { " enabled = false," }) + vim.notify("Plugin " .. entry[1] .. " Disabled", vim.log.levels.INFO, {}) + actions.close(prompt_bufnr) + vim.api.nvim_buf_call(bufnr, function() + vim.cmd "write" + end) end -M.enable_plugin = function (prompt_bufnr) - local entry = action_state.get_selected_entry() - local uri = vim.uri_from_fname(entry.cwd .. entry[1]) - local bufnr = vim.uri_to_bufnr(uri) - vim.fn.bufload(bufnr) - - local parsers = require("nvim-treesitter.parsers") - local parser = parsers.get_parser(bufnr) - - if type(parser:parse()) == "table" then - vim.notify("Expected number but got table ???", vim.log.levels.ERROR, {}) - P(parser:parse()) - return - end - local tree = unpack(parser:parse()) - - local disabled_stm_node = get_disable_stm_node(bufnr, tree) - if disabled_stm_node == nil then - vim.notify("Plugin is already Enable", vim.log.levels.WARN, {}) - return - end - - local enable_line = disabled_stm_node:start() - vim.api.nvim_buf_set_lines(bufnr, enable_line, enable_line + 1, false, {}) - vim.notify("Plugin " .. entry[1] .. " Enabled", vim.log.levels.INFO, {}) - actions.close(prompt_bufnr) - vim.api.nvim_buf_call(bufnr, function() - vim.cmd("write") - end) +M.enable_plugin = function(prompt_bufnr) + local entry = action_state.get_selected_entry() + local uri = vim.uri_from_fname(entry.cwd .. entry[1]) + local bufnr = vim.uri_to_bufnr(uri) + vim.fn.bufload(bufnr) + + local parsers = require "nvim-treesitter.parsers" + local parser = parsers.get_parser(bufnr) + + if type(parser:parse()) == "table" then + vim.notify("Expected number but got table ???", vim.log.levels.ERROR, {}) + P(parser:parse()) + return + end + local tree = unpack(parser:parse()) + + local disabled_stm_node = get_disable_stm_node(bufnr, tree) + if disabled_stm_node == nil then + vim.notify("Plugin is already Enable", vim.log.levels.WARN, {}) + return + end + + local enable_line = disabled_stm_node:start() + vim.api.nvim_buf_set_lines(bufnr, enable_line, enable_line + 1, false, {}) + vim.notify("Plugin " .. entry[1] .. " Enabled", vim.log.levels.INFO, {}) + actions.close(prompt_bufnr) + vim.api.nvim_buf_call(bufnr, function() + vim.cmd "write" + end) end return M diff --git a/lua/alpha/telescope/init.lua b/lua/alpha/telescope/init.lua index bfddbc3..b5087b3 100644 --- a/lua/alpha/telescope/init.lua +++ b/lua/alpha/telescope/init.lua @@ -1,174 +1,174 @@ SHOULD_RELOAD_TELESCOPE = true local reloader = function() - if SHOULD_RELOAD_TELESCOPE then - RELOAD("plenary") - RELOAD("telescope") - RELOAD("alpha.telescope.setup") - end + if SHOULD_RELOAD_TELESCOPE then + RELOAD "plenary" + RELOAD "telescope" + RELOAD "alpha.telescope.setup" + end end -local action_state = require("telescope.actions.state") +local action_state = require "telescope.actions.state" local fb_actions = require("telescope").extensions.file_browser.actions -local actions = require("telescope.actions") -local my_actions = require("alpha.telescope.actions") +local actions = require "telescope.actions" +local my_actions = require "alpha.telescope.actions" local M = {} function M.project_files() - local opts = { show_untracked = true } -- define here if you want to define something - local ok = pcall(require("telescope.builtin").git_files, opts) - if not ok then - require("telescope.builtin").find_files(opts) - end + local opts = { show_untracked = true } -- define here if you want to define something + local ok = pcall(require("telescope.builtin").git_files, opts) + if not ok then + require("telescope.builtin").find_files(opts) + end end function M.branches() - require("telescope.builtin").git_branches({ - attach_mappings = function(_, map) - map("i", "<c-j>", actions.git_create_branch) - map("n", "<c-j>", actions.git_create_branch) - return true - end, - }) + require("telescope.builtin").git_branches { + attach_mappings = function(_, map) + map("i", "<c-j>", actions.git_create_branch) + map("n", "<c-j>", actions.git_create_branch) + return true + end, + } end function M.search_config() - require("telescope.builtin").git_files({ - prompt_title = "< Dotfiles >", - cwd = "$HOME/.dotfiles", - show_untracked = true, - }) + require("telescope.builtin").git_files { + prompt_title = "< Dotfiles >", + cwd = "$HOME/.dotfiles", + show_untracked = true, + } end M.find_nvim_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_nvim_plugin = function() - require("telescope.builtin").find_files({ - prompt_title = "< Plugins >", - cwd = "$HOME/.config/nvim/lua/plugins/", - attach_mappings = function(_, map) - map("i", "<C-t>", my_actions.create_plugin) - map("i", "<C-d>", my_actions.disable_plugin) - map("i", "<C-e>", my_actions.enable_plugin) - - return true - end, - }) + require("telescope.builtin").find_files { + prompt_title = "< Plugins >", + cwd = "$HOME/.config/nvim/lua/plugins/", + attach_mappings = function(_, map) + map("i", "<C-t>", my_actions.create_plugin) + map("i", "<C-d>", my_actions.disable_plugin) + map("i", "<C-e>", my_actions.enable_plugin) + + return true + end, + } end function M.grep_string() - vim.ui.input({ prompt = "Grep for > " }, function(input) - if input == nil then - return - end - require("telescope.builtin").grep_string({ search = input }) - end) + vim.ui.input({ prompt = "Grep for > " }, function(input) + if input == nil then + return + end + require("telescope.builtin").grep_string { search = input } + end) end function M.grep_word() - require("telescope.builtin").grep_string({ search = vim.fn.expand("<cword>") }) + require("telescope.builtin").grep_string { search = vim.fn.expand "<cword>" } end function M.find_symbol() - vim.ui.input({ prompt = "Symbol for > " }, function(input) - if input == nil then - return - end - require("telescope.builtin").lsp_workspace_symbols({ query = input }) - end) + vim.ui.input({ prompt = "Symbol for > " }, function(input) + if input == nil then + return + end + require("telescope.builtin").lsp_workspace_symbols { query = input } + end) end function M.my_plugins() - if vim.fn.isdirectory("~/code/plugins/") == 0 then - vim.notify("Directory ~/code/plugins does not exists", vim.log.levels.WARN, { title = "Telescope Mappings" }) - return - end - require("telescope.builtin").find_files({ - cwd = "~/code/plugins/", - }) + if vim.fn.isdirectory "~/code/plugins/" == 0 then + vim.notify("Directory ~/code/plugins does not exists", vim.log.levels.WARN, { title = "Telescope Mappings" }) + return + end + require("telescope.builtin").find_files { + cwd = "~/code/plugins/", + } end function M.projectionist() - return require("telescope").extensions.projectionist.projectionist() + return require("telescope").extensions.projectionist.projectionist() end function M.laravel_commands() - return require("telescope").extensions.laravel.laravel() + return require("telescope").extensions.laravel.laravel() end function M.api_specs() - if vim.fn.isdirectory("./api-specification") == 0 then - vim.notify("Directory api-specification does not exists", vim.log.levels.WARN, { title = "Telescope Mappings" }) - return - end - require("telescope.builtin").git_files({ - cwd = "./api-specification", - show_untracked = true, - }) + if vim.fn.isdirectory "./api-specification" == 0 then + vim.notify("Directory api-specification does not exists", vim.log.levels.WARN, { title = "Telescope Mappings" }) + return + end + require("telescope.builtin").git_files { + cwd = "./api-specification", + show_untracked = true, + } end function M.worktree() - return require("telescope").extensions.git_worktree.git_worktrees() + return require("telescope").extensions.git_worktree.git_worktrees() end function M.worktree_create() - return require("telescope").extensions.git_worktree.create_git_worktree() + return require("telescope").extensions.git_worktree.create_git_worktree() end function M.refactor() - return require("telescope").extensions.refactoring.refactors() + return require("telescope").extensions.refactoring.refactors() end function M.file_browser_relative() - return M.file_browser({ path = "%:p:h" }) + return M.file_browser { path = "%:p:h" } end function M.gateway() - return require("alpha.php.gateway").graphql_definitions({ - layout_config = { - horizontal = { - preview_width = function(_, cols, _) - return math.floor(cols * 0.7) - end, - }, - }, - }) + return require("alpha.php.gateway").graphql_definitions { + layout_config = { + horizontal = { + preview_width = function(_, cols, _) + return math.floor(cols * 0.7) + end, + }, + }, + } end function M.file_browser(opts) - opts = opts or {} + opts = opts or {} - opts = { - path = opts.path, - sorting_strategy = "ascending", - scroll_strategy = "cycle", - layout_config = { - prompt_position = "top", - }, + opts = { + path = opts.path, + sorting_strategy = "ascending", + scroll_strategy = "cycle", + layout_config = { + prompt_position = "top", + }, - attach_mappings = function(_, map) - map("i", "<c-y>", fb_actions.create) + attach_mappings = function(_, map) + map("i", "<c-y>", fb_actions.create) - return true - end, - } + return true + end, + } - return require("telescope").extensions.file_browser.file_browser(opts) + return require("telescope").extensions.file_browser.file_browser(opts) end return setmetatable({}, { - __index = function(_, k) - reloader() - if M[k] then - return M[k] - else - return require("telescope.builtin")[k] - end - end, + __index = function(_, k) + reloader() + if M[k] then + return M[k] + else + return require("telescope.builtin")[k] + end + end, }) diff --git a/lua/alpha/telescope/mappings.lua b/lua/alpha/telescope/mappings.lua index 0845110..7d0f697 100644 --- a/lua/alpha/telescope/mappings.lua +++ b/lua/alpha/telescope/mappings.lua @@ -1,21 +1,21 @@ TelescopeMapArgs = TelescopeMapArgs or {} local map_tele = function(key, f, options, buffer, mode) - mode = mode or "n" + mode = mode or "n" - local rhs = function () - R('alpha.telescope')[f](options or {}) - end + local rhs = function() + R("alpha.telescope")[f](options or {}) + end - local map_options = { - remap = false, - silent = true, - } - if buffer then - map_options.buffer = buffer - end + local map_options = { + remap = false, + silent = true, + } + if buffer then + map_options.buffer = buffer + end - vim.keymap.set(mode, key, rhs, map_options) + vim.keymap.set(mode, key, rhs, map_options) end -- not shure what this line does diff --git a/lua/alpha/telescope/setup.lua b/lua/alpha/telescope/setup.lua index 627eaed..5e4a562 100644 --- a/lua/alpha/telescope/setup.lua +++ b/lua/alpha/telescope/setup.lua @@ -1,165 +1,165 @@ -local actions = require("telescope.actions") -local action_state = require("telescope.actions.state") -local action_layout = require("telescope.actions.layout") +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local action_layout = require "telescope.actions.layout" local set_prompt_to_entry_value = function(prompt_bufnr) - local entry = action_state.get_selected_entry() - if not entry or not type(entry) == "table" then - return - end + local entry = action_state.get_selected_entry() + if not entry or not type(entry) == "table" then + return + end - action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) + action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) end -require("telescope").setup({ - defaults = { - prompt_prefix = "❯ ", - selection_caret = "❯ ", - - winblend = 0, - - layout_strategy = "horizontal", - layout_config = { - width = 0.95, - height = 0.85, - -- preview_cutoff = 120, - prompt_position = "bottom", - - horizontal = { - preview_width = function(_, cols, _) - if cols > 200 then - return math.floor(cols * 0.5) - else - return math.floor(cols * 0.6) - end - end, - }, - - vertical = { - width = 0.9, - height = 0.95, - preview_height = 0.5, - }, - - flex = { - horizontal = { - preview_width = 0.9, - }, - }, - }, - - selection_strategy = "reset", - sorting_strategy = "descending", - scroll_strategy = "cycle", - color_devicons = true, - - mappings = { - i = { - ["<C-x>"] = false, - ["<C-s>"] = actions.select_horizontal, - ["<C-n>"] = "move_selection_next", - - ["<C-y>"] = set_prompt_to_entry_value, - - -- These are new :) - ["<M-p>"] = action_layout.toggle_preview, - ["<M-m>"] = action_layout.toggle_mirror, - -- ["<M-p>"] = action_layout.toggle_prompt_position, - - -- ["<M-m>"] = actions.master_stack, - - -- ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, - -- ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, - - -- This is nicer when used with smart-history plugin. - ["<C-k>"] = actions.cycle_history_next, - ["<C-j>"] = actions.cycle_history_prev, - - -- ["<c-space>"] = function(prompt_bufnr) - -- local opts = { - -- callback = actions.toggle_selection, - -- loop_callback = actions.send_selected_to_qflist, - -- } - -- require("telescope").extensions.hop._hop_loop(prompt_bufnr, opts) - -- end, - - -- ["<C-w>"] = function() - -- vim.api.nvim_input("<c-s-w>") - -- end, - }, - }, - - -- borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, - -- file_ignore_patterns = nil, - - file_previewer = require("telescope.previewers").vim_buffer_cat.new, - grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, - qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, - - history = { - path = "~/.local/share/nvim/databases/telescope_history.sqlite3", - limit = 100, - }, - }, - - pickers = { - fd = { - mappings = { - n = { - ["kj"] = "close", - }, - }, - }, - - git_branches = { - mappings = { - i = { - ["<C-a>"] = false, - }, - }, - }, - }, - - extensions = { - fzy_native = { - override_generic_sorter = true, - override_file_sorter = true, - }, - - fzf_writer = { - use_highlighter = false, - minimum_grep_characters = 6, - }, - - hop = { - -- keys define your hop keys in order; defaults to roughly lower- and uppercased home row - keys = { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";" }, -- ... and more - - -- Highlight groups to link to signs and lines; the below configuration refers to demo - -- sign_hl typically only defines foreground to possibly be combined with line_hl - sign_hl = { "WarningMsg", "Title" }, - - -- optional, typically a table of two highlight groups that are alternated between - line_hl = { "CursorLine", "Normal" }, - - -- options specific to `hop_loop` - -- true temporarily disables Telescope selection highlighting - clear_selection_hl = false, - -- highlight hopped to entry with telescope selection highlight - -- note: mutually exclusive with `clear_selection_hl` - trace_entry = true, - -- jump to entry where hoop loop was started from - reset_selection = true, - }, - - ["ui-select"] = { - require("telescope.themes").get_cursor({ - -- even more opts - }), - }, - }, -}) -_ = require("telescope").load_extension("notify") -_ = require("telescope").load_extension("file_browser") -_ = require("telescope").load_extension("ui-select") -_ = require("telescope").load_extension("fzf") +require("telescope").setup { + defaults = { + prompt_prefix = "❯ ", + selection_caret = "❯ ", + + winblend = 0, + + layout_strategy = "horizontal", + layout_config = { + width = 0.95, + height = 0.85, + -- preview_cutoff = 120, + prompt_position = "bottom", + + horizontal = { + preview_width = function(_, cols, _) + if cols > 200 then + return math.floor(cols * 0.5) + else + return math.floor(cols * 0.6) + end + end, + }, + + vertical = { + width = 0.9, + height = 0.95, + preview_height = 0.5, + }, + + flex = { + horizontal = { + preview_width = 0.9, + }, + }, + }, + + selection_strategy = "reset", + sorting_strategy = "descending", + scroll_strategy = "cycle", + color_devicons = true, + + mappings = { + i = { + ["<C-x>"] = false, + ["<C-s>"] = actions.select_horizontal, + ["<C-n>"] = "move_selection_next", + + ["<C-y>"] = set_prompt_to_entry_value, + + -- These are new :) + ["<M-p>"] = action_layout.toggle_preview, + ["<M-m>"] = action_layout.toggle_mirror, + -- ["<M-p>"] = action_layout.toggle_prompt_position, + + -- ["<M-m>"] = actions.master_stack, + + -- ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, + -- ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, + + -- This is nicer when used with smart-history plugin. + ["<C-k>"] = actions.cycle_history_next, + ["<C-j>"] = actions.cycle_history_prev, + + -- ["<c-space>"] = function(prompt_bufnr) + -- local opts = { + -- callback = actions.toggle_selection, + -- loop_callback = actions.send_selected_to_qflist, + -- } + -- require("telescope").extensions.hop._hop_loop(prompt_bufnr, opts) + -- end, + + -- ["<C-w>"] = function() + -- vim.api.nvim_input("<c-s-w>") + -- end, + }, + }, + + -- borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + -- file_ignore_patterns = nil, + + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + + history = { + path = "~/.local/share/nvim/databases/telescope_history.sqlite3", + limit = 100, + }, + }, + + pickers = { + fd = { + mappings = { + n = { + ["kj"] = "close", + }, + }, + }, + + git_branches = { + mappings = { + i = { + ["<C-a>"] = false, + }, + }, + }, + }, + + extensions = { + fzy_native = { + override_generic_sorter = true, + override_file_sorter = true, + }, + + fzf_writer = { + use_highlighter = false, + minimum_grep_characters = 6, + }, + + hop = { + -- keys define your hop keys in order; defaults to roughly lower- and uppercased home row + keys = { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";" }, -- ... and more + + -- Highlight groups to link to signs and lines; the below configuration refers to demo + -- sign_hl typically only defines foreground to possibly be combined with line_hl + sign_hl = { "WarningMsg", "Title" }, + + -- optional, typically a table of two highlight groups that are alternated between + line_hl = { "CursorLine", "Normal" }, + + -- options specific to `hop_loop` + -- true temporarily disables Telescope selection highlighting + clear_selection_hl = false, + -- highlight hopped to entry with telescope selection highlight + -- note: mutually exclusive with `clear_selection_hl` + trace_entry = true, + -- jump to entry where hoop loop was started from + reset_selection = true, + }, + + ["ui-select"] = { + require("telescope.themes").get_cursor { + -- even more opts + }, + }, + }, +} +_ = require("telescope").load_extension "notify" +_ = require("telescope").load_extension "file_browser" +_ = require("telescope").load_extension "ui-select" +_ = require("telescope").load_extension "fzf" diff --git a/lua/alpha/utils.lua b/lua/alpha/utils.lua index 47fd8c6..b1202d6 100644 --- a/lua/alpha/utils.lua +++ b/lua/alpha/utils.lua @@ -1,24 +1,24 @@ local M = {} M.save_and_exec = function() - local source_commands = { - lua = "luafi %", - vim = "source %", - } + local source_commands = { + lua = "luafi %", + vim = "source %", + } - local ft = vim.api.nvim_buf_get_option(0, "filetype") - local command = source_commands[ft] - if command == nil then - vim.notify("This type cant not be sourced", vim.log.levels.ERROR, { title = "Alpha Developer" }) - return - end + local ft = vim.api.nvim_buf_get_option(0, "filetype") + local command = source_commands[ft] + if command == nil then + vim.notify("This type cant not be sourced", vim.log.levels.ERROR, { title = "Alpha Developer" }) + return + end - -- Save and source - vim.api.nvim_command("silent w") - vim.api.nvim_command(command) + -- Save and source + vim.api.nvim_command "silent w" + vim.api.nvim_command(command) - local current_file_name = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":t") - vim.notify(string.format("File %s Sourced", current_file_name), vim.log.levels.INFO, { title = "Alpha Developer" }) + local current_file_name = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":t") + vim.notify(string.format("File %s Sourced", current_file_name), vim.log.levels.INFO, { title = "Alpha Developer" }) end return M |