From aa2db01a928c58817a7f997b61b22a3dc85677b9 Mon Sep 17 00:00:00 2001 From: Hawtian Wang Date: Fri, 29 Mar 2024 18:04:54 +0800 Subject: [PATCH] ... --- lua/dotvim/legacy/packages/_builtin/init.lua | 150 +++++++ .../legacy/packages/_builtin/plugins/_.lua | 328 ++++++++++++++ .../packages/_builtin/setup/autocmds.lua | 147 +++++++ .../packages/_builtin/setup/keymaps.lua | 90 ++++ .../packages/_builtin/setup/options.lua | 81 ++++ lua/dotvim/legacy/packages/coding/init.lua | 18 + .../packages/coding/plugins/comment.lua | 21 + .../packages/coding/plugins/conform.lua | 78 ++++ .../packages/coding/plugins/luasnip.lua | 91 ++++ .../legacy/packages/coding/plugins/neogen.lua | 29 ++ .../packages/coding/plugins/nvim-cmp.lua | 94 ++++ .../packages/coding/plugins/nvim-lint.lua | 38 ++ .../packages/coding/plugins/nvim-surround.lua | 8 + .../plugins/nvim-ts-context-commentstring.lua | 21 + .../coding/plugins/ultimate-autopair.lua | 44 ++ lua/dotvim/legacy/packages/editor/init.lua | 19 + .../packages/editor/plugins/_others.lua | 339 +++++++++++++++ .../packages/editor/plugins/bookmarks.lua | 89 ++++ .../legacy/packages/editor/plugins/dial.lua | 114 +++++ .../packages/editor/plugins/fzf-lua.lua | 29 ++ .../packages/editor/plugins/gitsigns.lua | 24 + .../editor/plugins/local-highlight.lua | 16 + .../packages/editor/plugins/neo-tree.lua | 202 +++++++++ .../packages/editor/plugins/telescope.lua | 158 +++++++ .../editor/plugins/vim-illuminate.lua | 104 +++++ .../packages/editor/plugins/which-key.lua | 50 +++ lua/dotvim/legacy/packages/extra/editor.lua | 135 ++++++ .../legacy/packages/extra/lang/cmake.lua | 61 +++ lua/dotvim/legacy/packages/extra/lang/cpp.lua | 253 +++++++++++ .../legacy/packages/extra/lang/dart.lua | 193 ++++++++ .../legacy/packages/extra/lang/latex.lua | 69 +++ lua/dotvim/legacy/packages/extra/lang/lua.lua | 103 +++++ .../legacy/packages/extra/lang/markdown.lua | 126 ++++++ lua/dotvim/legacy/packages/extra/lang/nix.lua | 52 +++ .../legacy/packages/extra/lang/python.lua | 58 +++ .../legacy/packages/extra/lang/rust.lua | 258 +++++++++++ .../legacy/packages/extra/lang/swift.lua | 45 ++ .../legacy/packages/extra/lang/typescript.lua | 113 +++++ lua/dotvim/legacy/packages/extra/lsp.lua | 47 ++ .../extra/misc/competitive-programming.lua | 74 ++++ .../legacy/packages/extra/misc/copilot.lua | 210 +++++++++ .../legacy/packages/extra/misc/darwin.lua | 45 ++ .../legacy/packages/extra/misc/rime.lua | 260 +++++++++++ .../legacy/packages/extra/misc/tools.lua | 57 +++ .../legacy/packages/extra/misc/wakatime.lua | 12 + lua/dotvim/legacy/packages/extra/obsidian.lua | 78 ++++ lua/dotvim/legacy/packages/extra/ui.lua | 36 ++ lua/dotvim/legacy/packages/lsp/init.lua | 83 ++++ .../legacy/packages/lsp/plugins/glance.lua | 58 +++ .../legacy/packages/lsp/plugins/lspkind.lua | 55 +++ .../packages/lsp/plugins/nvim-lspconfig.lua | 123 ++++++ .../legacy/packages/treesitter/init.lua | 11 + .../packages/treesitter/plugins/_others.lua | 105 +++++ .../treesitter/plugins/nvim-treesitter.lua | 125 ++++++ lua/dotvim/legacy/packages/ui/init.lua | 14 + .../legacy/packages/ui/plugins/_others.lua | 158 +++++++ .../legacy/packages/ui/plugins/alpha.lua | 411 ++++++++++++++++++ .../legacy/packages/ui/plugins/bufferline.lua | 89 ++++ .../legacy/packages/ui/plugins/lualine.lua | 98 +++++ .../legacy/packages/ui/plugins/noice.lua | 147 +++++++ 60 files changed, 6144 insertions(+) create mode 100644 lua/dotvim/legacy/packages/_builtin/init.lua create mode 100644 lua/dotvim/legacy/packages/_builtin/plugins/_.lua create mode 100644 lua/dotvim/legacy/packages/_builtin/setup/autocmds.lua create mode 100644 lua/dotvim/legacy/packages/_builtin/setup/keymaps.lua create mode 100644 lua/dotvim/legacy/packages/_builtin/setup/options.lua create mode 100644 lua/dotvim/legacy/packages/coding/init.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/comment.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/conform.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/luasnip.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/neogen.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/nvim-cmp.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/nvim-lint.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/nvim-surround.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/nvim-ts-context-commentstring.lua create mode 100644 lua/dotvim/legacy/packages/coding/plugins/ultimate-autopair.lua create mode 100644 lua/dotvim/legacy/packages/editor/init.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/_others.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/bookmarks.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/dial.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/fzf-lua.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/gitsigns.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/local-highlight.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/neo-tree.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/telescope.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/vim-illuminate.lua create mode 100644 lua/dotvim/legacy/packages/editor/plugins/which-key.lua create mode 100644 lua/dotvim/legacy/packages/extra/editor.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/cmake.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/cpp.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/dart.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/latex.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/lua.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/markdown.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/nix.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/python.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/rust.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/swift.lua create mode 100644 lua/dotvim/legacy/packages/extra/lang/typescript.lua create mode 100644 lua/dotvim/legacy/packages/extra/lsp.lua create mode 100644 lua/dotvim/legacy/packages/extra/misc/competitive-programming.lua create mode 100644 lua/dotvim/legacy/packages/extra/misc/copilot.lua create mode 100644 lua/dotvim/legacy/packages/extra/misc/darwin.lua create mode 100644 lua/dotvim/legacy/packages/extra/misc/rime.lua create mode 100644 lua/dotvim/legacy/packages/extra/misc/tools.lua create mode 100644 lua/dotvim/legacy/packages/extra/misc/wakatime.lua create mode 100644 lua/dotvim/legacy/packages/extra/obsidian.lua create mode 100644 lua/dotvim/legacy/packages/extra/ui.lua create mode 100644 lua/dotvim/legacy/packages/lsp/init.lua create mode 100644 lua/dotvim/legacy/packages/lsp/plugins/glance.lua create mode 100644 lua/dotvim/legacy/packages/lsp/plugins/lspkind.lua create mode 100644 lua/dotvim/legacy/packages/lsp/plugins/nvim-lspconfig.lua create mode 100644 lua/dotvim/legacy/packages/treesitter/init.lua create mode 100644 lua/dotvim/legacy/packages/treesitter/plugins/_others.lua create mode 100644 lua/dotvim/legacy/packages/treesitter/plugins/nvim-treesitter.lua create mode 100644 lua/dotvim/legacy/packages/ui/init.lua create mode 100644 lua/dotvim/legacy/packages/ui/plugins/_others.lua create mode 100644 lua/dotvim/legacy/packages/ui/plugins/alpha.lua create mode 100644 lua/dotvim/legacy/packages/ui/plugins/bufferline.lua create mode 100644 lua/dotvim/legacy/packages/ui/plugins/lualine.lua create mode 100644 lua/dotvim/legacy/packages/ui/plugins/noice.lua diff --git a/lua/dotvim/legacy/packages/_builtin/init.lua b/lua/dotvim/legacy/packages/_builtin/init.lua new file mode 100644 index 00000000..4999fb78 --- /dev/null +++ b/lua/dotvim/legacy/packages/_builtin/init.lua @@ -0,0 +1,150 @@ +---@type dora.lib +local lib = require("dora.lib") + +---@type dora.core.package.PackageOption +return { + name = "dora.packages._builtin", + plugins = lib.tbl.flatten_array { + require("dora.packages._builtin.plugins._"), + { "folke/lazy.nvim", lazy = true }, + { "TwIStOy/dora.nvim", lazy = true }, + { + "catppuccin/nvim", + name = "catppuccin", + lazy = true, + build = ":CatppuccinCompile", + opts = { + flavour = "frappe", + term_colors = true, + transparent_background = false, + compile_path = vim.fn.stdpath("cache") .. "/catppuccin", + dim_inactive = { enabled = false }, + styles = { + comments = { "italic" }, + conditionals = { "italic" }, + properties = {}, + functions = {}, + keywords = {}, + operators = {}, + loops = {}, + booleans = {}, + numbers = {}, + types = {}, + strings = {}, + variables = {}, + }, + custom_highlights = function(C) + return { + ["@lsp.typemod.variable.mutable.rust"] = { style = { "underline" } }, + ["@lsp.typemod.selfKeyword.mutable.rust"] = { + style = { "underline" }, + }, + ["@variable.builtin"] = { fg = C.maroon, style = { "italic" } }, + } + end, + integrations = { + alpha = true, + aerial = true, + barbecue = { + dim_dirname = true, + bold_basename = true, + }, + treesitter = true, + headlines = true, + flash = true, + gitsigns = true, + notify = true, + native_lsp = { + enabled = true, + virtual_text = { + errors = { "italic" }, + hints = { "italic" }, + warnings = { "italic" }, + information = { "italic" }, + }, + underlines = { + errors = { "undercurl" }, + hints = { "undercurl" }, + warnings = { "undercurl" }, + information = { "undercurl" }, + }, + }, + semantic_tokens = true, + lsp_trouble = true, + markdown = true, + noice = true, + telescope = { + enabled = true, + style = "nvchad", + }, + illuminate = true, + nvimtree = false, + mason = true, + neotree = true, + mini = true, + which_key = true, + hop = true, + cmp = true, + lsp_saga = true, + octo = true, + navic = { enabled = true }, + window_picker = true, + }, + }, + actions = { + { + id = "catppuccin.compile", + callback = "CatppuccinCompile", + description = "Recompile Catppuccin", + from = "catppuccin.nvim", + category = "Catppuccin", + }, + }, + }, + { + "dstein64/vim-startuptime", + cmd = "StartupTime", + config = function() + vim.g.startuptime_tries = 10 + end, + actions = { + { + id = "vim-startuptime.show", + title = "Show Vim's startup time", + callback = "StartupTime", + }, + }, + }, + { + "willothy/flatten.nvim", + lazy = false, + priority = 1001, + opts = { + window = { + open = "alternate", + }, + }, + }, + { + "MunifTanjim/nui.nvim", + lazy = true, + }, + { + "nvim-lua/popup.nvim", + lazy = true, + }, + { + "nvim-lua/plenary.nvim", + lazy = true, + }, + { + "nvim-tree/nvim-web-devicons", + lazy = true, + }, + }, + setup = function() + require("dora.packages._builtin.setup.options")() + require("dora.packages._builtin.setup.keymaps")() + require("dora.packages._builtin.setup.autocmds")() + end, +} diff --git a/lua/dotvim/legacy/packages/_builtin/plugins/_.lua b/lua/dotvim/legacy/packages/_builtin/plugins/_.lua new file mode 100644 index 00000000..608cee3e --- /dev/null +++ b/lua/dotvim/legacy/packages/_builtin/plugins/_.lua @@ -0,0 +1,328 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "tpope/vim-repeat", + event = "VeryLazy", + }, + { + "osyo-manga/vim-jplus", + event = "BufReadPost", + keys = { { "J", "(jplus)", mode = { "n", "v" }, noremap = false } }, + gui = "all", + }, + { + "williamboman/mason.nvim", + opts = { + PATH = "skip", + ui = { + icons = { + package_installed = "îȘČ ", + package_pending = "î©· ", + package_uninstalled = " ", + }, + }, + extra = { + outdated_check_interval = 1, -- in days + ensure_installed = {}, + update_installed_packages = true, + }, + }, + cmd = { + "Mason", + "MasonUpdate", + "MasonInstall", + "MasonUninstall", + "MasonUninstallAll", + "MasonLog", + }, + dependencies = { + "plenary.nvim", + }, + event = "VeryLazy", + config = function(_, opts) + ---@type dora.lib + local lib = require("dora.lib") + + local last_update_marker = (function() + local mason_settings = require("mason.settings").current + local mason_root = mason_settings.install_root_dir + local Path = require("plenary.path") + local marker_file = Path:new(mason_root) / "registry-last-update" + return tostring(marker_file) + end)() + + local check_registry_outdated = function() + local interval = vim.F.if_nil(opts.extra.outdated_check_interval, 1) + if interval < 0 then + -- disable + return false + end + local content = lib.fs.read_file(last_update_marker) + local last_update = 0 + if content ~= nil then + content = vim.trim(content) + last_update = tonumber(content) or 0 + end + local now = os.time(os.date("!*t") --[[@as osdateparam]]) + if now - last_update > 60 * 60 * 24 * interval then + lib.fs.write_file(last_update_marker, tostring(now)) + return true + end + return false + end + + local function install_package(pkg) + if pkg:is_installed() then + return + end + local handle = pkg:install() + handle:once( + "closed", + vim.schedule_wrap(function() + if pkg:is_installed() then + vim.notify( + ("%s was successfully installed"):format(pkg), + vim.log.levels.INFO, + { + title = "mason.nvim", + render = "compact", + } + ) + else + vim.notify( + ("Failed to install %s"):format(pkg), + vim.log.levels.ERROR, + { + title = "mason.nvim", + render = "compact", + } + ) + end + end) + ) + end + + local function check_package_outdated(pkg) + local ok, new_version = lib.async.wrap(pkg.check_new_version)(pkg) + if ok then + return new_version.name + end + end + + local function install_missing_or_update_packages() + local registry = require("mason-registry") + local outdated_packages = {} + for _, name in ipairs(opts.extra.ensure_installed) do + local pkg = registry.get_package(name) + if pkg == nil then + vim.notify( + ("%s is not a Mason package. Please check your config"):format( + name + ), + vim.log.levels.WARN, + { + title = "mason.nvim", + render = "compact", + } + ) + else + if pkg:is_installed() then + if opts.extra.update_installed_packages then + if check_package_outdated(pkg) ~= nil then + outdated_packages[#outdated_packages + 1] = name + end + end + else + install_package(pkg) + end + end + end + end + + local do_setup = coroutine.wrap(function() + if check_registry_outdated() then + local ok, data = lib.async.wrap(require("mason-registry").update)() + if ok then + vim.notify("Mason-registry updated!", vim.log.levels.INFO, { + title = "mason.nvim", + render = "compact", + }) + else + vim.notify( + "Mason-registry update failed, reason: " .. tostring(data), + vim.log.levels.ERROR, + { + title = "mason.nvim", + render = "compact", + } + ) + end + end + install_missing_or_update_packages() + end) + + vim.defer_fn(function() + require("mason").setup(opts) + do_setup() + end, 200) + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "mason.nvim", + category = "Mason", + actions = { + { + id = "mason.open-window", + title = "Open mason window", + callback = "Mason", + }, + { + id = "mason.install", + title = "Install a tool", + callback = "MasonInstall", + }, + { + id = "mason.update", + title = "Update a tool", + callback = "MasonUpdate", + }, + { + id = "mason.uninstall", + title = "Uninstall a tool", + callback = "MasonUninstall", + }, + { + id = "mason.uninstall-all", + title = "Uninstall all tools", + callback = "MasonUninstallAll", + }, + { + id = "mason.show-log", + title = "Show mason log", + callback = "MasonLog", + }, + }, + } + end, + }, + { + "akinsho/toggleterm.nvim", + version = "*", + init = function() -- code to run before plugin loaded + vim.g.toggleterm_terminal_mapping = "" + end, + config = function(_, opts) + require("toggleterm").setup(opts) + end, + lazy = true, + opts = { + open_mapping = "", + hide_numbers = true, + direction = "float", + start_in_insert = true, + shell = vim.o.shell, + close_on_exit = true, + float_opts = { border = "rounded" }, + }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + ---@type dora.config + local config = require("dora.config") + + ---@type dora.core.action.ActionOption[] + local actions = { + { + id = "toggleterm.toggle", + title = "Toggle terminal", + callback = "ToggleTerm", + keys = { "", desc = "toggle-terminal" }, + }, + } + + if config.integration.enabled("yazi") then + actions[#actions + 1] = { + id = "toggleterm.yazi", + title = "Open Yazi", + callback = function() + local executable = config.nix.resolve_bin("yazi") + if vim.fn.executable(executable) ~= 1 then + vim.notify( + "Command [yazi] not found!", + vim.log.levels.ERROR, + { title = "toggleterm.nvim" } + ) + return + end + local root = vim.fn.getcwd() + require("toggleterm.terminal").Terminal + :new({ + cmd = "yazi", + dir = root, + direction = "float", + close_on_exit = true, + float_opts = { border = "none" }, + start_in_insert = true, + hidden = true, + }) + :open() + end, + keys = { "ff", desc = "toggle-yazi" }, + } + end + + if config.integration.enabled("lazygit") then + actions[#actions + 1] = { + id = "toggleterm.lazygit", + title = "Open lazygit", + callback = function() + local executable = config.nix.resolve_bin("lazygit") + if vim.fn.executable(executable) ~= 1 then + vim.notify( + "Command [lazygit] not found!", + vim.log.levels.ERROR, + { title = "toggleterm.nvim" } + ) + return + end + local repo_path = require("dora.lib").fs.git_repo_path() + if repo_path == nil then + vim.notify( + "Not in a git repo!", + vim.log.levels.ERROR, + { title = "toggleterm.nvim" } + ) + return + end + require("toggleterm.terminal").Terminal + :new({ + cmd = "lazygit", + dir = repo_path, + direction = "float", + close_on_exit = true, + start_in_insert = true, + float_opts = { border = "none" }, + on_close = function(t) + vim.schedule(function() + t:shutdown() + end) + end, + }) + :open() + end, + keys = { "g", desc = "toggle-lazygit" }, + } + end + + return action.make_options { + from = "toggleterm.nvim", + category = "ToggleTerm", + actions = actions, + } + end, + }, +} diff --git a/lua/dotvim/legacy/packages/_builtin/setup/autocmds.lua b/lua/dotvim/legacy/packages/_builtin/setup/autocmds.lua new file mode 100644 index 00000000..eabba57c --- /dev/null +++ b/lua/dotvim/legacy/packages/_builtin/setup/autocmds.lua @@ -0,0 +1,147 @@ +local function mkdir() + local dir = vim.fn.expand(":p:h") + if vim.fn.isdirectory(dir) == 0 then + vim.fn.mkdir(dir, "p") + end +end + +return function() + ---@type dora.config + local config = require("dora.config") + + vim.api.nvim_create_autocmd("TermEnter", { + pattern = "*", + callback = function() + local winnr = vim.api.nvim_get_current_win() + vim.api.nvim_set_option_value("nu", false, { + scope = "local", + win = winnr, + }) + vim.api.nvim_set_option_value("rnu", false, { + scope = "local", + win = winnr, + }) + end, + }) + + vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "WinEnter" }, { + pattern = "*", + callback = function(event) + local lookup_table = vim.tbl_add_reverse_lookup( + vim.deepcopy(config.vim.config.relative_number_blacklist or {}) + ) + + local ft = vim.api.nvim_get_option_value("ft", { buf = event.buf }) + local bt = vim.api.nvim_get_option_value("bt", { buf = event.buf }) + if lookup_table[ft] == nil and bt ~= "nofile" then + local winnr = vim.api.nvim_get_current_win() + vim.api.nvim_set_option_value("nu", true, { + win = winnr, + }) + vim.api.nvim_set_option_value("rnu", true, { + win = winnr, + }) + vim.api.nvim_set_option_value("signcolumn", "yes", { + win = winnr, + }) + end + end, + }) + + vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "WinLeave" }, { + pattern = "*", + callback = function(event) + local lookup_table = vim.tbl_add_reverse_lookup( + vim.deepcopy(config.vim.config.relative_number_blacklist or {}) + ) + + local ft = vim.api.nvim_get_option_value("ft", { buf = event.buf }) + local bt = vim.api.nvim_get_option_value("bt", { buf = event.buf }) + if lookup_table[ft] == nil and bt ~= "nofile" then + local winnr = vim.api.nvim_get_current_win() + vim.api.nvim_set_option_value("nu", true, { + win = winnr, + }) + vim.api.nvim_set_option_value("rnu", false, { + win = winnr, + }) + end + end, + }) + + -- quick close buffers with + vim.api.nvim_create_autocmd("FileType", { + pattern = config.vim.config.quick_close_filetypes, + callback = function(event) + vim.bo[event.buf].buflisted = false + vim.api.nvim_buf_set_keymap( + event.buf, + "n", + "q", + "close", + { silent = true } + ) + end, + }) + + vim.api.nvim_create_autocmd({ "InsertLeave", "WinEnter" }, { + pattern = "*", + callback = function(event) + local ft = vim.api.nvim_get_option_value("ft", { buf = event.buf }) + local lookup_table = vim.tbl_add_reverse_lookup( + vim.deepcopy(config.vim.config.cursorline_blacklist or {}) + ) + if lookup_table[ft] == nil then + local winnr = vim.api.nvim_get_current_win() + vim.api.nvim_set_option_value("cursorline", true, { + win = winnr, + }) + end + end, + }) + + vim.api.nvim_create_autocmd({ "InsertEnter", "WinLeave" }, { + pattern = "*", + callback = function() + local winnr = vim.api.nvim_get_current_win() + vim.api.nvim_set_option_value("cursorline", false, { + win = winnr, + }) + end, + }) + + vim.api.nvim_create_autocmd({ "VimResized" }, { + callback = function() + vim.cmd("wincmd =") + vim.cmd("tabdo wincmd =") + end, + }) + + -- move quickfix windows to botright automatically + vim.api.nvim_create_autocmd( + "FileType", + { pattern = "qf", command = "wincmd J" } + ) + + -- highlight on yank + vim.api.nvim_create_autocmd("TextYankPost", { + callback = function() + vim.highlight.on_yank() + end, + }) + + vim.api.nvim_create_autocmd({ "BufEnter", "WinClosed", "WinEnter" }, { + pattern = "*", + callback = function() + -- close when all windows are uncountable + config.vim.check_last_window() + end, + }) + + vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*", + callback = function() + mkdir() + end, + }) +end diff --git a/lua/dotvim/legacy/packages/_builtin/setup/keymaps.lua b/lua/dotvim/legacy/packages/_builtin/setup/keymaps.lua new file mode 100644 index 00000000..1715549d --- /dev/null +++ b/lua/dotvim/legacy/packages/_builtin/setup/keymaps.lua @@ -0,0 +1,90 @@ +return function() + ---@type dora.config + local config = require("dora.config") + + ---@type dora.lib + local lib = require("dora.lib") + + -- Disable arrows + vim.api.nvim_set_keymap("", "", "", {}) + vim.api.nvim_set_keymap("", "", "", {}) + vim.api.nvim_set_keymap("", "", "", {}) + vim.api.nvim_set_keymap("", "", "", {}) + + if lib.vim.current_gui() == "vscode" then + vim.keymap.set("n", "1", function() + require("vscode-neovim").call("workbench.action.focusFirstEditorGroup") + end, { desc = "goto-win-1" }) + vim.keymap.set("n", "2", function() + require("vscode-neovim").call("workbench.action.focusSecondEditorGroup") + end, { desc = "goto-win-2" }) + vim.keymap.set("n", "3", function() + require("vscode-neovim").call("workbench.action.focusThirdEditorGroup") + end, { desc = "goto-win-3" }) + else + vim.keymap.set("n", "wv", "wincmd v", { + desc = "split-window-vertical", + }) + + vim.keymap.set("n", "w-", "wincmd s", { + desc = "split-window-horizontal", + }) + + vim.keymap.set("n", "w=", "wincmd =", { + desc = "balance-window", + }) + + vim.keymap.set("n", "wr", "wincmd r", { + desc = "rotate-window-rightwards", + }) + + vim.keymap.set("n", "wx", "wincmd x", { + desc = "exchange-window-with-next", + }) + + local function goto_countable_window(i) + local function skip_uncountable_windows(cnt) + local rest = cnt + + for _, win_id in pairs(vim.api.nvim_tabpage_list_wins(0)) do + if + not config.vim.is_uncountable(win_id) + and vim.api.nvim_win_is_valid(win_id) + then + rest = rest - 1 + if rest == 0 then + return win_id + end + end + end + + return 0 + end + + vim.schedule(function() + local win_id = skip_uncountable_windows(i) + if win_id > 0 then + vim.api.nvim_set_current_win(win_id) + end + end) + end + + for i = 1, 9 do + vim.keymap.set("n", "" .. i, function() + goto_countable_window(i) + end, { desc = "goto-win-" .. i }) + end + end + + vim.keymap.set("n", "fs", "update", { desc = "update" }) + + vim.keymap.set("n", "", "nohl", { desc = "nohl" }) + + vim.keymap.set("n", "q", "q", { desc = "quit" }) + vim.keymap.set( + "n", + "Q", + "confirm qall", + { desc = "quit-all" } + ) +end diff --git a/lua/dotvim/legacy/packages/_builtin/setup/options.lua b/lua/dotvim/legacy/packages/_builtin/setup/options.lua new file mode 100644 index 00000000..9d9ffc2a --- /dev/null +++ b/lua/dotvim/legacy/packages/_builtin/setup/options.lua @@ -0,0 +1,81 @@ +return function() + vim.opt.title = false + vim.opt.ttyfast = true + + vim.opt.termguicolors = true + + vim.o.updatetime = 100 + vim.o.redrawtime = 1500 + vim.o.timeout = true + vim.o.ttimeout = true + vim.o.timeoutlen = 500 + vim.o.ttimeoutlen = 10 + + vim.o.foldcolumn = "1" + vim.o.foldlevel = 99 + vim.o.foldlevelstart = 99 + vim.o.foldenable = true + + vim.o.sessionoptions = + "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions" + + -- no bells + vim.cmd([[set noerrorbells novisualbell t_vb=]]) + + -- numbers + vim.opt.number = true + vim.opt.relativenumber = true + vim.opt.signcolumn = "yes" + vim.opt.cursorline = true + + -- cursor settings + vim.opt.guicursor = + "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20,n-v-c:blinkon500-blinkoff500,a:Cursor/lCursor" + vim.opt.termsync = true + + -- mouse mode + vim.opt.mouse = "a" + vim.opt.mousemoveevent = true + + -- statusline + vim.opt.laststatus = 3 + + -- edit settings + vim.opt.expandtab = true + vim.opt.smartindent = true + vim.opt.autoindent = true + + -- default tab width: 2 + vim.opt.tabstop = 2 + vim.opt.shiftwidth = 2 + + vim.opt.showmode = false + vim.opt.cmdheight = 1 + + vim.opt.exrc = true + + vim.opt.wrap = true + + vim.opt.fillchars = "eob: " + + vim.opt.scrolloff = 5 + + vim.opt.timeoutlen = 300 + + vim.opt.hidden = true + + -- jump options + vim.opt.jumpoptions = "stack" + + if vim.fn.has("nvim-0.10") == 1 then + vim.opt.smoothscroll = true + end + + vim.opt.virtualedit = "block" + + -- allow misspellings + vim.cmd.cnoreabbrev("qw", "wq") + vim.cmd.cnoreabbrev("W", "w") + vim.cmd.cnoreabbrev("Wq", "wq") + vim.cmd.cnoreabbrev("WQ", "wq") +end diff --git a/lua/dotvim/legacy/packages/coding/init.lua b/lua/dotvim/legacy/packages/coding/init.lua new file mode 100644 index 00000000..2bd51159 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/init.lua @@ -0,0 +1,18 @@ +---@type dora.lib +local lib = require("dora.lib") + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.coding", + plugins = lib.tbl.flatten_array { + require("dora.packages.coding.plugins.nvim-cmp"), + require("dora.packages.coding.plugins.luasnip"), + require("dora.packages.coding.plugins.conform"), + require("dora.packages.coding.plugins.ultimate-autopair"), + require("dora.packages.coding.plugins.nvim-surround"), + require("dora.packages.coding.plugins.nvim-ts-context-commentstring"), + require("dora.packages.coding.plugins.comment"), + require("dora.packages.coding.plugins.neogen"), + require("dora.packages.coding.plugins.nvim-lint"), + }, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/comment.lua b/lua/dotvim/legacy/packages/coding/plugins/comment.lua new file mode 100644 index 00000000..65176bd0 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/comment.lua @@ -0,0 +1,21 @@ +---@type dora.core.plugin.PluginOption +return { + "numToStr/Comment.nvim", + gui = "all", + dependencies = { "JoosepAlviste/nvim-ts-context-commentstring" }, + keys = { + { "gcc", desc = "toggle-line-comment" }, + { "gcc", mode = "x", desc = "toggle-line-comment" }, + { "gbc", desc = "toggle-block-comment" }, + { "gbc", mode = "x", desc = "toggle-block-comment" }, + }, + opts = { + toggler = { line = "gcc", block = "gbc" }, + opleader = { line = "gcc", block = "gbc" }, + mappings = { basic = true, extra = false }, + pre_hook = function() + require("ts_context_commentstring.integrations.comment_nvim").create_pre_hook() + end, + }, + config = true, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/conform.lua b/lua/dotvim/legacy/packages/coding/plugins/conform.lua new file mode 100644 index 00000000..7aa853c1 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/conform.lua @@ -0,0 +1,78 @@ +---@type dora.core.plugin.PluginOption +return { + "stevearc/conform.nvim", + gui = "all", + opts = { + format = { + timeout_ms = 3000, + async = false, + quiet = false, + }, + formatters = {}, + formatters_by_ft = {}, + }, + cmd = { "Conform" }, + event = { "BufReadPost" }, + keys = { + { + "fc", + function() + local conform = require("conform") + conform.format { + async = true, + lsp_fallback = true, + } + end, + desc = "format-file", + mode = { "n", "v" }, + }, + }, + config = function(_, opts) + local used_formatters = {} + for _, value in pairs(opts.formatters_by_ft) do + if type(value) == "string" then + used_formatters[#used_formatters + 1] = value + else + for _, val in ipairs(value) do + if type(val) == "string" then + used_formatters[#used_formatters + 1] = val + else + vim.list_extend(used_formatters, val) + end + end + end + end + + ---@type dora.utils + local utils = require("dora.utils") + + local custom_formatters = {} + for _, formatter in ipairs(used_formatters) do + local formatter_opts + if opts.formatters[formatter] ~= nil then + formatter_opts = opts.formatters[formatter] + else + local ok, module = pcall(require, "conform.formatters." .. formatter) + if not ok then + error("Formatter " .. formatter .. " not found") + end + formatter_opts = module + end + local command = formatter_opts.command + if command == nil then + error("Formatter " .. formatter .. " does not have a command") + end + local resolved_command = utils.which_binary(command) + if resolved_command ~= command then + custom_formatters[formatter] = vim.tbl_extend("force", formatter_opts, { + command = resolved_command, + }) + end + + opts.formatters = + vim.tbl_extend("force", opts.formatters, custom_formatters) + + require("conform").setup(opts) + end + end, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/luasnip.lua b/lua/dotvim/legacy/packages/coding/plugins/luasnip.lua new file mode 100644 index 00000000..485a9a6c --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/luasnip.lua @@ -0,0 +1,91 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "TwIStOy/luasnip-snippets", + lazy = true, + dependencies = "nvim-treesitter", + gui = "all", + opts = { + user = { + name = "Hawtian Wang", + }, + }, + }, + { + "L3MON4D3/LuaSnip", + gui = "all", + build = "make install_jsregex", + dependencies = { + { + "nvim-cmp", + dependencies = { + "saadparwaiz1/cmp_luasnip", + }, + opts = function(_, opts) + opts.snippet = { + expand = function(args) + local indent_nodes = true + if + vim.api.nvim_get_option_value("filetype", { buf = 0 }) == "dart" + then + indent_nodes = false + end + local ls = require("luasnip") + ls.lsp_expand(args.body, { + indent = indent_nodes, + }) + end, + } + opts.sources[#opts.sources + 1] = { + name = "luasnip", + group_index = 2, + } + end, + }, + "luasnip-snippets", + }, + opts = { + enable_autosnippets = true, + history = false, + updateevents = "TextChanged,TextChangedI", + region_check_events = { + "CursorMoved", + "CursorMovedI", + "CursorHold", + }, + store_select_keys = "", + }, + keys = { + { + "", + function() + local ls = require("luasnip") + if ls.choice_active() then + ls.change_choice(1) + end + end, + mode = { "i", "s", "n", "v" }, + }, + { + "", + function() + local ls = require("luasnip") + if ls.jumpable(-1) then + ls.jump(-1) + end + end, + mode = { "i", "s", "n", "v" }, + }, + { + "", + function() + local ls = require("luasnip") + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end, + mode = { "i", "s", "n", "v" }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/neogen.lua b/lua/dotvim/legacy/packages/coding/plugins/neogen.lua new file mode 100644 index 00000000..abbe9c88 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/neogen.lua @@ -0,0 +1,29 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "danymat/neogen", + dependencies = { + "nvim-treesitter/nvim-treesitter", + }, + cmd = { "Neogen" }, + gui = "all", + opts = { + input_after_comment = false, + snippet_engine = "luasnip", + }, + actions = { + { + id = "neogen.generate-annotation", + title = "Generate annotation on this", + icon = "📝", + callback = function() + require("neogen").generate() + end, + condition = function(buf) + return #buf.ts_highlighter > 0 + end, + category = "Neogen", + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/nvim-cmp.lua b/lua/dotvim/legacy/packages/coding/plugins/nvim-cmp.lua new file mode 100644 index 00000000..c1279ea4 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/nvim-cmp.lua @@ -0,0 +1,94 @@ +---@type dora.core.plugin.PluginOption +return { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-calc", + "lukas-reineke/cmp-under-comparator", + }, + opts = function() + local cmp = require("cmp") + + return { + matching = { + disallow_fuzzy_matching = false, + disallow_fullfuzzy_matching = true, + disallow_partial_fuzzy_matching = false, + disallow_partial_matching = false, + }, + preselect = cmp.PreselectMode.None, + experimental = { ghost_text = false }, + window = { + completion = { + border = "none", + winhighlight = "Normal:Normal,FloatBorder:FloatBorder", + focusable = false, + col_offset = 0, + }, + documentation = { + border = "single", + winhighlight = "FloatBorder:FloatBorder", + focusable = false, + }, + }, + sources = { + { name = "nvim_lsp", group_index = 1, max_item_count = 100 }, + { name = "async_path", group_index = 4 }, + { + name = "buffer", + group_index = 5, + option = { + get_bufnrs = function() + local buf = vim.api.nvim_get_current_buf() + local byte_size = vim.api.nvim_buf_get_offset( + buf, + vim.api.nvim_buf_line_count(buf) + ) + if byte_size > 1024 * 1024 then -- 1 Megabyte max + return {} + end + return { buf } + end, + }, + max_item_count = 10, + }, + }, + completion = { + completeopt = "menu,menuone,noselect,noinsert,preview", + }, + mapping = { + [""] = cmp.mapping.confirm { select = true }, + [""] = cmp.mapping.select_prev_item {}, + [""] = cmp.mapping.select_next_item {}, + [""] = cmp.mapping.select_prev_item {}, + [""] = cmp.mapping.select_next_item {}, + [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i" }), + }, + enabled = function() + local bt = vim.api.nvim_get_option_value("buftype", { + buf = 0, + }) + return bt ~= "prompt" + end, + sorting = { + priority_weight = 2, + comparators = { + cmp.config.compare.offset, + cmp.config.compare.exact, + cmp.config.compare.score, + require("cmp-under-comparator").under, + cmp.config.compare.locality, + cmp.config.compare.recently_used, + cmp.config.compare.kind, + cmp.config.compare.sort_text, + cmp.config.compare.length, + cmp.config.compare.order, + }, + }, + } + end, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/nvim-lint.lua b/lua/dotvim/legacy/packages/coding/plugins/nvim-lint.lua new file mode 100644 index 00000000..b886bae4 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/nvim-lint.lua @@ -0,0 +1,38 @@ +---@type dora.core.plugin.PluginOption +return { + "mfussenegger/nvim-lint", + event = { "BufReadPost", "BufNewFile" }, + opts = { + linters_by_ft = {}, + }, + config = function(_, opts) + require("lint").linters_by_ft = opts.linters_by_ft + + local used_linters = {} + for _, linter in pairs(opts.linters_by_ft) do + if type(linter) == "string" then + used_linters[#used_linters + 1] = linter + else + for _, l in pairs(linter) do + used_linters[#used_linters + 1] = l + end + end + end + + ---@type dora.utils + local utils = require("dora.utils") + for _, name in pairs(used_linters) do + local linter = require("lint").linters[name] + if linter == nil then + error("Linter " .. linter .. " not found") + end + linter.cmd = utils.which_binary(linter.cmd) + end + + vim.api.nvim_create_autocmd("BufWritePost", { + callback = function() + require("lint").try_lint() + end, + }) + end, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/nvim-surround.lua b/lua/dotvim/legacy/packages/coding/plugins/nvim-surround.lua new file mode 100644 index 00000000..696cb413 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/nvim-surround.lua @@ -0,0 +1,8 @@ +---@type dora.core.plugin.PluginOption +return { + "kylechui/nvim-surround", + gui = "all", + version = "*", + event = "BufReadPost", + opts = {}, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/nvim-ts-context-commentstring.lua b/lua/dotvim/legacy/packages/coding/plugins/nvim-ts-context-commentstring.lua new file mode 100644 index 00000000..fefc1dcc --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/nvim-ts-context-commentstring.lua @@ -0,0 +1,21 @@ +---@type dora.core.plugin.PluginOption +return { + "JoosepAlviste/nvim-ts-context-commentstring", + gui = "all", + event = { + "BufReadPost", + "BufNewFile", + }, + dependencies = { + "nvim-treesitter/nvim-treesitter", + }, + opts = { + context_commentstring = { + enable = true, + }, + }, + config = function(_, opts) + vim.g.skip_ts_context_commentstring_module = true + require("ts_context_commentstring").setup(opts) + end, +} diff --git a/lua/dotvim/legacy/packages/coding/plugins/ultimate-autopair.lua b/lua/dotvim/legacy/packages/coding/plugins/ultimate-autopair.lua new file mode 100644 index 00000000..4e3dadd5 --- /dev/null +++ b/lua/dotvim/legacy/packages/coding/plugins/ultimate-autopair.lua @@ -0,0 +1,44 @@ +---@type dora.core.plugin.PluginOption +return { + "altermo/ultimate-autopair.nvim", + gui = "all", + event = { + "InsertEnter", + "CmdlineEnter", + }, + opts = { + close = { + map = "", + cmap = "", + }, + tabout = { + hopout = true, + }, + fastwarp = { + enable = true, + map = "", + rmap = "", + cmap = "", + crmap = "", + enable_normal = true, + enable_reverse = true, + hopout = false, + multiline = true, + nocursormove = true, + no_nothing_if_fail = false, + }, + config_internal_pairs = { + { + "'", + "'", + suround = true, + cond = function(fn) + return not fn.in_lisp() or fn.in_string() + end, + alpha = true, + nft = { "tex", "rust" }, + multiline = false, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/editor/init.lua b/lua/dotvim/legacy/packages/editor/init.lua new file mode 100644 index 00000000..22c12bfa --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/init.lua @@ -0,0 +1,19 @@ +---@type dora.lib +local lib = require("dora.lib") + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.editor", + plugins = lib.tbl.flatten_array { + require("dora.packages.editor.plugins.neo-tree"), + require("dora.packages.editor.plugins.telescope"), + require("dora.packages.editor.plugins.fzf-lua"), + -- require("dora.packages.editor.plugins.vim-illuminate"), + require("dora.packages.editor.plugins.local-highlight"), + require("dora.packages.editor.plugins.which-key"), + require("dora.packages.editor.plugins.bookmarks"), + require("dora.packages.editor.plugins.dial"), + require("dora.packages.editor.plugins.gitsigns"), + require("dora.packages.editor.plugins._others"), + }, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/_others.lua b/lua/dotvim/legacy/packages/editor/plugins/_others.lua new file mode 100644 index 00000000..ed7e6b6f --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/_others.lua @@ -0,0 +1,339 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "m4xshen/smartcolumn.nvim", + event = { "BufReadPre", "BufNewFile" }, + opts = { + colorcolumn = "80", + disabled_filetypes = { + "help", + "NvimTree", + "lazy", + "mason", + "help", + "alpha", + "bookmarks_input", + "noice", + }, + }, + }, + { + "kazhala/close-buffers.nvim", + cmd = { + "BDelete", + "BWipeout", + }, + opts = { + filetype_ignore = { + "dashboard", + "NvimTree", + "TelescopePrompt", + "terminal", + "toggleterm", + "packer", + "fzf", + }, + preserve_window_layout = { "this" }, + next_buffer_cmd = function(windows) + require("bufferline").cycle(1) + local bufnr = vim.api.nvim_get_current_buf() + for _, window in ipairs(windows) do + vim.api.nvim_win_set_buf(window, bufnr) + end + end, + }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + local function redraw_all() + vim.api.nvim_command("redrawstatus!") + vim.api.nvim_command("redraw!") + end + + return action.make_options { + from = "close-buffers", + category = "CloseBuffer", + actions = { + { + id = "close-buffer.delete-all-hidden-buffers", + title = "Delete all hidden buffers", + callback = function() + require("close_buffers").delete { type = "hidden", force = true } + redraw_all() + end, + keys = { "ch", desc = "delete-hidden-buffers" }, + }, + { + id = "close-buffer.delete-all-buffers-without-name", + title = "Delete all buffers without name", + callback = function() + require("close_buffers").delete { type = "nameless" } + redraw_all() + end, + }, + { + id = "close-buffer.delete-current-buffer", + title = "Delete current buffer", + callback = function() + require("close_buffers").delete { type = "this" } + redraw_all() + end, + }, + { + id = "close-buffer.delete-all-buffers-matching-the-regex", + title = "Delete all buffers matching the regex", + callback = function() + vim.ui.input({ prompt = "Regex" }, function(input) + if input ~= nil and #input > 0 then + require("close_buffers").delete { regex = input } + end + end) + redraw_all() + end, + }, + }, + } + end, + }, + { + "folke/trouble.nvim", + dependencies = { "folke/lsp-colors.nvim", "telescope.nvim" }, + cmd = { "Trouble", "TroubleClose", "TroubleToggle", "TroubleRefresh" }, + opts = { use_diagnostic_signs = true }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + local lsp_actions = action.make_options { + from = "trouble.nvim", + category = "Trouble", + condition = function(buffer) + return #buffer.lsp_servers > 0 + end, + actions = { + { + id = "trouble.open-workspace-diagnostic", + title = "Open workspace diagnostic", + callback = "Trouble workspace_diagnostic", + keys = { "xw", desc = "lsp-workspace-diagnostic" }, + }, + { + id = "trouble.open-document-diagnostic", + title = "Open document diagnostic", + callback = "Trouble document_diagnostic", + keys = { "xd", desc = "lsp-document-diagnostic" }, + }, + }, + } + + local common_actions = action.make_options { + from = "trouble.nvim", + category = "Trouble", + actions = { + { + id = "trouble.toggle-window", + title = "Toggle trouble window", + callback = "TroubleToggle", + keys = { "xx", desc = "trouble-toggle" }, + }, + }, + } + + local actions_in_trouble_window = action.make_options { + from = "trouble.nvim", + category = "Trouble", + condition = function() + return require("trouble").is_open() + end, + actions = { + { + id = "trouble.previous-trouble", + title = "Previous trouble", + callback = function() + require("trouble").previous { skip_groups = true, jump = true } + end, + keys = { "[q", desc = "previous-trouble" }, + }, + { + id = "trouble.next-trouble", + title = "Next trouble", + callback = function() + require("trouble").next { skip_groups = true, jump = true } + end, + keys = { "]q", desc = "next-trouble" }, + }, + }, + } + + return { + unpack(lsp_actions), + unpack(common_actions), + unpack(actions_in_trouble_window), + } + end, + }, + { + "folke/todo-comments.nvim", + event = "BufReadPost", + cmd = { "TodoTrouble", "TodoTelescope" }, + dependencies = { "nvim-lua/plenary.nvim", "telescope.nvim", "trouble.nvim" }, + opts = { + highlight = { keyword = "wide_bg", pattern = "(KEYWORDS)\\([^)]*\\):" }, + search = { pattern = "(KEYWORDS)\\([^)]*\\):" }, + keywords = { + HACK = { alt = { "UNSAFE" } }, + FIX = { alt = { "FIXME", "BUG", "FIXIT", "ISSUE", "FUCKING" } }, + }, + }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "todo-comments.nvim", + category = "TodoComments", + actions = { + { + id = "todo-comments.open-todos-in-trouble", + title = "Open todos in trouble", + callback = "TodoTrouble", + keys = { "xt", desc = "touble-todo" }, + }, + { + id = "todo-comments.open-todos-fix-fixme-in-trouble", + title = "Open todos,fix,fixme in trouble", + callback = "TodoTrouble keywords=TODO,FIX,FIXME", + keys = { "xT", desc = "trouble-TFF" }, + }, + { + id = "todo-comments.list-all-todos-in-telescope", + title = "List all todos in telescope", + callback = "TodoTelescope", + keys = { "lt", desc = "list-todos" }, + }, + { + id = "todo-comments.goto-next-todo", + title = "Goto next todo", + callback = function() + require("todo-comments").jump_next() + end, + keys = { "]t", desc = "jump-next-todo" }, + }, + { + id = "todo-comments.goto-previous-todo", + title = "Goto previous todo", + callback = function() + require("todo-comments").jump_prev() + end, + keys = { "[t", desc = "jump-previous-todo" }, + }, + }, + } + end, + }, + { + "echasnovski/mini.move", + gui = "all", + opts = { + mappings = { + left = "", + right = "", + down = "", + up = "", + line_left = "", + line_right = "", + line_down = "", + line_up = "", + }, + }, + keys = { + { "", mode = { "n", "v" } }, + { "", mode = { "n", "v" } }, + { "", mode = { "n", "v" } }, + { "", mode = { "n", "v" } }, + }, + }, + { + "abecodes/tabout.nvim", + event = "InsertEnter", + dependencies = { "nvim-treesitter/nvim-treesitter" }, + opts = { + tabouts = { + { open = "'", close = "'" }, + { open = '"', close = '"' }, + { open = "`", close = "`" }, + { open = "(", close = ")" }, + { open = "[", close = "]" }, + { open = "{", close = "}" }, + { open = "<", close = ">" }, + }, + }, + keys = { + { + "", + "(TaboutMulti)", + mode = "i", + silent = true, + }, + { + "", + "(TaboutBackMulti)", + mode = "i", + silent = true, + }, + }, + }, + { + "aperezdc/vim-template", + cmd = { "Template", "TemplateHere" }, + init = function() + vim.g.templates_directory = { + vim.fn.stdpath("config") .. "/templates", + } + vim.g.templates_no_autocmd = 0 + vim.g.templates_debug = 0 + vim.g.templates_no_builtin_templates = 1 + end, + gui = "all", + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + ---@type dora.lib + local lib = require("dora.lib") + + return action.make_options { + from = "vim-template", + category = "Template", + actions = { + { + id = "template.expand-template-into-current-buffer", + title = "Expand template into current buffer", + callback = lib.vim.input_then_exec("Template"), + description = "Expand a mated template fron the beginning of the buffer", + }, + { + id = "template.expand-template-under-cursor", + title = "Expand template under cursor", + callback = lib.vim.input_then_exec("TemplateHere"), + description = "Expand a matched template under the cursor", + }, + }, + } + end, + }, + { + "TwIStOy/nvim-lastplace", + event = "BufReadPre", + opts = { + lastplace_ignore_buftype = { "quickfix", "nofile", "help" }, + lastplace_ignore_filetype = { + "gitcommit", + "gitrebase", + "svn", + "hgcommit", + }, + lastplace_open_folds = false, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/bookmarks.lua b/lua/dotvim/legacy/packages/editor/plugins/bookmarks.lua new file mode 100644 index 00000000..a2f9b6ca --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/bookmarks.lua @@ -0,0 +1,89 @@ +---@type dora.core.plugin.PluginOption +return { + "crusj/bookmarks.nvim", + dependencies = { + "nvim-tree/nvim-web-devicons", + "nvim-telescope/telescope.nvim", + }, + event = "BufReadPost", + opts = function() + ---@type dora.config + local config = require("dora.config") + + return { + mappings_enabled = false, + sign_icon = config.icon.predefined_icon("Bookmark"), + virt_pattern = { + "*.dart", + "*.cpp", + "*.ts", + "*.lua", + "*.js", + "*.c", + "*.h", + "*.cc", + "*.hh", + "*.hpp", + "*.md", + "*.rs", + "*.toml", + }, + fix_enable = true, + } + end, + config = function(_, opts) + require("bookmarks").setup(opts) + require("telescope").load_extension("bookmarks") + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "bookmarks.nvim", + category = "Bookmarks", + actions = { + { + id = "bookmarks.list-bookmarks", + title = "List bookmarks", + callback = function() + vim.api.nvim_command("Telescope bookmarks") + end, + keys = { "lm", desc = "list-bookmarks", silent = true }, + }, + { + id = "bookmarks.toggle-bookmarks", + title = "Toggle bookmarks", + callback = function() + require("bookmarks").toggle_bookmarks() + end, + keys = { "bt", desc = "toggle-bookmarks", silent = true }, + }, + { + id = "bookmarks.add-bookmark", + title = "Add bookmark", + callback = function() + require("bookmarks").add_bookmarks() + end, + keys = { "ba", desc = "add-bookmark", silent = true }, + }, + { + id = "bookmarks.delete-at-virt-line", + title = "Delete bookmark at virt text line", + callback = function() + require("bookmarks.list").delete_on_virt() + end, + keys = { "bd", desc = "delete-at-virt-line", silent = true }, + }, + { + id = "bookmarks.show-bookmark-desc", + title = "Show bookmark desc", + callback = function() + require("bookmarks.list").show_desc() + end, + keys = { "bs", desc = "show-bookmark-desc", silent = true }, + }, + }, + } + end, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/dial.lua b/lua/dotvim/legacy/packages/editor/plugins/dial.lua new file mode 100644 index 00000000..d420cea3 --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/dial.lua @@ -0,0 +1,114 @@ +---@type dora.core.plugin.PluginOption +return { + "monaqa/dial.nvim", + gui = "all", + event = { "BufReadPost" }, + keys = { + { + "", + desc = "dial inc", + mode = { "n", "v" }, + }, + { + "", + desc = "dial dec", + mode = { "n", "v" }, + }, + }, + opts = function() + local augend = require("dial.augend") + + local function define_custom(...) + return augend.constant.new { + elements = { ... }, + word = true, + cyclic = true, + } + end + + local opts = {} + + opts.commons = { + augend.integer.alias.decimal, + augend.integer.alias.hex, + augend.integer.alias.binary, + augend.date.alias["%Y/%m/%d"], + augend.date.alias["%Y-%m-%d"], + define_custom("true", "false"), + define_custom("yes", "no"), + define_custom("YES", "NO"), + define_custom("||", "&&"), + define_custom("enable", "disable"), + define_custom( + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday" + ), + define_custom( + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" + ), + } + + opts.ft = { + toml = { augend.semver.alias.semver }, + } + + return opts + end, + config = function(_, opts) + local groups = {} + for ft, ft_opts in pairs(opts.ft) do + groups[ft] = { + unpack(opts.commons), + unpack(ft_opts), + } + end + require("dial.config").augends:register_group(groups) + + vim.keymap.set({ "n", "v" }, "", require("dial.map").inc_normal(), { + desc = "dial inc", + }) + vim.keymap.set({ "n", "v" }, "", require("dial.map").dec_normal(), { + desc = "dial dec", + }) + + for ft, _ in pairs(opts.ft) do + vim.api.nvim_create_autocmd("FileType", { + pattern = ft, + callback = function() + vim.keymap.set( + { "n", "v" }, + "", + require("dial.map").inc_normal(ft), + { + desc = "dial inc", + } + ) + vim.keymap.set( + { "n", "v" }, + "", + require("dial.map").dec_normal(ft), + { + desc = "dial dec", + } + ) + end, + }) + end + end, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/fzf-lua.lua b/lua/dotvim/legacy/packages/editor/plugins/fzf-lua.lua new file mode 100644 index 00000000..104bca8f --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/fzf-lua.lua @@ -0,0 +1,29 @@ +---@type dora.core.plugin.PluginOption +return { + "ibhagwan/fzf-lua", + url = "https://gitlab.com/ibhagwan/fzf-lua.git", + dependencies = { + "nvim-web-devicons", + }, + lazy = true, + opts = {}, + cmd = { "FzfLua" }, + config = function(_, opts) + ---@type dora.utils + local utils = require("dora.utils") + opts = opts or {} + + local bins = { + { "fzf", { "fzf_bin" } }, + { "cat", { "previewers", "cat", "cmd" } }, + { "bat", { "previewers", "bat", "cmd" } }, + { "head", { "previewers", "head", "cmd" } }, + } + + for _, bin in ipairs(bins) do + utils.fix_opts_cmd(opts, bin[1], unpack(bin[2])) + end + + require("fzf-lua").setup(opts) + end, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/gitsigns.lua b/lua/dotvim/legacy/packages/editor/plugins/gitsigns.lua new file mode 100644 index 00000000..d1bdac16 --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/gitsigns.lua @@ -0,0 +1,24 @@ +---@type dora.core.plugin.PluginOption +return { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + opts = { + signs = { + add = { text = "▎" }, + change = { text = "▎" }, + delete = { text = "" }, + topdelete = { text = "" }, + changedelete = { text = "▎" }, + untracked = { text = "▎" }, + }, + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + watch_gitdir = { + interval = 1000, + follow_files = true, + }, + update_debounce = 20, + }, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/local-highlight.lua b/lua/dotvim/legacy/packages/editor/plugins/local-highlight.lua new file mode 100644 index 00000000..a433ab71 --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/local-highlight.lua @@ -0,0 +1,16 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "tzachar/local-highlight.nvim", + event = { "BufReadPost", "BufNewFile" }, + opts = { + hlgroup = "IlluminatedWordWrite", + disable_file_types = { + "nuipopup", + "rightclickpopup", + "NvimTree", + "help", + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/neo-tree.lua b/lua/dotvim/legacy/packages/editor/plugins/neo-tree.lua new file mode 100644 index 00000000..230425a7 --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/neo-tree.lua @@ -0,0 +1,202 @@ +---@type dora.core.plugin.PluginOption +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "main", + dependencies = { + "MunifTanjim/nui.nvim", + "nvim-tree/nvim-web-devicons", + "nvim-telescope/telescope.nvim", + }, + cmd = { "Neotree" }, + init = function() + vim.g.neo_tree_remove_legacy_commands = true + end, + keys = { + { + "", + function() + vim.api.nvim_command("Neotree action=focus") + end, + desc = "file-explorer", + }, + { + "ft", + function() + vim.api.nvim_command("Neotree action=focus") + end, + desc = "file-explorer", + }, + }, + opts = function() + ---@type dora.config + local config = require("dora.config") + local predefined_icon = config.icon.predefined_icon + + return { + auto_clean_after_session_restore = true, + close_if_last_window = true, + enable_refresh_on_write = false, + sources = { "filesystem", "buffers", "git_status" }, + source_selector = { + winbar = true, + content_layout = "center", + sources = { + { + source = "filesystem", + display_name = predefined_icon("FolderClosed", 1) .. "File", + }, + { + source = "buffers", + display_name = predefined_icon("DefaultFile", 1) .. "Bufs", + }, + { + source = "git_status", + display_name = predefined_icon("Git", 1) .. "Git", + }, + { + source = "diagnostics", + display_name = predefined_icon("Diagnostic", 1) .. "Diagnostic", + }, + }, + }, + default_component_configs = { + indent = { padding = 0 }, + icon = { + folder_closed = predefined_icon("FolderClosed"), + folder_open = predefined_icon("FolderOpen"), + folder_empty = predefined_icon("FolderEmpty"), + folder_empty_open = predefined_icon("FolderEmpty"), + default = predefined_icon("DefaultFile"), + }, + modified = { symbol = predefined_icon("FileModified") }, + git_status = { + symbols = { + added = predefined_icon("GitAdd"), + deleted = predefined_icon("GitDelete"), + modified = predefined_icon("GitChange"), + renamed = predefined_icon("GitRenamed"), + untracked = predefined_icon("GitUntracked"), + ignored = predefined_icon("GitIgnored"), + unstaged = predefined_icon("GitUnstaged"), + staged = predefined_icon("GitStaged"), + conflict = predefined_icon("GitConflict"), + }, + }, + }, + commands = { + parent_or_close = function(state) + local node = state.tree.get_node() + if + (node.type == "directory" or node.has_children()) + and node.is_expanded() + then + state.commands.toggle_node(state) + else + require("neo-tree.ui.renderer").focus_node( + state, + node.get_parent_id() + ) + end + end, + child_or_open = function(state) + local node = state.tree.get_node() + if node.type == "directory" or node.has_children() then + if not node.is_expanded() then + state.commands.toggle_node(state) + else + require("neo-tree.ui.renderer").focus_node( + state, + node.get_child_ids()[1] + ) + end + else + state.commands.open(state) + end + end, + copy_selector = function(state) + local node = state.tree.get_node() + local filepath = node.get_id() + local filename = node.name + local modify = vim.fn.fnamemodify + local vals = { + BASENAME = modify(filename, ":r"), + EXTENSION = modify(filename, ":e"), + FILENAME = filename, + ["PATH (CWD)"] = modify(filepath, ":."), + ["PATH (HOME)"] = modify(filepath, ":~"), + PATH = filepath, + URI = vim.uri_from_fname(filepath), + } + local options = vim.tbl_filter(function(val) + return vals[val] ~= "" + end, vim.tbl_keys(vals)) + if #options == 0 then + vim.notify("No values to copy", vim.log.levels.WARN) + return + end + table.sort(options) + vim.ui.select(options, { + prompt = "Choose to copy to clipboard:", + format_item = function(item) + return tostring(item) .. ": " .. tostring(vals[item]) .. "}" + end, + }, function(choice) + local result = vals[choice] + if result then + vim.notify("Copied: " .. tostring(result)) + vim.fn.setreg("+", result) + end + end) + end, + find_in_dir = function(state) + local node = state.tree.get_node() + local path = node.get_id() + local cwd + if node.type == "directory" then + cwd = path + else + cwd = vim.fn.fnamemodify(path, ":h") + end + require("telescope.builtin").find_files { cwd = cwd } + end, + }, + window = { + width = 40, + mappings = { + [""] = false, + ["[b"] = "prev_source", + ["]b"] = "next_source", + [""] = "open_with_window_picker", + F = "find_in_dir", + Y = "copy_selector", + h = "parent_or_close", + l = "child_or_open", + o = "open", + }, + fuzzy_finder_mappings = { + [""] = "move_cursor_down", + [""] = "move_cursor_up", + }, + }, + filesystem = { + follow_current_file = { enabled = true }, + hijack_netrw_behavior = "open_current", + use_libuv_file_watcher = false, + filtered_items = { + hide_gitignored = true, + hide_dotfiles = false, + hide_by_name = { "node_modules" }, + never_show = { ".DS_Store", "thumbs.db" }, + }, + }, + event_handlers = { + { + event = "neo_tree_buffer_enter", + handler = function() + vim.opt_local.signcolumn = "auto" + end, + }, + }, + } + end, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/telescope.lua b/lua/dotvim/legacy/packages/editor/plugins/telescope.lua new file mode 100644 index 00000000..dac63fed --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/telescope.lua @@ -0,0 +1,158 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "nvim-telescope/telescope-fzf-native.nvim", + name = "telescope-fzf-native.nvim", + lazy = true, + build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build", + }, + { + "nvim-telescope/telescope.nvim", + cmd = { "Telescope" }, + lazy = true, + dependencies = { + "nvim-lua/plenary.nvim", + "kkharji/sqlite.lua", + "folke/flash.nvim", + "telescope-fzf-native.nvim", + "TwIStOy/project.nvim", + }, + opts = function() + ---@type dora.lib + local lib = require("dora.lib") + local actions = require("telescope.actions") + + return { + defaults = { + selection_caret = "➀ ", + selection_strategy = "reset", + sorting_strategy = "descending", + layout_strategy = "horizontal", + history = { + path = vim.fn.stdpath("data") + .. "/database/telescope_history.sqlite3", + }, + winblend = lib.vim.current_gui() ~= nil and 20 or 0, + color_devicons = true, + + mappings = { + i = { + [""] = false, + [""] = false, + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + [""] = actions.cycle_history_prev, + [""] = actions.cycle_history_next, + [""] = actions.close, + }, + n = { ["q"] = actions.close }, + }, + }, + pickers = { + find_files = { + theme = "ivy", + layout_config = { + height = 0.4, + }, + }, + }, + extensions = { + fzf = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case", + }, + }, + } + end, + config = function(_, opts) + require("telescope").setup(opts) + require("telescope").load_extension("fzf") + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + local lsp_actions = action.make_options { + from = "telescope.nvim", + category = "Telescope", + condition = function(buffer) + return #buffer.lsp_servers > 0 + end, + actions = { + { + id = "telescope.lsp-document-symbols", + title = "Find document symbols", + callback = function() + require("telescope.builtin").lsp_document_symbols {} + end, + keys = { "ls", desc = "document-symbols" }, + }, + { + id = "telescope.lsp-workspace-symbols", + title = "Find workspace symbols", + callback = function() + require("telescope.builtin").lsp_workspace_symbols {} + end, + keys = { "lw", desc = "workspace-symbols" }, + }, + }, + } + + local common_actions = action.make_options { + from = "telescope.nvim", + category = "Telescope", + actions = { + { + id = "telescope.all-buffers", + title = "Find all buffers", + callback = function() + require("telescope.builtin").buffers {} + end, + keys = { "", desc = "all-buffers" }, + }, + { + id = "telescope.find-files", + callback = function() + if vim.b._dora_project_cwd ~= nil then + require("telescope.builtin").find_files { + cwd = vim.b._dora_project_cwd, + no_ignore = vim.b._dora_project_no_ignore, + follow = true, + } + else + require("telescope.builtin").find_files {} + end + end, + title = "Edit project files", + keys = { "e", desc = "edit-project-files" }, + }, + { + id = "telescope.live-grep", + callback = function() + if vim.b._dora_project_cwd ~= nil then + require("telescope.builtin").live_grep { + cwd = vim.b._dora_project_cwd, + no_ignore = vim.b._dora_project_no_ignore, + follow = true, + } + else + require("telescope.builtin").live_grep {} + end + end, + title = "Search for a string in current working directory", + keys = { "lg", desc = "live-grep" }, + }, + }, + } + + return { + unpack(lsp_actions), + unpack(common_actions), + } + end, + }, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/vim-illuminate.lua b/lua/dotvim/legacy/packages/editor/plugins/vim-illuminate.lua new file mode 100644 index 00000000..34aa8646 --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/vim-illuminate.lua @@ -0,0 +1,104 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "RRethy/vim-illuminate", + event = { "BufReadPost", "BufNewFile" }, + opts = { + delay = 200, + filetypes_denylist = { + "nuipopup", + "rightclickpopup", + "NvimTree", + "help", + }, + }, + config = function(_, opts) + require("illuminate").configure(opts) + vim.api.nvim_create_autocmd("FileType", { + callback = function() + local buffer = vim.api.nvim_get_current_buf() + pcall(vim.keymap.del, "n", "]]", { buffer = buffer }) + pcall(vim.keymap.del, "n", "[[", { buffer = buffer }) + end, + }) + end, + keys = { + { + "]]", + function() + require("illuminate").goto_next_reference(false) + end, + desc = "Next Reference", + }, + { + "[[", + function() + require("illuminate").goto_prev_reference(false) + end, + desc = "Prev Reference", + }, + }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "vim-illuminate", + category = "Illuminate", + actions = { + { + id = "illuminate.pause", + callback = "IlluminatePause", + title = "Globally pause vim-illuminate", + }, + { + id = "illuminate.resume", + callback = "IlluminateResume", + title = "Globally resume vim-illuminate", + }, + { + id = "illuminate.toggle", + callback = "IlluminateToggle", + title = "Globally toggle the pause/resume for vim-illuminate", + }, + { + id = "illuminate.pause_buf", + callback = "IlluminatePauseBuf", + title = "Buffer-local pause of vim-illuminate", + }, + { + id = "illuminate.resume_buf", + callback = "IlluminateResumeBuf", + title = "Buffer-local resume of vim-illuminate", + }, + { + id = "illuminate.toggle_buf", + callback = "IlluminateToggleBuf", + title = "Buffer-local toggle of the pause/resume for vim-illuminate", + }, + { + id = "illuminate.freeze", + callback = function() + require("illuminate").freeze_buf() + end, + title = "Freeze the illumination on the buffer, this won't clear the highlights", + }, + { + id = "illuminate.unfreeze", + callback = function() + require("illuminate").unfreeze_buf() + end, + title = "Unfreeze the illumination on the buffer", + }, + { + id = "illuminate.toggle_freeze", + callback = function() + require("illuminate").toggle_freeze_buf() + end, + title = "Toggle the frozen state of the buffer", + }, + }, + } + end, + }, +} diff --git a/lua/dotvim/legacy/packages/editor/plugins/which-key.lua b/lua/dotvim/legacy/packages/editor/plugins/which-key.lua new file mode 100644 index 00000000..84777419 --- /dev/null +++ b/lua/dotvim/legacy/packages/editor/plugins/which-key.lua @@ -0,0 +1,50 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + key_labels = { [""] = "SPC", [""] = "RET", [""] = "TAB" }, + layout = { align = "center" }, + ignore_missing = false, + hidden = { + "", + "", + "", + "", + "call", + "lua", + "^:", + "^ ", + }, + show_help = true, + icons = { + breadcrumb = "»", + separator = "󰜮", + group = "+", + }, + }, + config = function(_, opts) + vim.defer_fn(function() + local wk = require("which-key") + wk.setup(opts) + wk.register { + mode = { "n", "v" }, + g = { name = "+goto" }, + ["]"] = { name = "+next" }, + ["["] = { name = "+prev" }, + ["b"] = { name = "+bookmarks" }, + ["f"] = { name = "+file" }, + ["l"] = { name = "+list" }, + ["n"] = { name = "+no" }, + ["p"] = { name = "+preview" }, + ["r"] = { name = "+remote" }, + ["t"] = { name = "+toggle" }, + ["v"] = { name = "+vcs" }, + ["w"] = { name = "+window" }, + ["x"] = { name = "+xray" }, + } + end, 100) + end, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/editor.lua b/lua/dotvim/legacy/packages/extra/editor.lua new file mode 100644 index 00000000..b118e0e8 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/editor.lua @@ -0,0 +1,135 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.editor", + deps = { + "dora.packages.editor", + }, + plugins = { + { + "folke/flash.nvim", + event = "BufReadPost", + dependencies = { + { + "telescope.nvim", + opts = function(_, opts) + local function flash(prompt_bufnr) + require("flash").jump { + pattern = "^", + label = { after = { 0, 0 } }, + search = { + mode = "search", + exclude = { + function(win) + return vim.bo[vim.api.nvim_win_get_buf(win)].filetype + ~= "TelescopeResults" + end, + }, + }, + action = function(match) + local picker = + require("telescope.actions.state").get_current_picker( + prompt_bufnr + ) + picker:set_selection(match.pos[1] - 1) + end, + } + end + opts.defaults.mappings.i[""] = flash + opts.defaults.mappings.n["s"] = flash + end, + }, + }, + }, + { + "phaazon/hop.nvim", + cmd = { + "HopWord", + "HopPattern", + "HopChar1", + "HopChar2", + "HopLine", + "HopLineStart", + }, + opts = { keys = "etovxqpdygfblzhckisuran", term_seq_bias = 0.5 }, + keys = { + { + ",l", + "HopLine", + desc = "jump-to-line", + }, + }, + }, + { + "kevinhwang91/nvim-hlslens", + opts = { + calm_down = false, + nearest_only = false, + nearest_float_when = "never", + }, + keys = { + { "*", "*lua require('hlslens').start()", silent = true }, + { "#", "#lua require('hlslens').start()", silent = true }, + { "g*", "g*lua require('hlslens').start()", silent = true }, + { "g#", "g#lua require('hlslens').start()", silent = true }, + { + "n", + "execute('normal! ' . v:count1 . 'n')lua require('hlslens').start()", + }, + { + "N", + "execute('normal! ' . v:count1 . 'N')lua require('hlslens').start()", + }, + }, + }, + { + "sindrets/diffview.nvim", + cmd = "DiffviewOpen", + opts = { + view = { + merge_tool = { + layout = "diff3_mixed", + }, + }, + }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + ---@type dora.core.action.ActionOption[] + local actions = { + { + id = "diffview.open", + title = "Open diffview", + callback = "DiffviewOpen", + }, + { + id = "diffview.close", + title = "Close the current diffview. You can also use :tabclose.", + callback = "DiffviewClose", + }, + { + id = "diffview.toggle", + title = "Toggle the file panel.", + callback = "DiffviewToggleFiles", + }, + { + id = "diffview.focus", + title = "Bring focus to the file panel.", + callback = "DiffviewFocusFiles", + }, + { + id = "diffview.refresh", + title = "Update stats and entries in the file list of the current Diffview.", + callback = "DiffviewRefresh", + }, + } + + return action.make_options { + from = "diffview.nvim", + category = "diffview", + actions = actions, + } + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/cmake.lua b/lua/dotvim/legacy/packages/extra/lang/cmake.lua new file mode 100644 index 00000000..05366316 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/cmake.lua @@ -0,0 +1,61 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.cmake", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "cmake" }) + end + end, + }, + { + "nvim-lspconfig", + opts = { + servers = { + opts = { + cmake = { + initializationOptions = { buildDirectory = "build" }, + }, + }, + }, + }, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + cmake = { "gersemi" }, + }, + }, + }, + { + "dial.nvim", + opts = function(_, opts) + local function define_custom(...) + local augend = require("dial.augend") + return augend.constant.new { + elements = { ... }, + word = true, + cyclic = true, + } + end + + if opts.ft.cmake == nil then + opts.ft.cmake = {} + end + + vim.list_extend(opts.ft.cmake, { + define_custom("on", "off"), + define_custom("ON", "OFF"), + }) + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/cpp.lua b/lua/dotvim/legacy/packages/extra/lang/cpp.lua new file mode 100644 index 00000000..fd1614cf --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/cpp.lua @@ -0,0 +1,253 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.cpp", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "c", "cpp" }) + end + end, + }, + { + "mason.nvim", + opts = function(_, opts) + vim.list_extend(opts.extra.ensure_installed, { + "clangd", + "cpplint", + "clang-format", + }) + end, + }, + { + "nvim-lspconfig", + opts = { + servers = { + opts = { + clangd = { + capabilities = { + offsetEncoding = { "utf-16" }, + }, + cmd = { + "clangd", + "--clang-tidy", + "--background-index", + "--background-index-priority=normal", + "--ranking-model=decision_forest", + "--completion-style=detailed", + "--header-insertion=iwyu", + "--limit-references=100", + "--limit-results=100", + "--include-cleaner-stdlib", + "-j=20", + }, + root_dir = function(fname) + return require("lspconfig.util").root_pattern( + "Makefile", + "configure.ac", + "configure.in", + "config.h.in", + "meson.build", + "meson_options.txt", + "build.ninja", + "BLADE_ROOT" + )(fname) or require("lspconfig.util").root_pattern( + "compile_commands.json", + "compile_flags.txt" + )(fname) or require("lspconfig.util").find_git_ancestor( + fname + ) + end, + init_options = { + usePlaceholders = true, + completeUnimported = true, + clangdFileStatus = true, + }, + }, + }, + setup = { + clangd = function(_, server_opts) + ---@type dora.lib + local lib = require("dora.lib") + + lib.vim.on_lsp_attach(function(client, bufnr) + if client and client.name == "clangd" then + vim.keymap.set("n", "fa", function() + vim.api.nvim_command("ClangdSwitchSourceHeader") + end, { + desc = "clangd-switch-header", + buffer = bufnr, + }) + end + end) + + require("clangd_extensions").setup { + autoSetHints = false, + hover_with_actions = true, + inlay_hints = { + inline = false, + only_current_line = false, + only_current_line_autocmd = "CursorHold", + show_parameter_hints = false, + show_variable_name = true, + other_hints_prefix = "", + max_len_align = false, + max_len_align_padding = 1, + right_align = false, + right_align_padding = 7, + highlight = "Comment", + }, + ast = { + role_icons = { + type = "🄣", + declaration = "🄓", + expression = "🄔", + statement = ";", + specifier = "🄱", + ["template argument"] = "🆃", + }, + kind_icons = { + Compound = "đŸ„Č", + Recovery = "🅁", + TranslationUnit = "🅄", + PackExpansion = "🄿", + TemplateTypeParm = "🅃", + TemplateTemplateParm = "🅃", + TemplateParamObject = "🅃", + }, + }, + memory_usage = { border = "rounded" }, + symbol_info = { border = "rounded" }, + } + + -- call default setup function + require("lspconfig").clangd.setup(server_opts) + + return true + end, + }, + }, + }, + }, + { + "p00f/clangd_extensions.nvim", + lazy = true, + after = { + "nvim-cmp", + "nvim-lspconfig", + }, + config = function() end, + }, + { + "nvim-cmp", + opts = function(_, opts) + table.insert( + opts.sorting.comparators, + 1, + require("clangd_extensions.cmp_scores") + ) + end, + }, + { + "TwIStOy/cpp-toolkit.nvim", + dependencies = { + "nvim-telescope/telescope.nvim", + "nvim-lua/plenary.nvim", + }, + gui = "all", + cmd = { "CppGenDef", "CppDebugPrint", "CppToolkit" }, + ft = { "cpp", "c" }, + opts = { + impl_return_type_style = "trailing", + }, + config = function(_, opts) + require("cpp-toolkit").setup(opts) + require("telescope").load_extension("cpptoolkit") + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "cpp-toolkit.nvim", + category = "CppToolkit", + actions = { + { + id = "cpptoolkit.insert-header", + title = "Insert header", + callback = "Telescope cpptoolkit insert_header", + }, + { + id = "cpptoolkit.gen-def", + title = "Generate function implementation", + callback = "CppGenDef", + }, + { + id = "cpptoolkit.move-value", + title = "Move value", + callback = "CppToolkit shortcut move_value", + }, + { + id = "cpptoolkit.forward-value", + title = "Forward value", + callback = "CppToolkit shortcut forward_value", + }, + }, + } + end, + }, + { + "mfussenegger/nvim-lint", + event = { "BufReadPost", "BufNewFile" }, + opts = function(_, opts) + opts.linters_by_ft.cpp = { "cpplint" } + end, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + cpp = { "clang_format" }, + }, + }, + }, + { + "dial.nvim", + opts = function(_, opts) + local function define_custom(...) + local augend = require("dial.augend") + return augend.constant.new { + elements = { ... }, + word = true, + cyclic = true, + } + end + + if opts.ft.cpp == nil then + opts.ft.cpp = {} + end + + vim.list_extend(opts.ft.cpp, { + define_custom("Debug", "Info", "Warn", "Error", "Fatal"), + define_custom("first", "second"), + define_custom("true_type", "false_type"), + define_custom("uint8_t", "uint16_t", "uint32_t", "uint64_t"), + define_custom("int8_t", "int16_t", "int32_t", "int64_t"), + define_custom("htonl", "ntohl"), + define_custom("htons", "ntohs"), + define_custom("ASSERT_EQ", "ASSERT_NE"), + define_custom("EXPECT_EQ", "EXPECT_NE"), + define_custom("==", "!="), + define_custom("static_cast", "dynamic_cast", "reinterpret_cast"), + define_custom("private", "public", "protected"), + }) + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/dart.lua b/lua/dotvim/legacy/packages/extra/lang/dart.lua new file mode 100644 index 00000000..290f0695 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/dart.lua @@ -0,0 +1,193 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.dart", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + "dora.packages.ui", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "dart" }) + end + end, + }, + { + "akinsho/flutter-tools.nvim", + dependencies = { + "plenary.nvim", + "dressing.nvim", + "telescope.nvim", + }, + lazy = true, + opts = {}, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "flutter-tools.nvim", + category = "Flutter", + condition = function(buffer) + return buffer.filetype == "dart" + end, + actions = { + { + id = "flutter-tools.run-project", + title = "Run the current project. " + .. "This need to be run from within a flutter project", + callback = "FlutterRun", + }, + { + id = "flutter-tools.select-devices", + title = "Brings up a list of connected devices to select from", + callback = "FlutterDevices", + }, + { + id = "flutter-tools.select-emulators", + title = "Similar to devices but shows a list of " + .. "emulators to choose from", + callback = "FlutterEmulators", + }, + { + id = "flutter-tools.hot-reload", + title = "Reload the running project", + callback = "FlutterReload", + }, + { + id = "flutter-tools.restart-project", + title = "Restart the current project", + callback = "FlutterRestart", + }, + { + id = "flutter-tools.quit-project", + title = "Ends a running session", + callback = "FlutterQuit", + }, + { + id = "flutter-tools.detach-project", + title = "Ends a running session, but keeps the process" + .. " running on the device", + callback = "FlutterDetach", + }, + { + id = "flutter-tools.toggle-outline", + title = "Toggle the outline window showing the widget tree for " + .. "the given file", + callback = "FlutterOutlineToggle", + }, + { + id = "flutter-tools.open-outline", + title = "Opens an outline window showing the widget tree for the" + .. " given file", + callback = "FlutterOutlineOpen", + }, + { + id = "flutter-tools.start-dev-tools", + title = "Starts a Dart Dev Tools server", + callback = "FlutterDevTools", + }, + { + id = "flutter-tools.active-dev-tools", + title = "Activates a Dart Dev Tools server", + callback = "FlutterDevToolsActivate", + }, + { + id = "flutter-tools.copy-profiler-url", + title = "Copies the profiler url to your system clipboard " + .. "(+ register). Note that commands FlutterRun and " + .. "FlutterDevTools must be executed first", + callback = "FlutterCopyProfilerUrl", + }, + { + id = "flutter-tools.lsp-restart", + title = "This command restarts the dart language server, and " + .. "is intended for situations where it begins to work" + .. " incorrectly", + callback = "FlutterLspRestart", + }, + { + id = "flutter-tools.goto-super-class", + title = "Go to super class, method using custom LSP method " + .. "dart/textDocument/super", + callback = "FlutterSuper", + }, + { + id = "flutter-tools.reanalyze", + title = "Forces LSP server reanalyze using custom LSP method " + .. "dart/reanalyze", + callback = "FlutterReanalyze", + }, + { + id = "flutter-tools.rename", + title = "Renames and updates imports " + .. "if lsp.settings.renameFilesWithClasses == 'always'", + callback = "FlutterRename", + }, + }, + } + end, + config = function() end, + }, + { + "nvim-lspconfig", + opts = { + servers = { + opts = { + dart = { + ["flutter-tools"] = { + fvm = true, + ui = { + border = "solid", + notification_style = "plugin", + }, + debugger = { + enabled = false, + }, + widget_guides = { + enabled = false, + }, + dev_log = { + enabled = true, + }, + }, + color = { + enabled = true, + }, + settings = { + showTodos = false, + enableSnippets = true, + completeFunctionCalls = true, + }, + }, + }, + setup = { + dart = function(_, server_opts) + ---@type dora.lib + local lib = require("dora.lib") + + local lsp_opts = + lib.tbl.filter_out_keys(server_opts, { "flutter-tools" }) + local flutter_tools_opts = server_opts["flutter-tools"] or {} + flutter_tools_opts.lsp = lsp_opts + require("flutter-tools").setup(flutter_tools_opts) + require("telescope").load_extension("flutter") + end, + }, + }, + }, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + dart = { "dart_format" }, + }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/latex.lua b/lua/dotvim/legacy/packages/extra/lang/latex.lua new file mode 100644 index 00000000..f8da48c0 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/latex.lua @@ -0,0 +1,69 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.latex", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "latex" }) + end + end, + }, + { + "kdheepak/cmp-latex-symbols", + ft = "latex", + }, + { + "nvim-cmp", + opts = function(_, opts) + local function in_latex_scope() + local context = require("cmp.config.context") + local ft = vim.api.nvim_get_option_value("filetype", { + buf = 0, + }) + if ft ~= "markdown" and ft ~= "latex" then + return false + end + return context.in_treesitter_capture("text.math") + end + + table.insert(opts.sources, { + name = "latex_symbols", + filetype = { "tex", "latex", "markdown" }, + group_index = 1, + option = { + cache = true, + strategy = 2, -- latex only + }, + entry_filter = function(_, ctx) + if ctx.in_latex_scope == nil then + ctx.in_latex_scope = in_latex_scope() + end + return ctx.in_latex_scope + end, + }) + end, + }, + { + "jbyuki/nabla.nvim", + ft = { "latex", "markdown" }, + keys = { + { + "pf", + function() + require("nabla").popup { + border = "solid", + } + end, + ft = { "latex", "markdown" }, + }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/lua.lua b/lua/dotvim/legacy/packages/extra/lang/lua.lua new file mode 100644 index 00000000..a7263736 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/lua.lua @@ -0,0 +1,103 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.lua", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "lua" }) + end + end, + }, + { + "nvim-lspconfig", + opts = function(_, opts) + local libraries = { + "${3rd}/luassert/library", + vim.fn.expand("$VIMRUNTIME/lua"), + vim.fn.expand("$VIMRUNTIME/lua/vim/lsp"), + } + local add_plugins = { + "lazy.nvim", + "plenary.nvim", + "noice.nvim", + "nui.nvim", + "plenary.nvim", + } + for _, plugin in ipairs(add_plugins) do + table.insert( + libraries, + vim.fn.stdpath("data") .. "/lazy/" .. plugin .. "/lua" + ) + end + + opts.servers.opts.lua_ls = { + settings = { + Lua = { + runtime = { + version = "LuaJIT", + path = vim.split(package.path, ";"), + }, + diagnostics = { + globals = { "vim" }, + disable = {}, + }, + workspace = { library = libraries }, + format = { + enable = true, + defaultConfig = { + indent_style = "space", + continuation_indent_size = "2", + }, + }, + }, + }, + } + end, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + lua = { "stylua" }, + }, + }, + }, + { + "dial.nvim", + opts = function(_, opts) + local function define_custom(...) + local augend = require("dial.augend") + return augend.constant.new { + elements = { ... }, + word = true, + cyclic = true, + } + end + + if opts.ft.lua == nil then + opts.ft.lua = {} + end + + vim.list_extend(opts.ft.lua, { + define_custom("==", "~="), + }) + end, + }, + { + "mason.nvim", + opts = function(_, opts) + vim.list_extend(opts.extra.ensure_installed, { + "lua-language-server", + "stylua", + }) + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/markdown.lua b/lua/dotvim/legacy/packages/extra/lang/markdown.lua new file mode 100644 index 00000000..3b3f4aa4 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/markdown.lua @@ -0,0 +1,126 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.markdown", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "jbyuki/nabla.nvim", + ft = { "latex", "markdown" }, + keys = { + { + "pf", + function() + require("nabla").popup { + border = "solid", + } + end, + ft = { "latex", "markdown" }, + }, + }, + }, + { + "iamcco/markdown-preview.nvim", + name = "markdown-preview.nvim", + ft = { "markdown" }, + build = function() + vim.fn["mkdp#util#install"]() + end, + init = function() + vim.g.mkdp_open_to_the_world = true + vim.g.mkdp_echo_preview_url = true + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "markdown-preview.nvim", + category = "MdPreview", + condition = function(buf) + return buf.filetype == "markdown" + end, + actions = { + { + id = "markdown-preview.start", + title = "Start md preview", + callback = function() + vim.api.nvim_command("MarkdownPreview") + end, + }, + { + id = "markdown-preview.stop", + title = "Stop md preview", + callback = function() + vim.api.nvim_command("MarkdownPreviewStop") + end, + }, + { + id = "markdown-preview.toggle", + title = "Toggle md preview", + callback = function() + vim.api.nvim_command("MarkdownPreviewToggle") + end, + }, + }, + } + end, + }, + { + "dhruvasagar/vim-table-mode", + ft = { "markdown" }, + cmd = { "TableModeEnable", "TableModeDisable" }, + gui = "all", + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "vim-table-mode", + category = "TableMode", + condition = function(buf) + return buf.filetype == "markdown" + end, + actions = { + { + id = "table-mode.enable", + title = "Enable table mode", + callback = function() + vim.api.nvim_command("TableModeEnable") + end, + }, + { + id = "table-mode.disable", + title = "Disable table mode", + callback = function() + vim.api.nvim_command("TableModeDisable") + end, + }, + }, + } + end, + }, + { + "lukas-reineke/headlines.nvim", + dependencies = { + "nvim-treesitter/nvim-treesitter", + }, + enabled = function() + return not vim.g.neovide + end, + ft = { "markdown", "vimwiki" }, + opts = {}, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + markdown = { "prettier" }, + }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/nix.lua b/lua/dotvim/legacy/packages/extra/lang/nix.lua new file mode 100644 index 00000000..3c7d640e --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/nix.lua @@ -0,0 +1,52 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.nix", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "nix" }) + end + end, + }, + { + "nvim-lspconfig", + opts = { + servers = { + opts = { + nil_ls = { + settings = { + ["nil"] = { + formatting = { + command = { "alejandra" }, + }, + nix = { + maxMemoryMB = 16 * 1024, + flake = { + autoArchive = true, + autoEvalInputs = true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + nix = { "alejandra" }, + }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/python.lua b/lua/dotvim/legacy/packages/extra/lang/python.lua new file mode 100644 index 00000000..32f3e31f --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/python.lua @@ -0,0 +1,58 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.python", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "python" }) + end + end, + }, + { + "nvim-lspconfig", + opts = { + servers = { + opts = { + pyright = {}, + }, + }, + }, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + python = { "black" }, + }, + }, + }, + { + "dial.nvim", + opts = function(_, opts) + local function define_custom(...) + local augend = require("dial.augend") + return augend.constant.new { + elements = { ... }, + word = true, + cyclic = true, + } + end + + if opts.ft.python == nil then + opts.ft.python = {} + end + + vim.list_extend(opts.ft.python, { + define_custom("True", "False"), + }) + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/rust.lua b/lua/dotvim/legacy/packages/extra/lang/rust.lua new file mode 100644 index 00000000..41236a58 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/rust.lua @@ -0,0 +1,258 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.rust", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "rust" }) + end + end, + }, + { + "saecki/crates.nvim", + dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim" }, + event = { + { + event = "BufEnter", + pattern = "Cargo.toml", + }, + }, + init = function() + vim.api.nvim_create_autocmd("BufRead", { + group = vim.api.nvim_create_augroup( + "CmpSourceCargo", + { clear = true } + ), + pattern = "Cargo.toml", + callback = function() + local cmp = require("cmp") + cmp.setup.buffer { sources = { { name = "crates" } } } + + vim.keymap.set("n", "K", function() + if require("crates").popup_available() then + require("crates").show_popup() + end + end, { + buffer = true, + }) + end, + }) + end, + opts = { + autoload = true, + popup = { autofocus = true, border = "rounded" }, + src = { + cmp = { + enabled = true, + }, + }, + }, + config = function(_, opts) + require("crates").setup(opts) + require("crates").update() + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "crates.nvim", + category = "Crates", + condition = function(buf) + --- check if buf.full_file_name endwidths "Cargo.toml" + return buf.full_file_name:match("Cargo.toml$") + end, + actions = { + { + id = "crates-nvim.open-homepage", + title = "Open homepage under cursor", + callback = function() + require("crates").open_homepage() + end, + }, + { + id = "crates-nvim.open-documentation", + title = "Open documentation under cursor", + callback = function() + require("crates").open_documentation() + end, + }, + { + id = "crates-nvim.open-repository", + title = "Open repository under cursor", + callback = function() + require("crates").open_repository() + end, + }, + { + id = "crates-nvim.upgrade-crate", + title = "Upgrade crate under cursor", + callback = function() + require("crates").upgrade_crate() + end, + }, + { + id = "crates-nvim.open-crate-popup", + title = "Open crate popup", + callback = function() + require("crates").show_crate_popup() + end, + }, + { + id = "crates-nvim.open-versions-popup", + title = "Open versions popup", + callback = function() + require("crates").show_versions_popup() + end, + }, + { + id = "crates-nvim.open-features-popup", + title = "Open features popup", + callback = function() + require("crates").show_features_popup() + end, + }, + { + id = "crates-nvim.open-dependencies-popup", + title = "Open dependencies popup", + callback = function() + require("crates").show_dependencies_popup() + end, + }, + }, + } + end, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + rust = { "rustfmt" }, + }, + }, + }, + { + "mrcjkb/rustaceanvim", + version = "^4", + dependencies = { "nvim-lua/plenary.nvim", "mfussenegger/nvim-dap" }, + ft = { "rust" }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "rustaceanvim", + category = "Rustaceanvim", + condition = function(buf) + for _, server in ipairs(buf.lsp_servers) do + if server.name == "rust-analyzer" then + return true + end + end + return false + end, + actions = { + { + id = "rustaceanvim.expand-macro", + title = "Expand macro", + callback = function() + vim.api.nvim_command("RustLsp expandMacro") + end, + }, + { + id = "rustaceanvim.rebuild-proc-macro", + title = "Rebuild proc macro", + callback = function() + vim.api.nvim_command("RustLsp rebuildProcMacros") + end, + }, + { + id = "rustaceanvim.move-item-up", + title = "Move item up", + callback = function() + vim.api.nvim_command("RustLsp moveItem up") + end, + }, + { + id = "rustaceanvim.move-item-down", + title = "Move item down", + callback = function() + vim.api.nvim_command("RustLsp moveItem down") + end, + }, + { + id = "rustaceanvim.hover-actions", + title = "Hover actions", + callback = function() + vim.api.nvim_command("RustLsp hover actions") + end, + }, + { + id = "rustaceanvim.hover-range", + title = "Hover range", + callback = function() + vim.api.nvim_command("RustLsp hover range") + end, + }, + { + id = "rustaceanvim.explain-errors", + title = "Explain errors", + callback = function() + vim.api.nvim_command("RustLsp explainError") + end, + }, + { + id = "rustaceanvim.render-diagnostic", + title = "Render diagnostic", + callback = function() + vim.api.nvim_command("RustLsp renderDiagnostic") + end, + }, + { + id = "rustaceanvim.open-cargo-toml", + title = "Open cargo.toml of this file", + callback = function() + vim.api.nvim_command("RustLsp openCargo") + end, + }, + { + id = "rustaceanvim.open-parent-module", + title = "Open parent module of this file", + callback = function() + vim.api.nvim_command("RustLsp parentModule") + end, + }, + { + id = "rustaceanvim.join-lines", + title = "Join lines", + callback = function() + vim.api.nvim_command("RustLsp joinLines") + end, + }, + { + id = "rustaceanvim.structural-search-replace", + title = "Structural search replace", + callback = function() + vim.api.nvim_command("RustLsp ssr") + end, + }, + { + id = "rustaceanvim.view-syntax-tree", + title = "View syntax tree", + callback = function() + vim.api.nvim_command("RustLsp syntaxTree") + end, + }, + }, + } + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/swift.lua b/lua/dotvim/legacy/packages/extra/lang/swift.lua new file mode 100644 index 00000000..5bcb759f --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/swift.lua @@ -0,0 +1,45 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.swift", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "swift" }) + end + end, + }, + { + "nvim-lspconfig", + opts = { + servers = { + opts = { + sourcekit = {}, + }, + setup = { + sourcekit = function(_, server_opts) + if vim.uv.os_uname().sysname == "Darwin" then + -- skip if not on macOS + require("lspconfig").sourcekit.setup(server_opts) + end + end, + }, + }, + }, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + swift = { "swift_format" }, + }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lang/typescript.lua b/lua/dotvim/legacy/packages/extra/lang/typescript.lua new file mode 100644 index 00000000..dbb1a540 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lang/typescript.lua @@ -0,0 +1,113 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lang.typescript", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + "dora.packages.treesitter", + }, + plugins = { + { + "nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "typescript" }) + end + end, + }, + { + "pmizio/typescript-tools.nvim", + lazy = true, + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + cmd = { + "TSToolsOrganizeImports", + "TSToolsSortImports", + "TSToolsRemoveUnusedImports", + "TSToolsRemoveUnused", + "TSToolsAddMissingImports", + "TSToolsFixAll", + "TSToolsGoToSourceDefinition", + "TSToolsRenameFile", + }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "typescript-tools.nvim", + category = "TSTools", + actions = { + { + id = "typescript-tools.organize-imports", + title = "Sorts and removes unused imports", + callback = "TSToolsOrganizeImports", + }, + { + id = "typescript-tools.sort-imports", + title = "Sorts imports", + callback = "TSToolsSortImports", + }, + { + id = "typescript-tools.remove-unused-imports", + title = "Removes unused imports", + callback = "TSToolsRemoveUnusedImports", + }, + { + id = "typescript-tools.remove-unused", + title = "Removes all unused statements", + callback = "TSToolsRemoveUnused", + }, + { + id = "typescript-tools.add-missing-imports", + title = "Adds imports for all statements that lack one and can be imported", + callback = "TSToolsAddMissingImports", + }, + { + id = "typescript-tools.fix-all", + title = "Fixes all fixable erros in the current file", + callback = "TSToolsFixAll", + }, + { + id = "typescript-tools.go-to-source-definition", + title = "Go to the source definition", + callback = "TSToolsGoToSourceDefinition", + }, + { + id = "typescript-tools.rename-file", + title = "Rename file and apply changes to connected files", + callback = "TSToolsRenameFile", + }, + }, + } + end, + }, + { + "nvim-lspconfig", + opts = { + servers = { + opts = { + typescript = { + settings = { + tsserver_locale = "en", + complete_function_calls = true, + }, + }, + }, + setup = { + typescript = function(_, server_opts) + require("typescript-tools").setup(server_opts) + end, + }, + }, + }, + }, + { + "conform.nvim", + opts = { + formatters_by_ft = { + typescript = { "prettier" }, + }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/lsp.lua b/lua/dotvim/legacy/packages/extra/lsp.lua new file mode 100644 index 00000000..b4842506 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/lsp.lua @@ -0,0 +1,47 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.lsp", + deps = { + "dora.packages.lsp", + "dora.packages.editor", + }, + plugins = { + { + "stevearc/aerial.nvim", + dependencies = { + "nvim-treesitter", + "nvim-web-devicons", + "telescope.nvim", + }, + cmd = { + "AerialToggle", + "AerialOpen", + "AerialOpenAll", + "AerialClose", + "AerialCloseAll", + "AerialNext", + "AerialPrev", + "AerialGo", + "AerialInfo", + "AerialNavToggle", + "AerialNavOpen", + "AerialNavClose", + }, + opts = { + backends = { "lsp", "markdown", "man" }, + layout = { + default_direction = "right", + placement = "edge", + preserve_equality = true, + }, + attach_mode = "global", + filter_kind = false, + show_guides = true, + }, + config = function(_, opts) + require("aerial").setup(opts) + require("telescope").load_extension("aerial") + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/misc/competitive-programming.lua b/lua/dotvim/legacy/packages/extra/misc/competitive-programming.lua new file mode 100644 index 00000000..3cedc4f0 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/misc/competitive-programming.lua @@ -0,0 +1,74 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.misc.competitive-programming", + plugins = { + { + "p00f/cphelper.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + cmd = { "CphReceive", "CphTest", "CphRetest", "CphEdit", "CphDelete" }, + keys = { + { + "", + "CphTest", + desc = "Run cp test", + }, + }, + init = function() + local home = os.getenv("HOME") + vim.g["cph#dir"] = home .. "/Projects/competitive-programming" + vim.g["cph#lang"] = "cpp" + vim.g["cph#rust#createjson"] = true + vim.g["cph#cpp#compile_command"] = + "g++ solution.cpp -std=c++20 -o cpp.out" + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + ---@type dora.lib + local lib = require("dora.lib") + + return action.make_options { + from = "cphelper.nvim", + category = "cphelper", + actions = { + { + id = "cphelper.receive-task", + title = "Receive a parsed task from browser", + callback = "CphReceive", + }, + { + id = "cphelper.run-all-cases", + title = "Test a solutions with all cases", + callback = "CphTest", + }, + { + id = "cphelper.run-specified-case", + title = "Test a solution with a specified case", + callback = lib.vim.input_then_exec("CphTest"), + }, + { + id = "cphelper.retest-all-cases", + title = "Retest a solution with all cases without recompiling", + callback = "CphRetest", + }, + { + id = "cphelper.retest-specified-case", + title = "Retest a solution with a specified case without recompiling", + callback = lib.vim.input_then_exec("CphRetest"), + }, + { + id = "cphelper.edit-task", + title = "Edit/Add a test case", + callback = lib.vim.input_then_exec("CphEdit"), + }, + { + id = "cphelper.delete-task", + title = "Delete a test case", + callback = lib.vim.input_then_exec("CphDelete"), + }, + }, + } + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/misc/copilot.lua b/lua/dotvim/legacy/packages/extra/misc/copilot.lua new file mode 100644 index 00000000..346871af --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/misc/copilot.lua @@ -0,0 +1,210 @@ +local _copilot_setup_done = false + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.misc.copilot", + deps = { + "dora.packages.coding", + "dora.packages.ui", + }, + plugins = { + { + "zbirenbaum/copilot.lua", + event = "InsertEnter", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = { + suggestion = { + auto_trigger = true, + keymap = { + accept = "", + }, + }, + }, + config = function(_, opts) + vim.defer_fn(function() + require("copilot").setup(opts) + _copilot_setup_done = true + end, 100) + end, + actions = function() + return { + { + id = "copilot.status", + title = "Copilot status", + description = "Show the status of Copilot", + callback = function() + vim.api.nvim_command("Copilot status") + end, + }, + { + id = "copilot.auth", + title = "Copilot auth", + callback = function() + vim.api.nvim_command("Copilot auth") + end, + }, + { + id = "copilot.show-panel", + title = "Copilot panel", + callback = function() + vim.api.nvim_command("Copilot panel") + end, + }, + } + end, + }, + { + "lualine.nvim", + opts = function(_, opts) + local spinners = { + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + } + local normal_icon = "ï’ž " + local disable_icon = "ï’č " + local warning_icon = "ï’ș " + local sleeping_icon = "ó°’Č " + + local function hl_fg(name) + local hl = vim.api.nvim_get_hl(0, { + name = name, + link = false, + }) + local fg = hl.fg + if fg ~= nil and fg ~= "" then + return string.format("#%x", fg) + end + return "" + end + + local is_current_buffer_attached = function() + if not _copilot_setup_done then + return false + end + return require("copilot.client").buf_is_attached( + vim.api.nvim_get_current_buf() + ) + end + + local function is_enabled() + if not _copilot_setup_done then + return false + end + + if require("copilot.client").is_disabled() then + return false + end + + if not is_current_buffer_attached() then + return false + end + + return true + end + + ---@return 'Disabled' | 'Error' | 'InProgress' | 'Sleeping' | 'Normal' + local function copilot_status() + if not _copilot_setup_done then + return "InProgress" + end + if not is_enabled() then + return "Disabled" + end + local data = require("copilot.api").status.data.status + if data == "Warning" then + return "Error" + elseif data == "InProgress" then + return "InProgress" + end + if vim.b.copilot_suggestion_auto_trigger == nil then + if not require("copilot.config").get("suggestion").auto_trigger then + return "Sleeping" + end + return "Normal" + else + if not vim.b.copilot_suggestion_auto_trigger then + return "Sleeping" + end + return "Normal" + end + end + + ---@type dora.lib + local lib = require("dora.lib") + + local spinner_count = 1 + + local component = require("lualine.component"):extend() + + local highlight = require("lualine.highlight") + + function component:init(options) + component.super:init(options) + lib.vim.on_lsp_attach(function(client, _) + if client and client.name == "copilot" then + require("copilot.api").register_status_notification_handler( + function() + require("lualine").refresh() + end + ) + return true + end + return false + end) + self.error_hl = highlight.create_component_highlight_group({ + { + fg = hl_fg("DiagnosticError"), + }, + }, "copilot_lualine_error", options) + self.in_progress_hl = highlight.create_component_highlight_group({ + { + fg = hl_fg("DiagnosticHint"), + }, + }, "copilot_lualine_in_progress", options) + self.sleeping_hl = highlight.create_component_highlight_group({ + { + fg = hl_fg("Comment"), + }, + }, "copilot_lualine_sleeping", options) + end + + function component:update_status() + local status = copilot_status() + if status == "Normal" then + return normal_icon + elseif status == "Disabled" then + return disable_icon + elseif status == "Error" then + return highlight.component_format_highlight(self.error_hl) + .. warning_icon + elseif status == "InProgress" then + local icon = spinners[spinner_count] + spinner_count = (spinner_count + 1) % #spinners + 1 + return highlight.component_format_highlight(self.in_progress_hl) + .. icon + elseif status == "Sleeping" then + return highlight.component_format_highlight(self.sleeping_hl) + .. sleeping_icon + else + return normal_icon + end + end + + table.insert(opts.sections.lualine_y, 1, component) + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/misc/darwin.lua b/lua/dotvim/legacy/packages/extra/misc/darwin.lua new file mode 100644 index 00000000..76436f34 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/misc/darwin.lua @@ -0,0 +1,45 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.misc.darwin", + plugins = { + { + "mrjones2014/dash.nvim", + build = "make install", + cmd = { "Dash", "DashWord" }, + enabled = function() + return vim.uv.os_uname().sysname == "Darwin" + end, + opts = { + dash_app_path = "/Applications/Dash.app", + search_engine = "google", + file_type_keywords = { + dashboard = false, + NvimTree = false, + TelescopePrompt = false, + terminal = false, + packer = false, + fzf = false, + ["neo-tree"] = false, + }, + }, + actions = function() + return { + { + id = "dash.search", + title = "Search Dash", + callback = function() + vim.api.nvim_command("Dash") + end, + }, + { + id = "dash.search-word", + title = "Search Word", + callback = function() + vim.api.nvim_command("DashWord") + end, + }, + } + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/misc/rime.lua b/lua/dotvim/legacy/packages/extra/misc/rime.lua new file mode 100644 index 00000000..3c85f294 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/misc/rime.lua @@ -0,0 +1,260 @@ +local just_inserted = false + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.misc.rime", + deps = { + "dora.packages.coding", + "dora.packages.lsp", + }, + plugins = { + { + "nvim-lspconfig", + opts = function(_, opts) + require("lspconfig.configs").rime_ls = { + default_config = { + name = "rime_ls", + cmd = { "rime_ls" }, + filetypes = { "markdown", "text" }, + single_file_support = true, + }, + settings = {}, + docs = { + description = [[ +https://www.github.com/wlh320/rime-ls + +A language server for librime +]], + }, + } + + opts.servers.opts.rime_ls = { + init_options = { + enabled = false, + shared_data_dir = "~/.local/share/rime-ls-data-files", + user_data_dir = "~/.local/share/rime-ls-files", + log_dir = "~/.local/share/rime-ls-files/log", + max_candidates = 9, + trigger_characters = {}, + schema_trigger_character = "&", + max_tokens = 4, + override_server_capabilities = { trigger_characters = {} }, + always_incomplete = true, + }, + } + + ---@type dora.lib + local lib = require("dora.lib") + + local function is_rime_entry(entry) + return vim.tbl_get(entry, "source", "name") == "nvim_lsp" + and vim.tbl_get(entry, "source", "source", "client", "name") + == "rime_ls" + end + + local function text_edit_range_length(entry) + local range = entry.completion_item.textEdit.range + return range["end"].character - range.start.character + end + + local rime_ls_auto_confirm = vim.schedule_wrap(function() + local cmp = require("cmp") + if not vim.g.global_rime_enabled or not cmp.visible() then + return + end + local entries = cmp.core.view:get_entries() + if entries == nil or #entries == 0 then + return + end + local rime_ls_entries_cnt = 0 + for _, entry in ipairs(entries) do + if is_rime_entry(entry) then + rime_ls_entries_cnt = rime_ls_entries_cnt + 1 + end + end + local first_entry = cmp.get_selected_entry() + if first_entry == nil then + first_entry = cmp.core.view:get_first_entry() + end + if + first_entry ~= nil + and rime_ls_entries_cnt == 1 + and is_rime_entry(first_entry) + and text_edit_range_length(first_entry) == 4 + then + cmp.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + } + end + end) + + opts.servers.setup.rime_ls = function(_, server_opts) + vim.g.global_rime_enabled = server_opts.init_options.enabled or false + + require("lspconfig").rime_ls.setup(server_opts) + + lib.vim.on_lsp_attach(function(client, bufnr) + local toggle_rime = function() + client.request( + "workspace/executeCommand", + { command = "rime-ls.toggle-rime" }, + function(_, result, ctx, _) + if ctx.client_id == client.id then + vim.g.global_rime_enabled = not not result + end + end, + bufnr + ) + end + + vim.keymap.set({ "n", "i" }, "", function() + toggle_rime() + end, { + silent = true, + desc = "rime-toggle", + buffer = bufnr, + }) + + local ft = vim.api.nvim_get_option_value("filetype", { + buf = bufnr, + }) + + if ft == "markdown" then + local toggle_markdown_code = function() + if vim.g.previous_markdown_code ~= nil then + if + vim.g.previous_markdown_code ~= vim.g.global_rime_enabled + then + toggle_rime() + end + vim.g.previous_markdown_code = nil + else + vim.g.previous_markdown_code = vim.g.global_rime_enabled + if vim.g.global_rime_enabled then + toggle_rime() + end + end + end + + vim.keymap.set({ "i" }, "`", function() + toggle_markdown_code() + vim.fn.feedkeys("`", "n") + end, { + silent = true, + desc = "rime-toggle", + buffer = bufnr, + }) + end + + vim.keymap.set("n", "rs", function() + vim.lsp.buf.execute_command { command = "rime-ls.sync-user-data" } + end, { desc = "rime-sync-user-data", buffer = bufnr }) + + vim.api.nvim_create_autocmd("InsertCharPre", { + buffer = bufnr, + callback = function() + just_inserted = true + end, + }) + vim.api.nvim_create_autocmd({ "TextChangedI", "TextChangedP" }, { + buffer = bufnr, + callback = function() + if just_inserted then + -- check completion + rime_ls_auto_confirm() + just_inserted = false + end + end, + }) + end) + end + end, + }, + { + "nvim-cmp", + opts = function(_, opts) + local cmp = require("cmp") + + local i_cr_action = function(fallback) + if not cmp.visible() then + fallback() + return + end + + -- test the first entry is rime_ls or not + local entry = cmp.get_selected_entry() + if entry == nil then + entry = cmp.core.view:get_first_entry() + end + if entry == nil then + -- entry still nil, fallback + fallback() + return + end + + if + entry.source ~= nil + and entry.source.name == "nvim_lsp" + and entry.source.source ~= nil + and entry.source.source.client ~= nil + and entry.source.source.client.name == "rime_ls" + then + -- if the first entry is from rime_ls, do not confirm, now is a simple + -- new line marker + cmp.abort() + return + end + + -- otherwise, confirm the selected entry + entry = cmp.get_selected_entry() + if entry == nil then + fallback() + return + end + + local is_insert_mode = function() + return vim.api.nvim_get_mode().mode:sub(1, 1) == "i" + end + local confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + } + if is_insert_mode() then + confirm_opts.behavior = cmp.ConfirmBehavior.Insert + end + if not cmp.confirm(confirm_opts) then + fallback() + end + end + + opts.mapping[""] = i_cr_action + opts.mapping[""] = cmp.mapping(function(fallback) + if not cmp.visible() then + fallback() + return + end + local entry = cmp.get_selected_entry() + if entry == nil then + entry = cmp.core.view:get_first_entry() + end + if entry == nil then + fallback() + return + end + if + entry ~= nil + and vim.g.global_rime_enabled + and entry.source.name == "nvim_lsp" + and entry.source.source.client.name == "rime_ls" + then + -- cmp enabled + cmp.confirm { behavior = cmp.ConfirmBehavior.Insert, select = true } + else + fallback() + end + end, { "i", "s" }) + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/misc/tools.lua b/lua/dotvim/legacy/packages/extra/misc/tools.lua new file mode 100644 index 00000000..4af0674a --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/misc/tools.lua @@ -0,0 +1,57 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.misc.tools", + plugins = { + { + "skywind3000/asynctasks.vim", + enabled = true, + cmd = { + "AsyncTask", + "AsyncTaskMacro", + "AsyncTaskProfile", + "AsyncTaskEdit", + }, + init = function() + vim.g.asyncrun_open = 10 + vim.g.asyncrun_bell = 0 + vim.g.asyncrun_rootmarks = { + "BLADE_ROOT", + "JK_ROOT", + "WORKSPACE", + ".buckconfig", + "CMakeLists.txt", + } + vim.g.asynctasks_extra_config = + { "~/.dotfiles/dots/tasks/asynctasks.ini" } + end, + dependencies = { + { "skywind3000/asyncrun.vim", cmd = { "AsyncRun", "AsyncStop" } }, + }, + }, + { + "topaxi/gh-actions.nvim", + name = "gh-actions.nvim", + pname = "gh-actions-nvim", + cmd = { "GhActions" }, + dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim" }, + build = "make", + opts = {}, + }, + { + "pwntester/octo.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope.nvim", + "nvim-tree/nvim-web-devicons", + }, + cmd = { "Octo" }, + opts = { + default_remote = { "origin", "upstream" }, + }, + }, + { + "edkolev/tmuxline.vim", + cmd = { "Tmuxline" }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/misc/wakatime.lua b/lua/dotvim/legacy/packages/extra/misc/wakatime.lua new file mode 100644 index 00000000..8498eac8 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/misc/wakatime.lua @@ -0,0 +1,12 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.misc.wakatime", + plugins = { + { + "wakatime/vim-wakatime", + event = "BufReadPost", + opts = {}, + config = function() end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/obsidian.lua b/lua/dotvim/legacy/packages/extra/obsidian.lua new file mode 100644 index 00000000..affed301 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/obsidian.lua @@ -0,0 +1,78 @@ +local vault_dir = function() + ---@type dora.lib + local lib = require("dora.lib") + return vim.F.if_nil( + lib.lazy.opts("obsidian.nvim").dir, + vim.fn.expand("~/obsidian-data") + ) +end + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.obsidian", + deps = { + "dora.packages.editor", + "dora.packages.coding", + }, + setup = function() + local au_group = + vim.api.nvim_create_augroup("obsidian_extra_setup", { clear = true }) + + ---@type dora.lib + local lib = require("dora.lib") + + vim.api.nvim_create_autocmd( + { "BufNewFile", "BufReadPost", "BufWinEnter" }, + { + group = au_group, + pattern = vault_dir() .. "/**.md", + callback = function() + vim.wo.conceallevel = 2 + vim.keymap.set("n", "gf", function() + if require("obsidian").util.cursor_on_markdown_link() then + vim.api.nvim_command("ObsidianFollowLink") + end + end, { buffer = true, desc = "obsidian-follow-link" }) + end, + } + ) + end, + plugins = { + { + "epwalsh/obsidian.nvim", + version = "*", + event = function() + return { + ("BufReadPre %s/*.md"):format(vault_dir()), + ("BufNewFile %s/*.md"):format(vault_dir()), + } + end, + dependencies = { + "plenary.nvim", + "telescope.nvim", + "nvim-treesitter", + }, + cmd = { + "ObsidianBacklinks", + "ObsidianExtractNote", + "ObsidianFollowLink", + "ObsidianLink", + "ObsidianLinkNew", + "ObsidianLinks", + "ObsidianNew", + "ObsidianOpen", + "ObsidianPasteImg", + "ObsidianQuickSwitch", + "ObsidianRename", + "ObsidianSearch", + "ObsidianTags", + "ObsidianTemplate", + "ObsidianToday", + "ObsidianTomorrow", + "ObsidianWorkspace", + "ObsidianYesterday", + }, + opts = {}, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/extra/ui.lua b/lua/dotvim/legacy/packages/extra/ui.lua new file mode 100644 index 00000000..9697c819 --- /dev/null +++ b/lua/dotvim/legacy/packages/extra/ui.lua @@ -0,0 +1,36 @@ +---@type dora.core.package.PackageOption +return { + name = "dora.packages.extra.ui", + deps = {}, + plugins = { + { + "NvChad/nvim-colorizer.lua", + ft = { "vim", "lua" }, + cmd = { + "ColorizerAttachToBuffer", + "ColorizerDetachFromBuffer", + "ColorizerReloadAllBuffers", + "ColorizerToggle", + }, + opts = { + filetypes = { "vim", "lua" }, + user_default_options = { + RRGGBB = true, + names = false, + AARRGGBB = true, + mode = "virtualtext", + }, + }, + config = function(_, opts) + require("colorizer").setup(opts) + + local ft = vim.api.nvim_get_option_value("filetype", { + buf = 0, + }) + if ft == "vim" or ft == "lua" then + require("colorizer").attach_to_buffer(0) + end + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/lsp/init.lua b/lua/dotvim/legacy/packages/lsp/init.lua new file mode 100644 index 00000000..11084108 --- /dev/null +++ b/lua/dotvim/legacy/packages/lsp/init.lua @@ -0,0 +1,83 @@ +---@type dora.lib +local lib = require("dora.lib") + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.lsp", + deps = { + "dora.packages.coding", + }, + plugins = lib.tbl.flatten_array { + require("dora.packages.lsp.plugins.nvim-lspconfig"), + require("dora.packages.lsp.plugins.lspkind"), + require("dora.packages.lsp.plugins.glance"), + }, + setup = function() + ---@type dora.config.lsp + local lsp = require("dora.config.lsp") + + ---@param buffer number + local function create_lsp_autocmds(buffer) + -- display diagnostic win on CursorHold + vim.api.nvim_create_autocmd("CursorHold", { + buffer = buffer, + callback = lsp.methods.open_diagnostic, + }) + end + + ---@param buffer? number + local function setup_lsp_keymaps(buffer) + ---comment normal map + ---@param lhs string + ---@param rhs any + ---@param desc string + local nmap = function(lhs, rhs, desc) + vim.keymap.set("n", lhs, rhs, { desc = desc, buffer = buffer }) + end + + nmap("gD", lsp.methods.declaration, "goto-declaration") + + nmap("gd", lsp.methods.definitions, "goto-definition") + + nmap("gt", lsp.methods.type_definitions, "goto-type-definition") + + if buffer ~= nil then + local current_k_map = vim.fn.mapcheck("K", "n") + -- empty or contains "nvim/runtime" + if current_k_map == "" or current_k_map:find("nvim/runtime") ~= nil then + nmap("K", lsp.methods.show_hover, "show-hover") + end + else + nmap("K", lsp.methods.show_hover, "show-hover") + end + + nmap("gi", lsp.methods.implementations, "goto-impl") + + nmap("gR", lsp.methods.rename, "rename-symbol") + + nmap("ga", lsp.methods.code_action, "code-action") + + nmap("gr", lsp.methods.references, "inspect-references") + + nmap("[c", lsp.methods.prev_diagnostic, "previous-diagnostic") + + nmap("]c", lsp.methods.next_diagnostic, "next-diagnostic") + end + + -- if in vscode environment, create key bindings globally, else only create + -- keybindings on lsp enabled buffers + if vim.g.vscode then + setup_lsp_keymaps() + else + lib.vim.on_lsp_attach(function(_, buffer) + local exists, value = + pcall(vim.api.nvim_buf_get_var, buffer, "_dora_lsp_attached") + if not exists or not value then + create_lsp_autocmds(buffer) + setup_lsp_keymaps(buffer) + vim.api.nvim_buf_set_var(buffer, "_dora_lsp_attached", true) + end + end) + end + end, +} diff --git a/lua/dotvim/legacy/packages/lsp/plugins/glance.lua b/lua/dotvim/legacy/packages/lsp/plugins/glance.lua new file mode 100644 index 00000000..462ebfcc --- /dev/null +++ b/lua/dotvim/legacy/packages/lsp/plugins/glance.lua @@ -0,0 +1,58 @@ +---@type dora.core.plugin.PluginOption +return { + "dnlhc/glance.nvim", + cmd = "Glance", + opts = function() + local actions = require("glance").actions + return { + detached = function(winid) + return vim.api.nvim_win_get_width(winid) < 100 + end, + preview_win_opts = { cursorline = true, number = true, wrap = false }, + border = { disable = true, top_char = "―", bottom_char = "―" }, + theme = { enable = true }, + list = { width = 0.2 }, + mappings = { + list = { + ["j"] = actions.next, + ["k"] = actions.previous, + [""] = false, + [""] = false, + [""] = actions.next_location, + [""] = actions.previous_location, + [""] = actions.preview_scroll_win(5), + [""] = actions.preview_scroll_win(-5), + ["v"] = false, + ["s"] = false, + ["t"] = false, + [""] = actions.jump, + ["o"] = false, + ["l"] = false, + ["q"] = actions.close, + ["Q"] = actions.close, + [""] = actions.close, + }, + preview = { + ["Q"] = actions.close, + [""] = false, + [""] = false, + ["l"] = false, + }, + }, + folds = { fold_closed = "󰅂", fold_open = "󰅀", folded = false }, + indent_lines = { enable = false }, + winbar = { enable = true }, + hooks = { + before_open = function(results, open, jump, method) + if method == "references" or method == "implementations" then + open(results) + elseif #results == 1 then + jump(results[1]) + else + open(results) + end + end, + }, + } + end, +} diff --git a/lua/dotvim/legacy/packages/lsp/plugins/lspkind.lua b/lua/dotvim/legacy/packages/lsp/plugins/lspkind.lua new file mode 100644 index 00000000..e22514f3 --- /dev/null +++ b/lua/dotvim/legacy/packages/lsp/plugins/lspkind.lua @@ -0,0 +1,55 @@ +---@type dora.core.plugin.PluginOption +return { + "onsails/lspkind.nvim", + lazy = true, + dependencies = { + { + "nvim-cmp", + opts = function(_, opts) + local lspkind = require("lspkind") + + opts.formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + local ret = lspkind.cmp_format { + mode = "symbol_text", + maxwidth = 50, + ellipsis_char = "...", + show_labelDetails = true, + before = function(e, item) + item.menu = ({ + buffer = "[Buf]", + nvim_lsp = "[LSP]", + ultisnips = "[Snip]", + luasnip = "[Snip]", + nvim_lua = "[Lua]", + orgmode = "[Org]", + path = "[Path]", + dap = "[DAP]", + emoji = "[Emoji]", + calc = "[CALC]", + latex_symbols = "[LaTeX]", + cmdline_history = "[History]", + cmdline = "[Command]", + copilot = "[Copilot]", + })[e.source.name] or ("[" .. e.source.name .. "]") + if e.source.name == "latex_symbols" then + item.kind = "Math" + end + return item + end, + }(entry, vim_item) + local strings = vim.split(ret.kind, "%s", { trimempty = true }) + ret.kind = strings[1] .. " " + if strings[2] and #strings[2] > 0 then + ret.menu = " (" .. strings[2] .. ")" + else + ret.menu = "" + end + return ret + end, + } + end, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/lsp/plugins/nvim-lspconfig.lua b/lua/dotvim/legacy/packages/lsp/plugins/nvim-lspconfig.lua new file mode 100644 index 00000000..1531fc42 --- /dev/null +++ b/lua/dotvim/legacy/packages/lsp/plugins/nvim-lspconfig.lua @@ -0,0 +1,123 @@ +---@type dora.core.plugin.PluginOption +return { + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + opts = function() + ---@type dora.config + local config = require("dora.config") + + return { + diagnostics = { + underline = true, + update_in_insert = false, + virtual_text = { + spacing = 4, + source = "if_many", + prefix = "●", + }, + severity_sort = true, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = config.icon.predefined_icon( + "DiagnosticError", + 1 + ), + [vim.diagnostic.severity.WARN] = config.icon.predefined_icon( + "DiagnosticWarn", + 1 + ), + [vim.diagnostic.severity.INFO] = config.icon.predefined_icon( + "DiagnosticInfo", + 1 + ), + [vim.diagnostic.severity.HINT] = config.icon.predefined_icon( + "DiagnosticHint", + 1 + ), + }, + }, + }, + inlay_hints = { + enabled = false, + }, + capabilities = {}, + servers = { + opts = {}, + setup = {}, + }, + } + end, + config = function(_, opts) + ---@type dora.lib + local lib = require("dora.lib") + + vim.diagnostic.config(vim.deepcopy(opts.diagnostics)) + + local capabilities = vim.tbl_deep_extend( + "force", + {}, + vim.lsp.protocol.make_client_capabilities(), + lib.func.require_then("cmp_nvim_lsp", function(cmp_nvim_lsp) + return cmp_nvim_lsp.default_capabilities() + end) or {}, + opts.capabilities or {} + ) + + ---@return string[]? + local function get_default_cmd(server) + local ok, server_module = + pcall(require, "lspconfig.server_configurations." .. server) + if not ok then + return nil + end + local default_config = server_module.default_config + return default_config.cmd + end + + ---@type dora.utils + local Utils = require("dora.utils") + + ---@param cmd string[] + local function try_to_replace_executable_from_nix_or_mason(cmd) + local executable = cmd[1] + local new_executable = Utils.which_binary(executable) + return { new_executable, unpack(cmd, 2) } + end + + ---@param server string + local function setup_server(server) + local server_opts = opts.servers.opts[server] or {} + local server_setup = opts.servers.setup[server] + local common_setup = opts.servers.setup["*"] + + server_opts = vim.tbl_deep_extend("force", { + capabilities = vim.deepcopy(capabilities), + }, server_opts) + + if server_opts.cmd ~= nil then + server_opts.cmd = + try_to_replace_executable_from_nix_or_mason(server_opts.cmd) + else + local default_cmd = get_default_cmd(server) + if default_cmd ~= nil then + server_opts.cmd = + try_to_replace_executable_from_nix_or_mason(default_cmd) + end + end + + if server_setup ~= nil then + server_setup(server, server_opts) + return + elseif common_setup ~= nil then + common_setup(server, server_opts) + return + else + require("lspconfig")[server].setup(server_opts) + end + end + + for server, _ in pairs(opts.servers.opts) do + setup_server(server) + end + end, +} diff --git a/lua/dotvim/legacy/packages/treesitter/init.lua b/lua/dotvim/legacy/packages/treesitter/init.lua new file mode 100644 index 00000000..0f2759c9 --- /dev/null +++ b/lua/dotvim/legacy/packages/treesitter/init.lua @@ -0,0 +1,11 @@ +---@type dora.lib +local lib = require("dora.lib") + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.treesitter", + plugins = lib.tbl.flatten_array { + require("dora.packages.treesitter.plugins.nvim-treesitter"), + require("dora.packages.treesitter.plugins._others"), + }, +} diff --git a/lua/dotvim/legacy/packages/treesitter/plugins/_others.lua b/lua/dotvim/legacy/packages/treesitter/plugins/_others.lua new file mode 100644 index 00000000..942a8feb --- /dev/null +++ b/lua/dotvim/legacy/packages/treesitter/plugins/_others.lua @@ -0,0 +1,105 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "IndianBoy42/tree-sitter-just", + gui = "all", + lazy = true, + config = function() + require("nvim-treesitter.parsers").get_parser_configs().just = { + install_info = { + url = "https://github.com/IndianBoy42/tree-sitter-just", -- local path or git repo + files = { "src/parser.c", "src/scanner.cc" }, + branch = "main", + use_makefile = true, -- this may be necessary on MacOS (try if you see compiler errors) + }, + maintainers = { "@IndianBoy42" }, + } + end, + }, + { + "windwp/nvim-ts-autotag", + gui = "all", + ft = { "markdown" }, + dependencies = { "nvim-treesitter" }, + config = function() + require("nvim-treesitter.configs").setup { + autotag = { + enable = true, + }, + } + end, + }, + { + "nvim-treesitter/nvim-treesitter-textobjects", + gui = "all", + event = { "BufReadPost", "BufNewFile" }, + dependencies = { "nvim-treesitter/nvim-treesitter" }, + opts = { + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + af = "@function.outer", + ["if"] = "@function.inner", + ["i,"] = "@parameter.inner", + ["a,"] = "@parameter.outer", + ["i:"] = "@assignment.rhs", + il = "@lifetime.inner", + ["a;"] = "@statement.outer", + ir = "@super_right.inner", + }, + }, + swap = { + enable = true, + swap_next = { [""] = "@parameter.inner" }, + swap_previous = { [""] = "@parameter.inner" }, + }, + move = { + enable = true, + set_jumps = true, + goto_next_start = { + ["],"] = "@parameter.inner", + ["]l"] = "@lifetime.inner", + ["]f"] = "@function.outer", + ["]r"] = "@super_right.inner", + }, + goto_previous_start = { + ["[,"] = "@parameter.inner", + ["[l"] = "@lifetime.inner", + ["[f"] = "@function.outer", + ["[r"] = "@super_right.inner", + }, + }, + }, + }, + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end, + }, + { + "RRethy/nvim-treesitter-endwise", + gui = "all", + ft = { "lua", "ruby", "vimscript" }, + dependencies = { "nvim-treesitter/nvim-treesitter" }, + opts = { + endwise = { enable = true }, + }, + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end, + }, + { + "Wansmer/treesj", + gui = "all", + dependencies = { + "nvim-treesitter/nvim-treesitter", + }, + cmd = { "TSJToggle", "TSJSplit", "TSJJoin" }, + opts = { + use_default_keymaps = false, + check_syntax_error = false, + max_join_length = 120, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/treesitter/plugins/nvim-treesitter.lua b/lua/dotvim/legacy/packages/treesitter/plugins/nvim-treesitter.lua new file mode 100644 index 00000000..93e31bc1 --- /dev/null +++ b/lua/dotvim/legacy/packages/treesitter/plugins/nvim-treesitter.lua @@ -0,0 +1,125 @@ +---@type dora.core.plugin.PluginOption +return { + "nvim-treesitter/nvim-treesitter", + gui = "all", + lazy = true, + dependencies = { + "IndianBoy42/tree-sitter-just", + }, + event = { "BufReadPost", "BufNewFile" }, + build = function() + if #vim.api.nvim_list_uis() ~= 0 and not vim.g.vscode then + vim.api.nvim_command("TSUpdate") + end + end, + init = function(plugin) + require("lazy.core.loader").add_to_rtp(plugin) + require("nvim-treesitter.query_predicates") + end, + cmd = { "TSInstall", "TSUpdate", "TSUpdateSync" }, + opts = function() + return { + ensure_installed = { + "astro", + "bash", + "cmake", + "css", + "diff", + "dockerfile", + "dot", + "ebnf", + "fish", + "git_config", + "git_rebase", + "gitattributes", + "gitcommit", + "gitignore", + "glimmer", + "go", + "graphql", + "html", + "http", + "ini", + "java", + "javascript", + "json", + "jsonc", + "jsonnet", + "just", + "llvm", + "lua", + "luadoc", + "make", + "markdown", + "markdown_inline", + "matlab", + "ninja", + "nix", + "pascal", + "perl", + "php", + "proto", + "python", + "query", + "regex", + "rust", + "scss", + "sql", + "svelte", + "swift", + "thrift", + "toml", + "tsx", + "twig", + "typescript", + "vim", + "vimdoc", + "vue", + "yaml", + }, + indent = { + enable = false, + }, + highlight = { + enable = not vim.g.vscode, + additional_vim_regex_highlighting = { "markdown" }, + disable = function(lang, bufnr) + if lang == "html" and vim.api.nvim_buf_line_count(bufnr) > 500 then + return true + end + for _, line in ipairs(vim.api.nvim_buf_get_lines(0, 0, 3, false)) do + if #line > 500 then + return true + end + end + return false + end, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = false, + node_decremental = "", + }, + }, + } + end, + keys = { + { "", desc = "init/increment-selection" }, + { "", desc = "decrement-selection" }, + }, + config = function(_, opts) + local parser = require("nvim-treesitter.parsers").get_parser_configs() + -- pin dart parser + parser.dart = { + install_info = { + url = "https://github.com/UserNobody14/tree-sitter-dart", + files = { "src/parser.c", "src/scanner.c" }, + revision = "8aa8ab977647da2d4dcfb8c4726341bee26fbce4", + }, + } + require("nvim-treesitter.configs").setup(opts) + end, +} diff --git a/lua/dotvim/legacy/packages/ui/init.lua b/lua/dotvim/legacy/packages/ui/init.lua new file mode 100644 index 00000000..26a1d2aa --- /dev/null +++ b/lua/dotvim/legacy/packages/ui/init.lua @@ -0,0 +1,14 @@ +---@type dora.lib +local lib = require("dora.lib") + +---@type dora.core.package.PackageOption +return { + name = "dora.packages.ui", + plugins = lib.tbl.flatten_array { + require("dora.packages.ui.plugins._others"), + require("dora.packages.ui.plugins.bufferline"), + require("dora.packages.ui.plugins.lualine"), + require("dora.packages.ui.plugins.noice"), + require("dora.packages.ui.plugins.alpha"), + }, +} diff --git a/lua/dotvim/legacy/packages/ui/plugins/_others.lua b/lua/dotvim/legacy/packages/ui/plugins/_others.lua new file mode 100644 index 00000000..6a129f46 --- /dev/null +++ b/lua/dotvim/legacy/packages/ui/plugins/_others.lua @@ -0,0 +1,158 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "rcarriga/nvim-notify", + opts = { + timeout = 3000, + stages = "static", + fps = 60, + max_height = function() + return math.floor( + vim.api.nvim_get_option_value("lines", { scope = "global" }) * 0.75 + ) + end, + max_width = function() + return math.floor( + vim.api.nvim_get_option_value("columns", { scope = "global" }) * 0.75 + ) + end, + on_open = function(win) + vim.api.nvim_win_set_config(win, { zindex = 100 }) + end, + }, + init = function() + local notifs = {} + local function temp(...) + table.insert(notifs, vim.F.pack_len(...)) + end + + local orig = vim.notify + vim.notify = temp + + local timer = vim.uv.new_timer() + local check = vim.uv.new_check() + + local replay = function() + timer:stop() + check:stop() + vim.schedule(function() + if vim.notify == temp then + -- try to load nvim-notify + local succ, notify = pcall(require, "notify") + if succ and notify ~= nil then + vim.notify = notify + else + vim.notify = orig -- put back the original notify if needed + end + end + vim.schedule(function() + for _, notif in ipairs(notifs) do + vim.notify(vim.F.unpack_len(notif)) + end + end) + end) + end + + -- wait till vim.notify has been replaced + check:start(function() + if vim.notify ~= temp then + replay() + end + end) + -- or if it took more than 500ms, then something went wrong + timer:start(500, 0, replay) + end, + config = function(_, opts) + vim.defer_fn(function() + require("notify").setup(opts) + + ---@type dora.core.registry + local registry = require("dora.core.registry") + + if registry.has("telescope.nvim") then + require("telescope").load_extension("notify") + end + end, 30) + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "nvim-notify", + category = "Notify", + actions = { + { + id = "notify.list-history", + title = "List notify histories using telescope", + callback = function() + require("telescope").extensions.notify.notify() + end, + keys = { "lh", desc = "list-history" }, + }, + { + id = "notify.dismiss-all", + title = "Dismiss all notifications", + callback = function() + require("notify").dismiss { silent = true, pending = true } + end, + keys = { "nn", desc = "dismiss-all" }, + }, + }, + } + end, + }, + { + "stevearc/dressing.nvim", + lazy = true, + opts = { + input = { + title_pos = "center", + relative = "editor", + insert_only = true, + start_in_insert = true, + }, + }, + init = function() + vim.ui.select = function(...) + require("lazy").load { plugins = { "dressing.nvim" } } + return vim.ui.select(...) + end + vim.ui.input = function(...) + require("lazy").load { plugins = { "dressing.nvim" } } + return vim.ui.input(...) + end + end, + }, + { + "nvim-zh/colorful-winsep.nvim", + event = "WinNew", + opts = { + create_event = function() + local winCount = + require("colorful-winsep.utils").calculate_number_windows() + if winCount == 2 then + local leftWinId = vim.fn.win_getid(vim.fn.winnr("h")) + local filetype = vim.api.nvim_get_option_value( + "filetype", + { buf = vim.api.nvim_win_get_buf(leftWinId) } + ) + if filetype == "NvimTree" or filetype == "neo-tree" then + require("colorful-winsep").NvimSeparatorDel() + end + end + end, + }, + }, + { + "s1n7ax/nvim-window-picker", + opts = { + filter_rules = { + bo = { + filetype = { "NvimTree", "neo-tree", "notify", "NvimSeparator", "" }, + buftype = { "terminal" }, + }, + }, + }, + }, +} diff --git a/lua/dotvim/legacy/packages/ui/plugins/alpha.lua b/lua/dotvim/legacy/packages/ui/plugins/alpha.lua new file mode 100644 index 00000000..610d0dee --- /dev/null +++ b/lua/dotvim/legacy/packages/ui/plugins/alpha.lua @@ -0,0 +1,411 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "goolord/alpha-nvim", + cond = function() + return vim.fn.argc() == 0 + and vim.o.lines >= 36 + and vim.o.columns >= 80 + and not vim.g.vscode + end, + lazy = false, + dependencies = { + "nvim-tree/nvim-web-devicons", + "nvim-lua/plenary.nvim", + }, + opts = function() + ---@type dora.lib + local lib = require("dora.lib") + ---@type dora.config + local config = require("dora.config") + + local redraw_alpha_autocmd = nil + + local function clear_autocmd() + if redraw_alpha_autocmd then + vim.api.nvim_del_autocmd(redraw_alpha_autocmd) + redraw_alpha_autocmd = nil + end + end + + ---@param sc string + ---@param txt string|fun(): string + ---@param callback string|fun():any + ---@param opts? table + local function make_button(sc, txt, callback, opts) + opts = opts or {} + local on_press = lib.func.normalize_callback( + callback, + vim.F.if_nil(opts.feedkeys, true) + ) + opts = vim.tbl_extend("force", { + position = "center", + shortcut = sc, + cursor = 3, + width = 50, + align_shortcut = "right", + hl_shortcut = "Keyword", + keymap = { + "n", + sc, + "", + { + noremap = true, + silent = true, + nowait = true, + callback = function() + on_press() + if opts.close_on_press then + clear_autocmd() + end + end, + }, + }, + }, opts) + return { + type = "button", + val = txt, + on_press = opts.keymap[4].callback, + opts = opts, + } + end + + ---@param filename string + ---@return string + local function get_extension(filename) + local match = filename:match("^.+(%..+)$") + local ext = "" + if match ~= nil then + ext = match:sub(2) + end + return ext + end + + ---@param filename string + ---@return string, string + local function get_icon_highlight(filename) + local nvim_web_devicons = require("nvim-web-devicons") + local ext = get_extension(filename) + return nvim_web_devicons.get_icon(filename, ext, { default = true }) + end + + ---@param filename string + ---@param sc string short cut + ---@param short_filename? string + local function make_file_button(filename, sc, short_filename) + local nvim_web_devicons = require("nvim-web-devicons") + + short_filename = short_filename or filename + local icon, highlight = get_icon_highlight(filename) + local button_highlights = {} + if type(nvim_web_devicons.highlight) == "boolean" then + if highlight and nvim_web_devicons.highlight then + button_highlights[#button_highlights + 1] = { + highlight, + 0, + 1, + } + end + elseif type(nvim_web_devicons.highlight) == "string" then + button_highlights[#button_highlights + 1] = { + nvim_web_devicons.highlight, + 0, + 1, + } + end + icon = icon .. " " + local fn_start = short_filename:match(".*/") + if fn_start ~= nil then + button_highlights[#button_highlights + 1] = { + "Comment", + #icon - 2, + #fn_start + #icon, + } + end + return make_button(sc, icon .. short_filename, "e " .. filename, { + hl = button_highlights, + feedkeys = false, + }) + end + + ---@param sc string + ---@param project_path string + local function make_project_button(sc, project_path) + local icon_txt = "î«· " + local on_press = function() + vim.api.nvim_command("cd " .. project_path) + -- schedule a redraw to show recent files in project + vim.schedule(function() + require("alpha").redraw() + end) + end + return make_button( + sc, + icon_txt .. vim.fn.fnamemodify(project_path, ":~"), + on_press + ) + end + + local function make_recent_files_buttons() + local path = require("plenary.path") + + local function mru(start, cwd, items_number, opts) + opts = opts + or { + ignore = function(p, ext) + return (string.find(p, "COMMIT_EDITMSG")) + or (vim.tbl_contains({ "gitcommit" }, ext)) + end, + } + + items_number = items_number or 9 + + local oldfiles = {} + for _, v in pairs(vim.v.oldfiles) do + if #oldfiles == items_number then + break + end + local cwd_cond + if not cwd then + cwd_cond = true + else + cwd_cond = vim.startswith(v, cwd) + end + local ignore = (opts.ignore and opts.ignore(v, get_extension(v))) + or false + if (vim.fn.filereadable(v) == 1) and cwd_cond and not ignore then + oldfiles[#oldfiles + 1] = v + end + end + + local target_width = 35 + + local tbl = {} + for i, fn in ipairs(oldfiles) do + local short_fn + if cwd then + short_fn = vim.fn.fnamemodify(fn, ":.") + else + short_fn = vim.fn.fnamemodify(fn, ":~") + end + + if #short_fn > target_width then + short_fn = path.new(short_fn):shorten(1, { -2, -1 }) + if #short_fn > target_width then + short_fn = path.new(short_fn):shorten(1, { -1 }) + end + end + + local special_shortcuts = { "a", "s", "d" } + local shortcut = "" + if i <= #special_shortcuts then + shortcut = special_shortcuts[i] + else + shortcut = tostring(i + start - 1 - #special_shortcuts) + end + + local file_button_el = + make_file_button(fn, " " .. shortcut, short_fn) + tbl[i] = file_button_el + end + return { type = "group", val = tbl, opts = {} } + end + + return { + { + type = "text", + val = "Recent files", + opts = { + hl = "SpecialComment", + shrink_margin = false, + position = "center", + }, + }, + { type = "padding", val = 1 }, + { + type = "group", + val = function() + return { mru(1, vim.fn.getcwd(), 5) } + end, + opts = { shrink_margin = false }, + }, + } + end + + local function make_recent_project_buttons() + local function _build_buttons() + local recent_projects = lib.func.require_then( + "project_nvim", + function(project_nvim) + return project_nvim.get_recent_projects() + end + ) or {} + lib.tbl.list_reverse(recent_projects) + + local buttons = {} + local special_shortcuts = { "a", "s", "d" } + + for i, project_path in ipairs(recent_projects) do + if i > 5 then + break + end + + local shortcut = "" + if i <= #special_shortcuts then + shortcut = special_shortcuts[i] + else + shortcut = tostring(i - #special_shortcuts) + end + buttons[#buttons + 1] = + make_project_button(" " .. shortcut, project_path) + end + + return buttons + end + + return { + { + type = "text", + val = "Recent Projects", + opts = { + hl = "SpecialComment", + shrink_margin = false, + position = "center", + }, + }, + { type = "padding", val = 1 }, + { + type = "group", + val = _build_buttons, + opts = { shrink_margin = false }, + }, + } + end + + local function make_recent_buttons() + local cwd = vim.fn.getcwd() + if cwd == "/" then + return make_recent_project_buttons() + else + return make_recent_files_buttons() + end + end + + local function make_fortune_text() + local stats = require("lazy").stats() + return string.format( + "󱐌 %d plugins loaded in %dms", + stats.count, + stats.startuptime + ) + end + + local function make_header_liens() + local lines = {} + for i, line in ipairs(config.ui.dashboard_header) do + lines[i] = { + type = "text", + val = line, + opts = { + hl = "StartLogo" .. i, + position = "center", + shrink_margin = false, + }, + } + end + lines[#lines + 1] = { + type = "text", + val = "dora.version: " .. require("dora.version").version(), + opts = { + hl = "SpecialComment", + position = "center", + }, + } + return { + type = "group", + val = lines, + opts = { + position = "center", + }, + } + end + + local function make_toolbar_buttons() + local buttons = { + { + type = "text", + val = "Quick Actions", + opts = { hl = "SpecialComment", position = "center" }, + }, + { type = "padding", val = 1 }, + } + + buttons[#buttons + 1] = + make_button("e", "ó±Ș New File", ":ene startinsert ") + + if lib.vim.current_gui() ~= nil then + buttons[#buttons + 1] = + make_button("p", " Projects", "PickRecentProject", { + feedkeys = false, + }) + end + + buttons[#buttons + 1] = make_button("q", "ó°—Œ Quit", function() + vim.cmd("qa") + end) + + return { + type = "group", + val = buttons, + opts = { position = "center" }, + } + end + + return { + layout = { + { type = "padding", val = 1 }, + make_header_liens(), + { type = "padding", val = 1 }, + { + type = "group", + val = make_recent_buttons, + }, + { type = "padding", val = 1 }, + make_toolbar_buttons(), + { type = "padding", val = 1 }, + { + type = "text", + val = make_fortune_text, + opts = { + hl = "AlphaQuote", + position = "center", + }, + }, + }, + opts = { + margin = 5, + redraw_on_resize = true, + setup = function() + vim.api.nvim_create_autocmd("User", { + pattern = "LazyVimStarted", + once = true, + callback = function() + vim.schedule(function() + require("alpha").redraw() + end) + end, + }) + redraw_alpha_autocmd = vim.api.nvim_create_autocmd("DirChanged", { + pattern = "*", + callback = function() + vim.schedule(function() + require("alpha").redraw() + end) + end, + }) + end, + }, + } + end, + }, +} diff --git a/lua/dotvim/legacy/packages/ui/plugins/bufferline.lua b/lua/dotvim/legacy/packages/ui/plugins/bufferline.lua new file mode 100644 index 00000000..120a2ad6 --- /dev/null +++ b/lua/dotvim/legacy/packages/ui/plugins/bufferline.lua @@ -0,0 +1,89 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "akinsho/bufferline.nvim", + event = "VeryLazy", + dependencies = { "nvim-tree/nvim-web-devicons", "catppuccin" }, + opts = { + options = { + view = "multiwindow", + sort_by = "insert_after_current", + always_show_bufferline = true, + themable = true, + right_mouse_command = nil, + middle_mouse_command = "bdelete! %d", + indicator = { style = "bold" }, + hover = { enabled = true, delay = 200 }, + separator_style = "thick", + close_command = "BDelete! %d", + numbers = "none", + diagnostics = "", + show_buf_icons = false, + offsets = { + { + filetype = "neo-tree", + text = "File Explorer", + text_align = "center", + highlight = "Directory", + }, + { + filetype = "NvimTree", + text = "File Explorer", + text_align = "center", + highlight = "Directory", + }, + }, + groups = { + options = { toggle_hidden_on_enter = true }, + items = { + { + name = "Tests", + priority = 2, + icon = "", + matcher = function(buf) + local ret0 = string.match(buf.name, "%_test") + local ret1 = string.match(buf.name, "%_spec") + return ret0 ~= nil or ret1 ~= nil + end, + }, + }, + }, + }, + }, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "bufferline.nvim", + category = "Bufferline", + actions = { + { + id = "bufferline.cycle-prev", + title = "Previous buffer", + callback = "BufferLineCyclePrev", + keys = { "", desc = "previous-buffer" }, + }, + { + id = "bufferline.cycle-next", + title = "Next buffer", + callback = "BufferLineCycleNext", + keys = { "", desc = "next-buffer" }, + }, + { + id = "bufferline.move-prev", + title = "Move buffer left", + callback = "BufferLineMovePrev", + keys = { "", desc = "move-buffer-left" }, + }, + { + id = "bufferline.move-next", + title = "Move buffer right", + callback = "BufferLineMoveNext", + keys = { ">", desc = "move-buffer-right" }, + }, + }, + } + end, + }, +} diff --git a/lua/dotvim/legacy/packages/ui/plugins/lualine.lua b/lua/dotvim/legacy/packages/ui/plugins/lualine.lua new file mode 100644 index 00000000..3ccde188 --- /dev/null +++ b/lua/dotvim/legacy/packages/ui/plugins/lualine.lua @@ -0,0 +1,98 @@ +---@type dora.core.plugin.PluginOption +return { + "nvim-lualine/lualine.nvim", + event = "VeryLazy", + init = function() + vim.g.lualine_laststatus = vim.o.laststatus + if vim.fn.argc(-1) > 0 then + -- set an empty statusline till lualine loads + vim.o.statusline = " " + else + -- hide the statusline on the starter page + vim.o.laststatus = 0 + end + end, + opts = function() + ---@type dora.config + local config = require("dora.config") + + local function cwd() + local dir = vim.fn.getcwd() + local home = os.getenv("HOME") --[[@as string]] + local match = string.find(dir, home, 1, true) + if match == 1 then + dir = "~" .. string.sub(dir, #home + 1) + end + return config.icon.predefined_icon("FolderOpen", 1) .. dir + end + + local function fileinfo() + local icon = "󰈚 " + local currentFile = vim.fn.expand("%") + local filename + if currentFile == "" then + filename = "Empty " + else + filename = vim.fn.fnamemodify(currentFile, ":.") + local deviconsPresent, devicons = pcall(require, "nvim-web-devicons") + if deviconsPresent then + local ftIcon = devicons.get_icon(filename) + if ftIcon ~= nil then + icon = ftIcon .. " " + end + if vim.fn.expand("%:e") == "md" then + icon = icon .. " " + end + end + end + return icon .. filename + end + + return { + options = { + component_separators = { left = "|", right = "|" }, + section_separators = { left = "î‚Œ", right = "î‚ș" }, + theme = "auto", + globalstatus = true, + disabled_filetypes = { + statusline = { "dashboard", "alpha", "starter" }, + }, + }, + sections = { + lualine_a = { + { + "mode", + icons_enabled = true, + icon = { + config.icon.predefined_icon("VimLogo", 1), + align = "left", + }, + }, + }, + lualine_b = { cwd }, + lualine_c = { + { fileinfo, separator = "" }, + }, + lualine_x = { + { + "diagnostics", + symbols = { + error = config.icon.predefined_icon("DiagnosticError", 1), + warn = config.icon.predefined_icon("DiagnosticWarn", 1), + info = config.icon.predefined_icon("DiagnosticInfo", 1), + hint = config.icon.predefined_icon("DiagnosticHint", 1), + }, + }, + "branch", + "diff", + }, + lualine_y = { + { "filetype", colored = true, icon_only = false }, + }, + lualine_z = { "progress", "location" }, + }, + tabline = {}, + extensions = { "neo-tree", "lazy" }, + } + end, +} diff --git a/lua/dotvim/legacy/packages/ui/plugins/noice.lua b/lua/dotvim/legacy/packages/ui/plugins/noice.lua new file mode 100644 index 00000000..dd1a0395 --- /dev/null +++ b/lua/dotvim/legacy/packages/ui/plugins/noice.lua @@ -0,0 +1,147 @@ +---@type dora.core.plugin.PluginOption[] +return { + { + "folke/noice.nvim", + event = { "ModeChanged", "BufReadPre", "InsertEnter" }, + dependencies = { "MunifTanjim/nui.nvim", "rcarriga/nvim-notify" }, + opts = { + lsp = { + progress = { + enabled = true, + throttle = 1000 / 10, + view = "mini", + }, + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + -- ["cmp.entry.get_documentation"] = true, + }, + signature = { + enabled = false, + auto_open = { + enabled = true, + trigger = true, + luasnip = true, + throttle = 50, + }, + }, + hover = { + enabled = true, + opts = { + border = { style = "none", padding = { 1, 2 } }, + position = { row = 2, col = 2 }, + }, + }, + }, + messages = { enabled = false }, + presets = { + bottom_search = false, + command_palette = true, + long_message_to_split = true, + inc_rename = false, + lsp_doc_border = false, + }, + }, + config = function(_, opts) + require("noice").setup(opts) + + local Format = require("noice.lsp.format") + local Hacks = require("noice.util.hacks") + + local function from_lsp_clangd(e) + return vim.tbl_get(e, "source", "name") == "nvim_lsp" + and vim.tbl_get(e, "source", "source", "client", "name") == "clangd" + end + + Hacks.on_module("cmp.entry", function(mod) + mod.get_documentation = function(self) + local item = self:get_completion_item() + + local lines = item.documentation + and Format.format_markdown(item.documentation) + or {} + local ret = table.concat(lines, "\n") + local detail = item.detail + if detail and type(detail) == "table" then + detail = table.concat(detail, "\n") + end + + if from_lsp_clangd(self) then + local label_details = item.labelDetails + if + label_details + and type(label_details) == "table" + and label_details.detail + then + if detail == nil then + detail = "" + end + detail = detail .. label_details.detail + end + end + + if detail and not ret:find(detail, 1, true) then + local ft = self.context.filetype + local dot_index = string.find(ft, "%.") + if dot_index ~= nil then + ft = string.sub(ft, 0, dot_index - 1) + end + ret = ("```%s\n%s\n```\n%s"):format(ft, vim.trim(detail), ret) + end + return vim.split(ret, "\n") + end + end) + end, + actions = function() + ---@type dora.core.action + local action = require("dora.core.action") + + return action.make_options { + from = "noice.nvim", + category = "Noice", + actions = { + { + id = "noice.show-message-history", + title = "Shows the message history", + callback = "Noice history", + }, + { + id = "noice.show-last-message", + title = "Shows the last message in a popup", + callback = "Noice last", + }, + { + id = "noice.dismiss-all-messages", + title = "Dismiss all visible messages", + callback = "Noice dismiss", + }, + { + id = "noice.disable", + title = "Disables Noice", + callback = "Noice disable", + }, + { + id = "noice.enable", + title = "Enables Noice", + callback = "Noice enable", + }, + { + id = "noice.show-stats", + title = "Show debugging stats", + callback = "Noice stats", + }, + { + id = "noice.show-message-history-in-telescope", + title = "Opens message history in Telescope", + callback = "Noice telescope", + }, + { + id = "noice.show-errors", + title = "Shows the error messages in a split", + callback = "Noice errors", + }, + }, + } + end, + }, +}