commit 61e95391fbaf50f40b55be13bd43aae781d4a7fe Author: alex-chevski Date: Wed Dec 13 00:27:19 2023 +0300 my demo first config lua diff --git a/after/ftplugin/cucumber.lua b/after/ftplugin/cucumber.lua new file mode 100644 index 0000000..241d229 --- /dev/null +++ b/after/ftplugin/cucumber.lua @@ -0,0 +1,9 @@ +local set = vim.bo + +set.expandtab = true +set.tabstop = 2 +set.softtabstop = 2 +set.shiftwidth = 2 +set.smartindent = false +set.cindent = false +set.indentexpr = "" diff --git a/after/ftplugin/dbout.vim b/after/ftplugin/dbout.vim new file mode 100644 index 0000000..e181ecc --- /dev/null +++ b/after/ftplugin/dbout.vim @@ -0,0 +1,2 @@ +set nofoldenable +set colorcolumn= diff --git a/after/ftplugin/go.vim b/after/ftplugin/go.vim new file mode 100644 index 0000000..a03721a --- /dev/null +++ b/after/ftplugin/go.vim @@ -0,0 +1,3 @@ +set listchars=tab:\ \ ,trail:- +set makeprg=go\ build +set efm=%-G%f:%l:%c:W:\ %m,%-G%f:%l::W:\ %m,%f:%l:%c:%t:\ %m,%f:%l:%c::\ %m,%f:%l::%t:\ %m diff --git a/after/ftplugin/json.vim b/after/ftplugin/json.vim new file mode 100644 index 0000000..71c3c00 --- /dev/null +++ b/after/ftplugin/json.vim @@ -0,0 +1,4 @@ +setlocal expandtab +setlocal tabstop=2 +setlocal softtabstop=2 +setlocal shiftwidth=2 diff --git a/after/ftplugin/lua.lua b/after/ftplugin/lua.lua new file mode 100644 index 0000000..c49ec18 --- /dev/null +++ b/after/ftplugin/lua.lua @@ -0,0 +1,6 @@ +local set = vim.bo + +set.tabstop = 2 +set.softtabstop = 2 +set.expandtab = true +set.shiftwidth = 2 diff --git a/after/ftplugin/make.vim b/after/ftplugin/make.vim new file mode 100644 index 0000000..ad69b18 --- /dev/null +++ b/after/ftplugin/make.vim @@ -0,0 +1,2 @@ +setl listchars=tab:\ \ ,trail:- +setl noexpandtab diff --git a/after/ftplugin/nix.lua b/after/ftplugin/nix.lua new file mode 100644 index 0000000..c49ec18 --- /dev/null +++ b/after/ftplugin/nix.lua @@ -0,0 +1,6 @@ +local set = vim.bo + +set.tabstop = 2 +set.softtabstop = 2 +set.expandtab = true +set.shiftwidth = 2 diff --git a/after/ftplugin/yaml.vim b/after/ftplugin/yaml.vim new file mode 100644 index 0000000..45fb090 --- /dev/null +++ b/after/ftplugin/yaml.vim @@ -0,0 +1,5 @@ +setlocal expandtab +setlocal tabstop=2 +setlocal softtabstop=2 +setlocal shiftwidth=2 +setlocal indentkeys -=<:> diff --git a/after/queries/yaml/captures.scm b/after/queries/yaml/captures.scm new file mode 100644 index 0000000..4e0f1fb --- /dev/null +++ b/after/queries/yaml/captures.scm @@ -0,0 +1,6 @@ +;; extends + +(block_mapping_pair + key: (flow_node) @key.resolve (#eq? @key.resolve "resolve") + value: (flow_node) @resolver +) diff --git a/back/lua/alpha/animations.lua b/back/lua/alpha/animations.lua new file mode 100644 index 0000000..c0b7a6c --- /dev/null +++ b/back/lua/alpha/animations.lua @@ -0,0 +1,50 @@ +local redraw_buffer = function() + local Animation = require "animation" + local fps = 45 -- frames per second + local easing = require "animation.easing" + + local buffer = 0 + local len = 0 + local place_holder = {} + + local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true) + + for _, line in ipairs(lines) do + len = len + string.len(line) + table.insert(place_holder, "") + end + + vim.api.nvim_buf_set_lines(buffer, 0, #lines, true, place_holder) + + local duration = math.ceil(len / fps * 1000) + + local i = 1 + local line_nr = 1 + local insertLine = "" + + local function callback() + if lines[line_nr] == nil then + return true + end + local char = string.sub(lines[line_nr], i, i) + if char == nil then + return true + end + insertLine = insertLine .. char + i = i + 1 + vim.api.nvim_buf_set_lines(buffer, line_nr - 1, line_nr, true, { insertLine }) + + if insertLine == lines[line_nr] then + i = 1 + line_nr = line_nr + 1 + insertLine = "" + end + end + + local animation = Animation(duration, fps, easing.line, callback) + animation:run() +end + +return { + redraw_buffer = redraw_buffer, +} diff --git a/back/lua/alpha/completition/init.lua b/back/lua/alpha/completition/init.lua new file mode 100644 index 0000000..92e1f91 --- /dev/null +++ b/back/lua/alpha/completition/init.lua @@ -0,0 +1,133 @@ +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.setup { + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + [""] = cmp.mapping.complete(), + }, + sources = { + { name = "nvim_lua" }, + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "copilot" }, + { + name = "buffer", + keyword_length = 4, + option = { + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + local bufnr = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_option(bufnr, "buftype") ~= "terminal" then + bufs[bufnr] = true + end + end + return vim.tbl_keys(bufs) + 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 = "[ ]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + copilot = "[ﮧ ]", + ["vim-dadbod-completion"] = "[DB]", + }, + }, + }, + + sorting = { + priority_weight = 2, + comparators = { + compare.kind, + compare.sort_text, + }, + }, + + experimental = { + native_menu = false, + + ghost_text = false, + }, +} + +vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" }) + +-- 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" }, + }), +}) + +-- 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" }, + }, +}) + +-- 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" }, + }), +}) + +cmp.setup.filetype({ "sql", "mysql", "plsql" }, { + sources = cmp.config.sources({ + { name = "vim-dadbod-completion" }, + }, { + { name = "buffer" }, + }), +}) diff --git a/back/lua/alpha/dap/configs/golang.lua b/back/lua/alpha/dap/configs/golang.lua new file mode 100644 index 0000000..1ec449a --- /dev/null +++ b/back/lua/alpha/dap/configs/golang.lua @@ -0,0 +1 @@ +require("dap-go").setup() diff --git a/back/lua/alpha/dap/configs/javascript.lua b/back/lua/alpha/dap/configs/javascript.lua new file mode 100644 index 0000000..b910f30 --- /dev/null +++ b/back/lua/alpha/dap/configs/javascript.lua @@ -0,0 +1,45 @@ +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}", + }, + } +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", + }, + } +end diff --git a/back/lua/alpha/dap/configs/php.lua b/back/lua/alpha/dap/configs/php.lua new file mode 100644 index 0000000..968bb9d --- /dev/null +++ b/back/lua/alpha/dap/configs/php.lua @@ -0,0 +1,27 @@ +local dap = require("dap") + +dap.adapters.php = { + 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}", + }, + }, +} diff --git a/back/lua/alpha/dap/configs/rust.lua b/back/lua/alpha/dap/configs/rust.lua new file mode 100644 index 0000000..9ca976f --- /dev/null +++ b/back/lua/alpha/dap/configs/rust.lua @@ -0,0 +1,57 @@ +local dap = require("dap") + +local rust_adapter = nil +local rust_adapters = { "lldb-vscode", "codelldb" } +for _, adapter in pairs(rust_adapters) do + if vim.fn.executable(adapter) then + rust_adapter = adapter + end +end + +if rust_adapter ~= nil then + dap.adapters.lldb = { + type = "executable", + command = rust_adapter, + name = "lldb", + } + + dap.configurations.rust = { + { + name = "launch", + type = "lldb", + request = "launch", + program = function() + local dir = vim.fn.getcwd() + return dir .. "/target/debug/" .. vim.fs.basename(dir) + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + { + name = "custom", + type = "lldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + } +end diff --git a/back/lua/alpha/dap/init.lua b/back/lua/alpha/dap/init.lua new file mode 100644 index 0000000..81651f7 --- /dev/null +++ b/back/lua/alpha/dap/init.lua @@ -0,0 +1,106 @@ +local dap, dapui, hydra = require "dap", require "dapui", require "hydra" + +-- Setup Virtual Text +require("nvim-dap-virtual-text").setup {} + +for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/alpha/dap/configs/*.lua", true)) do + loadfile(ft_path)() +end + +-- Signs +vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapStopped", { text = "▶", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointRejected", { text = "🚫", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointCondition", { text = "❓", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapLogPoint", { text = "💬", texthl = "", linehl = "", numhl = "" }) + +-- UI structure +dapui.setup { + icons = { expanded = "▾", collapsed = "▸" }, + layouts = { + { + elements = { + "scopes", + "breakpoints", + "stacks", + "watches", + }, + size = 80, + position = "right", + }, + { + elements = { + "repl", + "console", + }, + size = 10, + position = "bottom", + }, + }, +} + +-- Events Listeners +dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open {} +end + +local hint = [[ + Nvim DAP + _d_: Start/Continue _j_: StepOver _k_: StepOut _l_: StepInto ^ + _bp_: Toogle Breakpoint _bc_: Conditional Breakpoint ^ + _?_: log point ^ + _c_: Run To Cursor ^ + _h_: Show information of the variable under the cursor ^ + _x_: Stop Debbuging ^ + ^^ __ +]] + +hydra { + name = "dap", + hint = hint, + mode = "n", + config = { + color = "blue", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "d", + heads = { + { "d", dap.continue }, + { "bp", dap.toggle_breakpoint }, + { "l", dap.step_into }, + { "j", dap.step_over }, + { "k", dap.step_out }, + { "h", dapui.eval }, + { "c", dap.run_to_cursor }, + { + "bc", + function() + vim.ui.input({ prompt = "Condition: " }, function(condition) + dap.set_breakpoint(condition) + end) + end, + }, + { + "?", + function() + vim.ui.input({ prompt = "Log: " }, function(log) + dap.set_breakpoint(nil, nil, log) + end) + end, + }, + { + "x", + function() + dap.terminate() + dapui.close {} + dap.clear_breakpoints() + end, + }, + + { "", nil, { exit = true } }, + }, +} diff --git a/back/lua/alpha/globals.lua b/back/lua/alpha/globals.lua new file mode 100644 index 0000000..e445e72 --- /dev/null +++ b/back/lua/alpha/globals.lua @@ -0,0 +1,23 @@ +--- Dumps all values into pretty print +---@vararg any +---@return any +dump = function(...) + local args = {...} + + local mapped = {} + for _, v in ipairs(args) do + table.insert(mapped, vim.inspect(v)) + end + print(unpack(mapped)) + + return unpack(args) +end + +Reload = function(...) + return require("plenary.reload").reload_module(...) +end + +R = function(name) + Reload(name) + return require(name) +end diff --git a/back/lua/alpha/laravel-tinker.lua b/back/lua/alpha/laravel-tinker.lua new file mode 100644 index 0000000..214d958 --- /dev/null +++ b/back/lua/alpha/laravel-tinker.lua @@ -0,0 +1,64 @@ +local M = {} + +M.runCode = function() + local curBuff = vim.api.nvim_get_current_buf() + + local stats = vim.api.nvim_list_uis()[1] + + 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", + }) + + -- 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) + + -- print (vim.inspect(code)) + + local codeText = vim.fn.shellescape(table.concat(code, " ")) + -- print(codeText) + + local result = vim.fn.systemlist("php artisan tinker --execute=" .. codeText) + + 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") +end + +return M diff --git a/back/lua/alpha/lsp/attach.lua b/back/lua/alpha/lsp/attach.lua new file mode 100644 index 0000000..e71cb75 --- /dev/null +++ b/back/lua/alpha/lsp/attach.lua @@ -0,0 +1,29 @@ +local telescope_mapper = require "alpha.telescope.mappings" + +return function(client, bufnr) + -- keymaps for lsp + vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0, desc = "LSP Help information of symbol under the cursor" }) + vim.keymap.set("n", "vrn", vim.lsp.buf.rename, { buffer = 0, desc = "LSP Rename symbol under cursor" }) + vim.keymap.set("i", "", vim.lsp.buf.signature_help, { buffer = 0, desc = "LSP Signature help" }) + vim.keymap.set("n", "vo", ":LspRestart", { noremap = true, desc = "LSP Restart Server" }) + vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, { buffer = 0, desc = "LSP Code actions" }) + vim.keymap.set("n", "vf", function() + return vim.lsp.buf.format { + async = true, + filter = function(cli) + return cli.name ~= "lua_ls" + end, + } + end, { buffer = 0, desc = "LSP format file" }) + + telescope_mapper("gr", "lsp_references", { buffer = true, desc = "LSP References of symbol on cursor" }) + telescope_mapper("pv", "find_symbol", { buffer = true, desc = "LSP find symbol on the project" }) + telescope_mapper("pd", "lsp_document_symbols", { buffer = true, desc = "LSP document symbols" }) + telescope_mapper("gd", "lsp_definitions", { buffer = true, desc = "LSP go to definition" }) + + vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" + + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint(bufnr, true) + end +end diff --git a/back/lua/alpha/lsp/default.lua b/back/lua/alpha/lsp/default.lua new file mode 100644 index 0000000..4f53ddd --- /dev/null +++ b/back/lua/alpha/lsp/default.lua @@ -0,0 +1,26 @@ +return { + mason = { + enable = true, + auto_install = false, + }, + servers = { + emmet_ls = { enable = true }, + gopls = { enable = true }, + html = { enable = true }, + jsonls = { enable = true }, + lua_ls = { enable = true, neodev = true }, + nil_ls = { enable = true }, + phpactor = {enable = true }, + rust_analyzer = { enable = true }, + svelte = { enable = true }, + tailwindcss = { enable = true, filetypes = {"blade", "html", "svelte"} }, + tsserver = { enable = true }, + volar = { enable = true }, + }, + default_options = function (options) + return vim.tbl_deep_extend("force", { + on_attach = require"alpha.lsp.attach", + flags = require "alpha.lsp.flags", + }, options) + end, +} diff --git a/back/lua/alpha/lsp/flags.lua b/back/lua/alpha/lsp/flags.lua new file mode 100644 index 0000000..f70b467 --- /dev/null +++ b/back/lua/alpha/lsp/flags.lua @@ -0,0 +1,3 @@ +return { + debounce_text_changes = 150, +} diff --git a/back/lua/alpha/lsp/init.lua b/back/lua/alpha/lsp/init.lua new file mode 100644 index 0000000..0d69f07 --- /dev/null +++ b/back/lua/alpha/lsp/init.lua @@ -0,0 +1,65 @@ +return { + setup = function(ops) + ops = vim.tbl_deep_extend("force", require "alpha.lsp.default", ops) + + local lspconfig = require "lspconfig" + + local mason_servers = {} + for server, options in pairs(ops.servers) do + if options.enable == true then + local ok, definition = pcall(require, "alpha.lsp.servers." .. server) + local server_options + if not ok then + server_options = ops.default_options(options) + else + server_options = definition(options) + end + lspconfig[server].setup(server_options) + table.insert(mason_servers, server) + end + end + + -- Mason + if ops.mason.enable then + local mason_ops = {} + if ops.mason.auto_install == true then + mason_ops.ensure_installed = mason_servers + end + local mason_lspconfig = require "mason-lspconfig" + mason_lspconfig.setup(mason_ops) + end + + -- TODO: implement null ls with options + require "alpha.lsp.null-ls" + + local servers = {} + for server, options in pairs(ops.servers) do + table.insert(servers, string.format("%s <%s>", server, options.enable)) + end + + -- TODO: create an auto command that on write of the configuration, calls again the setup and restart the server if it's up. + -- can get the client by name of the file + + vim.api.nvim_create_user_command("AlphaLSP", function() + vim.ui.select(servers, { prompt = "LSP Servers" }, function(server) + if server == nil then + return + end + + server = string.match(server, "^(.+) <") + local path = string.format("%s/lua/alpha/lsp/servers/%s.lua", vim.fn.stdpath "config", server) + if vim.fn.filereadable(path) == 0 then + local create = vim.fn.confirm("Server Does Not exist. Create new server?", "&Yes\n&No\n&Cancel") + if create ~= 1 then + return + end + end + + local uri = vim.uri_from_fname(path) + local buffer = vim.uri_to_bufnr(uri) + + vim.api.nvim_win_set_buf(0, buffer) + end) + end, {}) + end, +} diff --git a/back/lua/alpha/lsp/mason.lua b/back/lua/alpha/lsp/mason.lua new file mode 100644 index 0000000..a8c6ce7 --- /dev/null +++ b/back/lua/alpha/lsp/mason.lua @@ -0,0 +1,23 @@ +local mason_lspconfig = require "mason-lspconfig" +local servers = require "alpha.lsp.servers" +local lspconfig = require "lspconfig" + +local mason_servers = {} + +for server, _ in pairs(servers) do + local cmd = lspconfig[server].cmd[1] + if vim.fn.executable(cmd) == 0 then + table.insert(mason_servers, server) + end +end + +mason_lspconfig.setup { + -- ensure_installed = mason_servers, +} + +-- filter the list for the ones not globally installed +-- require("mason-tool-installer").setup { +-- ensure_installed = vim.tbl_filter(function (tool) +-- return vim.fn.executable(tool) == 0 +-- end, require "alpha.lsp.tools"), +-- } diff --git a/back/lua/alpha/lsp/null-ls.lua b/back/lua/alpha/lsp/null-ls.lua new file mode 100644 index 0000000..b329ba6 --- /dev/null +++ b/back/lua/alpha/lsp/null-ls.lua @@ -0,0 +1,53 @@ +local null_ls = require "null-ls" +-- local php_actions = require "php-code-actions" +-- local laravel_actions = require("laravel.code-actions") + +null_ls.setup { + 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.diagnostics.yamllint, + + -- 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, + -- -- command = "./bin/phpstan", + -- -- condition = function () + -- -- return vim.fn.findfile("bin/phpstan") ~= "" + -- -- end + -- }, + null_ls.builtins.diagnostics.phpcs.with { + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + condition = function(utils) + return utils.root_has_file "phpcs.xml" + end, + }, + null_ls.builtins.formatting.pint, + }, +} + +vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, {desc = "LSP (null ls) Code actions"}) +vim.keymap.set("n", "vf", function() + return vim.lsp.buf.format { async = true } +end, {desc = "LSP (null ls) Format file"}) + +-- function to toogle and possible restart it +vim.api.nvim_create_user_command("NullLsToggle", function() + local sources = vim.tbl_map(function(el) + return el.name + end, null_ls.get_sources()) + vim.ui.select(sources, {}, function(selected) + if not selected then + return + end + null_ls.toggle(selected) + end) +end, {}) diff --git a/back/lua/alpha/lsp/servers/emmet_ls.lua b/back/lua/alpha/lsp/servers/emmet_ls.lua new file mode 100644 index 0000000..c4f1cb6 --- /dev/null +++ b/back/lua/alpha/lsp/servers/emmet_ls.lua @@ -0,0 +1,12 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + capabilities = capabilities, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, + }, ops) +end diff --git a/back/lua/alpha/lsp/servers/html.lua b/back/lua/alpha/lsp/servers/html.lua new file mode 100644 index 0000000..7b8ef54 --- /dev/null +++ b/back/lua/alpha/lsp/servers/html.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "html-languageserver" == 1 then + config.cmd = { "html-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/back/lua/alpha/lsp/servers/jsonls.lua b/back/lua/alpha/lsp/servers/jsonls.lua new file mode 100644 index 0000000..9c731ab --- /dev/null +++ b/back/lua/alpha/lsp/servers/jsonls.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "json-languageserver" == 1 then + config.cmd = { "json-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/back/lua/alpha/lsp/servers/lua_ls.lua b/back/lua/alpha/lsp/servers/lua_ls.lua new file mode 100644 index 0000000..c5f72bf --- /dev/null +++ b/back/lua/alpha/lsp/servers/lua_ls.lua @@ -0,0 +1,36 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + if ops.neodev == true then + require("neodev").setup() + end + + return vim.tbl_extend("force", { + 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, + }, + hint = { + enable = true, + }, + completion = { + callSnippet = "Replace", + }, + }, + }, + }, ops) +end diff --git a/back/lua/alpha/lsp/servers/phpactor.lua b/back/lua/alpha/lsp/servers/phpactor.lua new file mode 100644 index 0000000..e6bebcd --- /dev/null +++ b/back/lua/alpha/lsp/servers/phpactor.lua @@ -0,0 +1,80 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +local function phpactor_attach(_, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorReindex", function() + vim.lsp.buf_notify(bufnr, "phpactor/index/reindex", {}) + end, {}) + + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorStatus", function() + local results, _ = vim.lsp.buf_request_sync(bufnr, "phpactor/status", { ["return"] = true }) + + local content = "" + + for _, res in pairs(results or {}) do + if res ~= nil and res["result"] ~= nil then + content = content .. res["result"] + end + end + + local Popup = require "nui.popup" + local event = require("nui.utils.autocmd").event + + local popup = Popup { + enter = true, + focusable = true, + border = { + style = "rounded", + }, + position = "50%", + size = { + width = "80%", + height = "60%", + }, + } + + -- mount/open the component + popup:mount() + + -- unmount component when cursor leaves buffer + popup:on(event.BufLeave, function() + popup:unmount() + end) + local out = {} + for match in string.gmatch(content, "[^\n]+") do + table.insert(out, match) + end + + vim.api.nvim_buf_set_option(popup.bufnr, "filetype", "markdown") + vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, out) + end, {}) +end + +return function(ops) + return vim.tbl_extend("force", { + on_attach = function(client, bufnr) + lsp_attach(client, bufnr) + phpactor_attach(client, bufnr) + end, + flags = lsp_flags, + filetypes = { "php", "blade" }, + init_options = { + ["language_server_worse_reflection.inlay_hints.enable"] = true, + ["language_server_worse_reflection.inlay_hints.params"] = true, + -- ["language_server_worse_reflection.inlay_hints.types"] = true, + ["language_server_configuration.auto_config"] = false, + ["code_transform.import_globals"] = true, + ["language_server_phpstan.enabled"] = true, + ["language_server_phpstan.level"] = 7, + ["language_server_phpstan.bin"] = "phpstan", + }, + handlers = { + ["textDocument/inlayHint"] = function(err, result, ...) + for _, res in ipairs(result) do + res.label = res.label .. ": " + end + vim.lsp.handlers["textDocument/inlayHint"](err, result, ...) + end, + }, + }, ops) +end diff --git a/back/lua/alpha/lsp/servers/rust_analyzer.lua b/back/lua/alpha/lsp/servers/rust_analyzer.lua new file mode 100644 index 0000000..c0db321 --- /dev/null +++ b/back/lua/alpha/lsp/servers/rust_analyzer.lua @@ -0,0 +1,24 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["rust-analyzer"] = { + checkOnSave = { + allFeatures = true, + overrideCommand = { + "cargo", + "clippy", + "--workspace", + "--message-format=json", + "--all-targets", + "--all-features", + }, + }, + }, + }, + }, ops) +end diff --git a/back/lua/alpha/lsp/servers/tsserver.lua b/back/lua/alpha/lsp/servers/tsserver.lua new file mode 100644 index 0000000..e27d94a --- /dev/null +++ b/back/lua/alpha/lsp/servers/tsserver.lua @@ -0,0 +1,33 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }, ops) +end diff --git a/back/lua/alpha/lsp/tools.lua b/back/lua/alpha/lsp/tools.lua new file mode 100644 index 0000000..7919521 --- /dev/null +++ b/back/lua/alpha/lsp/tools.lua @@ -0,0 +1,8 @@ +return { + "codelldb", + "go-debug-adapter", + "js-debug-adapter", + "php-debug-adapter", + "phpcs", + "phpstan", +} diff --git a/back/lua/alpha/packer_install.lua b/back/lua/alpha/packer_install.lua new file mode 100644 index 0000000..9ef6658 --- /dev/null +++ b/back/lua/alpha/packer_install.lua @@ -0,0 +1,27 @@ +local download_packer = function() + if vim.fn.input "Download Packer? (y for yes)" ~= "y" then + return + end + + local directory = string.format("%s/site/pack/packer/start/", vim.fn.stdpath "data") + + vim.fn.mkdir(directory, "p") + + local out = vim.fn.system( + string.format("git clone %s %s", "https://github.com/wbthomason/packer.nvim", directory .. "/packer.nvim") + ) + + print(out) + print "Downloading packer.nvim..." + print "( You'll need to restart now )" +end + +return function() + if not pcall(require, "packer") then + download_packer() + + return true + end + + return false +end diff --git a/back/lua/alpha/php/gateway.lua b/back/lua/alpha/php/gateway.lua new file mode 100644 index 0000000..5f8ddae --- /dev/null +++ b/back/lua/alpha/php/gateway.lua @@ -0,0 +1,137 @@ +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 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) + + 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 + + return mutations_definitions +end + +-- "'@=mutation(\"App\\\\GraphQL\\\\Mutations\\\\Mutation::action\", ...)'", +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 + return + end + + local args_tbl = vim.split(args, ", ") + local fqn = string.match(args_tbl[1], '"(.+)"') + fqn = string.gsub(fqn, "\\\\", "\\") + -- P(fqn) + + require("alpha.php.lsp").find(fqn, "phpactor") +end + +--- @param bufnr integer Buff id +gateway.get_graphql_definitions = function(bufnr) + vim.treesitter.query.set( + "yaml", + "GraphQL_endpoints", + [[ + (document (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @mutation + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @resolve (#eq? @resolve "resolve") + value: (flow_node) @resolver + ))) + ))) + ))) + ))) + )))) + ]] + ) + + local query = vim.treesitter.query.get("yaml", "GraphQL_endpoints") + + local elements = {} + + local parsers = require "nvim-treesitter.parsers" + local parser = parsers.get_parser(bufnr) + local tree = parser:parse()[1] + + 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 +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\\\\Mutation::action\", ...)'", + -- value = "deleteVehicleImage" + return { + value = entry, + display = entry.value, + ordinal = entry.value, + path = vim.api.nvim_buf_get_name(entry.buffer), + lnum = entry.lnum, + resolver = entry.resolver, + } + end, + }, + sorter = conf.generic_sorter(opts), + previewer = conf.grep_previewer(opts), + attach_mappings = function(prompt_bufnr, map) + action_set.select:enhance { + post = function() + local selection = action_state.get_selected_entry() + vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) + end, + } + map("i", "", function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + open_resolver(selection.resolver) + end) + return true + end, + }) + :find() +end + +return gateway diff --git a/back/lua/alpha/php/lsp.lua b/back/lua/alpha/php/lsp.lua new file mode 100644 index 0000000..37e0bc0 --- /dev/null +++ b/back/lua/alpha/php/lsp.lua @@ -0,0 +1,151 @@ +local Path = require "plenary.path" + +local lsp = {} + +local open_filename = function(filename) + if vim.api.nvim_buf_get_name(0) ~= filename then + filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) + pcall(vim.cmd, string.format("%s %s", "edit", filename)) + end +end + +---@param server_name string +---@return table|nil, boolean +local get_client = function(server_name) + local clients = vim.lsp.get_active_clients { name = server_name } + local client = clients[1] or nil + local new_instance = false + + if not client then + local server = require("lspconfig")[server_name] + local config = server.make_config(vim.fn.getcwd()) + local client_id = vim.lsp.start(config) + client = vim.lsp.get_client_by_id(client_id) + new_instance = true + end + + return client, new_instance +end + +local function go_to(client, is_new_instance, full_class, method) + local class_parts = vim.split(full_class, "\\") + local class = class_parts[#class_parts] + + local resp = client.request_sync("workspace/symbol", { query = class }, nil) + + local locations = vim.lsp.util.symbols_to_items(resp.result or {}, nil) or {} + if vim.tbl_isempty(locations) then + vim.api.nvim_err_writeln("Empty response looking for class: " .. full_class) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local class_location = nil + for idx, location in pairs(locations) do + if location.text == string.format("[Class] %s", full_class) then + class_location = locations[idx] + break + end + end + + if class_location == nil then + vim.api.nvim_err_writeln("Could not find class for : " .. full_class) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + open_filename(class_location.filename) + + local params = vim.lsp.util.make_position_params(0) + if is_new_instance then + vim.lsp.buf_attach_client(0, client.id) + end + + vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(method_err, method_server_result, _, _) + if method_err then + vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. method_err.message) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local method_locations = vim.lsp.util.symbols_to_items(method_server_result or {}, 0) or {} + if vim.tbl_isempty(method_locations) then + vim.api.nvim_err_writeln(string.format("empty response looking for method: %s", method or "__invoke")) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local method_location = nil + for _, value in ipairs(method_locations) do + if value.text == string.format("[Method] %s", method or "__invoke") then + method_location = value + break + end + end + + if method_location == nil then + if is_new_instance then + vim.lsp.stop_client(client.id) + end + 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("Erro setting row and col " .. err_msg) + end + vim.cmd "normal zt" + end + if is_new_instance then + vim.lsp.stop_client(client.id) + end + end) +end + +---Return a buffer id for the given client +---@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 buffers = vim.lsp.get_buffers_by_client_id(clients[1].id) + + if #buffers == 0 then + return nil + end + + return buffers[1] +end + +--- @param fqn string: fully name to search Class::method +lsp.find = function(fqn, server_name) + local search = vim.split(fqn, "::") + local fqn_class = search[1] + local method = search[2] + + local client, is_new_instance = get_client(server_name) + + if not client then + vim.api.nvim_err_writeln "Could not get lsp client" + return + end + + go_to(client, is_new_instance, fqn_class, method) +end + +return lsp diff --git a/back/lua/alpha/php/servers.lua b/back/lua/alpha/php/servers.lua new file mode 100644 index 0000000..9450152 --- /dev/null +++ b/back/lua/alpha/php/servers.lua @@ -0,0 +1,38 @@ +local phpactor = {} + +-- TODO possible improvement look how it works underline +-- use the client directly to call, no need for the buffer +-- to find a class. +-- 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) +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) + +vim.lsp.get_client_by_id(client_id) +-- use client.request or request_sync +-- look for the direct of the symbol +return { + phpactor = phpactor, +} diff --git a/back/lua/alpha/select_to_quickfix.lua b/back/lua/alpha/select_to_quickfix.lua new file mode 100644 index 0000000..ebd1561 --- /dev/null +++ b/back/lua/alpha/select_to_quickfix.lua @@ -0,0 +1,53 @@ +local api = vim.api + +local function create_quickfix_entry(selection) + local filename, linenumber = selection:match "([^:]+):(%d+)" + + return { + filename = vim.fn.getcwd() .. "/" .. filename, + lnum = tonumber(linenumber), + col = 1, + text = filename, + } +end + +local function add_selections_to_quickfix(selections) + local quickfix_list = {} + + for _, selection in ipairs(selections) do + local entry = create_quickfix_entry(selection) + table.insert(quickfix_list, entry) + end + + vim.fn.setqflist(quickfix_list, "r") +end + +local function get_selections() + local _, end_line, _, _ = unpack(vim.fn.getpos "'>") + local _, start_line, _, _ = unpack(vim.fn.getpos "'<") + local lines = api.nvim_buf_get_lines(0, start_line - 1, end_line, false) + + local selections = {} + for _, line in ipairs(lines) do + for selection in line:gmatch "%S+" do + table.insert(selections, selection) + end + end + + return selections +end + +local function select_to_quickfix() + local selections = get_selections() + + if #selections > 0 then + add_selections_to_quickfix(selections) + print "Selections added to quickfix list" + else + print "No selections found" + end +end + +return { + handle = select_to_quickfix, +} diff --git a/back/lua/alpha/snips/ft/cucumber.lua b/back/lua/alpha/snips/ft/cucumber.lua new file mode 100644 index 0000000..6176a87 --- /dev/null +++ b/back/lua/alpha/snips/ft/cucumber.lua @@ -0,0 +1,71 @@ +local ls = require "luasnip" +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local fmt = require("luasnip.extras.fmt").fmt + +local M = { + clean = t [[Given clean stubs list]], + all = t [[And all stubs should be matched]], + status_code = fmt([[Then the response status code should be {}]], { i(1, "200") }), + no_error = t [[And the JSON path expression errors should not have result]], + json_data = fmt([[And the JSON path expression "data" should be equal to: +""" +{{ + {} +}} +""" + ]], {i(1)}), + feature = fmt( + [[Feature: {} + + {} +]], + { + i(1, "Feature Name"), + i(0), + } + ), + scenario = fmt( + [[Scenario: {} + {}]], + { + i(1, "Scenario name"), + i(0), + } + ), + stub = fmt([[And the APIClient will send a request with a stub from "{}"]], { i(1) }), + request = fmt( + [[When I send the GraphQL request: +""" +{} +"""]], + { i(1) } + ), + result = fmt( + [[And the JSON path expression "data" should be equal to: +""" +{{ + "result": {{ + {} + }} +}} +"""]], + { i(1) } + ), + query = fmt( + [[{} {{ +result: {}({}) {{ + {} +}} + }}]], + { c(1, { t "mutation", t "query" }), i(2, "mutation"), i(3, ""), i(4) } + ), + access = fmt( + [[And the Access Cache has Allowed the userId "{}" for inspectionId "{}"]], + { i(1, "3414054"), i(2, "42") } + ), + branch_access = fmt([[And the Access Cache has branch "{}" for userId "{}"]], { i(1, "1"), i(2, "3414054") }), +} + +return M diff --git a/back/lua/alpha/snips/ft/go.lua b/back/lua/alpha/snips/ft/go.lua new file mode 100644 index 0000000..9c3977f --- /dev/null +++ b/back/lua/alpha/snips/ft/go.lua @@ -0,0 +1,134 @@ +local ls = require "luasnip" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local 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 get_node_text = vim.treesitter.get_node_text + +vim.treesitter.query.set( + "go", + "LuaSnip_Result", + [[ + [ + (method_declaration result: (_) @id) + (function_declaration result: (_) @id) + (func_literal result: (_) @id) + ] +]] +) + +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) +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, +} + +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.query.get("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)) +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), + }, +} + +M.f = fmt("func {}({}) {} {{\n\t{}\n}}", { i(1, "name"), i(2), i(3), i(0) }) + +return M diff --git a/back/lua/alpha/snips/ft/lua.lua b/back/lua/alpha/snips/ft/lua.lua new file mode 100644 index 0000000..d896f3e --- /dev/null +++ b/back/lua/alpha/snips/ft/lua.lua @@ -0,0 +1,69 @@ +local ls = require "luasnip" + +-- local snippet = ls.s +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local d = ls.dynamic_node +local i = ls.insert_node +local f = ls.function_node +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 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), + }) +end + +local newline = function(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", + }, + + preq = fmt( + [[local ok, {} = pcall(require, "{}") +if not ok then + return +end]], + { + f(function(args) + return args[1][1] + end, { 1 }), + i(1), + } + ), + + plugin = fmt( + [[return {{ + "{}" +}}]], + { + i(1, "plugin"), + } + ), +} diff --git a/back/lua/alpha/snips/ft/php.lua b/back/lua/alpha/snips/ft/php.lua new file mode 100644 index 0000000..72936d8 --- /dev/null +++ b/back/lua/alpha/snips/ft/php.lua @@ -0,0 +1,163 @@ +local ls = require "luasnip" +local composer = require "composer" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local f = ls.function_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt + +local 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) +end + +local var_name = function(args) + return snippet_from_nodes(nil, { + i(1, args[1][1]:gsub("^%u", string.lower):gsub("Interface", "") or ""), + }) +end + +local class_name = function() + return vim.fn.expand "%:t:r" +end + +local M = {} + +M.v = fmt( + [[ +/** + * @var {} + */ +{} {} ${}; +]], + { + i(1, "type"), + visibility(2, "private"), + i(3, "Type"), + i(4, "var"), + } +) + +M.class = fmt( + [[ + + */ + private ObjectProphecy ${}; +]], + { + i(1, "Type"), + d(2, var_name, { 1 }), + } +) + +M.iop = fmt( + [[$this->{} = $this->prophesize({}::class);]], + { + i(1, ""), + i(2, ""), + } +) + +M.arg = fmt([[{} ${}]], { + i(1, "Type"), + d(2, var_name, { 1 }), +}) + +M._c = fmt( + [[{} function __construct({}) {{ + {} +}}]], + { + visibility(1, "public"), + i(2), + i(0), + } +) + +M._p = fmt( + [[{} function __construct( + {} +) {{ +}}]], + { + visibility(1, "public"), + i(2), + } +) + +M.strict = t "declare(strict_types=1);" + +M["fn"] = fmt( + [[{} function {}({}): {} +{{ + {} +}}]], + { visibility(1, "public"), i(2), i(3), i(4, "void"), i(0) } +) + +M["then"] = fmt( + [[->then( + function ({}) {{ + {} + }} +)]], + { i(1, ""), i(2, "") } +) + +M.test = fmt( + [[/** + * @test + */ +public function it_{}(): void +{{ + {} +}} +]], + { i(1, ""), i(0, "") } +) + +return M diff --git a/back/lua/alpha/snips/ft/yaml.lua b/back/lua/alpha/snips/ft/yaml.lua new file mode 100644 index 0000000..3924c6f --- /dev/null +++ b/back/lua/alpha/snips/ft/yaml.lua @@ -0,0 +1,225 @@ +local ls = require "luasnip" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local f = ls.function_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt +local rep = require("luasnip.extras").rep + +local M = { + str = fmt( + [[{}: + type: string +{}]], + { + i(1, ""), + i(2, ""), + } + ), + bool = fmt( + [[{}: + type: boolean +{}]], + { + i(1, ""), + i(2, ""), + } + ), + float = fmt( + [[{}: + type: number + format: float +{}]], + { + i(1, ""), + i(2, ""), + } + ), + int = fmt( + [[{}: + type: integer +{}]], + { + i(1, ""), + i(2, ""), + } + ), + id = fmt( + [[{}: + type: integer + format: int64 +{}]], + { + i(1, ""), + i(2, ""), + } + ), + class = fmt( + [[{}: + $ref: '#/components/schemas/{}' +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + date = fmt( + [[{}: + type: string + format: date-time +{}]], + { + i(1, ""), + i(2, ""), + } + ), + arr = fmt( + [[{}: + type: array + items: + {} +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + ref = fmt([[$ref: '#/components/schemas/{}']], { i(1, "") }), + obj = fmt( + [[type: object +properties: + {}]], + i(1, "") + ), + aint = fmt( + [[{}: + type: array + items: + type: int + format: int64 +{}]], + { + i(1, ""), + i(2, ""), + } + ), + astr = fmt( + [[{}: + type: array + items: + type: string +{}]], + { + i(1, ""), + i(2, ""), + } + ), + + mut = fmt( + [[{}: + type: "{}" + resolve: '@=mutation("App\\GraphQL\\Mutation\\{}::{}", {}, info)' + args: + {} +]], + { + i(1, ""), + i(2, ""), + i(3, ""), + rep(1), + i(5, ""), + i(6, ""), + } + ), + + input = fmt( + [[{}: + type: input-object + config: + fields: + {} +]], + { + i(1, ""), + i(2, ""), + } + ), + f = fmt([[{}: {{ type: "{}" }}]], { i(1, ""), i(2, "") }), + + api = fmt( + [[openapi: 3.0.2 +info: + title: {} + contact: + name: eva-team-be + version: {} +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(0, "") } + ), + param = fmt( + [[parameters: + - name: {} + description: {} + in: path + required: true + schema: + type: integer + format: int64 +]], + { i(1, ""), i(2, "") } + ), + get = fmt( + [[get: + operationId: {} + description: {} + tags: [ {} ] + responses: + 200: + description: Response + content: + application/json: + schema: + {} + ]], + { i(1, "GetOperation"), i(2, "description"), i(3, "tag"), i(4, "") } + ), + + put = fmt( + [[put: + operationId: {} + tags: [ {} ] + description: {} + requestBody: + content: + application/json: + schema: + {} + required: true + responses: + 200: + description: {} + content: + application/json: + schema: + {} + ]], + { i(1, "PutOperation"), i(2, "tag"), i(3, "description"), i(4, ""), i(5, "description"), i(6, "") } + ), +} + +return M diff --git a/back/lua/alpha/telescope/init.lua b/back/lua/alpha/telescope/init.lua new file mode 100644 index 0000000..c4daf6c --- /dev/null +++ b/back/lua/alpha/telescope/init.lua @@ -0,0 +1,186 @@ +local SHOULD_RELOAD_TELESCOPE = false + +local reloader = function() + if SHOULD_RELOAD_TELESCOPE then + Reload "plenary" + Reload "telescope" + Reload "alpha.telescope.setup" + end +end + +local fb_actions = require("telescope").extensions.file_browser.actions +local actions = require "telescope.actions" +local my_actions = require "alpha.telescope.my_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 +end + +function M.branches() + require("telescope.builtin").git_branches { + attach_mappings = function(_, map) + map("i", "", actions.git_create_branch) + map("n", "", 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, + } +end + +M.find_nvim_config = function() + 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", "", my_actions.create_plugin) + map("i", "", my_actions.disable_plugin) + map("i", "", 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) +end + +function M.grep_word() + require("telescope.builtin").grep_string { search = vim.fn.expand "" } +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) +end + +function M.my_plugins() + if vim.fn.isdirectory(vim.fn.getenv "HOME" .. "/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.scratchs() + require("telescope.builtin").find_files { + prompt_title = "Scratchs", + no_ignore = true, + cwd = "~/.config/nvim/lua/scratchs/", + attach_mappings = function(_, map) + map("i", "", my_actions.create_scratch_file) + + return true + end, + } +end + +function M.projectionist() + return require("telescope").extensions.projectionist.projectionist() +end + +function M.laravel_commands() + 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, + } +end + +function M.worktree() + return require("telescope").extensions.git_worktree.git_worktrees() +end + +function M.worktree_create() + return require("telescope").extensions.git_worktree.create_git_worktree() +end + +function M.refactor() + return require("telescope").extensions.refactoring.refactors() +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, + }, + }, + } +end + +function M.file_browser_relative() + return M.file_browser { path = "%:p:h" } +end + +function M.file_browser(opts) + opts = opts or {} + + opts = { + path = opts.path, + sorting_strategy = "ascending", + scroll_strategy = "cycle", + layout_config = { + prompt_position = "top", + }, + + attach_mappings = function(_, map) + map("i", "", fb_actions.create_from_prompt) + + return true + end, + } + + 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, +}) diff --git a/back/lua/alpha/telescope/mappings.lua b/back/lua/alpha/telescope/mappings.lua new file mode 100644 index 0000000..89472bc --- /dev/null +++ b/back/lua/alpha/telescope/mappings.lua @@ -0,0 +1,55 @@ +local map_tele = function(key, f, opts) + local default = { + mode = "n", + options = {}, + buffer = nil, + desc = nil, + } + opts = opts or {} + opts = vim.tbl_deep_extend("force", default, opts or {}) + + local rhs = function() + R("alpha.telescope")[f](opts.options) + end + + local map_options = { + remap = false, + silent = true, + } + if opts.buffer then + map_options.buffer = opts.buffer + end + if opts.desc then + map_options.desc = "Telescope: " .. opts.desc + end + + vim.keymap.set(opts.mode, key, rhs, map_options) +end + +-- not shure what this line does +vim.api.nvim_set_keymap( + "c", + "", + "(TelescopeFuzzyCommandSearch)", + { noremap = false, nowait = true, desc = "In comand look for previous commands" } +) + +map_tele("pp", "project_files", { desc = "Open Project files" }) +map_tele("gc", "branches", { desc = "Git Branches selector" }) +map_tele("pw", "grep_word", { desc = "Grep word under cursor" }) +map_tele("ps", "grep_string", { desc = "Grep provided input string" }) +map_tele("rc", "search_config", { desc = "Search Files in .dotfiles directory" }) +map_tele("rn", "find_nvim_config", { desc = "Search Files in nvim config directory" }) +map_tele("rp", "find_nvim_plugin", { desc = "Search Neovim plugins" }) +map_tele("rs", "scratchs", { desc = "Search Neovim Scratchs files" }) +map_tele("ph", "help_tags", { desc = "Neovim Help" }) +map_tele("pe", "buffers", { desc = "Open buffers" }) +map_tele("pr", "treesitter", { desc = "Treesitter buffer elements" }) +map_tele("bb", "file_browser_relative", { desc = "Current directory" }) +map_tele("bp", "file_browser", { desc = "Project directory" }) +map_tele("gs", "git_status", { desc = "Git status" }) +map_tele("ve", "diagnostics", { desc = "Diagnostic of the buffer" }) +map_tele("po", "api_specs", { desc = "Openapi directory" }) +map_tele("pm", "gateway", { desc = "Graphql mutations and queries" }) + +return map_tele diff --git a/back/lua/alpha/telescope/my_actions.lua b/back/lua/alpha/telescope/my_actions.lua new file mode 100644 index 0000000..b0e9f10 --- /dev/null +++ b/back/lua/alpha/telescope/my_actions.lua @@ -0,0 +1,170 @@ +local M = {} + +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)) +end + + +local get_disable_stm_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_is_disabled", + [[ +(return_statement + (expression_list + (table_constructor + (field + name: (identifier) @enabled (#eq? @enabled "enabled") + value: (false) @is_false + ) + ) + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_is_disabled") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node + end + end + + return nil +end + +local get_enabled_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_has_enable_property", + [[ +(return_statement + (expression_list + (table_constructor + (field + name: (identifier) @enabled (#eq? @enabled "enabled") + ) + ) + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_has_enable_property") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node + end + end + + return nil +end + +local get_return_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_return_table_constructor", + [[ +(return_statement + (expression_list + (table_constructor) @table_constructor + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_return_table_constructor") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "table_constructor" then + return node + end + end + + 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) + local tree = parser:parse()[1] + + 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) +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) + + local tree = parser:parse()[1] + + 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 + +M.create_scratch_file = function(prompt_bufnr) + local new_scratch = action_state.get_current_line() + actions.close(prompt_bufnr) + vim.cmd(string.format("edit ~/.config/nvim/lua/scratchs/%s.lua", new_scratch)) +end + +return M diff --git a/back/lua/alpha/telescope/setup.lua b/back/lua/alpha/telescope/setup.lua new file mode 100644 index 0000000..0e368c7 --- /dev/null +++ b/back/lua/alpha/telescope/setup.lua @@ -0,0 +1,222 @@ +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 + + action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) +end + +local filetype_hook = function(filepath, bufnr, opts) + -- Here for example you can say: if ft == "xyz" then this_regex_highlighing else nothing end + -- + local is_image = function(filepath) + local image_extensions = { "png", "jpg" } -- Supported image formats + local split_path = vim.split(filepath:lower(), ".", { plain = true }) + local extension = split_path[#split_path] + return vim.tbl_contains(image_extensions, extension) + end + if not is_image(filepath) then + return true + end + local ui = require "image.ui" + local options = require "image.options" + local dimensions = require "image.dimensions" + local api = require "image.api" + local config = require "image.config" + local user_opts = { + render = { + foreground_color = true, + background_color = true, + }, + } + local global_opts = vim.tbl_deep_extend("force", config.DEFAULT_OPTS, user_opts) + + local ascii_width, ascii_height, horizontal_padding, vertical_padding, img_width, img_height = + dimensions.calculate_ascii_width_height(opts.winid, filepath, global_opts) + options.set_options_before_render(bufnr) + ui.buf_clear(bufnr) + local label = ui.create_label( + filepath, + ascii_width, + horizontal_padding, + global_opts.render.show_image_dimensions, + img_width, + img_height + ) + + api.get_ascii_data_sync(filepath, ascii_width, ascii_height, global_opts, function(ascii_data) + ui.buf_insert_data_with_padding(bufnr, ascii_data, horizontal_padding, vertical_padding, label, global_opts) + + options.set_options_after_render(bufnr) + end) + return false +end + +require("telescope").setup { + defaults = { + preview = { + filetype_hook = filetype_hook, + }, + 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.7) + 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 = { + -- [""] = false, + -- [""] = actions.select_horizontal, + [""] = "move_selection_next", + + [""] = set_prompt_to_entry_value, + + -- These are new :) + [""] = action_layout.toggle_preview, + [""] = action_layout.toggle_mirror, + -- [""] = action_layout.toggle_prompt_position, + + -- [""] = actions.master_stack, + + -- [""] = actions.send_to_qflist + actions.open_qflist, + -- [""] = actions.send_selected_to_qflist + actions.open_qflist, + + -- This is nicer when used with smart-history plugin. + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + + -- [""] = 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, + + -- [""] = function() + -- vim.api.nvim_input("") + -- 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, + }, + -- buffer_previewer_maker = new_maker, + }, + + pickers = { + fd = { + mappings = { + n = { + ["kj"] = "close", + }, + }, + }, + + git_branches = { + mappings = { + i = { + [""] = 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_dropdown { + borderchars = { + prompt = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + results = { "─", "│", "─", "│", "╭", "╮", "┤", "├" }, + preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + }, + width = 0.8, + previewer = false, + }, + }, + }, +} + +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/back/lua/alpha/test_menu.lua b/back/lua/alpha/test_menu.lua new file mode 100644 index 0000000..afe3a9e --- /dev/null +++ b/back/lua/alpha/test_menu.lua @@ -0,0 +1,50 @@ +local hydra = require "hydra" + +local hint = [[ + Vim Tests + _n_: Near test _h_: Harpoon ^ + _f_: Current file _s_: Test Suit ^ + _l_: Test Last _g_: Visit + _w_: Watch last Test _p_: stop watch + ^ ^ __ ^ +]] +local auto_cmd_id = nil +local stopAutoCommand = function() + if auto_cmd_id ~= nil then + vim.api.nvim_del_autocmd(auto_cmd_id) + auto_cmd_id = nil + end +end +local startAutoCommand = function() + stopAutoCommand() + auto_cmd_id = vim.api.nvim_create_autocmd({ "BufWritePost" }, { + pattern = { "*.php", "*.feature", "*.yaml" }, + command = "TestLast", + }) +end + +hydra { + name = "vimtest", + hint = hint, + mode = "n", + config = { + color = "teal", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "t", + heads = { + { "n", ":TestNearest" }, + { "h", ":TestNearest -strategy=harpoon" }, + { "f", ":TestFile" }, + { "s", ":TestSuit" }, + { "l", ":TestLast" }, + { "g", ":TestVisit" }, + { "w", startAutoCommand }, + { "p", stopAutoCommand }, + { "", nil, { exit = true } }, + }, +} diff --git a/back/lua/alpha/test_strategy.lua b/back/lua/alpha/test_strategy.lua new file mode 100644 index 0000000..9a2d34a --- /dev/null +++ b/back/lua/alpha/test_strategy.lua @@ -0,0 +1,65 @@ +local Job = require "plenary.job" + +local function splitString(input_string) + local parts = {} + local in_quote = false + local part_start = 1 + + for i = 1, #input_string do + local char = input_string:sub(i, i) + + if char == "'" then + in_quote = not in_quote + elseif char == " " and not in_quote then + local part = input_string:sub(part_start, i - 1) + -- Remove surrounding quotes if they exist + if part:sub(1, 1) == "'" and part:sub(-1) == "'" then + part = part:sub(2, -2) + end + table.insert(parts, part) + part_start = i + 1 + end + end + + -- Add the last part (and remove surrounding quotes if they exist) + local part = input_string:sub(part_start) + if part:sub(1, 1) == "'" and part:sub(-1) == "'" then + part = part:sub(2, -2) + end + table.insert(parts, part) + + return parts +end + +local function myStrategy(cmd) + --convert cmd from string to table + if type(cmd) == "string" then + -- do not split quoted parts of the string + cmd = splitString(cmd) + end + + -- get first element of cmd and remove from the cmd + local cmd_name = table.remove(cmd, 1) + + ---@diagnostic disable-next-line: missing-fields + Job:new({ + command = cmd_name, + args = cmd, + on_exit = function(j, return_val) + -- in case of result val 0 show success message + if return_val == 0 then + vim.notify("Test run successfully", vim.log.levels.INFO, { title = "Test" }) + return + end + local result = j:stderr_result() or j:stdout_result() + -- join result in a single string + result = table.concat(result, "\n") + -- escape / characters + result = result:gsub("/", "\\/") + vim.notify(result, vim.log.levels.ERROR, { title = "Test" }) + end, + }):start() +end + +vim.g["test#custom_strategies"] = { myStrategy = myStrategy } +vim.g["test#strategy"] = "myStrategy" diff --git a/back/lua/alpha/utils.lua b/back/lua/alpha/utils.lua new file mode 100644 index 0000000..b7b0fbc --- /dev/null +++ b/back/lua/alpha/utils.lua @@ -0,0 +1,11 @@ +local M = {} + +M.save_and_exec = function() + vim.api.nvim_command "silent w" + vim.api.nvim_command "so" + + 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 diff --git a/back/lua/config/autocmds.lua b/back/lua/config/autocmds.lua new file mode 100644 index 0000000..41026bc --- /dev/null +++ b/back/lua/config/autocmds.lua @@ -0,0 +1,14 @@ +-- Autocmds are automatically loaded on the VeryLazy event +-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua +-- Add any additional autocmds here + +-- https://www.reddit.com/r/neovim/comments/13zd9sc/is_there_a_way_to_configure_indentation_per/ +-- https://www.reddit.com/r/neovim/comments/vu1y6e/correct_way_to_set_language_specific_settings_in/ +vim.cmd([[ + augroup myfiletypes + autocmd! + autocmd FileType ruby,lua,eruby,yaml,javascript,typescript,html,css set ai sw=2 sts=2 et + autocmd FileType java,kotlin,xml set ai sw=4 sts=4 et + autocmd FileType asciidoc setlocal wrap + augroup END +]]) diff --git a/back/lua/config/keymaps.lua b/back/lua/config/keymaps.lua new file mode 100644 index 0000000..471ed89 --- /dev/null +++ b/back/lua/config/keymaps.lua @@ -0,0 +1,20 @@ +-- Keymaps are automatically loaded on the VeryLazy event +-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua +-- Add any additional keymaps here + +local bind = vim.keymap.set +local opts = { silent = true, noremap = true } + +-- for russian layout +bind("i", "", "", opts) +bind("n", "л", "gk", opts) +bind("n", "о", "gj", opts) +bind("i", "", "u", opts) +bind("i", "", "u", opts) + +bind("n", "[c", function() + require("treesitter-context").go_to_context() +end) + +vim.keymap.set("n", "[", "call append(line('.') - 1, repeat([''], v:count1))") +vim.keymap.set("n", "]", "call append(line('.'), repeat([''], v:count1))") diff --git a/back/lua/config/lazy.lua b/back/lua/config/lazy.lua new file mode 100644 index 0000000..d8c2aeb --- /dev/null +++ b/back/lua/config/lazy.lua @@ -0,0 +1,57 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + -- bootstrap lazy.nvim + -- stylua: ignore + vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath }) +end +vim.opt.rtp:prepend(vim.env.LAZY or lazypath) + +require('lazy').setup({ + change_detection = { notify = false }, + spec = { + { "LazyVim/LazyVim", import = "lazyvim.plugins" }, + { import = "lazyvim.plugins.extras.formatting.prettier" }, + -- { import = "lazyvim.plugins.extras.linting.eslint" }, + -- { import = "lazyvim.plugins.extras.lsp.none-ls" }, + { import = "lazyvim.plugins.extras.dap.core" }, + { import = "lazyvim.plugins.extras.coding.yanky" }, + { import = "lazyvim.plugins.extras.lang.markdown" }, + { import = "lazyvim.plugins.extras.lang.typescript" }, + { import = "lazyvim.plugins.extras.lang.docker" }, + { import = "lazyvim.plugins.extras.lang.json" }, + { import = "lazyvim.plugins.extras.lang.go" }, + { import = "lazyvim.plugins.extras.lang.elixir" }, + { import = "lazyvim.plugins.extras.lang.java" }, + { import = "lazyvim.plugins.extras.lang.python" }, + { import = "lazyvim.plugins.extras.lang.ruby" }, + { import = "lazyvim.plugins.extras.lang.terraform" }, + { import = "lazyvim.plugins.extras.lang.yaml" }, + { import = "plugins" }, + }, + defaults = { + -- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup. + -- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default. + lazy = false, + -- It's recommended to leave version=false for now, since a lot the plugin that support versioning, + -- have outdated releases, which may break your Neovim install. + version = false, -- always use the latest git commit + -- version = "*", -- try installing the latest stable version for plugins that support semver + }, + -- install = { colorscheme = { "tokyonight", "habamax" } }, + checker = { enabled = true }, -- automatically check for plugin updates + performance = { + rtp = { + -- disable some rtp plugins + disabled_plugins = { + "gzip", + -- "matchit", + -- "matchparen", + -- "netrwPlugin", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", + }, + }, + }, +}) diff --git a/back/lua/config/options.lua b/back/lua/config/options.lua new file mode 100644 index 0000000..67983ad --- /dev/null +++ b/back/lua/config/options.lua @@ -0,0 +1,13 @@ +-- Options are automatically loaded before lazy.nvim startup +-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua +-- Add any additional options here + +vim.o.langmap = + "ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz" + +vim.o.relativenumber = false +vim.o.spelllang = "ru_ru,en_us" +vim.o.linebreak = true +vim.g.autoformat = false + +require("lazyvim.util").get_root = vim.loop.cwd diff --git a/back/lua/config/usercmds.lua b/back/lua/config/usercmds.lua new file mode 100644 index 0000000..e69de29 diff --git a/back/lua/plugins/cmp.lua b/back/lua/plugins/cmp.lua new file mode 100644 index 0000000..2e3e819 --- /dev/null +++ b/back/lua/plugins/cmp.lua @@ -0,0 +1,75 @@ +return { + { + "L3MON4D3/LuaSnip", + keys = function() + return {} + end, + }, + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-emoji", + config = function() + local cmp = require("cmp") + + -- cmp.setup.cmdline(":", { + -- mapping = cmp.mapping.preset.cmdline(), + -- sources = cmp.config.sources({ + -- { name = "path" }, + -- }, { + -- { + -- name = "cmdline", + -- option = { + -- ignore_cmds = { "Man", "!" }, + -- }, + -- }, + -- }), + -- }) + + end, + }, + -- @param opts cmp.ConfigSchema + opts = function(_, opts) + local cmp = require("cmp") + + opts.preselect = cmp.PreselectMode.None + opts.completion = { + completeopt = "noselect", + } + + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local luasnip = require("luasnip") + + opts.mapping = vim.tbl_extend("force", opts.mapping, { + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- this way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }) + end, + }, +} diff --git a/back/lua/plugins/colorscheme.lua b/back/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..9b11a2c --- /dev/null +++ b/back/lua/plugins/colorscheme.lua @@ -0,0 +1,11 @@ +return { + "neanias/everforest-nvim", + lazy = false, + priority = 1000, + config = function() + vim.cmd.colorscheme "everforest" + vim.cmd "let g:everforest_better_performance = 1" + vim.cmd "let g:everforest_background = 'soft'" + vim.cmd "let g:airline_theme = 'everforest'" + end, +} diff --git a/back/lua/plugins/core.lua b/back/lua/plugins/core.lua new file mode 100644 index 0000000..4a1d982 --- /dev/null +++ b/back/lua/plugins/core.lua @@ -0,0 +1,8 @@ +return { + { + "LazyVim/LazyVim", + opts = { + colorscheme = "catppuccin" + }, + }, +} diff --git a/back/lua/plugins/disabled.lua b/back/lua/plugins/disabled.lua new file mode 100644 index 0000000..94cb3a5 --- /dev/null +++ b/back/lua/plugins/disabled.lua @@ -0,0 +1,8 @@ +return { + { "echasnovski/mini.indentscope", enabled = false }, + { "folke/noice.nvim", enabled = false }, + { "rcarriga/nvim-notify", enabled = false }, + { "folke/flash.nvim", enabled = false }, + { "ggandor/flit.nvim", enabled = false }, + -- { "ggandor/leap.nvim", enabled = false }, +} diff --git a/back/lua/plugins/init.lua b/back/lua/plugins/init.lua new file mode 100644 index 0000000..0ee99f4 --- /dev/null +++ b/back/lua/plugins/init.lua @@ -0,0 +1,15 @@ +return { + { + "jwalton512/vim-blade", + enabled = true, + }, + { + "tpope/vim-dispatch", + cmd = { "Make", "Dispatch" }, + }, + "tpope/vim-surround", + "tpope/vim-repeat", + "tpope/vim-rhubarb", + "tpope/vim-dotenv", + "tpope/vim-eunuch", +} diff --git a/back/lua/plugins/lspconfig.lua b/back/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..adcf203 --- /dev/null +++ b/back/lua/plugins/lspconfig.lua @@ -0,0 +1,26 @@ +return { + { + "neovim/nvim-lspconfig", + opts = { + diagnostics = { + underline = true, + virtual_text = false, + float = { + border = "rounded", + }, + }, + servers = { + kotlin_language_server = {}, + bashls = {}, + lemminx = {}, + ltex = { + settings = { + ltex = { + language = "ru-RU", + }, + }, + }, + }, + }, + }, +} diff --git a/back/lua/plugins/mason.lua b/back/lua/plugins/mason.lua new file mode 100644 index 0000000..a791aa2 --- /dev/null +++ b/back/lua/plugins/mason.lua @@ -0,0 +1,8 @@ +return { + { + "williamboman/mason.nvim", + opts = function(_, opts) + -- table.insert(opts.ensure_installed, "google-java-format") + end, + }, +} diff --git a/back/lua/plugins/neo-tree.lua b/back/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..ca69803 --- /dev/null +++ b/back/lua/plugins/neo-tree.lua @@ -0,0 +1,254 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + reqrires = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + { + -- only needed if you want to use the commands with "_with_window_picker" suffix + 's1n7ax/nvim-window-picker', + tag = "v1.*", + config = function() + require 'window-picker'.setup({ + autoselect_one = true, + include_current = false, + filter_rules = { + -- filter using buffer options + bo = { + -- if the file type is one of following, the window will be ignored + filetype = { 'neo-tree', "neo-tree-popup", "notify" }, + + -- if the buffer type is one of following, the window will be ignored + buftype = { 'terminal', "quickfix" }, + }, + }, + other_win_hl_color = '#e35e4f', + }) + end, + } + }, + config = function() + -- Unless you are still migrating, remove the deprecated commands from v1.x + vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) + + -- If you want icons for diagnostic errors, you'll need to define them somewhere: + vim.fn.sign_define("DiagnosticSignError", + { text = " ", texthl = "DiagnosticSignError" }) + vim.fn.sign_define("DiagnosticSignWarn", + { text = " ", texthl = "DiagnosticSignWarn" }) + vim.fn.sign_define("DiagnosticSignInfo", + { text = " ", texthl = "DiagnosticSignInfo" }) + vim.fn.sign_define("DiagnosticSignHint", + { text = "", texthl = "DiagnosticSignHint" }) + -- NOTE: this is changed from v1.x, which used the old style of highlight groups + -- in the form "LspDiagnosticsSignWarning" + + require("neo-tree").setup({ + close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab + popup_border_style = "rounded", + enable_git_status = true, + enable_diagnostics = true, + sort_case_insensitive = false, -- used when sorting files and directories in the tree + sort_function = nil, -- use a custom function for sorting files and directories in the tree + -- sort_function = function (a,b) + -- if a.type == b.type then + -- return a.path > b.path + -- else + -- return a.type > b.type + -- end + -- end , -- this sorts files and directories descendantly + default_component_configs = { + container = { + enable_character_fade = true + }, + indent = { + indent_size = 2, + padding = 1, -- extra padding on left hand side + -- indent guides + with_markers = true, + indent_marker = "│", + last_indent_marker = "└", + highlight = "NeoTreeIndentMarker", + -- expander config, needed for nesting files + with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", + }, + icon = { + folder_closed = "", + folder_open = "", + folder_empty = "ﰊ", + -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there + -- then these will never be used. + default = "*", + highlight = "NeoTreeFileIcon" + }, + modified = { + symbol = "[+]", + highlight = "NeoTreeModified", + }, + name = { + trailing_slash = false, + use_git_status_colors = true, + highlight = "NeoTreeFileName", + }, + git_status = { + symbols = { + -- Change type + added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name + modified = "", -- or "", but this is redundant info if you use git_status_colors on the name + deleted = "✖", -- this can only be used in the git_status source + renamed = "", -- this can only be used in the git_status source + -- Status type + untracked = "", + ignored = "", + unstaged = "", + staged = "", + conflict = "", + } + }, + }, + window = { + position = "left", + width = 40, + mapping_options = { + noremap = true, + nowait = true, + }, + mappings = { + [""] = { + "toggle_node", + nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use + }, + ["<2-LeftMouse>"] = "open", + [""] = "open", + [""] = "revert_preview", + ["P"] = { "toggle_preview", config = { use_float = true } }, + ["l"] = "focus_preview", + ["S"] = "open_split", + ["s"] = "open_vsplit", + -- ["S"] = "split_with_window_picker", + -- ["s"] = "vsplit_with_window_picker", + ["t"] = "open_tabnew", + -- [""] = "open_drop", + -- ["t"] = "open_tab_drop", + ["w"] = "open_with_window_picker", + --["P"] = "toggle_preview", -- enter preview mode, which shows the current node without focusing + ["C"] = "close_node", + -- ['C'] = 'close_all_subnodes', + ["z"] = "close_all_nodes", + --["Z"] = "expand_all_nodes", + ["a"] = { + "add", + -- this command supports BASH style brace expansion ("x{a,b,c}" -> xa,xb,xc). see `:h neo-tree-file-actions` for details + -- some commands may take optional config options, see `:h neo-tree-mappings` for details + config = { + show_path = "none" -- "none", "relative", "absolute" + } + }, + ["A"] = "add_directory", -- also accepts the optional config.show_path option like "add". this also supports BASH style brace expansion. + ["d"] = "delete", + ["r"] = "rename", + ["y"] = "copy_to_clipboard", + ["x"] = "cut_to_clipboard", + ["p"] = "paste_from_clipboard", + ["c"] = "copy", -- takes text input for destination, also accepts the optional config.show_path option like "add": + -- ["c"] = { + -- "copy", + -- config = { + -- show_path = "none" -- "none", "relative", "absolute" + -- } + --} + ["m"] = "move", -- takes text input for destination, also accepts the optional config.show_path option like "add". + ["q"] = "close_window", + ["R"] = "refresh", + ["?"] = "show_help", + ["<"] = "prev_source", + [">"] = "next_source", + } + }, + nesting_rules = {}, + filesystem = { + filtered_items = { + visible = false, -- when true, they will just be displayed differently than normal items + hide_dotfiles = true, + hide_gitignored = true, + hide_hidden = true, -- only works on Windows for hidden files/directories + hide_by_name = { + --"node_modules" + }, + hide_by_pattern = { -- uses glob style patterns + --"*.meta", + --"*/src/*/tsconfig.json", + }, + always_show = { -- remains visible even if other settings would normally hide it + --".gitignored", + }, + never_show = { -- remains hidden even if visible is toggled to true, this overrides always_show + --".DS_Store", + --"thumbs.db" + }, + never_show_by_pattern = { -- uses glob style patterns + --".null-ls_*", + }, + }, + follow_current_file = false, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = false, -- when true, empty folders will be grouped together + hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree + -- in whatever position is specified in window.position + -- "open_current", -- netrw disabled, opening a directory opens within the + -- window like netrw would, regardless of window.position + -- "disabled", -- netrw left alone, neo-tree does not handle opening dirs + use_libuv_file_watcher = false, -- This will use the OS level file watchers to detect changes + -- instead of relying on nvim autocmd events. + window = { + mappings = { + [""] = "navigate_up", + ["."] = "set_root", + ["H"] = "toggle_hidden", + ["/"] = "fuzzy_finder", + ["D"] = "fuzzy_finder_directory", + ["#"] = "fuzzy_sorter", -- fuzzy sorting using the fzy algorithm + -- ["D"] = "fuzzy_sorter_directory", + ["f"] = "filter_on_submit", + [""] = "clear_filter", + ["[g"] = "prev_git_modified", + ["]g"] = "next_git_modified", + } + } + }, + buffers = { + follow_current_file = true, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = true, -- when true, empty folders will be grouped together + show_unloaded = true, + window = { + mappings = { + ["bd"] = "buffer_delete", + [""] = "navigate_up", + ["."] = "set_root", + } + }, + }, + git_status = { + window = { + position = "float", + mappings = { + ["A"] = "git_add_all", + ["gu"] = "git_unstage_file", + ["ga"] = "git_add_file", + ["gr"] = "git_revert_file", + ["gc"] = "git_commit", + ["gp"] = "git_push", + ["gg"] = "git_commit_and_push", + } + } + } + }) + + vim.cmd([[nnoremap \ :Neotree reveal]]) + end +} diff --git a/back/lua/plugins/others.lua b/back/lua/plugins/others.lua new file mode 100644 index 0000000..a5568ec --- /dev/null +++ b/back/lua/plugins/others.lua @@ -0,0 +1,46 @@ +return { + { + "tigion/nvim-asciidoc-preview", + ft = { "asciidoc" }, + -- opts = {}, + }, + { + "windwp/nvim-autopairs", + event = "InsertEnter", + opts = {}, -- this is equalent to setup({}) function + }, + { "isobit/vim-caddyfile" }, + { -- maybe https://github.com/0x00-ketsu/autosave.nvim + "0x00-ketsu/autosave.nvim", + opts = {}, + }, + { + "Wansmer/treesj", + keys = { + { "j", "TSJToggle", desc = "Join Toggle" }, + }, + opts = { use_default_keymaps = false, max_join_length = 150 }, + }, + { + "s1n7ax/nvim-window-picker", + name = "window-picker", + event = "VeryLazy", + version = "2.*", + config = function() + require("window-picker").setup() + end, + }, + { "slim-template/vim-slim" }, + { "tpope/vim-rails" }, + -- use 'slim-template/vim-slim' + { "dhruvasagar/vim-table-mode" }, + { "tree-sitter/tree-sitter-embedded-template" }, + { "RRethy/nvim-treesitter-endwise" }, + { "dyng/ctrlsf.vim" }, + { + "kylechui/nvim-surround", + version = "*", -- Use for stability; omit to use `main` branch for the latest features + event = "VeryLazy", + opts = {}, + }, +} diff --git a/back/lua/plugins/telescope.lua b/back/lua/plugins/telescope.lua new file mode 100644 index 0000000..a5e8042 --- /dev/null +++ b/back/lua/plugins/telescope.lua @@ -0,0 +1,24 @@ +return { + { + "nvim-telescope/telescope.nvim", + opts = { + defaults = { + -- sorting_strategy = "ascending", + mappings = { + -- restore default behavior + i = { + [""] = false, + [""] = false, + }, + n = {}, + }, + }, + pickers = { + buffers = { + ignore_current_buffer = true, + sort_mru = true, + }, + }, + }, + }, +} diff --git a/back/lua/plugins/treesitter.lua b/back/lua/plugins/treesitter.lua new file mode 100644 index 0000000..1ea2d0a --- /dev/null +++ b/back/lua/plugins/treesitter.lua @@ -0,0 +1,10 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + opts = { + endwise = { + enable = true, + }, + }, + }, +} diff --git a/back/lua/scratchs/.gitkeep b/back/lua/scratchs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/current_config/lua/alpha/animations.lua b/current_config/lua/alpha/animations.lua new file mode 100644 index 0000000..c0b7a6c --- /dev/null +++ b/current_config/lua/alpha/animations.lua @@ -0,0 +1,50 @@ +local redraw_buffer = function() + local Animation = require "animation" + local fps = 45 -- frames per second + local easing = require "animation.easing" + + local buffer = 0 + local len = 0 + local place_holder = {} + + local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true) + + for _, line in ipairs(lines) do + len = len + string.len(line) + table.insert(place_holder, "") + end + + vim.api.nvim_buf_set_lines(buffer, 0, #lines, true, place_holder) + + local duration = math.ceil(len / fps * 1000) + + local i = 1 + local line_nr = 1 + local insertLine = "" + + local function callback() + if lines[line_nr] == nil then + return true + end + local char = string.sub(lines[line_nr], i, i) + if char == nil then + return true + end + insertLine = insertLine .. char + i = i + 1 + vim.api.nvim_buf_set_lines(buffer, line_nr - 1, line_nr, true, { insertLine }) + + if insertLine == lines[line_nr] then + i = 1 + line_nr = line_nr + 1 + insertLine = "" + end + end + + local animation = Animation(duration, fps, easing.line, callback) + animation:run() +end + +return { + redraw_buffer = redraw_buffer, +} diff --git a/current_config/lua/alpha/completition/init.lua b/current_config/lua/alpha/completition/init.lua new file mode 100644 index 0000000..92e1f91 --- /dev/null +++ b/current_config/lua/alpha/completition/init.lua @@ -0,0 +1,133 @@ +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.setup { + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + [""] = cmp.mapping.complete(), + }, + sources = { + { name = "nvim_lua" }, + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "copilot" }, + { + name = "buffer", + keyword_length = 4, + option = { + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + local bufnr = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_option(bufnr, "buftype") ~= "terminal" then + bufs[bufnr] = true + end + end + return vim.tbl_keys(bufs) + 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 = "[ ]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + copilot = "[ﮧ ]", + ["vim-dadbod-completion"] = "[DB]", + }, + }, + }, + + sorting = { + priority_weight = 2, + comparators = { + compare.kind, + compare.sort_text, + }, + }, + + experimental = { + native_menu = false, + + ghost_text = false, + }, +} + +vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" }) + +-- 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" }, + }), +}) + +-- 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" }, + }, +}) + +-- 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" }, + }), +}) + +cmp.setup.filetype({ "sql", "mysql", "plsql" }, { + sources = cmp.config.sources({ + { name = "vim-dadbod-completion" }, + }, { + { name = "buffer" }, + }), +}) diff --git a/current_config/lua/alpha/dap/configs/golang.lua b/current_config/lua/alpha/dap/configs/golang.lua new file mode 100644 index 0000000..1ec449a --- /dev/null +++ b/current_config/lua/alpha/dap/configs/golang.lua @@ -0,0 +1 @@ +require("dap-go").setup() diff --git a/current_config/lua/alpha/dap/configs/javascript.lua b/current_config/lua/alpha/dap/configs/javascript.lua new file mode 100644 index 0000000..b910f30 --- /dev/null +++ b/current_config/lua/alpha/dap/configs/javascript.lua @@ -0,0 +1,45 @@ +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}", + }, + } +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", + }, + } +end diff --git a/current_config/lua/alpha/dap/configs/php.lua b/current_config/lua/alpha/dap/configs/php.lua new file mode 100644 index 0000000..968bb9d --- /dev/null +++ b/current_config/lua/alpha/dap/configs/php.lua @@ -0,0 +1,27 @@ +local dap = require("dap") + +dap.adapters.php = { + 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}", + }, + }, +} diff --git a/current_config/lua/alpha/dap/configs/rust.lua b/current_config/lua/alpha/dap/configs/rust.lua new file mode 100644 index 0000000..9ca976f --- /dev/null +++ b/current_config/lua/alpha/dap/configs/rust.lua @@ -0,0 +1,57 @@ +local dap = require("dap") + +local rust_adapter = nil +local rust_adapters = { "lldb-vscode", "codelldb" } +for _, adapter in pairs(rust_adapters) do + if vim.fn.executable(adapter) then + rust_adapter = adapter + end +end + +if rust_adapter ~= nil then + dap.adapters.lldb = { + type = "executable", + command = rust_adapter, + name = "lldb", + } + + dap.configurations.rust = { + { + name = "launch", + type = "lldb", + request = "launch", + program = function() + local dir = vim.fn.getcwd() + return dir .. "/target/debug/" .. vim.fs.basename(dir) + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + { + name = "custom", + type = "lldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + } +end diff --git a/current_config/lua/alpha/dap/init.lua b/current_config/lua/alpha/dap/init.lua new file mode 100644 index 0000000..81651f7 --- /dev/null +++ b/current_config/lua/alpha/dap/init.lua @@ -0,0 +1,106 @@ +local dap, dapui, hydra = require "dap", require "dapui", require "hydra" + +-- Setup Virtual Text +require("nvim-dap-virtual-text").setup {} + +for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/alpha/dap/configs/*.lua", true)) do + loadfile(ft_path)() +end + +-- Signs +vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapStopped", { text = "▶", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointRejected", { text = "🚫", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointCondition", { text = "❓", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapLogPoint", { text = "💬", texthl = "", linehl = "", numhl = "" }) + +-- UI structure +dapui.setup { + icons = { expanded = "▾", collapsed = "▸" }, + layouts = { + { + elements = { + "scopes", + "breakpoints", + "stacks", + "watches", + }, + size = 80, + position = "right", + }, + { + elements = { + "repl", + "console", + }, + size = 10, + position = "bottom", + }, + }, +} + +-- Events Listeners +dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open {} +end + +local hint = [[ + Nvim DAP + _d_: Start/Continue _j_: StepOver _k_: StepOut _l_: StepInto ^ + _bp_: Toogle Breakpoint _bc_: Conditional Breakpoint ^ + _?_: log point ^ + _c_: Run To Cursor ^ + _h_: Show information of the variable under the cursor ^ + _x_: Stop Debbuging ^ + ^^ __ +]] + +hydra { + name = "dap", + hint = hint, + mode = "n", + config = { + color = "blue", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "d", + heads = { + { "d", dap.continue }, + { "bp", dap.toggle_breakpoint }, + { "l", dap.step_into }, + { "j", dap.step_over }, + { "k", dap.step_out }, + { "h", dapui.eval }, + { "c", dap.run_to_cursor }, + { + "bc", + function() + vim.ui.input({ prompt = "Condition: " }, function(condition) + dap.set_breakpoint(condition) + end) + end, + }, + { + "?", + function() + vim.ui.input({ prompt = "Log: " }, function(log) + dap.set_breakpoint(nil, nil, log) + end) + end, + }, + { + "x", + function() + dap.terminate() + dapui.close {} + dap.clear_breakpoints() + end, + }, + + { "", nil, { exit = true } }, + }, +} diff --git a/current_config/lua/alpha/globals.lua b/current_config/lua/alpha/globals.lua new file mode 100644 index 0000000..e445e72 --- /dev/null +++ b/current_config/lua/alpha/globals.lua @@ -0,0 +1,23 @@ +--- Dumps all values into pretty print +---@vararg any +---@return any +dump = function(...) + local args = {...} + + local mapped = {} + for _, v in ipairs(args) do + table.insert(mapped, vim.inspect(v)) + end + print(unpack(mapped)) + + return unpack(args) +end + +Reload = function(...) + return require("plenary.reload").reload_module(...) +end + +R = function(name) + Reload(name) + return require(name) +end diff --git a/current_config/lua/alpha/laravel-tinker.lua b/current_config/lua/alpha/laravel-tinker.lua new file mode 100644 index 0000000..214d958 --- /dev/null +++ b/current_config/lua/alpha/laravel-tinker.lua @@ -0,0 +1,64 @@ +local M = {} + +M.runCode = function() + local curBuff = vim.api.nvim_get_current_buf() + + local stats = vim.api.nvim_list_uis()[1] + + 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", + }) + + -- 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) + + -- print (vim.inspect(code)) + + local codeText = vim.fn.shellescape(table.concat(code, " ")) + -- print(codeText) + + local result = vim.fn.systemlist("php artisan tinker --execute=" .. codeText) + + 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") +end + +return M diff --git a/current_config/lua/alpha/lsp/attach.lua b/current_config/lua/alpha/lsp/attach.lua new file mode 100644 index 0000000..e71cb75 --- /dev/null +++ b/current_config/lua/alpha/lsp/attach.lua @@ -0,0 +1,29 @@ +local telescope_mapper = require "alpha.telescope.mappings" + +return function(client, bufnr) + -- keymaps for lsp + vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0, desc = "LSP Help information of symbol under the cursor" }) + vim.keymap.set("n", "vrn", vim.lsp.buf.rename, { buffer = 0, desc = "LSP Rename symbol under cursor" }) + vim.keymap.set("i", "", vim.lsp.buf.signature_help, { buffer = 0, desc = "LSP Signature help" }) + vim.keymap.set("n", "vo", ":LspRestart", { noremap = true, desc = "LSP Restart Server" }) + vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, { buffer = 0, desc = "LSP Code actions" }) + vim.keymap.set("n", "vf", function() + return vim.lsp.buf.format { + async = true, + filter = function(cli) + return cli.name ~= "lua_ls" + end, + } + end, { buffer = 0, desc = "LSP format file" }) + + telescope_mapper("gr", "lsp_references", { buffer = true, desc = "LSP References of symbol on cursor" }) + telescope_mapper("pv", "find_symbol", { buffer = true, desc = "LSP find symbol on the project" }) + telescope_mapper("pd", "lsp_document_symbols", { buffer = true, desc = "LSP document symbols" }) + telescope_mapper("gd", "lsp_definitions", { buffer = true, desc = "LSP go to definition" }) + + vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" + + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint(bufnr, true) + end +end diff --git a/current_config/lua/alpha/lsp/default.lua b/current_config/lua/alpha/lsp/default.lua new file mode 100644 index 0000000..4f53ddd --- /dev/null +++ b/current_config/lua/alpha/lsp/default.lua @@ -0,0 +1,26 @@ +return { + mason = { + enable = true, + auto_install = false, + }, + servers = { + emmet_ls = { enable = true }, + gopls = { enable = true }, + html = { enable = true }, + jsonls = { enable = true }, + lua_ls = { enable = true, neodev = true }, + nil_ls = { enable = true }, + phpactor = {enable = true }, + rust_analyzer = { enable = true }, + svelte = { enable = true }, + tailwindcss = { enable = true, filetypes = {"blade", "html", "svelte"} }, + tsserver = { enable = true }, + volar = { enable = true }, + }, + default_options = function (options) + return vim.tbl_deep_extend("force", { + on_attach = require"alpha.lsp.attach", + flags = require "alpha.lsp.flags", + }, options) + end, +} diff --git a/current_config/lua/alpha/lsp/flags.lua b/current_config/lua/alpha/lsp/flags.lua new file mode 100644 index 0000000..f70b467 --- /dev/null +++ b/current_config/lua/alpha/lsp/flags.lua @@ -0,0 +1,3 @@ +return { + debounce_text_changes = 150, +} diff --git a/current_config/lua/alpha/lsp/init.lua b/current_config/lua/alpha/lsp/init.lua new file mode 100644 index 0000000..0d69f07 --- /dev/null +++ b/current_config/lua/alpha/lsp/init.lua @@ -0,0 +1,65 @@ +return { + setup = function(ops) + ops = vim.tbl_deep_extend("force", require "alpha.lsp.default", ops) + + local lspconfig = require "lspconfig" + + local mason_servers = {} + for server, options in pairs(ops.servers) do + if options.enable == true then + local ok, definition = pcall(require, "alpha.lsp.servers." .. server) + local server_options + if not ok then + server_options = ops.default_options(options) + else + server_options = definition(options) + end + lspconfig[server].setup(server_options) + table.insert(mason_servers, server) + end + end + + -- Mason + if ops.mason.enable then + local mason_ops = {} + if ops.mason.auto_install == true then + mason_ops.ensure_installed = mason_servers + end + local mason_lspconfig = require "mason-lspconfig" + mason_lspconfig.setup(mason_ops) + end + + -- TODO: implement null ls with options + require "alpha.lsp.null-ls" + + local servers = {} + for server, options in pairs(ops.servers) do + table.insert(servers, string.format("%s <%s>", server, options.enable)) + end + + -- TODO: create an auto command that on write of the configuration, calls again the setup and restart the server if it's up. + -- can get the client by name of the file + + vim.api.nvim_create_user_command("AlphaLSP", function() + vim.ui.select(servers, { prompt = "LSP Servers" }, function(server) + if server == nil then + return + end + + server = string.match(server, "^(.+) <") + local path = string.format("%s/lua/alpha/lsp/servers/%s.lua", vim.fn.stdpath "config", server) + if vim.fn.filereadable(path) == 0 then + local create = vim.fn.confirm("Server Does Not exist. Create new server?", "&Yes\n&No\n&Cancel") + if create ~= 1 then + return + end + end + + local uri = vim.uri_from_fname(path) + local buffer = vim.uri_to_bufnr(uri) + + vim.api.nvim_win_set_buf(0, buffer) + end) + end, {}) + end, +} diff --git a/current_config/lua/alpha/lsp/mason.lua b/current_config/lua/alpha/lsp/mason.lua new file mode 100644 index 0000000..a8c6ce7 --- /dev/null +++ b/current_config/lua/alpha/lsp/mason.lua @@ -0,0 +1,23 @@ +local mason_lspconfig = require "mason-lspconfig" +local servers = require "alpha.lsp.servers" +local lspconfig = require "lspconfig" + +local mason_servers = {} + +for server, _ in pairs(servers) do + local cmd = lspconfig[server].cmd[1] + if vim.fn.executable(cmd) == 0 then + table.insert(mason_servers, server) + end +end + +mason_lspconfig.setup { + -- ensure_installed = mason_servers, +} + +-- filter the list for the ones not globally installed +-- require("mason-tool-installer").setup { +-- ensure_installed = vim.tbl_filter(function (tool) +-- return vim.fn.executable(tool) == 0 +-- end, require "alpha.lsp.tools"), +-- } diff --git a/current_config/lua/alpha/lsp/null-ls.lua b/current_config/lua/alpha/lsp/null-ls.lua new file mode 100644 index 0000000..b329ba6 --- /dev/null +++ b/current_config/lua/alpha/lsp/null-ls.lua @@ -0,0 +1,53 @@ +local null_ls = require "null-ls" +-- local php_actions = require "php-code-actions" +-- local laravel_actions = require("laravel.code-actions") + +null_ls.setup { + 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.diagnostics.yamllint, + + -- 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, + -- -- command = "./bin/phpstan", + -- -- condition = function () + -- -- return vim.fn.findfile("bin/phpstan") ~= "" + -- -- end + -- }, + null_ls.builtins.diagnostics.phpcs.with { + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + condition = function(utils) + return utils.root_has_file "phpcs.xml" + end, + }, + null_ls.builtins.formatting.pint, + }, +} + +vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, {desc = "LSP (null ls) Code actions"}) +vim.keymap.set("n", "vf", function() + return vim.lsp.buf.format { async = true } +end, {desc = "LSP (null ls) Format file"}) + +-- function to toogle and possible restart it +vim.api.nvim_create_user_command("NullLsToggle", function() + local sources = vim.tbl_map(function(el) + return el.name + end, null_ls.get_sources()) + vim.ui.select(sources, {}, function(selected) + if not selected then + return + end + null_ls.toggle(selected) + end) +end, {}) diff --git a/current_config/lua/alpha/lsp/servers/emmet_ls.lua b/current_config/lua/alpha/lsp/servers/emmet_ls.lua new file mode 100644 index 0000000..c4f1cb6 --- /dev/null +++ b/current_config/lua/alpha/lsp/servers/emmet_ls.lua @@ -0,0 +1,12 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + capabilities = capabilities, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, + }, ops) +end diff --git a/current_config/lua/alpha/lsp/servers/html.lua b/current_config/lua/alpha/lsp/servers/html.lua new file mode 100644 index 0000000..7b8ef54 --- /dev/null +++ b/current_config/lua/alpha/lsp/servers/html.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "html-languageserver" == 1 then + config.cmd = { "html-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/current_config/lua/alpha/lsp/servers/jsonls.lua b/current_config/lua/alpha/lsp/servers/jsonls.lua new file mode 100644 index 0000000..9c731ab --- /dev/null +++ b/current_config/lua/alpha/lsp/servers/jsonls.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "json-languageserver" == 1 then + config.cmd = { "json-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/current_config/lua/alpha/lsp/servers/lua_ls.lua b/current_config/lua/alpha/lsp/servers/lua_ls.lua new file mode 100644 index 0000000..c5f72bf --- /dev/null +++ b/current_config/lua/alpha/lsp/servers/lua_ls.lua @@ -0,0 +1,36 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + if ops.neodev == true then + require("neodev").setup() + end + + return vim.tbl_extend("force", { + 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, + }, + hint = { + enable = true, + }, + completion = { + callSnippet = "Replace", + }, + }, + }, + }, ops) +end diff --git a/current_config/lua/alpha/lsp/servers/phpactor.lua b/current_config/lua/alpha/lsp/servers/phpactor.lua new file mode 100644 index 0000000..e6bebcd --- /dev/null +++ b/current_config/lua/alpha/lsp/servers/phpactor.lua @@ -0,0 +1,80 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +local function phpactor_attach(_, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorReindex", function() + vim.lsp.buf_notify(bufnr, "phpactor/index/reindex", {}) + end, {}) + + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorStatus", function() + local results, _ = vim.lsp.buf_request_sync(bufnr, "phpactor/status", { ["return"] = true }) + + local content = "" + + for _, res in pairs(results or {}) do + if res ~= nil and res["result"] ~= nil then + content = content .. res["result"] + end + end + + local Popup = require "nui.popup" + local event = require("nui.utils.autocmd").event + + local popup = Popup { + enter = true, + focusable = true, + border = { + style = "rounded", + }, + position = "50%", + size = { + width = "80%", + height = "60%", + }, + } + + -- mount/open the component + popup:mount() + + -- unmount component when cursor leaves buffer + popup:on(event.BufLeave, function() + popup:unmount() + end) + local out = {} + for match in string.gmatch(content, "[^\n]+") do + table.insert(out, match) + end + + vim.api.nvim_buf_set_option(popup.bufnr, "filetype", "markdown") + vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, out) + end, {}) +end + +return function(ops) + return vim.tbl_extend("force", { + on_attach = function(client, bufnr) + lsp_attach(client, bufnr) + phpactor_attach(client, bufnr) + end, + flags = lsp_flags, + filetypes = { "php", "blade" }, + init_options = { + ["language_server_worse_reflection.inlay_hints.enable"] = true, + ["language_server_worse_reflection.inlay_hints.params"] = true, + -- ["language_server_worse_reflection.inlay_hints.types"] = true, + ["language_server_configuration.auto_config"] = false, + ["code_transform.import_globals"] = true, + ["language_server_phpstan.enabled"] = true, + ["language_server_phpstan.level"] = 7, + ["language_server_phpstan.bin"] = "phpstan", + }, + handlers = { + ["textDocument/inlayHint"] = function(err, result, ...) + for _, res in ipairs(result) do + res.label = res.label .. ": " + end + vim.lsp.handlers["textDocument/inlayHint"](err, result, ...) + end, + }, + }, ops) +end diff --git a/current_config/lua/alpha/lsp/servers/rust_analyzer.lua b/current_config/lua/alpha/lsp/servers/rust_analyzer.lua new file mode 100644 index 0000000..c0db321 --- /dev/null +++ b/current_config/lua/alpha/lsp/servers/rust_analyzer.lua @@ -0,0 +1,24 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["rust-analyzer"] = { + checkOnSave = { + allFeatures = true, + overrideCommand = { + "cargo", + "clippy", + "--workspace", + "--message-format=json", + "--all-targets", + "--all-features", + }, + }, + }, + }, + }, ops) +end diff --git a/current_config/lua/alpha/lsp/servers/tsserver.lua b/current_config/lua/alpha/lsp/servers/tsserver.lua new file mode 100644 index 0000000..e27d94a --- /dev/null +++ b/current_config/lua/alpha/lsp/servers/tsserver.lua @@ -0,0 +1,33 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }, ops) +end diff --git a/current_config/lua/alpha/lsp/tools.lua b/current_config/lua/alpha/lsp/tools.lua new file mode 100644 index 0000000..7919521 --- /dev/null +++ b/current_config/lua/alpha/lsp/tools.lua @@ -0,0 +1,8 @@ +return { + "codelldb", + "go-debug-adapter", + "js-debug-adapter", + "php-debug-adapter", + "phpcs", + "phpstan", +} diff --git a/current_config/lua/alpha/packer_install.lua b/current_config/lua/alpha/packer_install.lua new file mode 100644 index 0000000..9ef6658 --- /dev/null +++ b/current_config/lua/alpha/packer_install.lua @@ -0,0 +1,27 @@ +local download_packer = function() + if vim.fn.input "Download Packer? (y for yes)" ~= "y" then + return + end + + local directory = string.format("%s/site/pack/packer/start/", vim.fn.stdpath "data") + + vim.fn.mkdir(directory, "p") + + local out = vim.fn.system( + string.format("git clone %s %s", "https://github.com/wbthomason/packer.nvim", directory .. "/packer.nvim") + ) + + print(out) + print "Downloading packer.nvim..." + print "( You'll need to restart now )" +end + +return function() + if not pcall(require, "packer") then + download_packer() + + return true + end + + return false +end diff --git a/current_config/lua/alpha/php/gateway.lua b/current_config/lua/alpha/php/gateway.lua new file mode 100644 index 0000000..5f8ddae --- /dev/null +++ b/current_config/lua/alpha/php/gateway.lua @@ -0,0 +1,137 @@ +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 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) + + 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 + + return mutations_definitions +end + +-- "'@=mutation(\"App\\\\GraphQL\\\\Mutations\\\\Mutation::action\", ...)'", +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 + return + end + + local args_tbl = vim.split(args, ", ") + local fqn = string.match(args_tbl[1], '"(.+)"') + fqn = string.gsub(fqn, "\\\\", "\\") + -- P(fqn) + + require("alpha.php.lsp").find(fqn, "phpactor") +end + +--- @param bufnr integer Buff id +gateway.get_graphql_definitions = function(bufnr) + vim.treesitter.query.set( + "yaml", + "GraphQL_endpoints", + [[ + (document (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @mutation + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @resolve (#eq? @resolve "resolve") + value: (flow_node) @resolver + ))) + ))) + ))) + ))) + )))) + ]] + ) + + local query = vim.treesitter.query.get("yaml", "GraphQL_endpoints") + + local elements = {} + + local parsers = require "nvim-treesitter.parsers" + local parser = parsers.get_parser(bufnr) + local tree = parser:parse()[1] + + 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 +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\\\\Mutation::action\", ...)'", + -- value = "deleteVehicleImage" + return { + value = entry, + display = entry.value, + ordinal = entry.value, + path = vim.api.nvim_buf_get_name(entry.buffer), + lnum = entry.lnum, + resolver = entry.resolver, + } + end, + }, + sorter = conf.generic_sorter(opts), + previewer = conf.grep_previewer(opts), + attach_mappings = function(prompt_bufnr, map) + action_set.select:enhance { + post = function() + local selection = action_state.get_selected_entry() + vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) + end, + } + map("i", "", function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + open_resolver(selection.resolver) + end) + return true + end, + }) + :find() +end + +return gateway diff --git a/current_config/lua/alpha/php/lsp.lua b/current_config/lua/alpha/php/lsp.lua new file mode 100644 index 0000000..37e0bc0 --- /dev/null +++ b/current_config/lua/alpha/php/lsp.lua @@ -0,0 +1,151 @@ +local Path = require "plenary.path" + +local lsp = {} + +local open_filename = function(filename) + if vim.api.nvim_buf_get_name(0) ~= filename then + filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) + pcall(vim.cmd, string.format("%s %s", "edit", filename)) + end +end + +---@param server_name string +---@return table|nil, boolean +local get_client = function(server_name) + local clients = vim.lsp.get_active_clients { name = server_name } + local client = clients[1] or nil + local new_instance = false + + if not client then + local server = require("lspconfig")[server_name] + local config = server.make_config(vim.fn.getcwd()) + local client_id = vim.lsp.start(config) + client = vim.lsp.get_client_by_id(client_id) + new_instance = true + end + + return client, new_instance +end + +local function go_to(client, is_new_instance, full_class, method) + local class_parts = vim.split(full_class, "\\") + local class = class_parts[#class_parts] + + local resp = client.request_sync("workspace/symbol", { query = class }, nil) + + local locations = vim.lsp.util.symbols_to_items(resp.result or {}, nil) or {} + if vim.tbl_isempty(locations) then + vim.api.nvim_err_writeln("Empty response looking for class: " .. full_class) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local class_location = nil + for idx, location in pairs(locations) do + if location.text == string.format("[Class] %s", full_class) then + class_location = locations[idx] + break + end + end + + if class_location == nil then + vim.api.nvim_err_writeln("Could not find class for : " .. full_class) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + open_filename(class_location.filename) + + local params = vim.lsp.util.make_position_params(0) + if is_new_instance then + vim.lsp.buf_attach_client(0, client.id) + end + + vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(method_err, method_server_result, _, _) + if method_err then + vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. method_err.message) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local method_locations = vim.lsp.util.symbols_to_items(method_server_result or {}, 0) or {} + if vim.tbl_isempty(method_locations) then + vim.api.nvim_err_writeln(string.format("empty response looking for method: %s", method or "__invoke")) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local method_location = nil + for _, value in ipairs(method_locations) do + if value.text == string.format("[Method] %s", method or "__invoke") then + method_location = value + break + end + end + + if method_location == nil then + if is_new_instance then + vim.lsp.stop_client(client.id) + end + 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("Erro setting row and col " .. err_msg) + end + vim.cmd "normal zt" + end + if is_new_instance then + vim.lsp.stop_client(client.id) + end + end) +end + +---Return a buffer id for the given client +---@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 buffers = vim.lsp.get_buffers_by_client_id(clients[1].id) + + if #buffers == 0 then + return nil + end + + return buffers[1] +end + +--- @param fqn string: fully name to search Class::method +lsp.find = function(fqn, server_name) + local search = vim.split(fqn, "::") + local fqn_class = search[1] + local method = search[2] + + local client, is_new_instance = get_client(server_name) + + if not client then + vim.api.nvim_err_writeln "Could not get lsp client" + return + end + + go_to(client, is_new_instance, fqn_class, method) +end + +return lsp diff --git a/current_config/lua/alpha/php/servers.lua b/current_config/lua/alpha/php/servers.lua new file mode 100644 index 0000000..9450152 --- /dev/null +++ b/current_config/lua/alpha/php/servers.lua @@ -0,0 +1,38 @@ +local phpactor = {} + +-- TODO possible improvement look how it works underline +-- use the client directly to call, no need for the buffer +-- to find a class. +-- 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) +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) + +vim.lsp.get_client_by_id(client_id) +-- use client.request or request_sync +-- look for the direct of the symbol +return { + phpactor = phpactor, +} diff --git a/current_config/lua/alpha/select_to_quickfix.lua b/current_config/lua/alpha/select_to_quickfix.lua new file mode 100644 index 0000000..ebd1561 --- /dev/null +++ b/current_config/lua/alpha/select_to_quickfix.lua @@ -0,0 +1,53 @@ +local api = vim.api + +local function create_quickfix_entry(selection) + local filename, linenumber = selection:match "([^:]+):(%d+)" + + return { + filename = vim.fn.getcwd() .. "/" .. filename, + lnum = tonumber(linenumber), + col = 1, + text = filename, + } +end + +local function add_selections_to_quickfix(selections) + local quickfix_list = {} + + for _, selection in ipairs(selections) do + local entry = create_quickfix_entry(selection) + table.insert(quickfix_list, entry) + end + + vim.fn.setqflist(quickfix_list, "r") +end + +local function get_selections() + local _, end_line, _, _ = unpack(vim.fn.getpos "'>") + local _, start_line, _, _ = unpack(vim.fn.getpos "'<") + local lines = api.nvim_buf_get_lines(0, start_line - 1, end_line, false) + + local selections = {} + for _, line in ipairs(lines) do + for selection in line:gmatch "%S+" do + table.insert(selections, selection) + end + end + + return selections +end + +local function select_to_quickfix() + local selections = get_selections() + + if #selections > 0 then + add_selections_to_quickfix(selections) + print "Selections added to quickfix list" + else + print "No selections found" + end +end + +return { + handle = select_to_quickfix, +} diff --git a/current_config/lua/alpha/snips/ft/cucumber.lua b/current_config/lua/alpha/snips/ft/cucumber.lua new file mode 100644 index 0000000..6176a87 --- /dev/null +++ b/current_config/lua/alpha/snips/ft/cucumber.lua @@ -0,0 +1,71 @@ +local ls = require "luasnip" +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local fmt = require("luasnip.extras.fmt").fmt + +local M = { + clean = t [[Given clean stubs list]], + all = t [[And all stubs should be matched]], + status_code = fmt([[Then the response status code should be {}]], { i(1, "200") }), + no_error = t [[And the JSON path expression errors should not have result]], + json_data = fmt([[And the JSON path expression "data" should be equal to: +""" +{{ + {} +}} +""" + ]], {i(1)}), + feature = fmt( + [[Feature: {} + + {} +]], + { + i(1, "Feature Name"), + i(0), + } + ), + scenario = fmt( + [[Scenario: {} + {}]], + { + i(1, "Scenario name"), + i(0), + } + ), + stub = fmt([[And the APIClient will send a request with a stub from "{}"]], { i(1) }), + request = fmt( + [[When I send the GraphQL request: +""" +{} +"""]], + { i(1) } + ), + result = fmt( + [[And the JSON path expression "data" should be equal to: +""" +{{ + "result": {{ + {} + }} +}} +"""]], + { i(1) } + ), + query = fmt( + [[{} {{ +result: {}({}) {{ + {} +}} + }}]], + { c(1, { t "mutation", t "query" }), i(2, "mutation"), i(3, ""), i(4) } + ), + access = fmt( + [[And the Access Cache has Allowed the userId "{}" for inspectionId "{}"]], + { i(1, "3414054"), i(2, "42") } + ), + branch_access = fmt([[And the Access Cache has branch "{}" for userId "{}"]], { i(1, "1"), i(2, "3414054") }), +} + +return M diff --git a/current_config/lua/alpha/snips/ft/go.lua b/current_config/lua/alpha/snips/ft/go.lua new file mode 100644 index 0000000..9c3977f --- /dev/null +++ b/current_config/lua/alpha/snips/ft/go.lua @@ -0,0 +1,134 @@ +local ls = require "luasnip" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local 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 get_node_text = vim.treesitter.get_node_text + +vim.treesitter.query.set( + "go", + "LuaSnip_Result", + [[ + [ + (method_declaration result: (_) @id) + (function_declaration result: (_) @id) + (func_literal result: (_) @id) + ] +]] +) + +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) +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, +} + +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.query.get("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)) +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), + }, +} + +M.f = fmt("func {}({}) {} {{\n\t{}\n}}", { i(1, "name"), i(2), i(3), i(0) }) + +return M diff --git a/current_config/lua/alpha/snips/ft/lua.lua b/current_config/lua/alpha/snips/ft/lua.lua new file mode 100644 index 0000000..d896f3e --- /dev/null +++ b/current_config/lua/alpha/snips/ft/lua.lua @@ -0,0 +1,69 @@ +local ls = require "luasnip" + +-- local snippet = ls.s +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local d = ls.dynamic_node +local i = ls.insert_node +local f = ls.function_node +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 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), + }) +end + +local newline = function(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", + }, + + preq = fmt( + [[local ok, {} = pcall(require, "{}") +if not ok then + return +end]], + { + f(function(args) + return args[1][1] + end, { 1 }), + i(1), + } + ), + + plugin = fmt( + [[return {{ + "{}" +}}]], + { + i(1, "plugin"), + } + ), +} diff --git a/current_config/lua/alpha/snips/ft/php.lua b/current_config/lua/alpha/snips/ft/php.lua new file mode 100644 index 0000000..72936d8 --- /dev/null +++ b/current_config/lua/alpha/snips/ft/php.lua @@ -0,0 +1,163 @@ +local ls = require "luasnip" +local composer = require "composer" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local f = ls.function_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt + +local 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) +end + +local var_name = function(args) + return snippet_from_nodes(nil, { + i(1, args[1][1]:gsub("^%u", string.lower):gsub("Interface", "") or ""), + }) +end + +local class_name = function() + return vim.fn.expand "%:t:r" +end + +local M = {} + +M.v = fmt( + [[ +/** + * @var {} + */ +{} {} ${}; +]], + { + i(1, "type"), + visibility(2, "private"), + i(3, "Type"), + i(4, "var"), + } +) + +M.class = fmt( + [[ + + */ + private ObjectProphecy ${}; +]], + { + i(1, "Type"), + d(2, var_name, { 1 }), + } +) + +M.iop = fmt( + [[$this->{} = $this->prophesize({}::class);]], + { + i(1, ""), + i(2, ""), + } +) + +M.arg = fmt([[{} ${}]], { + i(1, "Type"), + d(2, var_name, { 1 }), +}) + +M._c = fmt( + [[{} function __construct({}) {{ + {} +}}]], + { + visibility(1, "public"), + i(2), + i(0), + } +) + +M._p = fmt( + [[{} function __construct( + {} +) {{ +}}]], + { + visibility(1, "public"), + i(2), + } +) + +M.strict = t "declare(strict_types=1);" + +M["fn"] = fmt( + [[{} function {}({}): {} +{{ + {} +}}]], + { visibility(1, "public"), i(2), i(3), i(4, "void"), i(0) } +) + +M["then"] = fmt( + [[->then( + function ({}) {{ + {} + }} +)]], + { i(1, ""), i(2, "") } +) + +M.test = fmt( + [[/** + * @test + */ +public function it_{}(): void +{{ + {} +}} +]], + { i(1, ""), i(0, "") } +) + +return M diff --git a/current_config/lua/alpha/snips/ft/yaml.lua b/current_config/lua/alpha/snips/ft/yaml.lua new file mode 100644 index 0000000..3924c6f --- /dev/null +++ b/current_config/lua/alpha/snips/ft/yaml.lua @@ -0,0 +1,225 @@ +local ls = require "luasnip" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local f = ls.function_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt +local rep = require("luasnip.extras").rep + +local M = { + str = fmt( + [[{}: + type: string +{}]], + { + i(1, ""), + i(2, ""), + } + ), + bool = fmt( + [[{}: + type: boolean +{}]], + { + i(1, ""), + i(2, ""), + } + ), + float = fmt( + [[{}: + type: number + format: float +{}]], + { + i(1, ""), + i(2, ""), + } + ), + int = fmt( + [[{}: + type: integer +{}]], + { + i(1, ""), + i(2, ""), + } + ), + id = fmt( + [[{}: + type: integer + format: int64 +{}]], + { + i(1, ""), + i(2, ""), + } + ), + class = fmt( + [[{}: + $ref: '#/components/schemas/{}' +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + date = fmt( + [[{}: + type: string + format: date-time +{}]], + { + i(1, ""), + i(2, ""), + } + ), + arr = fmt( + [[{}: + type: array + items: + {} +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + ref = fmt([[$ref: '#/components/schemas/{}']], { i(1, "") }), + obj = fmt( + [[type: object +properties: + {}]], + i(1, "") + ), + aint = fmt( + [[{}: + type: array + items: + type: int + format: int64 +{}]], + { + i(1, ""), + i(2, ""), + } + ), + astr = fmt( + [[{}: + type: array + items: + type: string +{}]], + { + i(1, ""), + i(2, ""), + } + ), + + mut = fmt( + [[{}: + type: "{}" + resolve: '@=mutation("App\\GraphQL\\Mutation\\{}::{}", {}, info)' + args: + {} +]], + { + i(1, ""), + i(2, ""), + i(3, ""), + rep(1), + i(5, ""), + i(6, ""), + } + ), + + input = fmt( + [[{}: + type: input-object + config: + fields: + {} +]], + { + i(1, ""), + i(2, ""), + } + ), + f = fmt([[{}: {{ type: "{}" }}]], { i(1, ""), i(2, "") }), + + api = fmt( + [[openapi: 3.0.2 +info: + title: {} + contact: + name: eva-team-be + version: {} +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(0, "") } + ), + param = fmt( + [[parameters: + - name: {} + description: {} + in: path + required: true + schema: + type: integer + format: int64 +]], + { i(1, ""), i(2, "") } + ), + get = fmt( + [[get: + operationId: {} + description: {} + tags: [ {} ] + responses: + 200: + description: Response + content: + application/json: + schema: + {} + ]], + { i(1, "GetOperation"), i(2, "description"), i(3, "tag"), i(4, "") } + ), + + put = fmt( + [[put: + operationId: {} + tags: [ {} ] + description: {} + requestBody: + content: + application/json: + schema: + {} + required: true + responses: + 200: + description: {} + content: + application/json: + schema: + {} + ]], + { i(1, "PutOperation"), i(2, "tag"), i(3, "description"), i(4, ""), i(5, "description"), i(6, "") } + ), +} + +return M diff --git a/current_config/lua/alpha/telescope/init.lua b/current_config/lua/alpha/telescope/init.lua new file mode 100644 index 0000000..c4daf6c --- /dev/null +++ b/current_config/lua/alpha/telescope/init.lua @@ -0,0 +1,186 @@ +local SHOULD_RELOAD_TELESCOPE = false + +local reloader = function() + if SHOULD_RELOAD_TELESCOPE then + Reload "plenary" + Reload "telescope" + Reload "alpha.telescope.setup" + end +end + +local fb_actions = require("telescope").extensions.file_browser.actions +local actions = require "telescope.actions" +local my_actions = require "alpha.telescope.my_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 +end + +function M.branches() + require("telescope.builtin").git_branches { + attach_mappings = function(_, map) + map("i", "", actions.git_create_branch) + map("n", "", 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, + } +end + +M.find_nvim_config = function() + 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", "", my_actions.create_plugin) + map("i", "", my_actions.disable_plugin) + map("i", "", 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) +end + +function M.grep_word() + require("telescope.builtin").grep_string { search = vim.fn.expand "" } +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) +end + +function M.my_plugins() + if vim.fn.isdirectory(vim.fn.getenv "HOME" .. "/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.scratchs() + require("telescope.builtin").find_files { + prompt_title = "Scratchs", + no_ignore = true, + cwd = "~/.config/nvim/lua/scratchs/", + attach_mappings = function(_, map) + map("i", "", my_actions.create_scratch_file) + + return true + end, + } +end + +function M.projectionist() + return require("telescope").extensions.projectionist.projectionist() +end + +function M.laravel_commands() + 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, + } +end + +function M.worktree() + return require("telescope").extensions.git_worktree.git_worktrees() +end + +function M.worktree_create() + return require("telescope").extensions.git_worktree.create_git_worktree() +end + +function M.refactor() + return require("telescope").extensions.refactoring.refactors() +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, + }, + }, + } +end + +function M.file_browser_relative() + return M.file_browser { path = "%:p:h" } +end + +function M.file_browser(opts) + opts = opts or {} + + opts = { + path = opts.path, + sorting_strategy = "ascending", + scroll_strategy = "cycle", + layout_config = { + prompt_position = "top", + }, + + attach_mappings = function(_, map) + map("i", "", fb_actions.create_from_prompt) + + return true + end, + } + + 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, +}) diff --git a/current_config/lua/alpha/telescope/mappings.lua b/current_config/lua/alpha/telescope/mappings.lua new file mode 100644 index 0000000..89472bc --- /dev/null +++ b/current_config/lua/alpha/telescope/mappings.lua @@ -0,0 +1,55 @@ +local map_tele = function(key, f, opts) + local default = { + mode = "n", + options = {}, + buffer = nil, + desc = nil, + } + opts = opts or {} + opts = vim.tbl_deep_extend("force", default, opts or {}) + + local rhs = function() + R("alpha.telescope")[f](opts.options) + end + + local map_options = { + remap = false, + silent = true, + } + if opts.buffer then + map_options.buffer = opts.buffer + end + if opts.desc then + map_options.desc = "Telescope: " .. opts.desc + end + + vim.keymap.set(opts.mode, key, rhs, map_options) +end + +-- not shure what this line does +vim.api.nvim_set_keymap( + "c", + "", + "(TelescopeFuzzyCommandSearch)", + { noremap = false, nowait = true, desc = "In comand look for previous commands" } +) + +map_tele("pp", "project_files", { desc = "Open Project files" }) +map_tele("gc", "branches", { desc = "Git Branches selector" }) +map_tele("pw", "grep_word", { desc = "Grep word under cursor" }) +map_tele("ps", "grep_string", { desc = "Grep provided input string" }) +map_tele("rc", "search_config", { desc = "Search Files in .dotfiles directory" }) +map_tele("rn", "find_nvim_config", { desc = "Search Files in nvim config directory" }) +map_tele("rp", "find_nvim_plugin", { desc = "Search Neovim plugins" }) +map_tele("rs", "scratchs", { desc = "Search Neovim Scratchs files" }) +map_tele("ph", "help_tags", { desc = "Neovim Help" }) +map_tele("pe", "buffers", { desc = "Open buffers" }) +map_tele("pr", "treesitter", { desc = "Treesitter buffer elements" }) +map_tele("bb", "file_browser_relative", { desc = "Current directory" }) +map_tele("bp", "file_browser", { desc = "Project directory" }) +map_tele("gs", "git_status", { desc = "Git status" }) +map_tele("ve", "diagnostics", { desc = "Diagnostic of the buffer" }) +map_tele("po", "api_specs", { desc = "Openapi directory" }) +map_tele("pm", "gateway", { desc = "Graphql mutations and queries" }) + +return map_tele diff --git a/current_config/lua/alpha/telescope/my_actions.lua b/current_config/lua/alpha/telescope/my_actions.lua new file mode 100644 index 0000000..b0e9f10 --- /dev/null +++ b/current_config/lua/alpha/telescope/my_actions.lua @@ -0,0 +1,170 @@ +local M = {} + +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)) +end + + +local get_disable_stm_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_is_disabled", + [[ +(return_statement + (expression_list + (table_constructor + (field + name: (identifier) @enabled (#eq? @enabled "enabled") + value: (false) @is_false + ) + ) + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_is_disabled") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node + end + end + + return nil +end + +local get_enabled_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_has_enable_property", + [[ +(return_statement + (expression_list + (table_constructor + (field + name: (identifier) @enabled (#eq? @enabled "enabled") + ) + ) + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_has_enable_property") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node + end + end + + return nil +end + +local get_return_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_return_table_constructor", + [[ +(return_statement + (expression_list + (table_constructor) @table_constructor + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_return_table_constructor") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "table_constructor" then + return node + end + end + + 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) + local tree = parser:parse()[1] + + 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) +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) + + local tree = parser:parse()[1] + + 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 + +M.create_scratch_file = function(prompt_bufnr) + local new_scratch = action_state.get_current_line() + actions.close(prompt_bufnr) + vim.cmd(string.format("edit ~/.config/nvim/lua/scratchs/%s.lua", new_scratch)) +end + +return M diff --git a/current_config/lua/alpha/telescope/setup.lua b/current_config/lua/alpha/telescope/setup.lua new file mode 100644 index 0000000..0e368c7 --- /dev/null +++ b/current_config/lua/alpha/telescope/setup.lua @@ -0,0 +1,222 @@ +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 + + action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) +end + +local filetype_hook = function(filepath, bufnr, opts) + -- Here for example you can say: if ft == "xyz" then this_regex_highlighing else nothing end + -- + local is_image = function(filepath) + local image_extensions = { "png", "jpg" } -- Supported image formats + local split_path = vim.split(filepath:lower(), ".", { plain = true }) + local extension = split_path[#split_path] + return vim.tbl_contains(image_extensions, extension) + end + if not is_image(filepath) then + return true + end + local ui = require "image.ui" + local options = require "image.options" + local dimensions = require "image.dimensions" + local api = require "image.api" + local config = require "image.config" + local user_opts = { + render = { + foreground_color = true, + background_color = true, + }, + } + local global_opts = vim.tbl_deep_extend("force", config.DEFAULT_OPTS, user_opts) + + local ascii_width, ascii_height, horizontal_padding, vertical_padding, img_width, img_height = + dimensions.calculate_ascii_width_height(opts.winid, filepath, global_opts) + options.set_options_before_render(bufnr) + ui.buf_clear(bufnr) + local label = ui.create_label( + filepath, + ascii_width, + horizontal_padding, + global_opts.render.show_image_dimensions, + img_width, + img_height + ) + + api.get_ascii_data_sync(filepath, ascii_width, ascii_height, global_opts, function(ascii_data) + ui.buf_insert_data_with_padding(bufnr, ascii_data, horizontal_padding, vertical_padding, label, global_opts) + + options.set_options_after_render(bufnr) + end) + return false +end + +require("telescope").setup { + defaults = { + preview = { + filetype_hook = filetype_hook, + }, + 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.7) + 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 = { + -- [""] = false, + -- [""] = actions.select_horizontal, + [""] = "move_selection_next", + + [""] = set_prompt_to_entry_value, + + -- These are new :) + [""] = action_layout.toggle_preview, + [""] = action_layout.toggle_mirror, + -- [""] = action_layout.toggle_prompt_position, + + -- [""] = actions.master_stack, + + -- [""] = actions.send_to_qflist + actions.open_qflist, + -- [""] = actions.send_selected_to_qflist + actions.open_qflist, + + -- This is nicer when used with smart-history plugin. + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + + -- [""] = 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, + + -- [""] = function() + -- vim.api.nvim_input("") + -- 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, + }, + -- buffer_previewer_maker = new_maker, + }, + + pickers = { + fd = { + mappings = { + n = { + ["kj"] = "close", + }, + }, + }, + + git_branches = { + mappings = { + i = { + [""] = 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_dropdown { + borderchars = { + prompt = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + results = { "─", "│", "─", "│", "╭", "╮", "┤", "├" }, + preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + }, + width = 0.8, + previewer = false, + }, + }, + }, +} + +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/current_config/lua/alpha/test_menu.lua b/current_config/lua/alpha/test_menu.lua new file mode 100644 index 0000000..afe3a9e --- /dev/null +++ b/current_config/lua/alpha/test_menu.lua @@ -0,0 +1,50 @@ +local hydra = require "hydra" + +local hint = [[ + Vim Tests + _n_: Near test _h_: Harpoon ^ + _f_: Current file _s_: Test Suit ^ + _l_: Test Last _g_: Visit + _w_: Watch last Test _p_: stop watch + ^ ^ __ ^ +]] +local auto_cmd_id = nil +local stopAutoCommand = function() + if auto_cmd_id ~= nil then + vim.api.nvim_del_autocmd(auto_cmd_id) + auto_cmd_id = nil + end +end +local startAutoCommand = function() + stopAutoCommand() + auto_cmd_id = vim.api.nvim_create_autocmd({ "BufWritePost" }, { + pattern = { "*.php", "*.feature", "*.yaml" }, + command = "TestLast", + }) +end + +hydra { + name = "vimtest", + hint = hint, + mode = "n", + config = { + color = "teal", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "t", + heads = { + { "n", ":TestNearest" }, + { "h", ":TestNearest -strategy=harpoon" }, + { "f", ":TestFile" }, + { "s", ":TestSuit" }, + { "l", ":TestLast" }, + { "g", ":TestVisit" }, + { "w", startAutoCommand }, + { "p", stopAutoCommand }, + { "", nil, { exit = true } }, + }, +} diff --git a/current_config/lua/alpha/test_strategy.lua b/current_config/lua/alpha/test_strategy.lua new file mode 100644 index 0000000..9a2d34a --- /dev/null +++ b/current_config/lua/alpha/test_strategy.lua @@ -0,0 +1,65 @@ +local Job = require "plenary.job" + +local function splitString(input_string) + local parts = {} + local in_quote = false + local part_start = 1 + + for i = 1, #input_string do + local char = input_string:sub(i, i) + + if char == "'" then + in_quote = not in_quote + elseif char == " " and not in_quote then + local part = input_string:sub(part_start, i - 1) + -- Remove surrounding quotes if they exist + if part:sub(1, 1) == "'" and part:sub(-1) == "'" then + part = part:sub(2, -2) + end + table.insert(parts, part) + part_start = i + 1 + end + end + + -- Add the last part (and remove surrounding quotes if they exist) + local part = input_string:sub(part_start) + if part:sub(1, 1) == "'" and part:sub(-1) == "'" then + part = part:sub(2, -2) + end + table.insert(parts, part) + + return parts +end + +local function myStrategy(cmd) + --convert cmd from string to table + if type(cmd) == "string" then + -- do not split quoted parts of the string + cmd = splitString(cmd) + end + + -- get first element of cmd and remove from the cmd + local cmd_name = table.remove(cmd, 1) + + ---@diagnostic disable-next-line: missing-fields + Job:new({ + command = cmd_name, + args = cmd, + on_exit = function(j, return_val) + -- in case of result val 0 show success message + if return_val == 0 then + vim.notify("Test run successfully", vim.log.levels.INFO, { title = "Test" }) + return + end + local result = j:stderr_result() or j:stdout_result() + -- join result in a single string + result = table.concat(result, "\n") + -- escape / characters + result = result:gsub("/", "\\/") + vim.notify(result, vim.log.levels.ERROR, { title = "Test" }) + end, + }):start() +end + +vim.g["test#custom_strategies"] = { myStrategy = myStrategy } +vim.g["test#strategy"] = "myStrategy" diff --git a/current_config/lua/alpha/utils.lua b/current_config/lua/alpha/utils.lua new file mode 100644 index 0000000..b7b0fbc --- /dev/null +++ b/current_config/lua/alpha/utils.lua @@ -0,0 +1,11 @@ +local M = {} + +M.save_and_exec = function() + vim.api.nvim_command "silent w" + vim.api.nvim_command "so" + + 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 diff --git a/current_config/lua/config/autocmds.lua b/current_config/lua/config/autocmds.lua new file mode 100644 index 0000000..1e51b62 --- /dev/null +++ b/current_config/lua/config/autocmds.lua @@ -0,0 +1,39 @@ +-- resize splits if window got resized +vim.api.nvim_create_autocmd({ "VimResized" }, { + callback = function() + vim.cmd("tabdo wincmd =") + end, +}) + +-- close some filetypes with +vim.api.nvim_create_autocmd("FileType", { + pattern = { + "qf", + "help", + "man", + "notify", + "lspinfo", + "spectre_panel", + "startuptime", + "tsplayground", + "PlenaryTestPopup", + }, + callback = function(event) + vim.bo[event.buf].buflisted = false + vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) + end, +}) + +vim.api.nvim_create_autocmd("FileType", { + pattern = { "gitcommit", "markdown", "NeogitCommitMessage", "norg" }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, +}) + +vim.api.nvim_create_autocmd({ "BufWritePre" }, { + callback = function() + vim.cmd([[%s/\s\+$//e]]) + end, +}) diff --git a/current_config/lua/config/diagnostic.lua b/current_config/lua/config/diagnostic.lua new file mode 100644 index 0000000..67465ae --- /dev/null +++ b/current_config/lua/config/diagnostic.lua @@ -0,0 +1,9 @@ +vim.diagnostic.config { + virtual_text = false, +} + +local signs = { Error = "", Warn = "", Hint = "", Info = "" } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end diff --git a/current_config/lua/config/init.lua b/current_config/lua/config/init.lua new file mode 100644 index 0000000..008ebf5 --- /dev/null +++ b/current_config/lua/config/init.lua @@ -0,0 +1,13 @@ +require "config.options" +-- autocmds and keymaps can wait to load +vim.api.nvim_create_autocmd("User", { + group = vim.api.nvim_create_augroup("LazyVim", { clear = true }), + pattern = "VeryLazy", + callback = function() + require "config.autocmds" + require "config.usercmds" + require "config.keymaps" + require "config.diagnostic" + end, +}) +require "config.lazy" diff --git a/current_config/lua/config/keymaps.lua b/current_config/lua/config/keymaps.lua new file mode 100644 index 0000000..284db4f --- /dev/null +++ b/current_config/lua/config/keymaps.lua @@ -0,0 +1,43 @@ +-- Keymaps are automatically loaded on the VeryLazy event +-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua +-- Add any additional keymaps here + +local bind = vim.keymap.set +local opts = { silent = true, noremap = true } + +-- for russian layout +bind("i", "", "", opts) +bind("n", "л", "gk", opts) +bind("n", "о", "gj", opts) +bind("i", "", "u", opts) +bind("i", "", "u", opts) + +bind("n", "[c", function() + require("treesitter-context").go_to_context() +end) + +-- Terminal +bind("t", "", "") +bind("t", "h", "h") +bind("t", "j", "j") +bind("t", "k", "k") +bind("t", "l", "l") + +--personal +--normal mode +bind("i", "jk", "") +--save +bind("n", "zz", ":update") + + +bind("n", ",", ":nohlsearch" ) + +--windows +-- bind("n", "", "h") +-- nnoremap h +-- nnoremap j +-- nnoremap k +-- nnoremap l + +vim.keymap.set("n", "[", "call append(line('.') - 1, repeat([''], v:count1))") +vim.keymap.set("n", "]", "call append(line('.'), repeat([''], v:count1))") diff --git a/current_config/lua/config/lazy.lua b/current_config/lua/config/lazy.lua new file mode 100644 index 0000000..5ee9699 --- /dev/null +++ b/current_config/lua/config/lazy.lua @@ -0,0 +1,57 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + -- bootstrap lazy.nvim + -- stylua: ignore + vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath }) +end +vim.opt.rtp:prepend(vim.env.LAZY or lazypath) + +require('lazy').setup({ + change_detection = { notify = false }, + spec = { + { "LazyVim/LazyVim", import = "lazyvim.plugins" }, + { import = "lazyvim.plugins.extras.formatting.prettier" }, + -- { import = "lazyvim.plugins.extras.linting.eslint" }, + -- { import = "lazyvim.plugins.extras.lsp.none-ls" }, + -- { import = "lazyvim.plugins.extras.dap.core" }, + -- { import = "lazyvim.plugins.extras.coding.yanky" }, + { import = "lazyvim.plugins.extras.lang.markdown" }, + -- { import = "lazyvim.plugins.extras.lang.typescript" }, + { import = "lazyvim.plugins.extras.lang.docker" }, + { import = "lazyvim.plugins.extras.lang.json" }, + -- { import = "lazyvim.plugins.extras.lang.go" }, + -- { import = "lazyvim.plugins.extras.lang.elixir" }, + -- { import = "lazyvim.plugins.extras.lang.java" }, + -- { import = "lazyvim.plugins.extras.lang.python" }, + -- { import = "lazyvim.plugins.extras.lang.ruby" }, + -- { import = "lazyvim.plugins.extras.lang.terraform" }, + { import = "lazyvim.plugins.extras.lang.yaml" }, + { import = "plugins" }, + }, + defaults = { + -- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup. + -- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default. + lazy = false, + -- It's recommended to leave version=false for now, since a lot the plugin that support versioning, + -- have outdated releases, which may break your Neovim install. + version = false, -- always use the latest git commit + -- version = "*", -- try installing the latest stable version for plugins that support semver + }, + -- install = { colorscheme = { "tokyonight", "habamax" } }, + checker = { enabled = true }, -- automatically check for plugin updates + performance = { + rtp = { + -- disable some rtp plugins + disabled_plugins = { + "gzip", + -- "matchit", + -- "matchparen", + -- "netrwPlugin", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", + }, + }, + }, +}) diff --git a/current_config/lua/config/options.lua b/current_config/lua/config/options.lua new file mode 100644 index 0000000..2beb6f5 --- /dev/null +++ b/current_config/lua/config/options.lua @@ -0,0 +1,54 @@ +-- Options are automatically loaded before lazy.nvim startup +-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua +-- Add any additional options here +vim.g.mapleader = " " +vim.g.snippets = "luasnip" + +vim.o.langmap = + "ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz" + +vim.o.relativenumber = false +vim.o.spelllang = "ru_ru,en_us" +vim.o.linebreak = true +vim.g.autoformat = false + +local opt = vim.o + +opt.mouse = "" +opt.number = true +opt.relativenumber = true +opt.conceallevel = 3 +opt.hidden = true +opt.expandtab = true +opt.tabstop = 4 +opt.softtabstop = 4 +opt.shiftwidth = 4 +opt.smartindent = true +opt.errorbells = false +opt.wrap = false +opt.swapfile = false +opt.undofile = true +opt.undodir = os.getenv "HOME" .. "/.cache/nvim/undodir" +opt.hlsearch = false +opt.incsearch = true +opt.ignorecase = true +opt.smartcase = true +opt.termguicolors = true +opt.scrolloff = 4 +opt.sidescrolloff = 4 +opt.showmode = false +opt.clipboard = "unnamedplus" +opt.splitbelow = true +opt.splitright = true +opt.autowrite = true +opt.list = true +opt.listchars = "tab:\\ ,trail:-" +opt.laststatus = 3 +opt.cmdheight = 1 +opt.updatetime = 50 +opt.signcolumn = "yes" +opt.equalalways = false +opt.splitkeep = "screen" +opt.shortmess = "filnxtToOFWIcC" + +require("lazyvim.util").get_root = vim.loop.cwd diff --git a/current_config/lua/config/usercmds.lua b/current_config/lua/config/usercmds.lua new file mode 100644 index 0000000..e69de29 diff --git a/current_config/lua/plugins/autopairs.lua b/current_config/lua/plugins/autopairs.lua new file mode 100644 index 0000000..245059f --- /dev/null +++ b/current_config/lua/plugins/autopairs.lua @@ -0,0 +1,5 @@ +return { + "windwp/nvim-autopairs", + lazy = true, + config = true, +} diff --git a/current_config/lua/plugins/cmp.lua b/current_config/lua/plugins/cmp.lua new file mode 100644 index 0000000..2e3e819 --- /dev/null +++ b/current_config/lua/plugins/cmp.lua @@ -0,0 +1,75 @@ +return { + { + "L3MON4D3/LuaSnip", + keys = function() + return {} + end, + }, + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-emoji", + config = function() + local cmp = require("cmp") + + -- cmp.setup.cmdline(":", { + -- mapping = cmp.mapping.preset.cmdline(), + -- sources = cmp.config.sources({ + -- { name = "path" }, + -- }, { + -- { + -- name = "cmdline", + -- option = { + -- ignore_cmds = { "Man", "!" }, + -- }, + -- }, + -- }), + -- }) + + end, + }, + -- @param opts cmp.ConfigSchema + opts = function(_, opts) + local cmp = require("cmp") + + opts.preselect = cmp.PreselectMode.None + opts.completion = { + completeopt = "noselect", + } + + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local luasnip = require("luasnip") + + opts.mapping = vim.tbl_extend("force", opts.mapping, { + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- this way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }) + end, + }, +} diff --git a/current_config/lua/plugins/color-picker.lua b/current_config/lua/plugins/color-picker.lua new file mode 100644 index 0000000..1e6c88b --- /dev/null +++ b/current_config/lua/plugins/color-picker.lua @@ -0,0 +1,7 @@ +return { + "ziontee113/color-picker.nvim", + keys = { + { "", "PickColorInsert", mode = "i", desc = "ColorPicker" }, + }, + config = true, +} diff --git a/current_config/lua/plugins/colorize.lua b/current_config/lua/plugins/colorize.lua new file mode 100644 index 0000000..89d4039 --- /dev/null +++ b/current_config/lua/plugins/colorize.lua @@ -0,0 +1,5 @@ +return { + "norcalli/nvim-colorizer.lua", + event = "VeryLazy", + config = true, +} diff --git a/current_config/lua/plugins/colorscheme.lua b/current_config/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..9b11a2c --- /dev/null +++ b/current_config/lua/plugins/colorscheme.lua @@ -0,0 +1,11 @@ +return { + "neanias/everforest-nvim", + lazy = false, + priority = 1000, + config = function() + vim.cmd.colorscheme "everforest" + vim.cmd "let g:everforest_better_performance = 1" + vim.cmd "let g:everforest_background = 'soft'" + vim.cmd "let g:airline_theme = 'everforest'" + end, +} diff --git a/current_config/lua/plugins/composer.lua b/current_config/lua/plugins/composer.lua new file mode 100644 index 0000000..f46406c --- /dev/null +++ b/current_config/lua/plugins/composer.lua @@ -0,0 +1,4 @@ +return { + "adalessa/composer.nvim", + lazy = true, +} diff --git a/current_config/lua/plugins/conform.lua b/current_config/lua/plugins/conform.lua new file mode 100644 index 0000000..592ab7a --- /dev/null +++ b/current_config/lua/plugins/conform.lua @@ -0,0 +1,39 @@ +return { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + -- Customize or remove this keymap to your liking + "cf", + function() + require("conform").format({ async = true, lsp_fallback = true }) + end, + mode = "", + desc = "Format buffer", + }, + }, + -- Everything in opts will be passed to setup() + opts = { + -- Define your formatters + formatters_by_ft = { + lua = { "stylua" }, + python = { "isort", "black" }, + javascript = { { "prettierd", "prettier" } }, + php = { { "php_cs_fixer" } }, + blade = { "blade-formatter" }, + }, + -- Set up format-on-save + format_on_save = { timeout_ms = 500, lsp_fallback = true }, + -- Customize formatters + formatters = { + shfmt = { + prepend_args = { "-i", "2" }, + }, + }, + }, + init = function() + -- If you want the formatexpr, here is the place to set it + vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + end, +} diff --git a/current_config/lua/plugins/dap.lua b/current_config/lua/plugins/dap.lua new file mode 100644 index 0000000..a6582a6 --- /dev/null +++ b/current_config/lua/plugins/dap.lua @@ -0,0 +1,31 @@ +return { + "mfussenegger/nvim-dap", + dependencies = { + "theHamsta/nvim-dap-virtual-text", + "rcarriga/nvim-dap-ui", + "leoluz/nvim-dap-go", + "mxsdev/nvim-dap-vscode-js", + "anuvyklack/hydra.nvim", + "nvim-telescope/telescope-dap.nvim", + "rcarriga/cmp-dap", + }, + keys = { { "d", desc = "Open Debug menu" } }, + config = function() + require "alpha.dap" + local ok_telescope, telescope = pcall(require, "telescope") + if ok_telescope then + telescope.load_extension "dap" + end + + local ok_cmp, cmp = pcall(require, "cmp") + if ok_cmp then + cmp.setup.filetype({ "dap-repl", "dapui_watches" }, { + sources = cmp.config.sources({ + { name = "dap" }, + }, { + { name = "buffer" }, + }), + }) + end + end, +} diff --git a/current_config/lua/plugins/deadcolumn.lua b/current_config/lua/plugins/deadcolumn.lua new file mode 100644 index 0000000..26457c2 --- /dev/null +++ b/current_config/lua/plugins/deadcolumn.lua @@ -0,0 +1,5 @@ +return { + "Bekaboo/deadcolumn.nvim", + enabled = false, + event = { "VeryLazy" }, +} diff --git a/current_config/lua/plugins/disabled.lua b/current_config/lua/plugins/disabled.lua new file mode 100644 index 0000000..fc746f8 --- /dev/null +++ b/current_config/lua/plugins/disabled.lua @@ -0,0 +1,8 @@ +return { + { "echasnovski/mini.indentscope", enabled = false }, + -- { "folke/noice.nvim", enabled = false }, + -- { "rcarriga/nvim-notify", enabled = false }, + { "folke/flash.nvim", enabled = false }, + { "ggandor/flit.nvim", enabled = false }, + -- { "ggandor/leap.nvim", enabled = false }, +} diff --git a/current_config/lua/plugins/dressing.lua b/current_config/lua/plugins/dressing.lua new file mode 100644 index 0000000..5cfb6cf --- /dev/null +++ b/current_config/lua/plugins/dressing.lua @@ -0,0 +1,160 @@ +return { + "stevearc/dressing.nvim", + event = "VeryLazy", + opts = { + input = { + -- Set to false to disable the vim.ui.input implementation + enabled = true, + + -- Default prompt string + default_prompt = "Input:", + + -- Can be 'left', 'right', or 'center' + prompt_align = "center", + + -- When true, will close the modal + insert_only = true, + + -- When true, input will start in insert mode. + start_in_insert = true, + + -- These are passed to nvim_open_win + -- anchor = "SW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "editor", + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + prefer_width = 40, + width = nil, + -- min_width and max_width can be a list of mixed types. + -- min_width = {20, 0.2} means "the greater of 20 columns or 20% of total" + max_width = { 140, 0.9 }, + min_width = { 20, 0.2 }, + win_options = { + -- Window transparency (0-100) + winblend = 10, + -- Disable line wrapping + wrap = false, + }, + + -- Set to `false` to disable + mappings = { + n = { + [""] = "Close", + [""] = "Confirm", + }, + i = { + [""] = "Close", + [""] = "Confirm", + [""] = "HistoryPrev", + [""] = "HistoryNext", + }, + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + + -- see :help dressing_get_config + get_config = nil, + }, + select = { + -- Set to false to disable the vim.ui.select implementation + enabled = false, + + -- Priority list of preferred vim.select implementations + backend = { "telescope", "fzf_lua", "fzf", "builtin", "nui" }, + + -- Trim trailing `:` from prompt + trim_prompt = true, + + -- Options for telescope selector + -- These are passed into the telescope picker directly. Can be used like: + -- telescope = require('telescope.themes').get_ivy({...}) + telescope = nil, + + -- Options for fzf selector + fzf = { + window = { + width = 0.5, + height = 0.4, + }, + }, + + -- Options for fzf_lua selector + fzf_lua = { + winopts = { + width = 0.5, + height = 0.4, + }, + }, + + -- Options for nui Menu + nui = { + position = "50%", + size = nil, + relative = "editor", + border = { + style = "rounded", + }, + buf_options = { + swapfile = false, + filetype = "DressingSelect", + }, + win_options = { + winblend = 10, + }, + max_width = 80, + max_height = 40, + min_width = 40, + min_height = 10, + }, + + -- Options for built-in selector + builtin = { + -- These are passed to nvim_open_win + -- anchor = "NW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "editor", + + win_options = { + -- Window transparency (0-100) + winblend = 10, + }, + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + -- the min_ and max_ options can be a list of mixed types. + -- max_width = {140, 0.8} means "the lesser of 140 columns or 80% of total" + width = nil, + max_width = { 140, 0.8 }, + min_width = { 40, 0.2 }, + height = nil, + max_height = 0.9, + min_height = { 10, 0.2 }, + + -- Set to `false` to disable + mappings = { + [""] = "Close", + [""] = "Close", + [""] = "Confirm", + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + }, + + -- Used to override format_item. See :help dressing-format + format_item_override = {}, + + -- see :help dressing_get_config + get_config = nil, + }, + }, +} diff --git a/current_config/lua/plugins/easy-align.lua b/current_config/lua/plugins/easy-align.lua new file mode 100644 index 0000000..7d33478 --- /dev/null +++ b/current_config/lua/plugins/easy-align.lua @@ -0,0 +1,4 @@ +return { + "junegunn/vim-easy-align", + keys = { { "ga", "(EasyAlign)", mode = { "n", "v" }, desc = "EasyAlign" } }, +} diff --git a/current_config/lua/plugins/init.lua b/current_config/lua/plugins/init.lua new file mode 100644 index 0000000..0ee99f4 --- /dev/null +++ b/current_config/lua/plugins/init.lua @@ -0,0 +1,15 @@ +return { + { + "jwalton512/vim-blade", + enabled = true, + }, + { + "tpope/vim-dispatch", + cmd = { "Make", "Dispatch" }, + }, + "tpope/vim-surround", + "tpope/vim-repeat", + "tpope/vim-rhubarb", + "tpope/vim-dotenv", + "tpope/vim-eunuch", +} diff --git a/current_config/lua/plugins/laravel.lua b/current_config/lua/plugins/laravel.lua new file mode 100644 index 0000000..b158221 --- /dev/null +++ b/current_config/lua/plugins/laravel.lua @@ -0,0 +1,45 @@ +return { + "adalessa/laravel.nvim", + dependencies = { + "rcarriga/nvim-notify", + "nvim-telescope/telescope.nvim", + "MunifTanjim/nui.nvim", + }, + cmd = { "Sail", "Artisan", "Composer", "Npm", "Laravel", "LaravelInfo", "DockerCompose" }, + keys = { + { "la", ":Laravel artisan", desc = "Laravel Application Commands" }, + { "lr", ":Laravel routes", desc = "Laravel Application Routes" }, + { + "lt", + function() + require("laravel.tinker").send_to_tinker() + end, + mode = "v", + desc = "Laravel Application Routes", + }, + }, + init = function() + vim.g.laravel_log_level = "debug" + end, + config = function() + local uid = vim.system({ "id", "-u" }, { text = true }):wait().stdout or "1000" + local gid = vim.system({ "id", "-g" }, { text = true }):wait().stdout or "1000" + + local user_arg = string.format("%s:%s", vim.trim(uid), vim.trim(gid)) + + require("laravel").setup { + route_info = { + position = "top", + }, + environment = { + environments = { + ["ao"] = require("laravel.environment.docker_compose").setup { + container_name = "panel-webserver", + cmd = { "docker", "compose", "exec", "-u", user_arg, "-it", "panel-webserver" }, + }, + }, + }, + } + require("telescope").load_extension "laravel" + end, +} diff --git a/current_config/lua/plugins/lsp.lua b/current_config/lua/plugins/lsp.lua new file mode 100644 index 0000000..ada6845 --- /dev/null +++ b/current_config/lua/plugins/lsp.lua @@ -0,0 +1,28 @@ +return { + "neovim/nvim-lspconfig", + dependencies = { + -- "jose-elias-alvarez/null-ls.nvim", + { + "williamboman/mason.nvim", + opts = { + ui = { + border = "rounded", + }, + }, + }, + "folke/neodev.nvim", + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", + }, + event = "VeryLazy", + main = "alpha.lsp", + opts = { + mason = { + enable = true, + auto_install = false, + }, + servers = { + phpactor = { enable = true }, + }, + }, +} diff --git a/current_config/lua/plugins/lualine.lua b/current_config/lua/plugins/lualine.lua new file mode 100644 index 0000000..3147f5a --- /dev/null +++ b/current_config/lua/plugins/lualine.lua @@ -0,0 +1,51 @@ +return { + "nvim-lualine/lualine.nvim", + dependencies = { "kyazdani42/nvim-web-devicons" }, + config = function() + require("lualine").setup { + options = { + theme = "auto", + icons_enabled = true, + globalstatus = true, + }, + extensions = { "quickfix", "fugitive" }, + sections = { + lualine_a = { { "mode", upper = true } }, + lualine_b = { { "branch", icon = "" }, "db_ui#statusline" }, + lualine_c = { { "filename", file_status = true, path = 1 } }, + lualine_x = { + "diagnostics", + "diff", + { + require("noice").api.status.mode.get, + cond = require("noice").api.status.mode.has, + color = { fg = "#ff9e64" }, + }, + { + require("lazy.status").updates, + cond = require("lazy.status").has_updates, + color = { fg = "ff9e64" }, + }, + }, + lualine_y = { "filetype" }, + lualine_z = { "location" }, + }, + winbar = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + inactive_winbar = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + } + end, +} diff --git a/current_config/lua/plugins/markdown-preview.lua b/current_config/lua/plugins/markdown-preview.lua new file mode 100644 index 0000000..15f57ce --- /dev/null +++ b/current_config/lua/plugins/markdown-preview.lua @@ -0,0 +1,8 @@ +return { + "adalessa/markdown-preview.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = true, + ft = "markdown", +} diff --git a/current_config/lua/plugins/mason.lua b/current_config/lua/plugins/mason.lua new file mode 100644 index 0000000..a791aa2 --- /dev/null +++ b/current_config/lua/plugins/mason.lua @@ -0,0 +1,8 @@ +return { + { + "williamboman/mason.nvim", + opts = function(_, opts) + -- table.insert(opts.ensure_installed, "google-java-format") + end, + }, +} diff --git a/current_config/lua/plugins/neo-tree.lua b/current_config/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..ca69803 --- /dev/null +++ b/current_config/lua/plugins/neo-tree.lua @@ -0,0 +1,254 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + reqrires = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + { + -- only needed if you want to use the commands with "_with_window_picker" suffix + 's1n7ax/nvim-window-picker', + tag = "v1.*", + config = function() + require 'window-picker'.setup({ + autoselect_one = true, + include_current = false, + filter_rules = { + -- filter using buffer options + bo = { + -- if the file type is one of following, the window will be ignored + filetype = { 'neo-tree', "neo-tree-popup", "notify" }, + + -- if the buffer type is one of following, the window will be ignored + buftype = { 'terminal', "quickfix" }, + }, + }, + other_win_hl_color = '#e35e4f', + }) + end, + } + }, + config = function() + -- Unless you are still migrating, remove the deprecated commands from v1.x + vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) + + -- If you want icons for diagnostic errors, you'll need to define them somewhere: + vim.fn.sign_define("DiagnosticSignError", + { text = " ", texthl = "DiagnosticSignError" }) + vim.fn.sign_define("DiagnosticSignWarn", + { text = " ", texthl = "DiagnosticSignWarn" }) + vim.fn.sign_define("DiagnosticSignInfo", + { text = " ", texthl = "DiagnosticSignInfo" }) + vim.fn.sign_define("DiagnosticSignHint", + { text = "", texthl = "DiagnosticSignHint" }) + -- NOTE: this is changed from v1.x, which used the old style of highlight groups + -- in the form "LspDiagnosticsSignWarning" + + require("neo-tree").setup({ + close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab + popup_border_style = "rounded", + enable_git_status = true, + enable_diagnostics = true, + sort_case_insensitive = false, -- used when sorting files and directories in the tree + sort_function = nil, -- use a custom function for sorting files and directories in the tree + -- sort_function = function (a,b) + -- if a.type == b.type then + -- return a.path > b.path + -- else + -- return a.type > b.type + -- end + -- end , -- this sorts files and directories descendantly + default_component_configs = { + container = { + enable_character_fade = true + }, + indent = { + indent_size = 2, + padding = 1, -- extra padding on left hand side + -- indent guides + with_markers = true, + indent_marker = "│", + last_indent_marker = "└", + highlight = "NeoTreeIndentMarker", + -- expander config, needed for nesting files + with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", + }, + icon = { + folder_closed = "", + folder_open = "", + folder_empty = "ﰊ", + -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there + -- then these will never be used. + default = "*", + highlight = "NeoTreeFileIcon" + }, + modified = { + symbol = "[+]", + highlight = "NeoTreeModified", + }, + name = { + trailing_slash = false, + use_git_status_colors = true, + highlight = "NeoTreeFileName", + }, + git_status = { + symbols = { + -- Change type + added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name + modified = "", -- or "", but this is redundant info if you use git_status_colors on the name + deleted = "✖", -- this can only be used in the git_status source + renamed = "", -- this can only be used in the git_status source + -- Status type + untracked = "", + ignored = "", + unstaged = "", + staged = "", + conflict = "", + } + }, + }, + window = { + position = "left", + width = 40, + mapping_options = { + noremap = true, + nowait = true, + }, + mappings = { + [""] = { + "toggle_node", + nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use + }, + ["<2-LeftMouse>"] = "open", + [""] = "open", + [""] = "revert_preview", + ["P"] = { "toggle_preview", config = { use_float = true } }, + ["l"] = "focus_preview", + ["S"] = "open_split", + ["s"] = "open_vsplit", + -- ["S"] = "split_with_window_picker", + -- ["s"] = "vsplit_with_window_picker", + ["t"] = "open_tabnew", + -- [""] = "open_drop", + -- ["t"] = "open_tab_drop", + ["w"] = "open_with_window_picker", + --["P"] = "toggle_preview", -- enter preview mode, which shows the current node without focusing + ["C"] = "close_node", + -- ['C'] = 'close_all_subnodes', + ["z"] = "close_all_nodes", + --["Z"] = "expand_all_nodes", + ["a"] = { + "add", + -- this command supports BASH style brace expansion ("x{a,b,c}" -> xa,xb,xc). see `:h neo-tree-file-actions` for details + -- some commands may take optional config options, see `:h neo-tree-mappings` for details + config = { + show_path = "none" -- "none", "relative", "absolute" + } + }, + ["A"] = "add_directory", -- also accepts the optional config.show_path option like "add". this also supports BASH style brace expansion. + ["d"] = "delete", + ["r"] = "rename", + ["y"] = "copy_to_clipboard", + ["x"] = "cut_to_clipboard", + ["p"] = "paste_from_clipboard", + ["c"] = "copy", -- takes text input for destination, also accepts the optional config.show_path option like "add": + -- ["c"] = { + -- "copy", + -- config = { + -- show_path = "none" -- "none", "relative", "absolute" + -- } + --} + ["m"] = "move", -- takes text input for destination, also accepts the optional config.show_path option like "add". + ["q"] = "close_window", + ["R"] = "refresh", + ["?"] = "show_help", + ["<"] = "prev_source", + [">"] = "next_source", + } + }, + nesting_rules = {}, + filesystem = { + filtered_items = { + visible = false, -- when true, they will just be displayed differently than normal items + hide_dotfiles = true, + hide_gitignored = true, + hide_hidden = true, -- only works on Windows for hidden files/directories + hide_by_name = { + --"node_modules" + }, + hide_by_pattern = { -- uses glob style patterns + --"*.meta", + --"*/src/*/tsconfig.json", + }, + always_show = { -- remains visible even if other settings would normally hide it + --".gitignored", + }, + never_show = { -- remains hidden even if visible is toggled to true, this overrides always_show + --".DS_Store", + --"thumbs.db" + }, + never_show_by_pattern = { -- uses glob style patterns + --".null-ls_*", + }, + }, + follow_current_file = false, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = false, -- when true, empty folders will be grouped together + hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree + -- in whatever position is specified in window.position + -- "open_current", -- netrw disabled, opening a directory opens within the + -- window like netrw would, regardless of window.position + -- "disabled", -- netrw left alone, neo-tree does not handle opening dirs + use_libuv_file_watcher = false, -- This will use the OS level file watchers to detect changes + -- instead of relying on nvim autocmd events. + window = { + mappings = { + [""] = "navigate_up", + ["."] = "set_root", + ["H"] = "toggle_hidden", + ["/"] = "fuzzy_finder", + ["D"] = "fuzzy_finder_directory", + ["#"] = "fuzzy_sorter", -- fuzzy sorting using the fzy algorithm + -- ["D"] = "fuzzy_sorter_directory", + ["f"] = "filter_on_submit", + [""] = "clear_filter", + ["[g"] = "prev_git_modified", + ["]g"] = "next_git_modified", + } + } + }, + buffers = { + follow_current_file = true, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = true, -- when true, empty folders will be grouped together + show_unloaded = true, + window = { + mappings = { + ["bd"] = "buffer_delete", + [""] = "navigate_up", + ["."] = "set_root", + } + }, + }, + git_status = { + window = { + position = "float", + mappings = { + ["A"] = "git_add_all", + ["gu"] = "git_unstage_file", + ["ga"] = "git_add_file", + ["gr"] = "git_revert_file", + ["gc"] = "git_commit", + ["gp"] = "git_push", + ["gg"] = "git_commit_and_push", + } + } + } + }) + + vim.cmd([[nnoremap \ :Neotree reveal]]) + end +} diff --git a/current_config/lua/plugins/neocolumn.lua b/current_config/lua/plugins/neocolumn.lua new file mode 100644 index 0000000..f02b5b5 --- /dev/null +++ b/current_config/lua/plugins/neocolumn.lua @@ -0,0 +1,5 @@ +return { + "ecthelionvi/NeoColumn.nvim", + opts = {}, + cmd = { "ToggleNeoColumn" }, +} diff --git a/current_config/lua/plugins/neogen.lua b/current_config/lua/plugins/neogen.lua new file mode 100644 index 0000000..6b234ae --- /dev/null +++ b/current_config/lua/plugins/neogen.lua @@ -0,0 +1,7 @@ +return { + "danymat/neogen", + dependencies = "nvim-treesitter/nvim-treesitter", + cmd = { "Neogen" }, + keys = { { "n", ":Neogen", desc = "Add comment to the near possible object" } }, + opts = { snippet_engine = "luasnip" }, +} diff --git a/current_config/lua/plugins/neorg.lua b/current_config/lua/plugins/neorg.lua new file mode 100644 index 0000000..bf27994 --- /dev/null +++ b/current_config/lua/plugins/neorg.lua @@ -0,0 +1,22 @@ +return { + "nvim-neorg/neorg", + build = ":Neorg sync-parsers", + cmd = { "Neorg" }, + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + require("neorg").setup { + load = { + ["core.defaults"] = {}, -- Loads default behaviour + ["core.concealer"] = {}, -- Adds pretty icons to your documents + ["core.dirman"] = { -- Manages Neorg workspaces + config = { + workspaces = { + notes = "~/notes", + }, + default_workspace = "notes", + }, + }, + }, + } + end, +} diff --git a/current_config/lua/plugins/neotest.lua b/current_config/lua/plugins/neotest.lua new file mode 100644 index 0000000..09e99b0 --- /dev/null +++ b/current_config/lua/plugins/neotest.lua @@ -0,0 +1,66 @@ +return { + "nvim-neotest/neotest", + enabled = true, + keys = { { "", desc = "Open Test menu" } }, + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "antoinemadec/FixCursorHold.nvim", + "nvim-neotest/neotest-go", + "rouge8/neotest-rust", + "nvim-neotest/neotest-plenary", + "nvim-neotest/neotest-vim-test", + "anuvyklack/hydra.nvim", + }, + config = function() + local neotest = require "neotest" + neotest.setup { + adapters = { + require "neotest-go", + require "neotest-rust", + require "neotest-plenary", + -- require "neotest-vim-test" { + -- ignore_file_types = { "go", "lua", "rust", "php" }, + -- }, + -- require("laravel.neotest"), + }, + library = { plugins = { "neotest" }, types = true }, + } + + local hydra = require "hydra" + + local hint = [[ + NeoTest + _n_: Near test _f_: Current file _l_: Last Test _m_: Run Marked _s_: Toggle Summary ^ + ^ ^ __ + ]] + + hydra { + name = "neotest", + hint = hint, + mode = "n", + config = { + color = "teal", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "", + heads = { + { "n", neotest.run.run }, + { + "f", + function() + neotest.run.run(vim.fn.expand "%") + end, + }, + { "l", neotest.run.run_last }, + { "m", neotest.summary.run_marked }, + { "s", neotest.summary.toggle }, + { "", nil, { exit = true } }, + }, + } + end, +} diff --git a/current_config/lua/plugins/noice.lua b/current_config/lua/plugins/noice.lua new file mode 100644 index 0000000..70e81e9 --- /dev/null +++ b/current_config/lua/plugins/noice.lua @@ -0,0 +1,112 @@ +return { + "folke/noice.nvim", + dependencies = { + "MunifTanjim/nui.nvim", + }, + event = "VeryLazy", + opts = { + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true, + }, + }, + -- -- you can enable a preset for easier configuration + presets = { + bottom_search = true, -- use a classic bottom cmdline for search + -- command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + -- inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = true, -- add a border to hover docs and signature help + }, + cmdline = { + view = "cmdline", + }, + messages = { + enabled = true, -- enables the Noice messages UI + view = "notify", -- default view for messages + view_error = "notify", -- view for errors + view_warn = "notify", -- view for warnings + view_history = "messages", -- view for :messages + view_search = false, -- view for search count messages. Set to `false` to disable + }, + routes = { + { + view = "split", + filter = { + cmdline = "G", + }, + opts = { + enter = true, + render = "plain", + format = { "{message}" }, + replace = true, + close = { + events = { "BufLeave" }, + keys = { "q" }, + }, + }, + }, + { + view = "split", + filter = { + cmdline = "Notifications", + }, + opts = { + enter = true, + render = "plain", + format = { "{message}" }, + replace = true, + close = { + events = { "BufLeave" }, + keys = { "q" }, + }, + }, + }, + { + view = "mini", + filter = { + cmdline = "w", + }, + }, + { + view = "mini", + filter = { + find = "Config Change Detected. Reloading...", + }, + }, + { + view = "mini", + filter = { + any = { + { + event = "msg_show", + find = "lines yanked", + }, + { + event = "msg_show", + find = "more lines", + }, + { + event = "msg_show", + find = "direnv:", + }, + { + find = "laravel.sail.", + }, + { + find = "Pattern not found", + }, + { + event = "msg_show", + kind = "", + find = "change;", + }, + }, + }, + }, + }, + }, +} diff --git a/current_config/lua/plugins/notify.lua b/current_config/lua/plugins/notify.lua new file mode 100644 index 0000000..97f6d1f --- /dev/null +++ b/current_config/lua/plugins/notify.lua @@ -0,0 +1,10 @@ +return { + "rcarriga/nvim-notify", + config = function() + local notify = require "notify" + -- this for transparency + notify.setup { background_colour = "#000000" } + -- this overwrites the vim notify function + vim.notify = notify.notify + end, +} diff --git a/current_config/lua/plugins/numb.lua b/current_config/lua/plugins/numb.lua new file mode 100644 index 0000000..3758657 --- /dev/null +++ b/current_config/lua/plugins/numb.lua @@ -0,0 +1,4 @@ +return { + "nacro90/numb.nvim", + config = true, +} diff --git a/current_config/lua/plugins/orgmode.lua b/current_config/lua/plugins/orgmode.lua new file mode 100644 index 0000000..e9f8667 --- /dev/null +++ b/current_config/lua/plugins/orgmode.lua @@ -0,0 +1,17 @@ +return { + "nvim-orgmode/orgmode", + enabled = false, + keys = { + { "oa" }, + { "oc" }, + }, + ft = { "org" }, + config = function() + require("orgmode").setup_ts_grammar() + require("orgmode").setup { + org_agenda_files = { "~/my-orgs/**/*" }, + org_default_notes_file = "~/my-orgs/refile.org", + } + require("cmp").setup { sources = { { name = "orgmode" } } } + end, +} diff --git a/current_config/lua/plugins/others.lua b/current_config/lua/plugins/others.lua new file mode 100644 index 0000000..b57bb77 --- /dev/null +++ b/current_config/lua/plugins/others.lua @@ -0,0 +1,46 @@ +return { + { + -- "tigion/nvim-asciidoc-preview", + -- ft = { "asciidoc" }, + -- opts = {}, + }, + { + "windwp/nvim-autopairs", + event = "InsertEnter", + opts = {}, -- this is equalent to setup({}) function + }, + { "isobit/vim-caddyfile" }, + -- { -- maybe https://github.com/0x00-ketsu/autosave.nvim + -- "0x00-ketsu/autosave.nvim", + -- opts = {}, + -- }, + { + "Wansmer/treesj", + keys = { + { "j", "TSJToggle", desc = "Join Toggle" }, + }, + opts = { use_default_keymaps = false, max_join_length = 150 }, + }, + { + "s1n7ax/nvim-window-picker", + name = "window-picker", + event = "VeryLazy", + version = "2.*", + config = function() + require("window-picker").setup() + end, + }, + { "slim-template/vim-slim" }, + { "tpope/vim-rails" }, + -- use 'slim-template/vim-slim' + { "dhruvasagar/vim-table-mode" }, + { "tree-sitter/tree-sitter-embedded-template" }, + { "RRethy/nvim-treesitter-endwise" }, + { "dyng/ctrlsf.vim" }, + { + "kylechui/nvim-surround", + version = "*", -- Use for stability; omit to use `main` branch for the latest features + event = "VeryLazy", + opts = {}, + }, +} diff --git a/current_config/lua/plugins/php.lua b/current_config/lua/plugins/php.lua new file mode 100644 index 0000000..3dfe032 --- /dev/null +++ b/current_config/lua/plugins/php.lua @@ -0,0 +1,91 @@ +return { -- lazy + -- "ccaglak/namespace.nvim", + -- dependencies = { + -- "nvim-lua/plenary.nvim", + -- }, +}, { + "ludovicchabant/vim-gutentags", + config = function() + -- https://www.reddit.com/r/vim/comments/d77t6j/guide_how_to_setup_ctags_with_gutentags_properly/ + vim.g.gutentags_ctags_exclude = { + "*.git", + "*.svg", + "*.hg", + "*/tests/*", + "build", + "dist", + "*sites/*/files/*", + "bin", + "node_modules", + "bower_components", + "cache", + "compiled", + "docs", + "example", + "bundle", + "vendor", + "*.md", + "*-lock.json", + "*.lock", + "*bundle*.js", + "*build*.js", + ".*rc*", + "*.json", + "*.min.*", + "*.map", + "*.bak", + "*.zip", + "*.pyc", + "*.class", + "*.sln", + "*.Master", + "*.csproj", + "*.tmp", + "*.csproj.user", + "*.cache", + "*.pdb", + "tags*", + "cscope.*", + -- '*.css', + -- '*.less', + -- '*.scss', + "*.exe", + "*.dll", + "*.mp3", + "*.ogg", + "*.flac", + "*.swp", + "*.swo", + "*.bmp", + "*.gif", + "*.ico", + "*.jpg", + "*.png", + "*.rar", + "*.zip", + "*.tar", + "*.tar.gz", + "*.tar.xz", + "*.tar.bz2", + "*.pdf", + "*.doc", + "*.docx", + "*.ppt", + "*.pptx", + } + + vim.g.gutentags_add_default_project_roots = false + vim.g.gutentags_project_root = { "package.json", ".git" } + vim.g.gutentags_cache_dir = vim.fn.stdpath("data") .. "/ctags" + vim.g.gutentags_generate_on_new = true + vim.g.gutentags_generate_on_missing = true + vim.g.gutentags_generate_on_write = true + vim.g.gutentags_generate_on_empty_buffer = true + vim.g.gutentags_modules = true + vim.cmd([[command! -nargs=0 GutentagsClearCache call system('rm ' . g:gutentags_cache_dir . '/*')]]) + vim.g.gutentags_ctags_extra_args = { "--tag-relative=yes", "--fields=+ailmnS" } + + -- custom + vim.g.gutentags_modules = { "ctags" } + end, +} diff --git a/current_config/lua/plugins/phpactor.lua b/current_config/lua/plugins/phpactor.lua new file mode 100644 index 0000000..1c636e1 --- /dev/null +++ b/current_config/lua/plugins/phpactor.lua @@ -0,0 +1,61 @@ +local phpactor = function () + vim.ui.select({ + "class_inflect", + "context_menu", + "expand_class", + "generate_accessor", + "change_visibility", + "copy_class", + "import_class", + "import_missing_classes", + "move_class", + "navigate", + "new_class", + "transform", + "update", + "config", + "status", + "cache_clear", + }, { + prompt = "Phpactor Action", + }, function(choice) + if choice == nil or choice == "" then + return + end + + -- TODO: add option for new class in same directory + if choice == "new_class" then + return vim.ui.input({ + prompt = "New Class", + }, function(value) + if value == nil then + return + end + -- TODO: check filename generation to validate the path + require("phpactor").rpc("new_class", { text_value = vim.fn.getcwd() .. '/' .. value .. ".php" }) + end) + end + + require("phpactor").rpc(choice, {}) + end) +end + +return { + "adalessa/phpactor.nvim", + cmd = { "PhpActor" }, + keys = { + { "pa", phpactor, desc = "PhpActor options" }, + { "pc", ":PhpActor context_menu", desc = "PhpActor context menu" }, + }, + dependencies = { + "nvim-lua/plenary.nvim", + }, + opts = { + install = { + bin = 'phpactor' + }, + lspconfig = { + enabled = true, + }, + }, +} diff --git a/current_config/lua/plugins/project-config.lua b/current_config/lua/plugins/project-config.lua new file mode 100644 index 0000000..ffa32f1 --- /dev/null +++ b/current_config/lua/plugins/project-config.lua @@ -0,0 +1,5 @@ +return { + "windwp/nvim-projectconfig", + enabled = false, + config = true, +} diff --git a/current_config/lua/plugins/refactoring.lua b/current_config/lua/plugins/refactoring.lua new file mode 100644 index 0000000..92cdf64 --- /dev/null +++ b/current_config/lua/plugins/refactoring.lua @@ -0,0 +1,21 @@ +return { + "ThePrimeagen/refactoring.nvim", + dependencies = { + { "nvim-lua/plenary.nvim" }, + { "nvim-treesitter/nvim-treesitter" }, + }, + keys = { + { + "rr", + function() + require("telescope").extensions.refactoring.refactors() + end, + mode = { "n", "v" }, + desc = "Refactoring menu", + }, + }, + config = function() + require("refactoring").setup {} + require("telescope").load_extension "refactoring" + end, +} diff --git a/current_config/lua/plugins/smart-splits.lua b/current_config/lua/plugins/smart-splits.lua new file mode 100644 index 0000000..57faedb --- /dev/null +++ b/current_config/lua/plugins/smart-splits.lua @@ -0,0 +1,34 @@ +return { + "mrjones2014/smart-splits.nvim", + config = true, + keys = { + { + "", + function() + require("smart-splits").resize_left() + end, + desc = "Resize window left +10", + }, + { + "", + function() + require("smart-splits").resize_down() + end, + desc = "Resize window down +10", + }, + { + "", + function() + require("smart-splits").resize_up() + end, + desc = "Resize window up +10", + }, + { + "", + function() + require("smart-splits").resize_right() + end, + desc = "Resize window right +10", + }, + }, +} diff --git a/current_config/lua/plugins/smooth-cursor.lua b/current_config/lua/plugins/smooth-cursor.lua new file mode 100644 index 0000000..71fe431 --- /dev/null +++ b/current_config/lua/plugins/smooth-cursor.lua @@ -0,0 +1,32 @@ +return { + "gen740/SmoothCursor.nvim", + config = function() + require("smoothcursor").setup { cursor = "󰀫" } + + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#8a9baa" }) + + local autocmd = vim.api.nvim_create_autocmd + + autocmd({ "ModeChanged" }, { + callback = function() + local current_mode = vim.fn.mode() + if current_mode == "n" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#8a9baa" }) + vim.fn.sign_define("smoothcursor", { text = "󰀫" }) + elseif current_mode == "v" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#bf616a" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "V" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#bf616a" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "\22" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#bf616a" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "i" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#668aab" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + end + end, + }) + end, +} diff --git a/current_config/lua/plugins/snippets.luaBack b/current_config/lua/plugins/snippets.luaBack new file mode 100644 index 0000000..48c93b8 --- /dev/null +++ b/current_config/lua/plugins/snippets.luaBack @@ -0,0 +1,138 @@ +local config = function() + if vim.g.snippets ~= "luasnip" then + return + end + + local ls = require "luasnip" + local types = require "luasnip.util.types" + + ls.config.set_config { + -- This tells LuaSnip to remember to keep around the last snippet. + -- You can jump back into even if you move outside of the selection + history = true, + + -- This one is cool cause if you have dynamic snippets, it updatesas you type! + updateevents = "TextChanged,TextChangedI", + + -- Autosnippets: + enable_autosnippets = true, + + ext_opts = { + [types.choiceNode] = { + active = { + virt_text = { { "<- Choice", "Error" } }, + }, + }, + }, + } + + -- create snippet + -- s(context, nodes, condition, ...) + local snippet = ls.s + + -- TODO: Write about this. + -- Useful for dynamic nodes and choice nodes + -- local snippet_from_nodes = ls.sn + + -- This is the simplest node. + -- Creates a new text node. Places cursor after node by default. + -- t { "this will be inserted" } + -- + -- Multiple lines are by passing a table of strings. + -- t { "line 1", "line 2" } + local t = ls.text_node + + -- Insert Node + -- Creates a location for the cursor to jump to. + -- Possible options to jump to are 1 - N + -- If you use 0, that's the final place to jump to. + -- + -- To create placeholder text, pass it as the second argument + -- i(2, "this is placeholder text") + local i = ls.insert_node + + -- Function Node + -- Takes a function that returns text + -- local f = ls.function_node + + -- This a choice snippet. You can move through with (in my config) + -- c(1, { t {"hello"}, t {"world"}, }), + -- + -- The first argument is the jump position + -- The second argument is a table of possible nodes. + -- Note, one thing that's nice is you don't have to include + -- the jump position for nodes that normally require one (can be nil) + -- local c = ls.choice_node + + -- local d = ls.dynamic_node + + -- TODO: Document what I've learned about lambda + -- local l = require("luasnip.extras").lambda + + -- local events = require("luasnip.util.events") + + local shortcut = function(val) + if type(val) == "string" then + return { t { val }, i(0) } + end + + if type(val) == "table" then + for k, v in ipairs(val) do + if type(v) == "string" then + val[k] = t { v } + end + end + end + + return val + end + + local make = function(tbl) + local result = {} + for k, v in pairs(tbl) do + table.insert(result, (snippet({ trig = k, desc = v.desc }, shortcut(v)))) + end + + return result + end + + ls.cleanup() + for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/alpha/snips/ft/*.lua", true)) do + local ft = vim.fn.fnamemodify(ft_path, ":t:r") + ls.add_snippets(ft, make(loadfile(ft_path)())) + end + + -- is my expansion key + -- this will expand the current item or jump to the next item within the snippet. + vim.keymap.set({ "i", "s" }, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end, { silent = true }) + + -- is my jump backwards key. + -- this always moves to the previous item within the snippet + vim.keymap.set({ "i", "s" }, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end + end, { silent = true }) + + -- is selecting within a list of options. + -- This is useful for choice nodes (introduced in the forthcoming episode 2) + vim.keymap.set("i", "", function() + if ls.choice_active() then + ls.change_choice(1) + end + end) +end + +return { + "L3MON4D3/LuaSnip", + version = "v1.*", + event = "VeryLazy", + config = function() + config() + vim.keymap.set("n", "s", config, { desc = "Reload snippets" }) + end, +} diff --git a/current_config/lua/plugins/spectre.lua b/current_config/lua/plugins/spectre.lua new file mode 100644 index 0000000..7510c7a --- /dev/null +++ b/current_config/lua/plugins/spectre.lua @@ -0,0 +1,5 @@ +return { + "nvim-pack/nvim-spectre", + keys = { { "F", ":Spectre", desc = "Spectre Search open" } }, + config = true, +} diff --git a/current_config/lua/plugins/telescope.lua b/current_config/lua/plugins/telescope.lua new file mode 100644 index 0000000..4f5b59d --- /dev/null +++ b/current_config/lua/plugins/telescope.lua @@ -0,0 +1,33 @@ +return { + "nvim-telescope/telescope.nvim", + dependencies = { + { "nvim-lua/plenary.nvim" }, + { "nvim-lua/popup.nvim" }, + { "nvim-telescope/telescope-fzy-native.nvim" }, + { "kyazdani42/nvim-web-devicons" }, + { "nvim-telescope/telescope-file-browser.nvim" }, + { "nvim-telescope/telescope-ui-select.nvim" }, + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + dependencies = { + "junegunn/fzf.vim", + dependencies = { + { + "tpope/vim-dispatch", + cmd = { "Make", "Dispatch" }, + }, + { + "junegunn/fzf", + build = ":call fzf#install()", + } + }, + }, + }, + }, + event = "VeryLazy", + config = function() + require "alpha.telescope.setup" + require "alpha.telescope.mappings" + end, +} diff --git a/current_config/lua/plugins/test.lua b/current_config/lua/plugins/test.lua new file mode 100644 index 0000000..5c8c218 --- /dev/null +++ b/current_config/lua/plugins/test.lua @@ -0,0 +1,54 @@ +return { + "vim-test/vim-test", + keys = { { "t", desc = "Open Test menu" } }, + dependencies = { + "anuvyklack/hydra.nvim", + }, + init = function() + vim.g["test#strategy"] = "harpoon" + vim.g["test#neovim#term_position"] = "vert" + vim.g["test#harpoon_term"] = 1 + vim.g["test#preserve_screen"] = 0 + vim.g["test#harpoon#gototerminal"] = 0 + vim.g["test#php#pest#executable"] = "./vendor/bin/sail test" + + local function dockerComposeTransform(cmd) + local uid = vim.fn.system("id -u"):gsub("%s*$", "") + local gid = vim.fn.system("id -g"):gsub("%s*$", "") + return string.format("docker compose exec -u %s:%s php-fpm %s", uid, gid, cmd) + end + + vim.g["test#php#behat#executable"] = "bin/behat --colors" + vim.g["test#custom_transformations"] = { docker = dockerComposeTransform } + end, + config = function() + local behat_paths = { + "tests/Functional/Context/**/*.php", + "tests/Behat/Context/*.php", + "tests/Behat/**/*.php", + "src/Behat/**/*.php", + } + + for _, path in ipairs(behat_paths) do + if vim.fn.glob(path) ~= "" then + vim.g["test#php#behat#bootstrap_directory"] = path + vim.g["test#transformation"] = "docker" + + -- many of my projects have variables necessaries so this is required + local env_vars = vim.fn.system "make vars" + for _, env_var in ipairs(vim.split(env_vars, "\n")) do + if env_var ~= "" then + env_var = env_var:gsub("^export ", "") + local key, value = unpack(vim.split(env_var, "=")) + vim.fn.setenv(key, value) + end + end + break + end + end + + require "alpha.test_strategy" + + require "alpha.test_menu" + end, +} diff --git a/current_config/lua/plugins/text-object.lua b/current_config/lua/plugins/text-object.lua new file mode 100644 index 0000000..844cf19 --- /dev/null +++ b/current_config/lua/plugins/text-object.lua @@ -0,0 +1,8 @@ +return { + "chrisgrieser/nvim-various-textobjs", + enabled = false, + event = "VeryLazy", + config = function () + require("various-textobjs").setup({ useDefaultKeymaps = true }) + end, +} diff --git a/current_config/lua/plugins/transparent.lua b/current_config/lua/plugins/transparent.lua new file mode 100644 index 0000000..e8a6939 --- /dev/null +++ b/current_config/lua/plugins/transparent.lua @@ -0,0 +1,5 @@ +return { + "xiyaowong/nvim-transparent", + lazy = false, + config = true, +} diff --git a/current_config/lua/plugins/treesitter.lua b/current_config/lua/plugins/treesitter.lua new file mode 100644 index 0000000..1ea2d0a --- /dev/null +++ b/current_config/lua/plugins/treesitter.lua @@ -0,0 +1,10 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + opts = { + endwise = { + enable = true, + }, + }, + }, +} diff --git a/current_config/lua/plugins/trouble.lua b/current_config/lua/plugins/trouble.lua new file mode 100644 index 0000000..5a87f26 --- /dev/null +++ b/current_config/lua/plugins/trouble.lua @@ -0,0 +1,7 @@ +return { + "folke/trouble.nvim", + enabled = true, + dependencies = "kyazdani42/nvim-web-devicons", + keys = { { "t", "TroubleToggle", desc = "Trouble toggle" } }, + config = true, +} diff --git a/current_config/lua/plugins/twilight.lua b/current_config/lua/plugins/twilight.lua new file mode 100644 index 0000000..144111f --- /dev/null +++ b/current_config/lua/plugins/twilight.lua @@ -0,0 +1,5 @@ +return { + "folke/twilight.nvim", + cmd = { "Twilight" }, + config = true, +} diff --git a/current_config/lua/plugins/worktree.lua b/current_config/lua/plugins/worktree.lua new file mode 100644 index 0000000..9e74a9c --- /dev/null +++ b/current_config/lua/plugins/worktree.lua @@ -0,0 +1,23 @@ +return { + "ThePrimeagen/git-worktree.nvim", + keys = { + { + "gt", + function() + require("telescope").extensions.git_worktree.git_worktrees() + end, + desc = "Git Worktree switch", + }, + { + "gn", + function() + require("telescope").extensions.git_worktree.create_git_worktree() + end, + desc = "Git Worktree new branch", + }, + }, + config = function() + require("git-worktree").setup {} + require("telescope").load_extension "git_worktree" + end, +} diff --git a/current_config/lua/scratchs/.gitkeep b/current_config/lua/scratchs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/files/lombok.jar b/files/lombok.jar new file mode 100644 index 0000000..dcaa423 Binary files /dev/null and b/files/lombok.jar differ diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..21a5371 --- /dev/null +++ b/init.lua @@ -0,0 +1,5 @@ +-- bootstrap lazy.nvim, LazyVim and your plugins +-- de +require("config.lazy") +require "config" +require "alpha.globals" diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..348fcef --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,117 @@ +{ + "FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" }, + "LazyVim": { "branch": "main", "commit": "879e29504d43e9f178d967ecc34d482f902e5a91" }, + "LuaSnip": { "branch": "master", "commit": "954c81b53989097faaff0fabc11c29575288c3e1" }, + "NeoColumn.nvim": { "branch": "main", "commit": "db7695c7c70fcacd290712deef659bca464634ee" }, + "SchemaStore.nvim": { "branch": "main", "commit": "177cae4f44ddf7c166ef263956378ae308ff77ff" }, + "SmoothCursor.nvim": { "branch": "main", "commit": "cc8780622a7b7c328f774762fa2d97d9f83be828" }, + "animation.nvim": { "branch": "main", "commit": "fb77091ab72ec9971aee0562e7081182527aaa6a" }, + "bufferline.nvim": { "branch": "main", "commit": "ac788fbc493839c1e76daa8d119934b715fdb90e" }, + "catppuccin": { "branch": "main", "commit": "64dc309bc157779691be38bbfc5123584e0a4a85" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-dap": { "branch": "master", "commit": "ea92773e84c0ad3288c3bc5e452ac91559669087" }, + "cmp-emoji": { "branch": "main", "commit": "19075c36d5820253d32e2478b6aaf3734aeaafa0" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "color-picker.nvim": { "branch": "master", "commit": "06cb5f853535dea529a523e9a0e8884cdf9eba4d" }, + "composer.nvim": { "branch": "main", "commit": "ec9537969adc7fc128cfe9c3a9925850455896c8" }, + "conform.nvim": { "branch": "master", "commit": "8b407bb6175846cdc4c499e2a8d28109615a2089" }, + "ctrlsf.vim": { "branch": "master", "commit": "32236a8b376d9311dec9b5fe795ca99d32060b13" }, + "dashboard-nvim": { "branch": "master", "commit": "63df28409d940f9cac0a925df09d3dc369db9841" }, + "dressing.nvim": { "branch": "master", "commit": "8b7ae53d7f04f33be3439a441db8071c96092d19" }, + "everforest-nvim": { "branch": "main", "commit": "ee032e31d2e824e59c38207e4351032539addf99" }, + "friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" }, + "fzf": { "branch": "master", "commit": "82954258c1c9f61bb6bb764c51470ffbcee01b6c" }, + "fzf.vim": { "branch": "master", "commit": "1e054c1d075d87903647db9320116d360eb8b024" }, + "git-worktree.nvim": { "branch": "master", "commit": "f247308e68dab9f1133759b05d944569ad054546" }, + "gitsigns.nvim": { "branch": "main", "commit": "d195f0c35ced5174d3ecce1c4c8ebb3b5bc23fa9" }, + "harpoon": { "branch": "master", "commit": "867e212ac153e793f95b316d1731f3ca1894625e" }, + "headlines.nvim": { "branch": "master", "commit": "e3d7bfdf40e41a020d966d35f8b48d75b90367d2" }, + "hydra.nvim": { "branch": "master", "commit": "3ced42c0b6a6c85583ff0f221635a7f4c1ab0dd0" }, + "indent-blankline.nvim": { "branch": "master", "commit": "7206c77cb931f79885fc47f88ae18f99148392eb" }, + "laravel.nvim": { "branch": "main", "commit": "8f8a0eab84191b1867b2f188cf475e6a05203908" }, + "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, + "lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" }, + "markdown-preview.nvim": { "branch": "main", "commit": "cc05a30393e2bf9f12e2d59fc35a1aa928ed1727" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "9453e3d6cd2ca45d96e20f343e8f1b927364b630" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "8b70e7f1e0a4119c1234c3bde4a01c241cabcc74" }, + "mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" }, + "middleclass": { "branch": "master", "commit": "9fab4d5bca67262614960960ca35c4740eb2be2c" }, + "mini.ai": { "branch": "main", "commit": "c28f7d7348f27425a180b1b7dcaa77651f8b71ee" }, + "mini.bufremove": { "branch": "main", "commit": "f53c7f27e36009fe61563c11cde154b94a0e5b94" }, + "mini.comment": { "branch": "main", "commit": "3d9c8009615857e982f09bc5357fc95f2a2175f3" }, + "mini.pairs": { "branch": "main", "commit": "71f117fd57f930da6ef4126b24f594dd398bac26" }, + "mini.surround": { "branch": "main", "commit": "af8129efcabe95fc08a233e9f91569829bed031f" }, + "neo-tree.nvim": { "branch": "v2.x", "commit": "80dc74d081823649809f78370fa5b204aa9a853a" }, + "neoconf.nvim": { "branch": "main", "commit": "64437787dba70fce50dad7bfbb97d184c5bc340f" }, + "neodev.nvim": { "branch": "main", "commit": "c4ce017bd4bacf60bf59330cec9e93c5d5e104a6" }, + "neogen": { "branch": "main", "commit": "70127baaff25611deaf1a29d801fc054ad9d2dc1" }, + "neorg": { "branch": "main", "commit": "baaf13a3145534144b795ad37db22bfffd2ad343" }, + "neotest": { "branch": "master", "commit": "8782d83869c64700fa419bd5278f4f62c80a2c1a" }, + "neotest-go": { "branch": "main", "commit": "d29d20d912aca81a07c50022d880cc66f0d26542" }, + "neotest-plenary": { "branch": "master", "commit": "dcaf5ed67a9e28a246e9783319e5aa6c9ea1c584" }, + "neotest-rust": { "branch": "main", "commit": "48c1e146ed0eb775fef6aca75903baf3cedadc01" }, + "neotest-vim-test": { "branch": "master", "commit": "75c4228882ae4883b11bfce9b8383e637eb44192" }, + "noice.nvim": { "branch": "main", "commit": "92433164e2f7118d4122c7674c3834d9511722ba" }, + "nui.nvim": { "branch": "main", "commit": "c9b4de623d19a85b353ff70d2ae9c77143abe69c" }, + "numb.nvim": { "branch": "master", "commit": "3f7d4a74bd456e747a1278ea1672b26116e0824d" }, + "nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" }, + "nvim-cmp": { "branch": "main", "commit": "41d7633e4146dce1072de32cea31ee31b056a131" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" }, + "nvim-dap": { "branch": "master", "commit": "bbe2c6f3438542a37cc2141a8e385f7dfe07d87d" }, + "nvim-dap-go": { "branch": "main", "commit": "a5cc8dcad43f0732585d4793deb02a25c4afb766" }, + "nvim-dap-ui": { "branch": "master", "commit": "34160a7ce6072ef332f350ae1d4a6a501daf0159" }, + "nvim-dap-virtual-text": { "branch": "master", "commit": "57f1dbd0458dd84a286b27768c142e1567f3ce3b" }, + "nvim-dap-vscode-js": { "branch": "main", "commit": "03bd29672d7fab5e515fc8469b7d07cc5994bbf6" }, + "nvim-lint": { "branch": "master", "commit": "849ccb610de3f6ce1a239ea1e68568ef1a53d5df" }, + "nvim-lspconfig": { "branch": "master", "commit": "f451052bd6804e9e5ccd0ac874d7df8d3d4c55b9" }, + "nvim-notify": { "branch": "master", "commit": "e4a2022f4fec2d5ebc79afa612f96d8b11c627b3" }, + "nvim-spectre": { "branch": "master", "commit": "a18a58015b46f02b4fe537ebfffd82e46110ff24" }, + "nvim-surround": { "branch": "main", "commit": "703ec63aa798e5e07d309b35e42def34bebe0174" }, + "nvim-transparent": { "branch": "main", "commit": "fd35a46f4b7c1b244249266bdcb2da3814f01724" }, + "nvim-treesitter": { "branch": "master", "commit": "78d75bce03f218ee30aedb6e24e3ec1189a3e9ff" }, + "nvim-treesitter-context": { "branch": "master", "commit": "cfa8ee19ac9bae9b7fb2958eabe2b45b70c56ccb" }, + "nvim-treesitter-endwise": { "branch": "master", "commit": "4c344ffc8d54d7e1ba2cefaaa2c10ea93aa1cc2d" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a" }, + "nvim-ts-autotag": { "branch": "main", "commit": "8515e48a277a2f4947d91004d9aa92c29fdc5e18" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "1277b4a1f451b0f18c0790e1a7f12e1e5fdebfee" }, + "nvim-web-devicons": { "branch": "master", "commit": "8b2e5ef9eb8a717221bd96cb8422686d65a09ed5" }, + "persistence.nvim": { "branch": "main", "commit": "ad538bfd5336f1335cdb6fd4e0b0eebfa6e12f32" }, + "phpactor.nvim": { "branch": "main", "commit": "0aa4ad09c2024e24d630c0ec616d65396caa39e0" }, + "plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" }, + "popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" }, + "refactoring.nvim": { "branch": "master", "commit": "156532476deb10b1b2a32cb38e1078b3f9951c42" }, + "smart-splits.nvim": { "branch": "master", "commit": "f0003bf9c3f11b8b9209264f865b8864453ca926" }, + "telescope-dap.nvim": { "branch": "master", "commit": "4e2d5efb92062f0b865fe59b200b5ed7793833bf" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "8e0543365fe5781c9babea7db89ef06bcff3716d" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, + "telescope-fzy-native.nvim": { "branch": "master", "commit": "282f069504515eec762ab6d6c89903377252bf5b" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, + "telescope.nvim": { "branch": "master", "commit": "6213322ab56eb27356fdc09a5078e41e3ea7f3bc" }, + "todo-comments.nvim": { "branch": "main", "commit": "4a6737a8d70fe1ac55c64dfa47fcb189ca431872" }, + "tokyonight.nvim": { "branch": "main", "commit": "f247ee700b569ed43f39320413a13ba9b0aef0db" }, + "tree-sitter-embedded-template": { "branch": "master", "commit": "203f7bd3c1bbfbd98fc19add4b8fcb213c059205" }, + "treesj": { "branch": "main", "commit": "1d6e89f4790aa04eaae38fa9460a3ee191961c96" }, + "trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" }, + "twilight.nvim": { "branch": "main", "commit": "8b7b50c0cb2dc781b2f4262a5ddd57571556d1e4" }, + "vim-blade": { "branch": "master", "commit": "9534101808cc320eef003129a40cab04b026a20c" }, + "vim-caddyfile": { "branch": "master", "commit": "24fe0720551883e407cb70ae1d7c03f162d1d5a0" }, + "vim-dispatch": { "branch": "master", "commit": "6cc2691576f97d43f8751664d1a1a908b99927e5" }, + "vim-dotenv": { "branch": "master", "commit": "5c51cfcf8d87280d6414e03cd6b253eb70ecb800" }, + "vim-easy-align": { "branch": "master", "commit": "12dd6316974f71ce333e360c0260b4e1f81169c3" }, + "vim-eunuch": { "branch": "master", "commit": "67f3dd32b4dcd1c427085f42ff5f29c7adc645c6" }, + "vim-fugitive": { "branch": "master", "commit": "46eaf8918b347906789df296143117774e827616" }, + "vim-gutentags": { "branch": "master", "commit": "aa47c5e29c37c52176c44e61c780032dfacef3dd" }, + "vim-illuminate": { "branch": "master", "commit": "3bd2ab64b5d63b29e05691e624927e5ebbf0fb86" }, + "vim-rails": { "branch": "master", "commit": "1ad9663ce31e8c08134849d04184cda94bb42aba" }, + "vim-repeat": { "branch": "master", "commit": "24afe922e6a05891756ecf331f39a1f6743d3d5a" }, + "vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" }, + "vim-slim": { "branch": "master", "commit": "f0758ea1c585d53b9c239177a8b891d8bbbb6fbb" }, + "vim-startuptime": { "branch": "master", "commit": "454b3de856b7bd298700de33d79774ca9b9e3875" }, + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, + "vim-table-mode": { "branch": "master", "commit": "4ff8de2ac93431ee6d85a9e04177012752e6abdc" }, + "vim-test": { "branch": "master", "commit": "84373ffca386edd667e09f2bf1024b1de7bdfdf1" }, + "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }, + "window-picker": { "branch": "main", "commit": "fd5d3348b3e254ca3134f97793b4a8c702c4ad1d" } +} \ No newline at end of file diff --git a/lazyvim.json b/lazyvim.json new file mode 100644 index 0000000..ff6a139 --- /dev/null +++ b/lazyvim.json @@ -0,0 +1,9 @@ +{ + "extras": [ + + ], + "news": { + "NEWS.md": "2123" + }, + "version": 2 +} \ No newline at end of file diff --git a/lua/alpha/animations.lua b/lua/alpha/animations.lua new file mode 100644 index 0000000..c0b7a6c --- /dev/null +++ b/lua/alpha/animations.lua @@ -0,0 +1,50 @@ +local redraw_buffer = function() + local Animation = require "animation" + local fps = 45 -- frames per second + local easing = require "animation.easing" + + local buffer = 0 + local len = 0 + local place_holder = {} + + local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true) + + for _, line in ipairs(lines) do + len = len + string.len(line) + table.insert(place_holder, "") + end + + vim.api.nvim_buf_set_lines(buffer, 0, #lines, true, place_holder) + + local duration = math.ceil(len / fps * 1000) + + local i = 1 + local line_nr = 1 + local insertLine = "" + + local function callback() + if lines[line_nr] == nil then + return true + end + local char = string.sub(lines[line_nr], i, i) + if char == nil then + return true + end + insertLine = insertLine .. char + i = i + 1 + vim.api.nvim_buf_set_lines(buffer, line_nr - 1, line_nr, true, { insertLine }) + + if insertLine == lines[line_nr] then + i = 1 + line_nr = line_nr + 1 + insertLine = "" + end + end + + local animation = Animation(duration, fps, easing.line, callback) + animation:run() +end + +return { + redraw_buffer = redraw_buffer, +} diff --git a/lua/alpha/completition/init.lua b/lua/alpha/completition/init.lua new file mode 100644 index 0000000..92e1f91 --- /dev/null +++ b/lua/alpha/completition/init.lua @@ -0,0 +1,133 @@ +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.setup { + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + [""] = cmp.mapping.complete(), + }, + sources = { + { name = "nvim_lua" }, + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "copilot" }, + { + name = "buffer", + keyword_length = 4, + option = { + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + local bufnr = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_option(bufnr, "buftype") ~= "terminal" then + bufs[bufnr] = true + end + end + return vim.tbl_keys(bufs) + 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 = "[ ]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + copilot = "[ﮧ ]", + ["vim-dadbod-completion"] = "[DB]", + }, + }, + }, + + sorting = { + priority_weight = 2, + comparators = { + compare.kind, + compare.sort_text, + }, + }, + + experimental = { + native_menu = false, + + ghost_text = false, + }, +} + +vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" }) + +-- 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" }, + }), +}) + +-- 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" }, + }, +}) + +-- 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" }, + }), +}) + +cmp.setup.filetype({ "sql", "mysql", "plsql" }, { + sources = cmp.config.sources({ + { name = "vim-dadbod-completion" }, + }, { + { name = "buffer" }, + }), +}) diff --git a/lua/alpha/dap/configs/golang.lua b/lua/alpha/dap/configs/golang.lua new file mode 100644 index 0000000..1ec449a --- /dev/null +++ b/lua/alpha/dap/configs/golang.lua @@ -0,0 +1 @@ +require("dap-go").setup() diff --git a/lua/alpha/dap/configs/javascript.lua b/lua/alpha/dap/configs/javascript.lua new file mode 100644 index 0000000..b910f30 --- /dev/null +++ b/lua/alpha/dap/configs/javascript.lua @@ -0,0 +1,45 @@ +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}", + }, + } +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", + }, + } +end diff --git a/lua/alpha/dap/configs/php.lua b/lua/alpha/dap/configs/php.lua new file mode 100644 index 0000000..968bb9d --- /dev/null +++ b/lua/alpha/dap/configs/php.lua @@ -0,0 +1,27 @@ +local dap = require("dap") + +dap.adapters.php = { + 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}", + }, + }, +} diff --git a/lua/alpha/dap/configs/rust.lua b/lua/alpha/dap/configs/rust.lua new file mode 100644 index 0000000..9ca976f --- /dev/null +++ b/lua/alpha/dap/configs/rust.lua @@ -0,0 +1,57 @@ +local dap = require("dap") + +local rust_adapter = nil +local rust_adapters = { "lldb-vscode", "codelldb" } +for _, adapter in pairs(rust_adapters) do + if vim.fn.executable(adapter) then + rust_adapter = adapter + end +end + +if rust_adapter ~= nil then + dap.adapters.lldb = { + type = "executable", + command = rust_adapter, + name = "lldb", + } + + dap.configurations.rust = { + { + name = "launch", + type = "lldb", + request = "launch", + program = function() + local dir = vim.fn.getcwd() + return dir .. "/target/debug/" .. vim.fs.basename(dir) + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + { + name = "custom", + type = "lldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + } +end diff --git a/lua/alpha/dap/init.lua b/lua/alpha/dap/init.lua new file mode 100644 index 0000000..81651f7 --- /dev/null +++ b/lua/alpha/dap/init.lua @@ -0,0 +1,106 @@ +local dap, dapui, hydra = require "dap", require "dapui", require "hydra" + +-- Setup Virtual Text +require("nvim-dap-virtual-text").setup {} + +for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/alpha/dap/configs/*.lua", true)) do + loadfile(ft_path)() +end + +-- Signs +vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapStopped", { text = "▶", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointRejected", { text = "🚫", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointCondition", { text = "❓", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapLogPoint", { text = "💬", texthl = "", linehl = "", numhl = "" }) + +-- UI structure +dapui.setup { + icons = { expanded = "▾", collapsed = "▸" }, + layouts = { + { + elements = { + "scopes", + "breakpoints", + "stacks", + "watches", + }, + size = 80, + position = "right", + }, + { + elements = { + "repl", + "console", + }, + size = 10, + position = "bottom", + }, + }, +} + +-- Events Listeners +dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open {} +end + +local hint = [[ + Nvim DAP + _d_: Start/Continue _j_: StepOver _k_: StepOut _l_: StepInto ^ + _bp_: Toogle Breakpoint _bc_: Conditional Breakpoint ^ + _?_: log point ^ + _c_: Run To Cursor ^ + _h_: Show information of the variable under the cursor ^ + _x_: Stop Debbuging ^ + ^^ __ +]] + +hydra { + name = "dap", + hint = hint, + mode = "n", + config = { + color = "blue", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "d", + heads = { + { "d", dap.continue }, + { "bp", dap.toggle_breakpoint }, + { "l", dap.step_into }, + { "j", dap.step_over }, + { "k", dap.step_out }, + { "h", dapui.eval }, + { "c", dap.run_to_cursor }, + { + "bc", + function() + vim.ui.input({ prompt = "Condition: " }, function(condition) + dap.set_breakpoint(condition) + end) + end, + }, + { + "?", + function() + vim.ui.input({ prompt = "Log: " }, function(log) + dap.set_breakpoint(nil, nil, log) + end) + end, + }, + { + "x", + function() + dap.terminate() + dapui.close {} + dap.clear_breakpoints() + end, + }, + + { "", nil, { exit = true } }, + }, +} diff --git a/lua/alpha/globals.lua b/lua/alpha/globals.lua new file mode 100644 index 0000000..e445e72 --- /dev/null +++ b/lua/alpha/globals.lua @@ -0,0 +1,23 @@ +--- Dumps all values into pretty print +---@vararg any +---@return any +dump = function(...) + local args = {...} + + local mapped = {} + for _, v in ipairs(args) do + table.insert(mapped, vim.inspect(v)) + end + print(unpack(mapped)) + + return unpack(args) +end + +Reload = function(...) + return require("plenary.reload").reload_module(...) +end + +R = function(name) + Reload(name) + return require(name) +end diff --git a/lua/alpha/laravel-tinker.lua b/lua/alpha/laravel-tinker.lua new file mode 100644 index 0000000..214d958 --- /dev/null +++ b/lua/alpha/laravel-tinker.lua @@ -0,0 +1,64 @@ +local M = {} + +M.runCode = function() + local curBuff = vim.api.nvim_get_current_buf() + + local stats = vim.api.nvim_list_uis()[1] + + 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", + }) + + -- 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) + + -- print (vim.inspect(code)) + + local codeText = vim.fn.shellescape(table.concat(code, " ")) + -- print(codeText) + + local result = vim.fn.systemlist("php artisan tinker --execute=" .. codeText) + + 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") +end + +return M diff --git a/lua/alpha/lsp/attach.lua b/lua/alpha/lsp/attach.lua new file mode 100644 index 0000000..e71cb75 --- /dev/null +++ b/lua/alpha/lsp/attach.lua @@ -0,0 +1,29 @@ +local telescope_mapper = require "alpha.telescope.mappings" + +return function(client, bufnr) + -- keymaps for lsp + vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0, desc = "LSP Help information of symbol under the cursor" }) + vim.keymap.set("n", "vrn", vim.lsp.buf.rename, { buffer = 0, desc = "LSP Rename symbol under cursor" }) + vim.keymap.set("i", "", vim.lsp.buf.signature_help, { buffer = 0, desc = "LSP Signature help" }) + vim.keymap.set("n", "vo", ":LspRestart", { noremap = true, desc = "LSP Restart Server" }) + vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, { buffer = 0, desc = "LSP Code actions" }) + vim.keymap.set("n", "vf", function() + return vim.lsp.buf.format { + async = true, + filter = function(cli) + return cli.name ~= "lua_ls" + end, + } + end, { buffer = 0, desc = "LSP format file" }) + + telescope_mapper("gr", "lsp_references", { buffer = true, desc = "LSP References of symbol on cursor" }) + telescope_mapper("pv", "find_symbol", { buffer = true, desc = "LSP find symbol on the project" }) + telescope_mapper("pd", "lsp_document_symbols", { buffer = true, desc = "LSP document symbols" }) + telescope_mapper("gd", "lsp_definitions", { buffer = true, desc = "LSP go to definition" }) + + vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" + + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint(bufnr, true) + end +end diff --git a/lua/alpha/lsp/default.lua b/lua/alpha/lsp/default.lua new file mode 100644 index 0000000..4f53ddd --- /dev/null +++ b/lua/alpha/lsp/default.lua @@ -0,0 +1,26 @@ +return { + mason = { + enable = true, + auto_install = false, + }, + servers = { + emmet_ls = { enable = true }, + gopls = { enable = true }, + html = { enable = true }, + jsonls = { enable = true }, + lua_ls = { enable = true, neodev = true }, + nil_ls = { enable = true }, + phpactor = {enable = true }, + rust_analyzer = { enable = true }, + svelte = { enable = true }, + tailwindcss = { enable = true, filetypes = {"blade", "html", "svelte"} }, + tsserver = { enable = true }, + volar = { enable = true }, + }, + default_options = function (options) + return vim.tbl_deep_extend("force", { + on_attach = require"alpha.lsp.attach", + flags = require "alpha.lsp.flags", + }, options) + end, +} diff --git a/lua/alpha/lsp/flags.lua b/lua/alpha/lsp/flags.lua new file mode 100644 index 0000000..f70b467 --- /dev/null +++ b/lua/alpha/lsp/flags.lua @@ -0,0 +1,3 @@ +return { + debounce_text_changes = 150, +} diff --git a/lua/alpha/lsp/init.lua b/lua/alpha/lsp/init.lua new file mode 100644 index 0000000..0d69f07 --- /dev/null +++ b/lua/alpha/lsp/init.lua @@ -0,0 +1,65 @@ +return { + setup = function(ops) + ops = vim.tbl_deep_extend("force", require "alpha.lsp.default", ops) + + local lspconfig = require "lspconfig" + + local mason_servers = {} + for server, options in pairs(ops.servers) do + if options.enable == true then + local ok, definition = pcall(require, "alpha.lsp.servers." .. server) + local server_options + if not ok then + server_options = ops.default_options(options) + else + server_options = definition(options) + end + lspconfig[server].setup(server_options) + table.insert(mason_servers, server) + end + end + + -- Mason + if ops.mason.enable then + local mason_ops = {} + if ops.mason.auto_install == true then + mason_ops.ensure_installed = mason_servers + end + local mason_lspconfig = require "mason-lspconfig" + mason_lspconfig.setup(mason_ops) + end + + -- TODO: implement null ls with options + require "alpha.lsp.null-ls" + + local servers = {} + for server, options in pairs(ops.servers) do + table.insert(servers, string.format("%s <%s>", server, options.enable)) + end + + -- TODO: create an auto command that on write of the configuration, calls again the setup and restart the server if it's up. + -- can get the client by name of the file + + vim.api.nvim_create_user_command("AlphaLSP", function() + vim.ui.select(servers, { prompt = "LSP Servers" }, function(server) + if server == nil then + return + end + + server = string.match(server, "^(.+) <") + local path = string.format("%s/lua/alpha/lsp/servers/%s.lua", vim.fn.stdpath "config", server) + if vim.fn.filereadable(path) == 0 then + local create = vim.fn.confirm("Server Does Not exist. Create new server?", "&Yes\n&No\n&Cancel") + if create ~= 1 then + return + end + end + + local uri = vim.uri_from_fname(path) + local buffer = vim.uri_to_bufnr(uri) + + vim.api.nvim_win_set_buf(0, buffer) + end) + end, {}) + end, +} diff --git a/lua/alpha/lsp/mason.lua b/lua/alpha/lsp/mason.lua new file mode 100644 index 0000000..a8c6ce7 --- /dev/null +++ b/lua/alpha/lsp/mason.lua @@ -0,0 +1,23 @@ +local mason_lspconfig = require "mason-lspconfig" +local servers = require "alpha.lsp.servers" +local lspconfig = require "lspconfig" + +local mason_servers = {} + +for server, _ in pairs(servers) do + local cmd = lspconfig[server].cmd[1] + if vim.fn.executable(cmd) == 0 then + table.insert(mason_servers, server) + end +end + +mason_lspconfig.setup { + -- ensure_installed = mason_servers, +} + +-- filter the list for the ones not globally installed +-- require("mason-tool-installer").setup { +-- ensure_installed = vim.tbl_filter(function (tool) +-- return vim.fn.executable(tool) == 0 +-- end, require "alpha.lsp.tools"), +-- } diff --git a/lua/alpha/lsp/null-ls.lua b/lua/alpha/lsp/null-ls.lua new file mode 100644 index 0000000..b329ba6 --- /dev/null +++ b/lua/alpha/lsp/null-ls.lua @@ -0,0 +1,53 @@ +local null_ls = require "null-ls" +-- local php_actions = require "php-code-actions" +-- local laravel_actions = require("laravel.code-actions") + +null_ls.setup { + 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.diagnostics.yamllint, + + -- 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, + -- -- command = "./bin/phpstan", + -- -- condition = function () + -- -- return vim.fn.findfile("bin/phpstan") ~= "" + -- -- end + -- }, + null_ls.builtins.diagnostics.phpcs.with { + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + condition = function(utils) + return utils.root_has_file "phpcs.xml" + end, + }, + null_ls.builtins.formatting.pint, + }, +} + +vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, {desc = "LSP (null ls) Code actions"}) +vim.keymap.set("n", "vf", function() + return vim.lsp.buf.format { async = true } +end, {desc = "LSP (null ls) Format file"}) + +-- function to toogle and possible restart it +vim.api.nvim_create_user_command("NullLsToggle", function() + local sources = vim.tbl_map(function(el) + return el.name + end, null_ls.get_sources()) + vim.ui.select(sources, {}, function(selected) + if not selected then + return + end + null_ls.toggle(selected) + end) +end, {}) diff --git a/lua/alpha/lsp/servers/emmet_ls.lua b/lua/alpha/lsp/servers/emmet_ls.lua new file mode 100644 index 0000000..c4f1cb6 --- /dev/null +++ b/lua/alpha/lsp/servers/emmet_ls.lua @@ -0,0 +1,12 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + capabilities = capabilities, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/html.lua b/lua/alpha/lsp/servers/html.lua new file mode 100644 index 0000000..7b8ef54 --- /dev/null +++ b/lua/alpha/lsp/servers/html.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "html-languageserver" == 1 then + config.cmd = { "html-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/lua/alpha/lsp/servers/jsonls.lua b/lua/alpha/lsp/servers/jsonls.lua new file mode 100644 index 0000000..9c731ab --- /dev/null +++ b/lua/alpha/lsp/servers/jsonls.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "json-languageserver" == 1 then + config.cmd = { "json-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/lua/alpha/lsp/servers/lua_ls.lua b/lua/alpha/lsp/servers/lua_ls.lua new file mode 100644 index 0000000..c5f72bf --- /dev/null +++ b/lua/alpha/lsp/servers/lua_ls.lua @@ -0,0 +1,36 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + if ops.neodev == true then + require("neodev").setup() + end + + return vim.tbl_extend("force", { + 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, + }, + hint = { + enable = true, + }, + completion = { + callSnippet = "Replace", + }, + }, + }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/phpactor.lua b/lua/alpha/lsp/servers/phpactor.lua new file mode 100644 index 0000000..e6bebcd --- /dev/null +++ b/lua/alpha/lsp/servers/phpactor.lua @@ -0,0 +1,80 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +local function phpactor_attach(_, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorReindex", function() + vim.lsp.buf_notify(bufnr, "phpactor/index/reindex", {}) + end, {}) + + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorStatus", function() + local results, _ = vim.lsp.buf_request_sync(bufnr, "phpactor/status", { ["return"] = true }) + + local content = "" + + for _, res in pairs(results or {}) do + if res ~= nil and res["result"] ~= nil then + content = content .. res["result"] + end + end + + local Popup = require "nui.popup" + local event = require("nui.utils.autocmd").event + + local popup = Popup { + enter = true, + focusable = true, + border = { + style = "rounded", + }, + position = "50%", + size = { + width = "80%", + height = "60%", + }, + } + + -- mount/open the component + popup:mount() + + -- unmount component when cursor leaves buffer + popup:on(event.BufLeave, function() + popup:unmount() + end) + local out = {} + for match in string.gmatch(content, "[^\n]+") do + table.insert(out, match) + end + + vim.api.nvim_buf_set_option(popup.bufnr, "filetype", "markdown") + vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, out) + end, {}) +end + +return function(ops) + return vim.tbl_extend("force", { + on_attach = function(client, bufnr) + lsp_attach(client, bufnr) + phpactor_attach(client, bufnr) + end, + flags = lsp_flags, + filetypes = { "php", "blade" }, + init_options = { + ["language_server_worse_reflection.inlay_hints.enable"] = true, + ["language_server_worse_reflection.inlay_hints.params"] = true, + -- ["language_server_worse_reflection.inlay_hints.types"] = true, + ["language_server_configuration.auto_config"] = false, + ["code_transform.import_globals"] = true, + ["language_server_phpstan.enabled"] = true, + ["language_server_phpstan.level"] = 7, + ["language_server_phpstan.bin"] = "phpstan", + }, + handlers = { + ["textDocument/inlayHint"] = function(err, result, ...) + for _, res in ipairs(result) do + res.label = res.label .. ": " + end + vim.lsp.handlers["textDocument/inlayHint"](err, result, ...) + end, + }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/rust_analyzer.lua b/lua/alpha/lsp/servers/rust_analyzer.lua new file mode 100644 index 0000000..c0db321 --- /dev/null +++ b/lua/alpha/lsp/servers/rust_analyzer.lua @@ -0,0 +1,24 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["rust-analyzer"] = { + checkOnSave = { + allFeatures = true, + overrideCommand = { + "cargo", + "clippy", + "--workspace", + "--message-format=json", + "--all-targets", + "--all-features", + }, + }, + }, + }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/tsserver.lua b/lua/alpha/lsp/servers/tsserver.lua new file mode 100644 index 0000000..e27d94a --- /dev/null +++ b/lua/alpha/lsp/servers/tsserver.lua @@ -0,0 +1,33 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }, ops) +end diff --git a/lua/alpha/lsp/tools.lua b/lua/alpha/lsp/tools.lua new file mode 100644 index 0000000..7919521 --- /dev/null +++ b/lua/alpha/lsp/tools.lua @@ -0,0 +1,8 @@ +return { + "codelldb", + "go-debug-adapter", + "js-debug-adapter", + "php-debug-adapter", + "phpcs", + "phpstan", +} diff --git a/lua/alpha/packer_install.lua b/lua/alpha/packer_install.lua new file mode 100644 index 0000000..9ef6658 --- /dev/null +++ b/lua/alpha/packer_install.lua @@ -0,0 +1,27 @@ +local download_packer = function() + if vim.fn.input "Download Packer? (y for yes)" ~= "y" then + return + end + + local directory = string.format("%s/site/pack/packer/start/", vim.fn.stdpath "data") + + vim.fn.mkdir(directory, "p") + + local out = vim.fn.system( + string.format("git clone %s %s", "https://github.com/wbthomason/packer.nvim", directory .. "/packer.nvim") + ) + + print(out) + print "Downloading packer.nvim..." + print "( You'll need to restart now )" +end + +return function() + if not pcall(require, "packer") then + download_packer() + + return true + end + + return false +end diff --git a/lua/alpha/php/gateway.lua b/lua/alpha/php/gateway.lua new file mode 100644 index 0000000..5f8ddae --- /dev/null +++ b/lua/alpha/php/gateway.lua @@ -0,0 +1,137 @@ +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 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) + + 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 + + return mutations_definitions +end + +-- "'@=mutation(\"App\\\\GraphQL\\\\Mutations\\\\Mutation::action\", ...)'", +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 + return + end + + local args_tbl = vim.split(args, ", ") + local fqn = string.match(args_tbl[1], '"(.+)"') + fqn = string.gsub(fqn, "\\\\", "\\") + -- P(fqn) + + require("alpha.php.lsp").find(fqn, "phpactor") +end + +--- @param bufnr integer Buff id +gateway.get_graphql_definitions = function(bufnr) + vim.treesitter.query.set( + "yaml", + "GraphQL_endpoints", + [[ + (document (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @mutation + value: (block_node (block_mapping (block_mapping_pair + key: (flow_node) @resolve (#eq? @resolve "resolve") + value: (flow_node) @resolver + ))) + ))) + ))) + ))) + )))) + ]] + ) + + local query = vim.treesitter.query.get("yaml", "GraphQL_endpoints") + + local elements = {} + + local parsers = require "nvim-treesitter.parsers" + local parser = parsers.get_parser(bufnr) + local tree = parser:parse()[1] + + 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 +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\\\\Mutation::action\", ...)'", + -- value = "deleteVehicleImage" + return { + value = entry, + display = entry.value, + ordinal = entry.value, + path = vim.api.nvim_buf_get_name(entry.buffer), + lnum = entry.lnum, + resolver = entry.resolver, + } + end, + }, + sorter = conf.generic_sorter(opts), + previewer = conf.grep_previewer(opts), + attach_mappings = function(prompt_bufnr, map) + action_set.select:enhance { + post = function() + local selection = action_state.get_selected_entry() + vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) + end, + } + map("i", "", function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + open_resolver(selection.resolver) + end) + return true + end, + }) + :find() +end + +return gateway diff --git a/lua/alpha/php/lsp.lua b/lua/alpha/php/lsp.lua new file mode 100644 index 0000000..37e0bc0 --- /dev/null +++ b/lua/alpha/php/lsp.lua @@ -0,0 +1,151 @@ +local Path = require "plenary.path" + +local lsp = {} + +local open_filename = function(filename) + if vim.api.nvim_buf_get_name(0) ~= filename then + filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) + pcall(vim.cmd, string.format("%s %s", "edit", filename)) + end +end + +---@param server_name string +---@return table|nil, boolean +local get_client = function(server_name) + local clients = vim.lsp.get_active_clients { name = server_name } + local client = clients[1] or nil + local new_instance = false + + if not client then + local server = require("lspconfig")[server_name] + local config = server.make_config(vim.fn.getcwd()) + local client_id = vim.lsp.start(config) + client = vim.lsp.get_client_by_id(client_id) + new_instance = true + end + + return client, new_instance +end + +local function go_to(client, is_new_instance, full_class, method) + local class_parts = vim.split(full_class, "\\") + local class = class_parts[#class_parts] + + local resp = client.request_sync("workspace/symbol", { query = class }, nil) + + local locations = vim.lsp.util.symbols_to_items(resp.result or {}, nil) or {} + if vim.tbl_isempty(locations) then + vim.api.nvim_err_writeln("Empty response looking for class: " .. full_class) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local class_location = nil + for idx, location in pairs(locations) do + if location.text == string.format("[Class] %s", full_class) then + class_location = locations[idx] + break + end + end + + if class_location == nil then + vim.api.nvim_err_writeln("Could not find class for : " .. full_class) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + open_filename(class_location.filename) + + local params = vim.lsp.util.make_position_params(0) + if is_new_instance then + vim.lsp.buf_attach_client(0, client.id) + end + + vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(method_err, method_server_result, _, _) + if method_err then + vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. method_err.message) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local method_locations = vim.lsp.util.symbols_to_items(method_server_result or {}, 0) or {} + if vim.tbl_isempty(method_locations) then + vim.api.nvim_err_writeln(string.format("empty response looking for method: %s", method or "__invoke")) + if is_new_instance then + vim.lsp.stop_client(client.id) + end + return + end + + local method_location = nil + for _, value in ipairs(method_locations) do + if value.text == string.format("[Method] %s", method or "__invoke") then + method_location = value + break + end + end + + if method_location == nil then + if is_new_instance then + vim.lsp.stop_client(client.id) + end + 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("Erro setting row and col " .. err_msg) + end + vim.cmd "normal zt" + end + if is_new_instance then + vim.lsp.stop_client(client.id) + end + end) +end + +---Return a buffer id for the given client +---@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 buffers = vim.lsp.get_buffers_by_client_id(clients[1].id) + + if #buffers == 0 then + return nil + end + + return buffers[1] +end + +--- @param fqn string: fully name to search Class::method +lsp.find = function(fqn, server_name) + local search = vim.split(fqn, "::") + local fqn_class = search[1] + local method = search[2] + + local client, is_new_instance = get_client(server_name) + + if not client then + vim.api.nvim_err_writeln "Could not get lsp client" + return + end + + go_to(client, is_new_instance, fqn_class, method) +end + +return lsp diff --git a/lua/alpha/php/servers.lua b/lua/alpha/php/servers.lua new file mode 100644 index 0000000..9450152 --- /dev/null +++ b/lua/alpha/php/servers.lua @@ -0,0 +1,38 @@ +local phpactor = {} + +-- TODO possible improvement look how it works underline +-- use the client directly to call, no need for the buffer +-- to find a class. +-- 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) +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) + +vim.lsp.get_client_by_id(client_id) +-- use client.request or request_sync +-- look for the direct of the symbol +return { + phpactor = phpactor, +} diff --git a/lua/alpha/select_to_quickfix.lua b/lua/alpha/select_to_quickfix.lua new file mode 100644 index 0000000..ebd1561 --- /dev/null +++ b/lua/alpha/select_to_quickfix.lua @@ -0,0 +1,53 @@ +local api = vim.api + +local function create_quickfix_entry(selection) + local filename, linenumber = selection:match "([^:]+):(%d+)" + + return { + filename = vim.fn.getcwd() .. "/" .. filename, + lnum = tonumber(linenumber), + col = 1, + text = filename, + } +end + +local function add_selections_to_quickfix(selections) + local quickfix_list = {} + + for _, selection in ipairs(selections) do + local entry = create_quickfix_entry(selection) + table.insert(quickfix_list, entry) + end + + vim.fn.setqflist(quickfix_list, "r") +end + +local function get_selections() + local _, end_line, _, _ = unpack(vim.fn.getpos "'>") + local _, start_line, _, _ = unpack(vim.fn.getpos "'<") + local lines = api.nvim_buf_get_lines(0, start_line - 1, end_line, false) + + local selections = {} + for _, line in ipairs(lines) do + for selection in line:gmatch "%S+" do + table.insert(selections, selection) + end + end + + return selections +end + +local function select_to_quickfix() + local selections = get_selections() + + if #selections > 0 then + add_selections_to_quickfix(selections) + print "Selections added to quickfix list" + else + print "No selections found" + end +end + +return { + handle = select_to_quickfix, +} diff --git a/lua/alpha/snips/ft/cucumber.lua b/lua/alpha/snips/ft/cucumber.lua new file mode 100644 index 0000000..6176a87 --- /dev/null +++ b/lua/alpha/snips/ft/cucumber.lua @@ -0,0 +1,71 @@ +local ls = require "luasnip" +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local fmt = require("luasnip.extras.fmt").fmt + +local M = { + clean = t [[Given clean stubs list]], + all = t [[And all stubs should be matched]], + status_code = fmt([[Then the response status code should be {}]], { i(1, "200") }), + no_error = t [[And the JSON path expression errors should not have result]], + json_data = fmt([[And the JSON path expression "data" should be equal to: +""" +{{ + {} +}} +""" + ]], {i(1)}), + feature = fmt( + [[Feature: {} + + {} +]], + { + i(1, "Feature Name"), + i(0), + } + ), + scenario = fmt( + [[Scenario: {} + {}]], + { + i(1, "Scenario name"), + i(0), + } + ), + stub = fmt([[And the APIClient will send a request with a stub from "{}"]], { i(1) }), + request = fmt( + [[When I send the GraphQL request: +""" +{} +"""]], + { i(1) } + ), + result = fmt( + [[And the JSON path expression "data" should be equal to: +""" +{{ + "result": {{ + {} + }} +}} +"""]], + { i(1) } + ), + query = fmt( + [[{} {{ +result: {}({}) {{ + {} +}} + }}]], + { c(1, { t "mutation", t "query" }), i(2, "mutation"), i(3, ""), i(4) } + ), + access = fmt( + [[And the Access Cache has Allowed the userId "{}" for inspectionId "{}"]], + { i(1, "3414054"), i(2, "42") } + ), + branch_access = fmt([[And the Access Cache has branch "{}" for userId "{}"]], { i(1, "1"), i(2, "3414054") }), +} + +return M diff --git a/lua/alpha/snips/ft/go.lua b/lua/alpha/snips/ft/go.lua new file mode 100644 index 0000000..9c3977f --- /dev/null +++ b/lua/alpha/snips/ft/go.lua @@ -0,0 +1,134 @@ +local ls = require "luasnip" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local 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 get_node_text = vim.treesitter.get_node_text + +vim.treesitter.query.set( + "go", + "LuaSnip_Result", + [[ + [ + (method_declaration result: (_) @id) + (function_declaration result: (_) @id) + (func_literal result: (_) @id) + ] +]] +) + +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) +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, +} + +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.query.get("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)) +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), + }, +} + +M.f = fmt("func {}({}) {} {{\n\t{}\n}}", { i(1, "name"), i(2), i(3), i(0) }) + +return M diff --git a/lua/alpha/snips/ft/lua.lua b/lua/alpha/snips/ft/lua.lua new file mode 100644 index 0000000..d896f3e --- /dev/null +++ b/lua/alpha/snips/ft/lua.lua @@ -0,0 +1,69 @@ +local ls = require "luasnip" + +-- local snippet = ls.s +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local d = ls.dynamic_node +local i = ls.insert_node +local f = ls.function_node +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 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), + }) +end + +local newline = function(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", + }, + + preq = fmt( + [[local ok, {} = pcall(require, "{}") +if not ok then + return +end]], + { + f(function(args) + return args[1][1] + end, { 1 }), + i(1), + } + ), + + plugin = fmt( + [[return {{ + "{}" +}}]], + { + i(1, "plugin"), + } + ), +} diff --git a/lua/alpha/snips/ft/php.lua b/lua/alpha/snips/ft/php.lua new file mode 100644 index 0000000..72936d8 --- /dev/null +++ b/lua/alpha/snips/ft/php.lua @@ -0,0 +1,163 @@ +local ls = require "luasnip" +local composer = require "composer" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local f = ls.function_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt + +local 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) +end + +local var_name = function(args) + return snippet_from_nodes(nil, { + i(1, args[1][1]:gsub("^%u", string.lower):gsub("Interface", "") or ""), + }) +end + +local class_name = function() + return vim.fn.expand "%:t:r" +end + +local M = {} + +M.v = fmt( + [[ +/** + * @var {} + */ +{} {} ${}; +]], + { + i(1, "type"), + visibility(2, "private"), + i(3, "Type"), + i(4, "var"), + } +) + +M.class = fmt( + [[ + + */ + private ObjectProphecy ${}; +]], + { + i(1, "Type"), + d(2, var_name, { 1 }), + } +) + +M.iop = fmt( + [[$this->{} = $this->prophesize({}::class);]], + { + i(1, ""), + i(2, ""), + } +) + +M.arg = fmt([[{} ${}]], { + i(1, "Type"), + d(2, var_name, { 1 }), +}) + +M._c = fmt( + [[{} function __construct({}) {{ + {} +}}]], + { + visibility(1, "public"), + i(2), + i(0), + } +) + +M._p = fmt( + [[{} function __construct( + {} +) {{ +}}]], + { + visibility(1, "public"), + i(2), + } +) + +M.strict = t "declare(strict_types=1);" + +M["fn"] = fmt( + [[{} function {}({}): {} +{{ + {} +}}]], + { visibility(1, "public"), i(2), i(3), i(4, "void"), i(0) } +) + +M["then"] = fmt( + [[->then( + function ({}) {{ + {} + }} +)]], + { i(1, ""), i(2, "") } +) + +M.test = fmt( + [[/** + * @test + */ +public function it_{}(): void +{{ + {} +}} +]], + { i(1, ""), i(0, "") } +) + +return M diff --git a/lua/alpha/snips/ft/yaml.lua b/lua/alpha/snips/ft/yaml.lua new file mode 100644 index 0000000..3924c6f --- /dev/null +++ b/lua/alpha/snips/ft/yaml.lua @@ -0,0 +1,225 @@ +local ls = require "luasnip" + +local snippet_from_nodes = ls.sn +local c = ls.choice_node +local t = ls.text_node +local d = ls.dynamic_node +local f = ls.function_node +local i = ls.insert_node +local fmt = require("luasnip.extras.fmt").fmt +local rep = require("luasnip.extras").rep + +local M = { + str = fmt( + [[{}: + type: string +{}]], + { + i(1, ""), + i(2, ""), + } + ), + bool = fmt( + [[{}: + type: boolean +{}]], + { + i(1, ""), + i(2, ""), + } + ), + float = fmt( + [[{}: + type: number + format: float +{}]], + { + i(1, ""), + i(2, ""), + } + ), + int = fmt( + [[{}: + type: integer +{}]], + { + i(1, ""), + i(2, ""), + } + ), + id = fmt( + [[{}: + type: integer + format: int64 +{}]], + { + i(1, ""), + i(2, ""), + } + ), + class = fmt( + [[{}: + $ref: '#/components/schemas/{}' +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + date = fmt( + [[{}: + type: string + format: date-time +{}]], + { + i(1, ""), + i(2, ""), + } + ), + arr = fmt( + [[{}: + type: array + items: + {} +{}]], + { + i(1, ""), + i(2, ""), + i(3, ""), + } + ), + ref = fmt([[$ref: '#/components/schemas/{}']], { i(1, "") }), + obj = fmt( + [[type: object +properties: + {}]], + i(1, "") + ), + aint = fmt( + [[{}: + type: array + items: + type: int + format: int64 +{}]], + { + i(1, ""), + i(2, ""), + } + ), + astr = fmt( + [[{}: + type: array + items: + type: string +{}]], + { + i(1, ""), + i(2, ""), + } + ), + + mut = fmt( + [[{}: + type: "{}" + resolve: '@=mutation("App\\GraphQL\\Mutation\\{}::{}", {}, info)' + args: + {} +]], + { + i(1, ""), + i(2, ""), + i(3, ""), + rep(1), + i(5, ""), + i(6, ""), + } + ), + + input = fmt( + [[{}: + type: input-object + config: + fields: + {} +]], + { + i(1, ""), + i(2, ""), + } + ), + f = fmt([[{}: {{ type: "{}" }}]], { i(1, ""), i(2, "") }), + + api = fmt( + [[openapi: 3.0.2 +info: + title: {} + contact: + name: eva-team-be + version: {} +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(0, "") } + ), + param = fmt( + [[parameters: + - name: {} + description: {} + in: path + required: true + schema: + type: integer + format: int64 +]], + { i(1, ""), i(2, "") } + ), + get = fmt( + [[get: + operationId: {} + description: {} + tags: [ {} ] + responses: + 200: + description: Response + content: + application/json: + schema: + {} + ]], + { i(1, "GetOperation"), i(2, "description"), i(3, "tag"), i(4, "") } + ), + + put = fmt( + [[put: + operationId: {} + tags: [ {} ] + description: {} + requestBody: + content: + application/json: + schema: + {} + required: true + responses: + 200: + description: {} + content: + application/json: + schema: + {} + ]], + { i(1, "PutOperation"), i(2, "tag"), i(3, "description"), i(4, ""), i(5, "description"), i(6, "") } + ), +} + +return M diff --git a/lua/alpha/telescope/init.lua b/lua/alpha/telescope/init.lua new file mode 100644 index 0000000..c4daf6c --- /dev/null +++ b/lua/alpha/telescope/init.lua @@ -0,0 +1,186 @@ +local SHOULD_RELOAD_TELESCOPE = false + +local reloader = function() + if SHOULD_RELOAD_TELESCOPE then + Reload "plenary" + Reload "telescope" + Reload "alpha.telescope.setup" + end +end + +local fb_actions = require("telescope").extensions.file_browser.actions +local actions = require "telescope.actions" +local my_actions = require "alpha.telescope.my_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 +end + +function M.branches() + require("telescope.builtin").git_branches { + attach_mappings = function(_, map) + map("i", "", actions.git_create_branch) + map("n", "", 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, + } +end + +M.find_nvim_config = function() + 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", "", my_actions.create_plugin) + map("i", "", my_actions.disable_plugin) + map("i", "", 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) +end + +function M.grep_word() + require("telescope.builtin").grep_string { search = vim.fn.expand "" } +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) +end + +function M.my_plugins() + if vim.fn.isdirectory(vim.fn.getenv "HOME" .. "/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.scratchs() + require("telescope.builtin").find_files { + prompt_title = "Scratchs", + no_ignore = true, + cwd = "~/.config/nvim/lua/scratchs/", + attach_mappings = function(_, map) + map("i", "", my_actions.create_scratch_file) + + return true + end, + } +end + +function M.projectionist() + return require("telescope").extensions.projectionist.projectionist() +end + +function M.laravel_commands() + 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, + } +end + +function M.worktree() + return require("telescope").extensions.git_worktree.git_worktrees() +end + +function M.worktree_create() + return require("telescope").extensions.git_worktree.create_git_worktree() +end + +function M.refactor() + return require("telescope").extensions.refactoring.refactors() +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, + }, + }, + } +end + +function M.file_browser_relative() + return M.file_browser { path = "%:p:h" } +end + +function M.file_browser(opts) + opts = opts or {} + + opts = { + path = opts.path, + sorting_strategy = "ascending", + scroll_strategy = "cycle", + layout_config = { + prompt_position = "top", + }, + + attach_mappings = function(_, map) + map("i", "", fb_actions.create_from_prompt) + + return true + end, + } + + 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, +}) diff --git a/lua/alpha/telescope/mappings.lua b/lua/alpha/telescope/mappings.lua new file mode 100644 index 0000000..89472bc --- /dev/null +++ b/lua/alpha/telescope/mappings.lua @@ -0,0 +1,55 @@ +local map_tele = function(key, f, opts) + local default = { + mode = "n", + options = {}, + buffer = nil, + desc = nil, + } + opts = opts or {} + opts = vim.tbl_deep_extend("force", default, opts or {}) + + local rhs = function() + R("alpha.telescope")[f](opts.options) + end + + local map_options = { + remap = false, + silent = true, + } + if opts.buffer then + map_options.buffer = opts.buffer + end + if opts.desc then + map_options.desc = "Telescope: " .. opts.desc + end + + vim.keymap.set(opts.mode, key, rhs, map_options) +end + +-- not shure what this line does +vim.api.nvim_set_keymap( + "c", + "", + "(TelescopeFuzzyCommandSearch)", + { noremap = false, nowait = true, desc = "In comand look for previous commands" } +) + +map_tele("pp", "project_files", { desc = "Open Project files" }) +map_tele("gc", "branches", { desc = "Git Branches selector" }) +map_tele("pw", "grep_word", { desc = "Grep word under cursor" }) +map_tele("ps", "grep_string", { desc = "Grep provided input string" }) +map_tele("rc", "search_config", { desc = "Search Files in .dotfiles directory" }) +map_tele("rn", "find_nvim_config", { desc = "Search Files in nvim config directory" }) +map_tele("rp", "find_nvim_plugin", { desc = "Search Neovim plugins" }) +map_tele("rs", "scratchs", { desc = "Search Neovim Scratchs files" }) +map_tele("ph", "help_tags", { desc = "Neovim Help" }) +map_tele("pe", "buffers", { desc = "Open buffers" }) +map_tele("pr", "treesitter", { desc = "Treesitter buffer elements" }) +map_tele("bb", "file_browser_relative", { desc = "Current directory" }) +map_tele("bp", "file_browser", { desc = "Project directory" }) +map_tele("gs", "git_status", { desc = "Git status" }) +map_tele("ve", "diagnostics", { desc = "Diagnostic of the buffer" }) +map_tele("po", "api_specs", { desc = "Openapi directory" }) +map_tele("pm", "gateway", { desc = "Graphql mutations and queries" }) + +return map_tele diff --git a/lua/alpha/telescope/my_actions.lua b/lua/alpha/telescope/my_actions.lua new file mode 100644 index 0000000..b0e9f10 --- /dev/null +++ b/lua/alpha/telescope/my_actions.lua @@ -0,0 +1,170 @@ +local M = {} + +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)) +end + + +local get_disable_stm_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_is_disabled", + [[ +(return_statement + (expression_list + (table_constructor + (field + name: (identifier) @enabled (#eq? @enabled "enabled") + value: (false) @is_false + ) + ) + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_is_disabled") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node + end + end + + return nil +end + +local get_enabled_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_has_enable_property", + [[ +(return_statement + (expression_list + (table_constructor + (field + name: (identifier) @enabled (#eq? @enabled "enabled") + ) + ) + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_has_enable_property") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "enabled" then + return node + end + end + + return nil +end + +local get_return_node = function(bufnr, tree) + vim.treesitter.query.set( + "lua", + "alpha_plugin_return_table_constructor", + [[ +(return_statement + (expression_list + (table_constructor) @table_constructor + ) + ) + ]] + ) + + local query = vim.treesitter.query.get("lua", "alpha_plugin_return_table_constructor") + + for id, node in query:iter_captures(tree:root(), bufnr) do + if query.captures[id] == "table_constructor" then + return node + end + end + + 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) + local tree = parser:parse()[1] + + 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) +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) + + local tree = parser:parse()[1] + + 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 + +M.create_scratch_file = function(prompt_bufnr) + local new_scratch = action_state.get_current_line() + actions.close(prompt_bufnr) + vim.cmd(string.format("edit ~/.config/nvim/lua/scratchs/%s.lua", new_scratch)) +end + +return M diff --git a/lua/alpha/telescope/setup.lua b/lua/alpha/telescope/setup.lua new file mode 100644 index 0000000..0e368c7 --- /dev/null +++ b/lua/alpha/telescope/setup.lua @@ -0,0 +1,222 @@ +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 + + action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) +end + +local filetype_hook = function(filepath, bufnr, opts) + -- Here for example you can say: if ft == "xyz" then this_regex_highlighing else nothing end + -- + local is_image = function(filepath) + local image_extensions = { "png", "jpg" } -- Supported image formats + local split_path = vim.split(filepath:lower(), ".", { plain = true }) + local extension = split_path[#split_path] + return vim.tbl_contains(image_extensions, extension) + end + if not is_image(filepath) then + return true + end + local ui = require "image.ui" + local options = require "image.options" + local dimensions = require "image.dimensions" + local api = require "image.api" + local config = require "image.config" + local user_opts = { + render = { + foreground_color = true, + background_color = true, + }, + } + local global_opts = vim.tbl_deep_extend("force", config.DEFAULT_OPTS, user_opts) + + local ascii_width, ascii_height, horizontal_padding, vertical_padding, img_width, img_height = + dimensions.calculate_ascii_width_height(opts.winid, filepath, global_opts) + options.set_options_before_render(bufnr) + ui.buf_clear(bufnr) + local label = ui.create_label( + filepath, + ascii_width, + horizontal_padding, + global_opts.render.show_image_dimensions, + img_width, + img_height + ) + + api.get_ascii_data_sync(filepath, ascii_width, ascii_height, global_opts, function(ascii_data) + ui.buf_insert_data_with_padding(bufnr, ascii_data, horizontal_padding, vertical_padding, label, global_opts) + + options.set_options_after_render(bufnr) + end) + return false +end + +require("telescope").setup { + defaults = { + preview = { + filetype_hook = filetype_hook, + }, + 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.7) + 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 = { + -- [""] = false, + -- [""] = actions.select_horizontal, + [""] = "move_selection_next", + + [""] = set_prompt_to_entry_value, + + -- These are new :) + [""] = action_layout.toggle_preview, + [""] = action_layout.toggle_mirror, + -- [""] = action_layout.toggle_prompt_position, + + -- [""] = actions.master_stack, + + -- [""] = actions.send_to_qflist + actions.open_qflist, + -- [""] = actions.send_selected_to_qflist + actions.open_qflist, + + -- This is nicer when used with smart-history plugin. + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + + -- [""] = 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, + + -- [""] = function() + -- vim.api.nvim_input("") + -- 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, + }, + -- buffer_previewer_maker = new_maker, + }, + + pickers = { + fd = { + mappings = { + n = { + ["kj"] = "close", + }, + }, + }, + + git_branches = { + mappings = { + i = { + [""] = 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_dropdown { + borderchars = { + prompt = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + results = { "─", "│", "─", "│", "╭", "╮", "┤", "├" }, + preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + }, + width = 0.8, + previewer = false, + }, + }, + }, +} + +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/test_menu.lua b/lua/alpha/test_menu.lua new file mode 100644 index 0000000..afe3a9e --- /dev/null +++ b/lua/alpha/test_menu.lua @@ -0,0 +1,50 @@ +local hydra = require "hydra" + +local hint = [[ + Vim Tests + _n_: Near test _h_: Harpoon ^ + _f_: Current file _s_: Test Suit ^ + _l_: Test Last _g_: Visit + _w_: Watch last Test _p_: stop watch + ^ ^ __ ^ +]] +local auto_cmd_id = nil +local stopAutoCommand = function() + if auto_cmd_id ~= nil then + vim.api.nvim_del_autocmd(auto_cmd_id) + auto_cmd_id = nil + end +end +local startAutoCommand = function() + stopAutoCommand() + auto_cmd_id = vim.api.nvim_create_autocmd({ "BufWritePost" }, { + pattern = { "*.php", "*.feature", "*.yaml" }, + command = "TestLast", + }) +end + +hydra { + name = "vimtest", + hint = hint, + mode = "n", + config = { + color = "teal", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "t", + heads = { + { "n", ":TestNearest" }, + { "h", ":TestNearest -strategy=harpoon" }, + { "f", ":TestFile" }, + { "s", ":TestSuit" }, + { "l", ":TestLast" }, + { "g", ":TestVisit" }, + { "w", startAutoCommand }, + { "p", stopAutoCommand }, + { "", nil, { exit = true } }, + }, +} diff --git a/lua/alpha/test_strategy.lua b/lua/alpha/test_strategy.lua new file mode 100644 index 0000000..9a2d34a --- /dev/null +++ b/lua/alpha/test_strategy.lua @@ -0,0 +1,65 @@ +local Job = require "plenary.job" + +local function splitString(input_string) + local parts = {} + local in_quote = false + local part_start = 1 + + for i = 1, #input_string do + local char = input_string:sub(i, i) + + if char == "'" then + in_quote = not in_quote + elseif char == " " and not in_quote then + local part = input_string:sub(part_start, i - 1) + -- Remove surrounding quotes if they exist + if part:sub(1, 1) == "'" and part:sub(-1) == "'" then + part = part:sub(2, -2) + end + table.insert(parts, part) + part_start = i + 1 + end + end + + -- Add the last part (and remove surrounding quotes if they exist) + local part = input_string:sub(part_start) + if part:sub(1, 1) == "'" and part:sub(-1) == "'" then + part = part:sub(2, -2) + end + table.insert(parts, part) + + return parts +end + +local function myStrategy(cmd) + --convert cmd from string to table + if type(cmd) == "string" then + -- do not split quoted parts of the string + cmd = splitString(cmd) + end + + -- get first element of cmd and remove from the cmd + local cmd_name = table.remove(cmd, 1) + + ---@diagnostic disable-next-line: missing-fields + Job:new({ + command = cmd_name, + args = cmd, + on_exit = function(j, return_val) + -- in case of result val 0 show success message + if return_val == 0 then + vim.notify("Test run successfully", vim.log.levels.INFO, { title = "Test" }) + return + end + local result = j:stderr_result() or j:stdout_result() + -- join result in a single string + result = table.concat(result, "\n") + -- escape / characters + result = result:gsub("/", "\\/") + vim.notify(result, vim.log.levels.ERROR, { title = "Test" }) + end, + }):start() +end + +vim.g["test#custom_strategies"] = { myStrategy = myStrategy } +vim.g["test#strategy"] = "myStrategy" diff --git a/lua/alpha/utils.lua b/lua/alpha/utils.lua new file mode 100644 index 0000000..b7b0fbc --- /dev/null +++ b/lua/alpha/utils.lua @@ -0,0 +1,11 @@ +local M = {} + +M.save_and_exec = function() + vim.api.nvim_command "silent w" + vim.api.nvim_command "so" + + 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 diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua new file mode 100644 index 0000000..1e51b62 --- /dev/null +++ b/lua/config/autocmds.lua @@ -0,0 +1,39 @@ +-- resize splits if window got resized +vim.api.nvim_create_autocmd({ "VimResized" }, { + callback = function() + vim.cmd("tabdo wincmd =") + end, +}) + +-- close some filetypes with +vim.api.nvim_create_autocmd("FileType", { + pattern = { + "qf", + "help", + "man", + "notify", + "lspinfo", + "spectre_panel", + "startuptime", + "tsplayground", + "PlenaryTestPopup", + }, + callback = function(event) + vim.bo[event.buf].buflisted = false + vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) + end, +}) + +vim.api.nvim_create_autocmd("FileType", { + pattern = { "gitcommit", "markdown", "NeogitCommitMessage", "norg" }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, +}) + +vim.api.nvim_create_autocmd({ "BufWritePre" }, { + callback = function() + vim.cmd([[%s/\s\+$//e]]) + end, +}) diff --git a/lua/config/diagnostic.lua b/lua/config/diagnostic.lua new file mode 100644 index 0000000..67465ae --- /dev/null +++ b/lua/config/diagnostic.lua @@ -0,0 +1,9 @@ +vim.diagnostic.config { + virtual_text = false, +} + +local signs = { Error = "", Warn = "", Hint = "", Info = "" } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end diff --git a/lua/config/init.lua b/lua/config/init.lua new file mode 100644 index 0000000..008ebf5 --- /dev/null +++ b/lua/config/init.lua @@ -0,0 +1,13 @@ +require "config.options" +-- autocmds and keymaps can wait to load +vim.api.nvim_create_autocmd("User", { + group = vim.api.nvim_create_augroup("LazyVim", { clear = true }), + pattern = "VeryLazy", + callback = function() + require "config.autocmds" + require "config.usercmds" + require "config.keymaps" + require "config.diagnostic" + end, +}) +require "config.lazy" diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua new file mode 100644 index 0000000..284db4f --- /dev/null +++ b/lua/config/keymaps.lua @@ -0,0 +1,43 @@ +-- Keymaps are automatically loaded on the VeryLazy event +-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua +-- Add any additional keymaps here + +local bind = vim.keymap.set +local opts = { silent = true, noremap = true } + +-- for russian layout +bind("i", "", "", opts) +bind("n", "л", "gk", opts) +bind("n", "о", "gj", opts) +bind("i", "", "u", opts) +bind("i", "", "u", opts) + +bind("n", "[c", function() + require("treesitter-context").go_to_context() +end) + +-- Terminal +bind("t", "", "") +bind("t", "h", "h") +bind("t", "j", "j") +bind("t", "k", "k") +bind("t", "l", "l") + +--personal +--normal mode +bind("i", "jk", "") +--save +bind("n", "zz", ":update") + + +bind("n", ",", ":nohlsearch" ) + +--windows +-- bind("n", "", "h") +-- nnoremap h +-- nnoremap j +-- nnoremap k +-- nnoremap l + +vim.keymap.set("n", "[", "call append(line('.') - 1, repeat([''], v:count1))") +vim.keymap.set("n", "]", "call append(line('.'), repeat([''], v:count1))") diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..5ee9699 --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,57 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + -- bootstrap lazy.nvim + -- stylua: ignore + vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath }) +end +vim.opt.rtp:prepend(vim.env.LAZY or lazypath) + +require('lazy').setup({ + change_detection = { notify = false }, + spec = { + { "LazyVim/LazyVim", import = "lazyvim.plugins" }, + { import = "lazyvim.plugins.extras.formatting.prettier" }, + -- { import = "lazyvim.plugins.extras.linting.eslint" }, + -- { import = "lazyvim.plugins.extras.lsp.none-ls" }, + -- { import = "lazyvim.plugins.extras.dap.core" }, + -- { import = "lazyvim.plugins.extras.coding.yanky" }, + { import = "lazyvim.plugins.extras.lang.markdown" }, + -- { import = "lazyvim.plugins.extras.lang.typescript" }, + { import = "lazyvim.plugins.extras.lang.docker" }, + { import = "lazyvim.plugins.extras.lang.json" }, + -- { import = "lazyvim.plugins.extras.lang.go" }, + -- { import = "lazyvim.plugins.extras.lang.elixir" }, + -- { import = "lazyvim.plugins.extras.lang.java" }, + -- { import = "lazyvim.plugins.extras.lang.python" }, + -- { import = "lazyvim.plugins.extras.lang.ruby" }, + -- { import = "lazyvim.plugins.extras.lang.terraform" }, + { import = "lazyvim.plugins.extras.lang.yaml" }, + { import = "plugins" }, + }, + defaults = { + -- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup. + -- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default. + lazy = false, + -- It's recommended to leave version=false for now, since a lot the plugin that support versioning, + -- have outdated releases, which may break your Neovim install. + version = false, -- always use the latest git commit + -- version = "*", -- try installing the latest stable version for plugins that support semver + }, + -- install = { colorscheme = { "tokyonight", "habamax" } }, + checker = { enabled = true }, -- automatically check for plugin updates + performance = { + rtp = { + -- disable some rtp plugins + disabled_plugins = { + "gzip", + -- "matchit", + -- "matchparen", + -- "netrwPlugin", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", + }, + }, + }, +}) diff --git a/lua/config/options.lua b/lua/config/options.lua new file mode 100644 index 0000000..2beb6f5 --- /dev/null +++ b/lua/config/options.lua @@ -0,0 +1,54 @@ +-- Options are automatically loaded before lazy.nvim startup +-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua +-- Add any additional options here +vim.g.mapleader = " " +vim.g.snippets = "luasnip" + +vim.o.langmap = + "ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz" + +vim.o.relativenumber = false +vim.o.spelllang = "ru_ru,en_us" +vim.o.linebreak = true +vim.g.autoformat = false + +local opt = vim.o + +opt.mouse = "" +opt.number = true +opt.relativenumber = true +opt.conceallevel = 3 +opt.hidden = true +opt.expandtab = true +opt.tabstop = 4 +opt.softtabstop = 4 +opt.shiftwidth = 4 +opt.smartindent = true +opt.errorbells = false +opt.wrap = false +opt.swapfile = false +opt.undofile = true +opt.undodir = os.getenv "HOME" .. "/.cache/nvim/undodir" +opt.hlsearch = false +opt.incsearch = true +opt.ignorecase = true +opt.smartcase = true +opt.termguicolors = true +opt.scrolloff = 4 +opt.sidescrolloff = 4 +opt.showmode = false +opt.clipboard = "unnamedplus" +opt.splitbelow = true +opt.splitright = true +opt.autowrite = true +opt.list = true +opt.listchars = "tab:\\ ,trail:-" +opt.laststatus = 3 +opt.cmdheight = 1 +opt.updatetime = 50 +opt.signcolumn = "yes" +opt.equalalways = false +opt.splitkeep = "screen" +opt.shortmess = "filnxtToOFWIcC" + +require("lazyvim.util").get_root = vim.loop.cwd diff --git a/lua/config/usercmds.lua b/lua/config/usercmds.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/plugins/animation.lua b/lua/plugins/animation.lua new file mode 100644 index 0000000..871cc71 --- /dev/null +++ b/lua/plugins/animation.lua @@ -0,0 +1,11 @@ +return { + "anuvyklack/animation.nvim", + dependencies = { + "anuvyklack/middleclass", + }, + keys = { + {"aa", function () + require("alpha.animations").redraw_buffer() + end} + }, +} diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua new file mode 100644 index 0000000..245059f --- /dev/null +++ b/lua/plugins/autopairs.lua @@ -0,0 +1,5 @@ +return { + "windwp/nvim-autopairs", + lazy = true, + config = true, +} diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua new file mode 100644 index 0000000..2e3e819 --- /dev/null +++ b/lua/plugins/cmp.lua @@ -0,0 +1,75 @@ +return { + { + "L3MON4D3/LuaSnip", + keys = function() + return {} + end, + }, + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-emoji", + config = function() + local cmp = require("cmp") + + -- cmp.setup.cmdline(":", { + -- mapping = cmp.mapping.preset.cmdline(), + -- sources = cmp.config.sources({ + -- { name = "path" }, + -- }, { + -- { + -- name = "cmdline", + -- option = { + -- ignore_cmds = { "Man", "!" }, + -- }, + -- }, + -- }), + -- }) + + end, + }, + -- @param opts cmp.ConfigSchema + opts = function(_, opts) + local cmp = require("cmp") + + opts.preselect = cmp.PreselectMode.None + opts.completion = { + completeopt = "noselect", + } + + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local luasnip = require("luasnip") + + opts.mapping = vim.tbl_extend("force", opts.mapping, { + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- this way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }) + end, + }, +} diff --git a/lua/plugins/color-picker.lua b/lua/plugins/color-picker.lua new file mode 100644 index 0000000..1e6c88b --- /dev/null +++ b/lua/plugins/color-picker.lua @@ -0,0 +1,7 @@ +return { + "ziontee113/color-picker.nvim", + keys = { + { "", "PickColorInsert", mode = "i", desc = "ColorPicker" }, + }, + config = true, +} diff --git a/lua/plugins/colorize.lua b/lua/plugins/colorize.lua new file mode 100644 index 0000000..89d4039 --- /dev/null +++ b/lua/plugins/colorize.lua @@ -0,0 +1,5 @@ +return { + "norcalli/nvim-colorizer.lua", + event = "VeryLazy", + config = true, +} diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..9b11a2c --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,11 @@ +return { + "neanias/everforest-nvim", + lazy = false, + priority = 1000, + config = function() + vim.cmd.colorscheme "everforest" + vim.cmd "let g:everforest_better_performance = 1" + vim.cmd "let g:everforest_background = 'soft'" + vim.cmd "let g:airline_theme = 'everforest'" + end, +} diff --git a/lua/plugins/composer.lua b/lua/plugins/composer.lua new file mode 100644 index 0000000..f46406c --- /dev/null +++ b/lua/plugins/composer.lua @@ -0,0 +1,4 @@ +return { + "adalessa/composer.nvim", + lazy = true, +} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 0000000..ee103e6 --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,39 @@ +return { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + -- Customize or remove this keymap to your liking + "cf", + function() + require("conform").format({ async = true, lsp_fallback = true }) + end, + mode = "", + desc = "Format buffer", + }, + }, + -- Everything in opts will be passed to setup() + opts = { + -- Define your formatters + formatters_by_ft = { + lua = { "stylua" }, + python = { "isort", "black" }, + javascript = { { "prettierd", "prettier" } }, + php = { { "php-cs-fixer", "pretty-php" } }, + blade = { "blade-formatter" }, + }, + -- Set up format-on-save + format_on_save = { timeout_ms = 500, lsp_fallback = true }, + -- Customize formatters + formatters = { + shfmt = { + prepend_args = { "-i", "2" }, + }, + }, + }, + init = function() + -- If you want the formatexpr, here is the place to set it + vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + end, +} diff --git a/lua/plugins/dap.lua b/lua/plugins/dap.lua new file mode 100644 index 0000000..a6582a6 --- /dev/null +++ b/lua/plugins/dap.lua @@ -0,0 +1,31 @@ +return { + "mfussenegger/nvim-dap", + dependencies = { + "theHamsta/nvim-dap-virtual-text", + "rcarriga/nvim-dap-ui", + "leoluz/nvim-dap-go", + "mxsdev/nvim-dap-vscode-js", + "anuvyklack/hydra.nvim", + "nvim-telescope/telescope-dap.nvim", + "rcarriga/cmp-dap", + }, + keys = { { "d", desc = "Open Debug menu" } }, + config = function() + require "alpha.dap" + local ok_telescope, telescope = pcall(require, "telescope") + if ok_telescope then + telescope.load_extension "dap" + end + + local ok_cmp, cmp = pcall(require, "cmp") + if ok_cmp then + cmp.setup.filetype({ "dap-repl", "dapui_watches" }, { + sources = cmp.config.sources({ + { name = "dap" }, + }, { + { name = "buffer" }, + }), + }) + end + end, +} diff --git a/lua/plugins/deadcolumn.lua b/lua/plugins/deadcolumn.lua new file mode 100644 index 0000000..26457c2 --- /dev/null +++ b/lua/plugins/deadcolumn.lua @@ -0,0 +1,5 @@ +return { + "Bekaboo/deadcolumn.nvim", + enabled = false, + event = { "VeryLazy" }, +} diff --git a/lua/plugins/disabled.lua b/lua/plugins/disabled.lua new file mode 100644 index 0000000..fc746f8 --- /dev/null +++ b/lua/plugins/disabled.lua @@ -0,0 +1,8 @@ +return { + { "echasnovski/mini.indentscope", enabled = false }, + -- { "folke/noice.nvim", enabled = false }, + -- { "rcarriga/nvim-notify", enabled = false }, + { "folke/flash.nvim", enabled = false }, + { "ggandor/flit.nvim", enabled = false }, + -- { "ggandor/leap.nvim", enabled = false }, +} diff --git a/lua/plugins/dressing.lua b/lua/plugins/dressing.lua new file mode 100644 index 0000000..5cfb6cf --- /dev/null +++ b/lua/plugins/dressing.lua @@ -0,0 +1,160 @@ +return { + "stevearc/dressing.nvim", + event = "VeryLazy", + opts = { + input = { + -- Set to false to disable the vim.ui.input implementation + enabled = true, + + -- Default prompt string + default_prompt = "Input:", + + -- Can be 'left', 'right', or 'center' + prompt_align = "center", + + -- When true, will close the modal + insert_only = true, + + -- When true, input will start in insert mode. + start_in_insert = true, + + -- These are passed to nvim_open_win + -- anchor = "SW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "editor", + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + prefer_width = 40, + width = nil, + -- min_width and max_width can be a list of mixed types. + -- min_width = {20, 0.2} means "the greater of 20 columns or 20% of total" + max_width = { 140, 0.9 }, + min_width = { 20, 0.2 }, + win_options = { + -- Window transparency (0-100) + winblend = 10, + -- Disable line wrapping + wrap = false, + }, + + -- Set to `false` to disable + mappings = { + n = { + [""] = "Close", + [""] = "Confirm", + }, + i = { + [""] = "Close", + [""] = "Confirm", + [""] = "HistoryPrev", + [""] = "HistoryNext", + }, + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + + -- see :help dressing_get_config + get_config = nil, + }, + select = { + -- Set to false to disable the vim.ui.select implementation + enabled = false, + + -- Priority list of preferred vim.select implementations + backend = { "telescope", "fzf_lua", "fzf", "builtin", "nui" }, + + -- Trim trailing `:` from prompt + trim_prompt = true, + + -- Options for telescope selector + -- These are passed into the telescope picker directly. Can be used like: + -- telescope = require('telescope.themes').get_ivy({...}) + telescope = nil, + + -- Options for fzf selector + fzf = { + window = { + width = 0.5, + height = 0.4, + }, + }, + + -- Options for fzf_lua selector + fzf_lua = { + winopts = { + width = 0.5, + height = 0.4, + }, + }, + + -- Options for nui Menu + nui = { + position = "50%", + size = nil, + relative = "editor", + border = { + style = "rounded", + }, + buf_options = { + swapfile = false, + filetype = "DressingSelect", + }, + win_options = { + winblend = 10, + }, + max_width = 80, + max_height = 40, + min_width = 40, + min_height = 10, + }, + + -- Options for built-in selector + builtin = { + -- These are passed to nvim_open_win + -- anchor = "NW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "editor", + + win_options = { + -- Window transparency (0-100) + winblend = 10, + }, + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + -- the min_ and max_ options can be a list of mixed types. + -- max_width = {140, 0.8} means "the lesser of 140 columns or 80% of total" + width = nil, + max_width = { 140, 0.8 }, + min_width = { 40, 0.2 }, + height = nil, + max_height = 0.9, + min_height = { 10, 0.2 }, + + -- Set to `false` to disable + mappings = { + [""] = "Close", + [""] = "Close", + [""] = "Confirm", + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + }, + + -- Used to override format_item. See :help dressing-format + format_item_override = {}, + + -- see :help dressing_get_config + get_config = nil, + }, + }, +} diff --git a/lua/plugins/easy-align.lua b/lua/plugins/easy-align.lua new file mode 100644 index 0000000..7d33478 --- /dev/null +++ b/lua/plugins/easy-align.lua @@ -0,0 +1,4 @@ +return { + "junegunn/vim-easy-align", + keys = { { "ga", "(EasyAlign)", mode = { "n", "v" }, desc = "EasyAlign" } }, +} diff --git a/lua/plugins/fugitive.lua b/lua/plugins/fugitive.lua new file mode 100644 index 0000000..4698d40 --- /dev/null +++ b/lua/plugins/fugitive.lua @@ -0,0 +1,10 @@ +return { + "tpope/vim-fugitive", + keys = { + { "ga", ":Git fetch --all -p", desc = "Git fetch" }, + { "gl", ":Git pull", desc = "Git pull" }, + { "gdh", ":diffget //2", desc = "Git diff grab from left" }, + { "gdl", ":diffget //3", desc = "Git diff grab from right" }, + }, + cmd = { "G", "Git" }, +} diff --git a/lua/plugins/harpoon.lua b/lua/plugins/harpoon.lua new file mode 100644 index 0000000..5cc6047 --- /dev/null +++ b/lua/plugins/harpoon.lua @@ -0,0 +1,72 @@ +local keys = {} +local terms = 3 +local binds = 5 + +table.insert(keys, { + "ss", + function() + require("harpoon.ui").toggle_quick_menu() + end, + desc = "Harpoon Menu", +}) + +table.insert(keys, { + "sa", + function() + require("harpoon.mark").add_file() + end, + desc = "Harpoon Add file", +}) + +table.insert(keys, { + "st", + function() + vim.api.nvim_command([[vsplit]]) + require("harpoon.term").gotoTerminal(1) + vim.api.nvim_command([[startinsert]]) + end, + desc = "Harpoon quick split Terminal", +}) + +for i = 1, terms do + table.insert(keys, { + string.format("%s", i), + function() + require("harpoon.term").gotoTerminal(i) + end, + desc = "Harpoon go to terminal " .. i, + }) +end + +for i = 1, binds do + table.insert(keys, { + string.format("%s", i), + function() + require("harpoon.ui").nav_file(i) + end, + desc = "Harpoon go to file " .. i, + }) +end + +return { + "ThePrimeagen/harpoon", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-lua/popup.nvim", + }, + keys = keys, + opts = { + global_settings = { + enter_on_sendcmd = true, + }, + projects = { + ["$HOME/code/svelte/snippets"] = { + term = { + cmds = { + "npm run dev", + }, + }, + }, + }, + }, +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 0000000..0ee99f4 --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,15 @@ +return { + { + "jwalton512/vim-blade", + enabled = true, + }, + { + "tpope/vim-dispatch", + cmd = { "Make", "Dispatch" }, + }, + "tpope/vim-surround", + "tpope/vim-repeat", + "tpope/vim-rhubarb", + "tpope/vim-dotenv", + "tpope/vim-eunuch", +} diff --git a/lua/plugins/laravel.lua b/lua/plugins/laravel.lua new file mode 100644 index 0000000..b158221 --- /dev/null +++ b/lua/plugins/laravel.lua @@ -0,0 +1,45 @@ +return { + "adalessa/laravel.nvim", + dependencies = { + "rcarriga/nvim-notify", + "nvim-telescope/telescope.nvim", + "MunifTanjim/nui.nvim", + }, + cmd = { "Sail", "Artisan", "Composer", "Npm", "Laravel", "LaravelInfo", "DockerCompose" }, + keys = { + { "la", ":Laravel artisan", desc = "Laravel Application Commands" }, + { "lr", ":Laravel routes", desc = "Laravel Application Routes" }, + { + "lt", + function() + require("laravel.tinker").send_to_tinker() + end, + mode = "v", + desc = "Laravel Application Routes", + }, + }, + init = function() + vim.g.laravel_log_level = "debug" + end, + config = function() + local uid = vim.system({ "id", "-u" }, { text = true }):wait().stdout or "1000" + local gid = vim.system({ "id", "-g" }, { text = true }):wait().stdout or "1000" + + local user_arg = string.format("%s:%s", vim.trim(uid), vim.trim(gid)) + + require("laravel").setup { + route_info = { + position = "top", + }, + environment = { + environments = { + ["ao"] = require("laravel.environment.docker_compose").setup { + container_name = "panel-webserver", + cmd = { "docker", "compose", "exec", "-u", user_arg, "-it", "panel-webserver" }, + }, + }, + }, + } + require("telescope").load_extension "laravel" + end, +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..ada6845 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,28 @@ +return { + "neovim/nvim-lspconfig", + dependencies = { + -- "jose-elias-alvarez/null-ls.nvim", + { + "williamboman/mason.nvim", + opts = { + ui = { + border = "rounded", + }, + }, + }, + "folke/neodev.nvim", + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", + }, + event = "VeryLazy", + main = "alpha.lsp", + opts = { + mason = { + enable = true, + auto_install = false, + }, + servers = { + phpactor = { enable = true }, + }, + }, +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..3147f5a --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,51 @@ +return { + "nvim-lualine/lualine.nvim", + dependencies = { "kyazdani42/nvim-web-devicons" }, + config = function() + require("lualine").setup { + options = { + theme = "auto", + icons_enabled = true, + globalstatus = true, + }, + extensions = { "quickfix", "fugitive" }, + sections = { + lualine_a = { { "mode", upper = true } }, + lualine_b = { { "branch", icon = "" }, "db_ui#statusline" }, + lualine_c = { { "filename", file_status = true, path = 1 } }, + lualine_x = { + "diagnostics", + "diff", + { + require("noice").api.status.mode.get, + cond = require("noice").api.status.mode.has, + color = { fg = "#ff9e64" }, + }, + { + require("lazy.status").updates, + cond = require("lazy.status").has_updates, + color = { fg = "ff9e64" }, + }, + }, + lualine_y = { "filetype" }, + lualine_z = { "location" }, + }, + winbar = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + inactive_winbar = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + } + end, +} diff --git a/lua/plugins/markdown-preview.lua b/lua/plugins/markdown-preview.lua new file mode 100644 index 0000000..15f57ce --- /dev/null +++ b/lua/plugins/markdown-preview.lua @@ -0,0 +1,8 @@ +return { + "adalessa/markdown-preview.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = true, + ft = "markdown", +} diff --git a/lua/plugins/mason.lua b/lua/plugins/mason.lua new file mode 100644 index 0000000..a791aa2 --- /dev/null +++ b/lua/plugins/mason.lua @@ -0,0 +1,8 @@ +return { + { + "williamboman/mason.nvim", + opts = function(_, opts) + -- table.insert(opts.ensure_installed, "google-java-format") + end, + }, +} diff --git a/lua/plugins/neo-tree.lua b/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..ca69803 --- /dev/null +++ b/lua/plugins/neo-tree.lua @@ -0,0 +1,254 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + reqrires = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + { + -- only needed if you want to use the commands with "_with_window_picker" suffix + 's1n7ax/nvim-window-picker', + tag = "v1.*", + config = function() + require 'window-picker'.setup({ + autoselect_one = true, + include_current = false, + filter_rules = { + -- filter using buffer options + bo = { + -- if the file type is one of following, the window will be ignored + filetype = { 'neo-tree', "neo-tree-popup", "notify" }, + + -- if the buffer type is one of following, the window will be ignored + buftype = { 'terminal', "quickfix" }, + }, + }, + other_win_hl_color = '#e35e4f', + }) + end, + } + }, + config = function() + -- Unless you are still migrating, remove the deprecated commands from v1.x + vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) + + -- If you want icons for diagnostic errors, you'll need to define them somewhere: + vim.fn.sign_define("DiagnosticSignError", + { text = " ", texthl = "DiagnosticSignError" }) + vim.fn.sign_define("DiagnosticSignWarn", + { text = " ", texthl = "DiagnosticSignWarn" }) + vim.fn.sign_define("DiagnosticSignInfo", + { text = " ", texthl = "DiagnosticSignInfo" }) + vim.fn.sign_define("DiagnosticSignHint", + { text = "", texthl = "DiagnosticSignHint" }) + -- NOTE: this is changed from v1.x, which used the old style of highlight groups + -- in the form "LspDiagnosticsSignWarning" + + require("neo-tree").setup({ + close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab + popup_border_style = "rounded", + enable_git_status = true, + enable_diagnostics = true, + sort_case_insensitive = false, -- used when sorting files and directories in the tree + sort_function = nil, -- use a custom function for sorting files and directories in the tree + -- sort_function = function (a,b) + -- if a.type == b.type then + -- return a.path > b.path + -- else + -- return a.type > b.type + -- end + -- end , -- this sorts files and directories descendantly + default_component_configs = { + container = { + enable_character_fade = true + }, + indent = { + indent_size = 2, + padding = 1, -- extra padding on left hand side + -- indent guides + with_markers = true, + indent_marker = "│", + last_indent_marker = "└", + highlight = "NeoTreeIndentMarker", + -- expander config, needed for nesting files + with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", + }, + icon = { + folder_closed = "", + folder_open = "", + folder_empty = "ﰊ", + -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there + -- then these will never be used. + default = "*", + highlight = "NeoTreeFileIcon" + }, + modified = { + symbol = "[+]", + highlight = "NeoTreeModified", + }, + name = { + trailing_slash = false, + use_git_status_colors = true, + highlight = "NeoTreeFileName", + }, + git_status = { + symbols = { + -- Change type + added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name + modified = "", -- or "", but this is redundant info if you use git_status_colors on the name + deleted = "✖", -- this can only be used in the git_status source + renamed = "", -- this can only be used in the git_status source + -- Status type + untracked = "", + ignored = "", + unstaged = "", + staged = "", + conflict = "", + } + }, + }, + window = { + position = "left", + width = 40, + mapping_options = { + noremap = true, + nowait = true, + }, + mappings = { + [""] = { + "toggle_node", + nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use + }, + ["<2-LeftMouse>"] = "open", + [""] = "open", + [""] = "revert_preview", + ["P"] = { "toggle_preview", config = { use_float = true } }, + ["l"] = "focus_preview", + ["S"] = "open_split", + ["s"] = "open_vsplit", + -- ["S"] = "split_with_window_picker", + -- ["s"] = "vsplit_with_window_picker", + ["t"] = "open_tabnew", + -- [""] = "open_drop", + -- ["t"] = "open_tab_drop", + ["w"] = "open_with_window_picker", + --["P"] = "toggle_preview", -- enter preview mode, which shows the current node without focusing + ["C"] = "close_node", + -- ['C'] = 'close_all_subnodes', + ["z"] = "close_all_nodes", + --["Z"] = "expand_all_nodes", + ["a"] = { + "add", + -- this command supports BASH style brace expansion ("x{a,b,c}" -> xa,xb,xc). see `:h neo-tree-file-actions` for details + -- some commands may take optional config options, see `:h neo-tree-mappings` for details + config = { + show_path = "none" -- "none", "relative", "absolute" + } + }, + ["A"] = "add_directory", -- also accepts the optional config.show_path option like "add". this also supports BASH style brace expansion. + ["d"] = "delete", + ["r"] = "rename", + ["y"] = "copy_to_clipboard", + ["x"] = "cut_to_clipboard", + ["p"] = "paste_from_clipboard", + ["c"] = "copy", -- takes text input for destination, also accepts the optional config.show_path option like "add": + -- ["c"] = { + -- "copy", + -- config = { + -- show_path = "none" -- "none", "relative", "absolute" + -- } + --} + ["m"] = "move", -- takes text input for destination, also accepts the optional config.show_path option like "add". + ["q"] = "close_window", + ["R"] = "refresh", + ["?"] = "show_help", + ["<"] = "prev_source", + [">"] = "next_source", + } + }, + nesting_rules = {}, + filesystem = { + filtered_items = { + visible = false, -- when true, they will just be displayed differently than normal items + hide_dotfiles = true, + hide_gitignored = true, + hide_hidden = true, -- only works on Windows for hidden files/directories + hide_by_name = { + --"node_modules" + }, + hide_by_pattern = { -- uses glob style patterns + --"*.meta", + --"*/src/*/tsconfig.json", + }, + always_show = { -- remains visible even if other settings would normally hide it + --".gitignored", + }, + never_show = { -- remains hidden even if visible is toggled to true, this overrides always_show + --".DS_Store", + --"thumbs.db" + }, + never_show_by_pattern = { -- uses glob style patterns + --".null-ls_*", + }, + }, + follow_current_file = false, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = false, -- when true, empty folders will be grouped together + hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree + -- in whatever position is specified in window.position + -- "open_current", -- netrw disabled, opening a directory opens within the + -- window like netrw would, regardless of window.position + -- "disabled", -- netrw left alone, neo-tree does not handle opening dirs + use_libuv_file_watcher = false, -- This will use the OS level file watchers to detect changes + -- instead of relying on nvim autocmd events. + window = { + mappings = { + [""] = "navigate_up", + ["."] = "set_root", + ["H"] = "toggle_hidden", + ["/"] = "fuzzy_finder", + ["D"] = "fuzzy_finder_directory", + ["#"] = "fuzzy_sorter", -- fuzzy sorting using the fzy algorithm + -- ["D"] = "fuzzy_sorter_directory", + ["f"] = "filter_on_submit", + [""] = "clear_filter", + ["[g"] = "prev_git_modified", + ["]g"] = "next_git_modified", + } + } + }, + buffers = { + follow_current_file = true, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = true, -- when true, empty folders will be grouped together + show_unloaded = true, + window = { + mappings = { + ["bd"] = "buffer_delete", + [""] = "navigate_up", + ["."] = "set_root", + } + }, + }, + git_status = { + window = { + position = "float", + mappings = { + ["A"] = "git_add_all", + ["gu"] = "git_unstage_file", + ["ga"] = "git_add_file", + ["gr"] = "git_revert_file", + ["gc"] = "git_commit", + ["gp"] = "git_push", + ["gg"] = "git_commit_and_push", + } + } + } + }) + + vim.cmd([[nnoremap \ :Neotree reveal]]) + end +} diff --git a/lua/plugins/neocolumn.lua b/lua/plugins/neocolumn.lua new file mode 100644 index 0000000..f02b5b5 --- /dev/null +++ b/lua/plugins/neocolumn.lua @@ -0,0 +1,5 @@ +return { + "ecthelionvi/NeoColumn.nvim", + opts = {}, + cmd = { "ToggleNeoColumn" }, +} diff --git a/lua/plugins/neogen.lua b/lua/plugins/neogen.lua new file mode 100644 index 0000000..6b234ae --- /dev/null +++ b/lua/plugins/neogen.lua @@ -0,0 +1,7 @@ +return { + "danymat/neogen", + dependencies = "nvim-treesitter/nvim-treesitter", + cmd = { "Neogen" }, + keys = { { "n", ":Neogen", desc = "Add comment to the near possible object" } }, + opts = { snippet_engine = "luasnip" }, +} diff --git a/lua/plugins/neorg.lua b/lua/plugins/neorg.lua new file mode 100644 index 0000000..bf27994 --- /dev/null +++ b/lua/plugins/neorg.lua @@ -0,0 +1,22 @@ +return { + "nvim-neorg/neorg", + build = ":Neorg sync-parsers", + cmd = { "Neorg" }, + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + require("neorg").setup { + load = { + ["core.defaults"] = {}, -- Loads default behaviour + ["core.concealer"] = {}, -- Adds pretty icons to your documents + ["core.dirman"] = { -- Manages Neorg workspaces + config = { + workspaces = { + notes = "~/notes", + }, + default_workspace = "notes", + }, + }, + }, + } + end, +} diff --git a/lua/plugins/neotest.lua b/lua/plugins/neotest.lua new file mode 100644 index 0000000..09e99b0 --- /dev/null +++ b/lua/plugins/neotest.lua @@ -0,0 +1,66 @@ +return { + "nvim-neotest/neotest", + enabled = true, + keys = { { "", desc = "Open Test menu" } }, + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "antoinemadec/FixCursorHold.nvim", + "nvim-neotest/neotest-go", + "rouge8/neotest-rust", + "nvim-neotest/neotest-plenary", + "nvim-neotest/neotest-vim-test", + "anuvyklack/hydra.nvim", + }, + config = function() + local neotest = require "neotest" + neotest.setup { + adapters = { + require "neotest-go", + require "neotest-rust", + require "neotest-plenary", + -- require "neotest-vim-test" { + -- ignore_file_types = { "go", "lua", "rust", "php" }, + -- }, + -- require("laravel.neotest"), + }, + library = { plugins = { "neotest" }, types = true }, + } + + local hydra = require "hydra" + + local hint = [[ + NeoTest + _n_: Near test _f_: Current file _l_: Last Test _m_: Run Marked _s_: Toggle Summary ^ + ^ ^ __ + ]] + + hydra { + name = "neotest", + hint = hint, + mode = "n", + config = { + color = "teal", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "", + heads = { + { "n", neotest.run.run }, + { + "f", + function() + neotest.run.run(vim.fn.expand "%") + end, + }, + { "l", neotest.run.run_last }, + { "m", neotest.summary.run_marked }, + { "s", neotest.summary.toggle }, + { "", nil, { exit = true } }, + }, + } + end, +} diff --git a/lua/plugins/noice.lua b/lua/plugins/noice.lua new file mode 100644 index 0000000..70e81e9 --- /dev/null +++ b/lua/plugins/noice.lua @@ -0,0 +1,112 @@ +return { + "folke/noice.nvim", + dependencies = { + "MunifTanjim/nui.nvim", + }, + event = "VeryLazy", + opts = { + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true, + }, + }, + -- -- you can enable a preset for easier configuration + presets = { + bottom_search = true, -- use a classic bottom cmdline for search + -- command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + -- inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = true, -- add a border to hover docs and signature help + }, + cmdline = { + view = "cmdline", + }, + messages = { + enabled = true, -- enables the Noice messages UI + view = "notify", -- default view for messages + view_error = "notify", -- view for errors + view_warn = "notify", -- view for warnings + view_history = "messages", -- view for :messages + view_search = false, -- view for search count messages. Set to `false` to disable + }, + routes = { + { + view = "split", + filter = { + cmdline = "G", + }, + opts = { + enter = true, + render = "plain", + format = { "{message}" }, + replace = true, + close = { + events = { "BufLeave" }, + keys = { "q" }, + }, + }, + }, + { + view = "split", + filter = { + cmdline = "Notifications", + }, + opts = { + enter = true, + render = "plain", + format = { "{message}" }, + replace = true, + close = { + events = { "BufLeave" }, + keys = { "q" }, + }, + }, + }, + { + view = "mini", + filter = { + cmdline = "w", + }, + }, + { + view = "mini", + filter = { + find = "Config Change Detected. Reloading...", + }, + }, + { + view = "mini", + filter = { + any = { + { + event = "msg_show", + find = "lines yanked", + }, + { + event = "msg_show", + find = "more lines", + }, + { + event = "msg_show", + find = "direnv:", + }, + { + find = "laravel.sail.", + }, + { + find = "Pattern not found", + }, + { + event = "msg_show", + kind = "", + find = "change;", + }, + }, + }, + }, + }, + }, +} diff --git a/lua/plugins/notify.lua b/lua/plugins/notify.lua new file mode 100644 index 0000000..97f6d1f --- /dev/null +++ b/lua/plugins/notify.lua @@ -0,0 +1,10 @@ +return { + "rcarriga/nvim-notify", + config = function() + local notify = require "notify" + -- this for transparency + notify.setup { background_colour = "#000000" } + -- this overwrites the vim notify function + vim.notify = notify.notify + end, +} diff --git a/lua/plugins/numb.lua b/lua/plugins/numb.lua new file mode 100644 index 0000000..3758657 --- /dev/null +++ b/lua/plugins/numb.lua @@ -0,0 +1,4 @@ +return { + "nacro90/numb.nvim", + config = true, +} diff --git a/lua/plugins/orgmode.lua b/lua/plugins/orgmode.lua new file mode 100644 index 0000000..e9f8667 --- /dev/null +++ b/lua/plugins/orgmode.lua @@ -0,0 +1,17 @@ +return { + "nvim-orgmode/orgmode", + enabled = false, + keys = { + { "oa" }, + { "oc" }, + }, + ft = { "org" }, + config = function() + require("orgmode").setup_ts_grammar() + require("orgmode").setup { + org_agenda_files = { "~/my-orgs/**/*" }, + org_default_notes_file = "~/my-orgs/refile.org", + } + require("cmp").setup { sources = { { name = "orgmode" } } } + end, +} diff --git a/lua/plugins/others.lua b/lua/plugins/others.lua new file mode 100644 index 0000000..b57bb77 --- /dev/null +++ b/lua/plugins/others.lua @@ -0,0 +1,46 @@ +return { + { + -- "tigion/nvim-asciidoc-preview", + -- ft = { "asciidoc" }, + -- opts = {}, + }, + { + "windwp/nvim-autopairs", + event = "InsertEnter", + opts = {}, -- this is equalent to setup({}) function + }, + { "isobit/vim-caddyfile" }, + -- { -- maybe https://github.com/0x00-ketsu/autosave.nvim + -- "0x00-ketsu/autosave.nvim", + -- opts = {}, + -- }, + { + "Wansmer/treesj", + keys = { + { "j", "TSJToggle", desc = "Join Toggle" }, + }, + opts = { use_default_keymaps = false, max_join_length = 150 }, + }, + { + "s1n7ax/nvim-window-picker", + name = "window-picker", + event = "VeryLazy", + version = "2.*", + config = function() + require("window-picker").setup() + end, + }, + { "slim-template/vim-slim" }, + { "tpope/vim-rails" }, + -- use 'slim-template/vim-slim' + { "dhruvasagar/vim-table-mode" }, + { "tree-sitter/tree-sitter-embedded-template" }, + { "RRethy/nvim-treesitter-endwise" }, + { "dyng/ctrlsf.vim" }, + { + "kylechui/nvim-surround", + version = "*", -- Use for stability; omit to use `main` branch for the latest features + event = "VeryLazy", + opts = {}, + }, +} diff --git a/lua/plugins/php.lua b/lua/plugins/php.lua new file mode 100644 index 0000000..541eec2 --- /dev/null +++ b/lua/plugins/php.lua @@ -0,0 +1,90 @@ +return { -- lazy + -- "ccaglak/namespace.nvim", + -- dependencies = { + -- "nvim-lua/plenary.nvim", + -- }, + "ludovicchabant/vim-gutentags", + config = function() + -- https://www.reddit.com/r/vim/comments/d77t6j/guide_how_to_setup_ctags_with_gutentags_properly/ + vim.g.gutentags_ctags_exclude = { + "*.git", + "*.svg", + "*.hg", + "*/tests/*", + "build", + "dist", + "*sites/*/files/*", + "bin", + "node_modules", + "bower_components", + "cache", + "compiled", + "docs", + "example", + "bundle", + "vendor", + "*.md", + "*-lock.json", + "*.lock", + "*bundle*.js", + "*build*.js", + ".*rc*", + "*.json", + "*.min.*", + "*.map", + "*.bak", + "*.zip", + "*.pyc", + "*.class", + "*.sln", + "*.Master", + "*.csproj", + "*.tmp", + "*.csproj.user", + "*.cache", + "*.pdb", + "tags*", + "cscope.*", + -- '*.css', + -- '*.less', + -- '*.scss', + "*.exe", + "*.dll", + "*.mp3", + "*.ogg", + "*.flac", + "*.swp", + "*.swo", + "*.bmp", + "*.gif", + "*.ico", + "*.jpg", + "*.png", + "*.rar", + "*.zip", + "*.tar", + "*.tar.gz", + "*.tar.xz", + "*.tar.bz2", + "*.pdf", + "*.doc", + "*.docx", + "*.ppt", + "*.pptx", + } + + vim.g.gutentags_add_default_project_roots = false + vim.g.gutentags_project_root = { "package.json", ".git" } + vim.g.gutentags_cache_dir = vim.fn.stdpath("data") .. "/ctags" + vim.g.gutentags_generate_on_new = true + vim.g.gutentags_generate_on_missing = true + vim.g.gutentags_generate_on_write = true + vim.g.gutentags_generate_on_empty_buffer = true + vim.g.gutentags_modules = true + vim.cmd([[command! -nargs=0 GutentagsClearCache call system('rm ' . g:gutentags_cache_dir . '/*')]]) + vim.g.gutentags_ctags_extra_args = { "--tag-relative=yes", "--fields=+ailmnS" } + + -- custom + vim.g.gutentags_modules = { "ctags" } + end, +} diff --git a/lua/plugins/phpactor.lua b/lua/plugins/phpactor.lua new file mode 100644 index 0000000..1c636e1 --- /dev/null +++ b/lua/plugins/phpactor.lua @@ -0,0 +1,61 @@ +local phpactor = function () + vim.ui.select({ + "class_inflect", + "context_menu", + "expand_class", + "generate_accessor", + "change_visibility", + "copy_class", + "import_class", + "import_missing_classes", + "move_class", + "navigate", + "new_class", + "transform", + "update", + "config", + "status", + "cache_clear", + }, { + prompt = "Phpactor Action", + }, function(choice) + if choice == nil or choice == "" then + return + end + + -- TODO: add option for new class in same directory + if choice == "new_class" then + return vim.ui.input({ + prompt = "New Class", + }, function(value) + if value == nil then + return + end + -- TODO: check filename generation to validate the path + require("phpactor").rpc("new_class", { text_value = vim.fn.getcwd() .. '/' .. value .. ".php" }) + end) + end + + require("phpactor").rpc(choice, {}) + end) +end + +return { + "adalessa/phpactor.nvim", + cmd = { "PhpActor" }, + keys = { + { "pa", phpactor, desc = "PhpActor options" }, + { "pc", ":PhpActor context_menu", desc = "PhpActor context menu" }, + }, + dependencies = { + "nvim-lua/plenary.nvim", + }, + opts = { + install = { + bin = 'phpactor' + }, + lspconfig = { + enabled = true, + }, + }, +} diff --git a/lua/plugins/project-config.lua b/lua/plugins/project-config.lua new file mode 100644 index 0000000..ffa32f1 --- /dev/null +++ b/lua/plugins/project-config.lua @@ -0,0 +1,5 @@ +return { + "windwp/nvim-projectconfig", + enabled = false, + config = true, +} diff --git a/lua/plugins/refactoring.lua b/lua/plugins/refactoring.lua new file mode 100644 index 0000000..92cdf64 --- /dev/null +++ b/lua/plugins/refactoring.lua @@ -0,0 +1,21 @@ +return { + "ThePrimeagen/refactoring.nvim", + dependencies = { + { "nvim-lua/plenary.nvim" }, + { "nvim-treesitter/nvim-treesitter" }, + }, + keys = { + { + "rr", + function() + require("telescope").extensions.refactoring.refactors() + end, + mode = { "n", "v" }, + desc = "Refactoring menu", + }, + }, + config = function() + require("refactoring").setup {} + require("telescope").load_extension "refactoring" + end, +} diff --git a/lua/plugins/smart-splits.lua b/lua/plugins/smart-splits.lua new file mode 100644 index 0000000..57faedb --- /dev/null +++ b/lua/plugins/smart-splits.lua @@ -0,0 +1,34 @@ +return { + "mrjones2014/smart-splits.nvim", + config = true, + keys = { + { + "", + function() + require("smart-splits").resize_left() + end, + desc = "Resize window left +10", + }, + { + "", + function() + require("smart-splits").resize_down() + end, + desc = "Resize window down +10", + }, + { + "", + function() + require("smart-splits").resize_up() + end, + desc = "Resize window up +10", + }, + { + "", + function() + require("smart-splits").resize_right() + end, + desc = "Resize window right +10", + }, + }, +} diff --git a/lua/plugins/smooth-cursor.lua b/lua/plugins/smooth-cursor.lua new file mode 100644 index 0000000..71fe431 --- /dev/null +++ b/lua/plugins/smooth-cursor.lua @@ -0,0 +1,32 @@ +return { + "gen740/SmoothCursor.nvim", + config = function() + require("smoothcursor").setup { cursor = "󰀫" } + + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#8a9baa" }) + + local autocmd = vim.api.nvim_create_autocmd + + autocmd({ "ModeChanged" }, { + callback = function() + local current_mode = vim.fn.mode() + if current_mode == "n" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#8a9baa" }) + vim.fn.sign_define("smoothcursor", { text = "󰀫" }) + elseif current_mode == "v" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#bf616a" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "V" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#bf616a" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "\22" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#bf616a" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "i" then + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = "#668aab" }) + vim.fn.sign_define("smoothcursor", { text = "" }) + end + end, + }) + end, +} diff --git a/lua/plugins/snippets.luaBack b/lua/plugins/snippets.luaBack new file mode 100644 index 0000000..48c93b8 --- /dev/null +++ b/lua/plugins/snippets.luaBack @@ -0,0 +1,138 @@ +local config = function() + if vim.g.snippets ~= "luasnip" then + return + end + + local ls = require "luasnip" + local types = require "luasnip.util.types" + + ls.config.set_config { + -- This tells LuaSnip to remember to keep around the last snippet. + -- You can jump back into even if you move outside of the selection + history = true, + + -- This one is cool cause if you have dynamic snippets, it updatesas you type! + updateevents = "TextChanged,TextChangedI", + + -- Autosnippets: + enable_autosnippets = true, + + ext_opts = { + [types.choiceNode] = { + active = { + virt_text = { { "<- Choice", "Error" } }, + }, + }, + }, + } + + -- create snippet + -- s(context, nodes, condition, ...) + local snippet = ls.s + + -- TODO: Write about this. + -- Useful for dynamic nodes and choice nodes + -- local snippet_from_nodes = ls.sn + + -- This is the simplest node. + -- Creates a new text node. Places cursor after node by default. + -- t { "this will be inserted" } + -- + -- Multiple lines are by passing a table of strings. + -- t { "line 1", "line 2" } + local t = ls.text_node + + -- Insert Node + -- Creates a location for the cursor to jump to. + -- Possible options to jump to are 1 - N + -- If you use 0, that's the final place to jump to. + -- + -- To create placeholder text, pass it as the second argument + -- i(2, "this is placeholder text") + local i = ls.insert_node + + -- Function Node + -- Takes a function that returns text + -- local f = ls.function_node + + -- This a choice snippet. You can move through with (in my config) + -- c(1, { t {"hello"}, t {"world"}, }), + -- + -- The first argument is the jump position + -- The second argument is a table of possible nodes. + -- Note, one thing that's nice is you don't have to include + -- the jump position for nodes that normally require one (can be nil) + -- local c = ls.choice_node + + -- local d = ls.dynamic_node + + -- TODO: Document what I've learned about lambda + -- local l = require("luasnip.extras").lambda + + -- local events = require("luasnip.util.events") + + local shortcut = function(val) + if type(val) == "string" then + return { t { val }, i(0) } + end + + if type(val) == "table" then + for k, v in ipairs(val) do + if type(v) == "string" then + val[k] = t { v } + end + end + end + + return val + end + + local make = function(tbl) + local result = {} + for k, v in pairs(tbl) do + table.insert(result, (snippet({ trig = k, desc = v.desc }, shortcut(v)))) + end + + return result + end + + ls.cleanup() + for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/alpha/snips/ft/*.lua", true)) do + local ft = vim.fn.fnamemodify(ft_path, ":t:r") + ls.add_snippets(ft, make(loadfile(ft_path)())) + end + + -- is my expansion key + -- this will expand the current item or jump to the next item within the snippet. + vim.keymap.set({ "i", "s" }, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end, { silent = true }) + + -- is my jump backwards key. + -- this always moves to the previous item within the snippet + vim.keymap.set({ "i", "s" }, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end + end, { silent = true }) + + -- is selecting within a list of options. + -- This is useful for choice nodes (introduced in the forthcoming episode 2) + vim.keymap.set("i", "", function() + if ls.choice_active() then + ls.change_choice(1) + end + end) +end + +return { + "L3MON4D3/LuaSnip", + version = "v1.*", + event = "VeryLazy", + config = function() + config() + vim.keymap.set("n", "s", config, { desc = "Reload snippets" }) + end, +} diff --git a/lua/plugins/spectre.lua b/lua/plugins/spectre.lua new file mode 100644 index 0000000..7510c7a --- /dev/null +++ b/lua/plugins/spectre.lua @@ -0,0 +1,5 @@ +return { + "nvim-pack/nvim-spectre", + keys = { { "F", ":Spectre", desc = "Spectre Search open" } }, + config = true, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..4f5b59d --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,33 @@ +return { + "nvim-telescope/telescope.nvim", + dependencies = { + { "nvim-lua/plenary.nvim" }, + { "nvim-lua/popup.nvim" }, + { "nvim-telescope/telescope-fzy-native.nvim" }, + { "kyazdani42/nvim-web-devicons" }, + { "nvim-telescope/telescope-file-browser.nvim" }, + { "nvim-telescope/telescope-ui-select.nvim" }, + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + dependencies = { + "junegunn/fzf.vim", + dependencies = { + { + "tpope/vim-dispatch", + cmd = { "Make", "Dispatch" }, + }, + { + "junegunn/fzf", + build = ":call fzf#install()", + } + }, + }, + }, + }, + event = "VeryLazy", + config = function() + require "alpha.telescope.setup" + require "alpha.telescope.mappings" + end, +} diff --git a/lua/plugins/test.lua b/lua/plugins/test.lua new file mode 100644 index 0000000..5c8c218 --- /dev/null +++ b/lua/plugins/test.lua @@ -0,0 +1,54 @@ +return { + "vim-test/vim-test", + keys = { { "t", desc = "Open Test menu" } }, + dependencies = { + "anuvyklack/hydra.nvim", + }, + init = function() + vim.g["test#strategy"] = "harpoon" + vim.g["test#neovim#term_position"] = "vert" + vim.g["test#harpoon_term"] = 1 + vim.g["test#preserve_screen"] = 0 + vim.g["test#harpoon#gototerminal"] = 0 + vim.g["test#php#pest#executable"] = "./vendor/bin/sail test" + + local function dockerComposeTransform(cmd) + local uid = vim.fn.system("id -u"):gsub("%s*$", "") + local gid = vim.fn.system("id -g"):gsub("%s*$", "") + return string.format("docker compose exec -u %s:%s php-fpm %s", uid, gid, cmd) + end + + vim.g["test#php#behat#executable"] = "bin/behat --colors" + vim.g["test#custom_transformations"] = { docker = dockerComposeTransform } + end, + config = function() + local behat_paths = { + "tests/Functional/Context/**/*.php", + "tests/Behat/Context/*.php", + "tests/Behat/**/*.php", + "src/Behat/**/*.php", + } + + for _, path in ipairs(behat_paths) do + if vim.fn.glob(path) ~= "" then + vim.g["test#php#behat#bootstrap_directory"] = path + vim.g["test#transformation"] = "docker" + + -- many of my projects have variables necessaries so this is required + local env_vars = vim.fn.system "make vars" + for _, env_var in ipairs(vim.split(env_vars, "\n")) do + if env_var ~= "" then + env_var = env_var:gsub("^export ", "") + local key, value = unpack(vim.split(env_var, "=")) + vim.fn.setenv(key, value) + end + end + break + end + end + + require "alpha.test_strategy" + + require "alpha.test_menu" + end, +} diff --git a/lua/plugins/text-object.lua b/lua/plugins/text-object.lua new file mode 100644 index 0000000..844cf19 --- /dev/null +++ b/lua/plugins/text-object.lua @@ -0,0 +1,8 @@ +return { + "chrisgrieser/nvim-various-textobjs", + enabled = false, + event = "VeryLazy", + config = function () + require("various-textobjs").setup({ useDefaultKeymaps = true }) + end, +} diff --git a/lua/plugins/transparent.lua b/lua/plugins/transparent.lua new file mode 100644 index 0000000..e8a6939 --- /dev/null +++ b/lua/plugins/transparent.lua @@ -0,0 +1,5 @@ +return { + "xiyaowong/nvim-transparent", + lazy = false, + config = true, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..937346c --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,99 @@ +-- return { +-- { +-- "nvim-treesitter/nvim-treesitter", +-- opts = { +-- endwise = { +-- enable = true, +-- }, +-- }, +-- }, +-- } +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + }, + event = "VeryLazy", + main = "nvim-treesitter.configs", + opts = { + ensure_installed = { + "c", + "lua", + "rust", + "bash", + "blade", + "css", + "go", + "gomod", + "html", + "javascript", + "json", + "lua", + "luadoc", + "markdown", + "markdown_inline", + "nix", + "org", + "php", + "phpdoc", + "query", + "rust", + "sql", + "svelte", + "typescript", + "regex", + "vim", + "yaml", + }, + highlight = { + enable = true, + additional_vim_regex_highlighting = { "org" }, + }, + indent = { + enable = true, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@conditional.outer", + ["ic"] = "@conditional.inner", + ["al"] = "@loop.outer", + ["il"] = "@loop.inner", + }, + }, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + }, + }, + }, + config = function(plug, config) + local parser_config = require "nvim-treesitter.parsers".get_parser_configs() + parser_config.blade = { + install_info = { + url = "https://github.com/EmranMR/tree-sitter-blade", + files = {"src/parser.c"}, + branch = "main", + }, + filetype = "blade" + } + + vim.filetype.add({ + pattern = { + ['.*%.blade%.php'] = 'blade', + } + }) + + require(plug.main).setup(config); + end, +} diff --git a/lua/plugins/trouble.lua b/lua/plugins/trouble.lua new file mode 100644 index 0000000..5a87f26 --- /dev/null +++ b/lua/plugins/trouble.lua @@ -0,0 +1,7 @@ +return { + "folke/trouble.nvim", + enabled = true, + dependencies = "kyazdani42/nvim-web-devicons", + keys = { { "t", "TroubleToggle", desc = "Trouble toggle" } }, + config = true, +} diff --git a/lua/plugins/twilight.lua b/lua/plugins/twilight.lua new file mode 100644 index 0000000..144111f --- /dev/null +++ b/lua/plugins/twilight.lua @@ -0,0 +1,5 @@ +return { + "folke/twilight.nvim", + cmd = { "Twilight" }, + config = true, +} diff --git a/lua/plugins/worktree.lua b/lua/plugins/worktree.lua new file mode 100644 index 0000000..9e74a9c --- /dev/null +++ b/lua/plugins/worktree.lua @@ -0,0 +1,23 @@ +return { + "ThePrimeagen/git-worktree.nvim", + keys = { + { + "gt", + function() + require("telescope").extensions.git_worktree.git_worktrees() + end, + desc = "Git Worktree switch", + }, + { + "gn", + function() + require("telescope").extensions.git_worktree.create_git_worktree() + end, + desc = "Git Worktree new branch", + }, + }, + config = function() + require("git-worktree").setup {} + require("telescope").load_extension "git_worktree" + end, +} diff --git a/lua/scratchs/.gitkeep b/lua/scratchs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/queries/php/highlights.scm b/queries/php/highlights.scm new file mode 100644 index 0000000..85ddc08 --- /dev/null +++ b/queries/php/highlights.scm @@ -0,0 +1,7 @@ +;; extends + +[ + "readonly" +] @keyword.function + +(declare_directive) @constant diff --git a/queries/php/injections.scm b/queries/php/injections.scm new file mode 100644 index 0000000..365bcf5 --- /dev/null +++ b/queries/php/injections.scm @@ -0,0 +1,14 @@ +;; extends +(function_call_expression + ( + (name) @_function (#eq? @_function "json_decode") + (arguments (argument (string (string_value) @json ))) + ) +) + +(function_call_expression + ( + (name) @_function (#eq? @_function "render") + (arguments (argument (nowdoc (nowdoc_body) @html ))) + ) +) diff --git a/queries/phpdoc/highlights.scm b/queries/phpdoc/highlights.scm new file mode 100644 index 0000000..ff014dc --- /dev/null +++ b/queries/phpdoc/highlights.scm @@ -0,0 +1,10 @@ +;;extends + +(tag + (type_list + (named_type + (name) @typeName (#eq? @typeName "Promise") + ) + ) + (description) @type +) diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add new file mode 100644 index 0000000..9f90bf1 --- /dev/null +++ b/spell/en.utf-8.add @@ -0,0 +1,11 @@ +carin +Treesitter +Neovim +Laravel +adalessa +laravel +nvim +cr +lua +async +GraphQL diff --git a/spell/en.utf-8.add.spl b/spell/en.utf-8.add.spl new file mode 100644 index 0000000..cfc4479 Binary files /dev/null and b/spell/en.utf-8.add.spl differ diff --git a/spell/es.latin1.spl b/spell/es.latin1.spl new file mode 100644 index 0000000..291460b Binary files /dev/null and b/spell/es.latin1.spl differ diff --git a/spell/es.latin1.sug b/spell/es.latin1.sug new file mode 100644 index 0000000..fd26034 Binary files /dev/null and b/spell/es.latin1.sug differ diff --git a/spell/es.utf-8.add b/spell/es.utf-8.add new file mode 100644 index 0000000..8c80cee --- /dev/null +++ b/spell/es.utf-8.add @@ -0,0 +1,4 @@ +plugin +neovim +plugins +Lua diff --git a/spell/es.utf-8.add.spl b/spell/es.utf-8.add.spl new file mode 100644 index 0000000..ebcf32b Binary files /dev/null and b/spell/es.utf-8.add.spl differ diff --git a/spell/es.utf-8.spl b/spell/es.utf-8.spl new file mode 100644 index 0000000..505c4d3 Binary files /dev/null and b/spell/es.utf-8.spl differ diff --git a/spell/es.utf-8.sug b/spell/es.utf-8.sug new file mode 100644 index 0000000..6c65c5f Binary files /dev/null and b/spell/es.utf-8.sug differ