diff options
Diffstat (limited to 'mac/.config/LunarVim/lua')
64 files changed, 7846 insertions, 0 deletions
diff --git a/mac/.config/LunarVim/lua/lvim/bootstrap.lua b/mac/.config/LunarVim/lua/lvim/bootstrap.lua new file mode 100644 index 0000000..2a2ac1d --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/bootstrap.lua @@ -0,0 +1,123 @@ +local M = {} + +if vim.fn.has "nvim-0.10" ~= 1 then + vim.notify("Please upgrade your Neovim base installation. Lunarvim requires v0.10+", vim.log.levels.WARN) + vim.wait(5000, function() + ---@diagnostic disable-next-line: redundant-return-value + return false + end) + vim.cmd "cquit" +end + +local uv = vim.loop +local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/" + +---Join path segments that were passed as input +---@return string +function _G.join_paths(...) + local result = table.concat({ ... }, path_sep) + return result +end + +_G.require_clean = require("lvim.utils.modules").require_clean +_G.require_safe = require("lvim.utils.modules").require_safe +_G.reload = require("lvim.utils.modules").reload + +---Get the full path to `$LUNARVIM_RUNTIME_DIR` +---@return string|nil +function _G.get_runtime_dir() + local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" + if not lvim_runtime_dir then + -- when nvim is used directly + return vim.call("stdpath", "data") + end + return lvim_runtime_dir +end + +---Get the full path to `$LUNARVIM_CONFIG_DIR` +---@return string|nil +function _G.get_config_dir() + local lvim_config_dir = os.getenv "LUNARVIM_CONFIG_DIR" + if not lvim_config_dir then + return vim.call("stdpath", "config") + end + return lvim_config_dir +end + +---Get the full path to `$LUNARVIM_CACHE_DIR` +---@return string|nil +function _G.get_cache_dir() + local lvim_cache_dir = os.getenv "LUNARVIM_CACHE_DIR" + if not lvim_cache_dir then + return vim.call("stdpath", "cache") + end + return lvim_cache_dir +end + +---Initialize the `&runtimepath` variables and prepare for startup +---@return table +function M:init(base_dir) + self.runtime_dir = get_runtime_dir() + self.config_dir = get_config_dir() + self.cache_dir = get_cache_dir() + self.pack_dir = join_paths(self.runtime_dir, "site", "pack") + self.lazy_install_dir = join_paths(self.pack_dir, "lazy", "opt", "lazy.nvim") + + ---@meta overridden to use LUNARVIM_CACHE_DIR instead, since a lot of plugins call this function internally + ---NOTE: changes to "data" are currently unstable, see #2507 + ---@diagnostic disable-next-line: duplicate-set-field + vim.fn.stdpath = function(what) + if what == "cache" then + return _G.get_cache_dir() + end + return vim.call("stdpath", what) + end + + ---Get the full path to LunarVim's base directory + ---@return string + function _G.get_lvim_base_dir() + return base_dir + end + + if os.getenv "LUNARVIM_RUNTIME_DIR" then + vim.opt.rtp:remove(join_paths(vim.call("stdpath", "data"), "site")) + vim.opt.rtp:remove(join_paths(vim.call("stdpath", "data"), "site", "after")) + -- vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site")) + vim.opt.rtp:append(join_paths(self.runtime_dir, "lvim", "after")) + vim.opt.rtp:append(join_paths(self.runtime_dir, "site", "after")) + + vim.opt.rtp:remove(vim.call("stdpath", "config")) + vim.opt.rtp:remove(join_paths(vim.call("stdpath", "config"), "after")) + vim.opt.rtp:prepend(self.config_dir) + vim.opt.rtp:append(join_paths(self.config_dir, "after")) + + vim.opt.packpath = vim.opt.rtp:get() + end + + require("lvim.plugin-loader").init { + package_root = self.pack_dir, + install_path = self.lazy_install_dir, + } + + require("lvim.config"):init() + + require("lvim.core.mason").bootstrap() + + return self +end + +---Update LunarVim +---pulls the latest changes from github and, resets the startup cache +function M:update() + require("lvim.core.log"):info "Trying to update LunarVim..." + + vim.schedule(function() + reload("lvim.utils.hooks").run_pre_update() + local ret = reload("lvim.utils.git").update_base_lvim() + if ret then + reload("lvim.utils.hooks").run_post_update() + end + end) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/config/_deprecated.lua b/mac/.config/LunarVim/lua/lvim/config/_deprecated.lua new file mode 100644 index 0000000..ebcdbe9 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/config/_deprecated.lua @@ -0,0 +1,215 @@ +---@diagnostic disable: deprecated +local M = {} + +local function deprecate(name, alternative) + local in_headless = #vim.api.nvim_list_uis() == 0 + if in_headless then + return + end + + alternative = alternative or "See https://github.com/LunarVim/LunarVim#breaking-changes" + + local trace = debug.getinfo(3, "Sl") + local shorter_src = trace.short_src + local t = shorter_src .. ":" .. (trace.currentline or trace.lastlinedefined) + vim.schedule(function() + vim.notify_once(string.format("%s: `%s` is deprecated.\n %s.", t, name, alternative), vim.log.levels.WARN) + end) +end + +function M.handle() + local mt = { + __newindex = function(_, k, _) + deprecate(k) + end, + } + + ---@deprecated + lvim.builtin.theme.options = {} + setmetatable(lvim.builtin.theme.options, { + __newindex = function(_, k, v) + deprecate("lvim.builtin.theme.options." .. k, "Use `lvim.builtin.theme.<theme>.options` instead") + lvim.builtin.theme.tokyonight.options[k] = v + end, + }) + + ---@deprecated + lvim.builtin.notify = {} + setmetatable(lvim.builtin.notify, { + __newindex = function(_, k, _) + deprecate("lvim.builtin.notify." .. k, "See LunarVim#3294") + end, + }) + + ---@deprecated + lvim.builtin.dashboard = {} + setmetatable(lvim.builtin.dashboard, { + __newindex = function(_, k, _) + deprecate("lvim.builtin.dashboard." .. k, "Use `lvim.builtin.alpha` instead. See LunarVim#1906") + end, + }) + + ---@deprecated + lvim.lsp.popup_border = {} + setmetatable(lvim.lsp.popup_border, mt) + + ---@deprecated + lvim.lsp.float = {} + setmetatable(lvim.lsp.float, { + __newindex = function(_, k, _) + deprecate("lvim.lsp.float." .. k, "Use options provided by the handler instead") + end, + }) + + ---@deprecated + lvim.lsp.diagnostics = {} + setmetatable(lvim.lsp.diagnostics, { + __newindex = function(table, k, v) + deprecate("lvim.lsp.diagnostics." .. k, string.format("Use `vim.diagnostic.config({ %s = %s })` instead", k, v)) + rawset(table, k, v) + end, + }) + + ---@deprecated + lvim.lang = {} + setmetatable(lvim.lang, mt) +end + +function M.post_load() + if lvim.lsp.diagnostics and not vim.tbl_isempty(lvim.lsp.diagnostics) then + vim.diagnostic.config(lvim.lsp.diagnostics) + end + + if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then + deprecate("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead") + vim.tbl_map(function(c) + if not vim.tbl_contains(lvim.lsp.automatic_configuration.skipped_servers, c) then + table.insert(lvim.lsp.automatic_configuration.skipped_servers, c) + end + end, lvim.lsp.override) + end + + if lvim.autocommands.custom_groups then + deprecate( + "lvim.autocommands.custom_groups", + "Use vim.api.nvim_create_autocmd instead or check LunarVim#2592 to learn about the new syntax" + ) + end + + if lvim.lsp.automatic_servers_installation then + deprecate( + "lvim.lsp.automatic_servers_installation", + "Use `lvim.lsp.installer.setup.automatic_installation` instead" + ) + end + + local function convert_spec_to_lazy(spec) + local alternatives = { + setup = "init", + as = "name", + opt = "lazy", + run = "build", + lock = "pin", + requires = "dependencies", + } + + alternatives.tag = function() + if spec.tag == "*" then + spec.version = "*" + return [[version = "*"]] + end + end + + alternatives.disable = function() + if type(spec.disabled) == "function" then + spec.enabled = function() + return not spec.disabled() + end + else + spec.enabled = not spec.disabled + end + return "enabled = " .. vim.inspect(spec.enabled) + end + + alternatives.wants = function() + return "dependencies = [value]" + end + alternatives.needs = alternatives.wants + + alternatives.module = function() + spec.lazy = true + return "lazy = true" + end + + for old_key, alternative in pairs(alternatives) do + if spec[old_key] ~= nil then + local message + local old_value = vim.inspect(spec[old_key]) or "value" + + if type(alternative) == "function" then + message = alternative() + else + spec[alternative] = spec[old_key] + end + + -- not every function in alternatives returns a message (e.g. tag) + if type(alternative) ~= "function" or message then + spec[old_key] = nil + + local new_value = vim.inspect(spec[alternative] or "[value]") + message = message or string.format("%s = %s", alternative, new_value) + vim.schedule(function() + vim.notify_once( + string.format( + [[`%s = %s` in `lvim.plugins` has been deprecated since the migration to lazy.nvim. Use `%s` instead. +Example: +`lvim.plugins = {... {... %s = %s ...} ...}` +-> +`lvim.plugins = {... {... %s ...} ...}` +See https://github.com/folke/lazy.nvim#-migration-guide"]], + old_key, + old_value, + message, + old_key, + old_value, + message + ), + vim.log.levels.WARN + ) + end) + end + end + end + + if spec[1] and spec[1]:match "^http" then + spec.url = spec[1] + spec[1] = nil + + vim.schedule(function() + vim.notify_once( + + string.format( + [[`"http..."` in `lvim.plugins` has been deprecated since the migration to lazy.nvim. Use `url = "http..."` instead. +Example: +`lvim.plugins = {... { "%s" ...} ...}` +-> +`lvim.plugins = {... { url = "%s" ...} ...}` +See https://github.com/folke/lazy.nvim#-migration-guide"]], + spec.url, + spec.url + ), + + vim.log.levels.WARN + ) + end) + end + end + + for _, plugin in ipairs(lvim.plugins) do + if type(plugin) == "table" then + convert_spec_to_lazy(plugin) + end + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/config/defaults.lua b/mac/.config/LunarVim/lua/lvim/config/defaults.lua new file mode 100644 index 0000000..5fa8a91 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/config/defaults.lua @@ -0,0 +1,75 @@ +return { + leader = "space", + reload_config_on_save = true, + colorscheme = "lunar", + transparent_window = false, + format_on_save = { + ---@usage boolean: format on save (Default: false) + enabled = false, + ---@usage pattern string pattern used for the autocommand (Default: '*') + pattern = "*", + ---@usage timeout number timeout in ms for the format request (Default: 1000) + timeout = 1000, + ---@usage filter func to select client + filter = require("lvim.lsp.utils").format_filter, + }, + keys = {}, + + use_icons = true, + icons = require "lvim.icons", + + builtin = {}, + + plugins = { + -- use config.lua for this not put here + }, + + lazy = { + opts = { + install = { + missing = true, + colorscheme = { "lunar", "habamax" }, + }, + ui = { + border = "rounded", + }, + root = require("lvim.utils").join_paths(get_runtime_dir(), "site", "pack", "lazy", "opt"), + git = { + timeout = 120, + }, + lockfile = require("lvim.utils").join_paths(get_config_dir(), "lazy-lock.json"), + performance = { + rtp = { + reset = false, + }, + }, + defaults = { + lazy = false, + version = nil, + }, + readme = { + root = require("lvim.utils").join_paths(get_runtime_dir(), "lazy", "readme"), + }, + }, + }, + + autocommands = {}, + lang = {}, + log = { + ---@usage can be { "trace", "debug", "info", "warn", "error", "fatal" }, + level = "info", + viewer = { + ---@usage this will fallback on "less +F" if not found + cmd = "lnav", + layout_config = { + ---@usage direction = 'vertical' | 'horizontal' | 'window' | 'float', + direction = "horizontal", + open_mapping = "", + size = 40, + float_opts = {}, + }, + }, + -- currently disabled due to instabilities + override_notify = false, + }, +} diff --git a/mac/.config/LunarVim/lua/lvim/config/init.lua b/mac/.config/LunarVim/lua/lvim/config/init.lua new file mode 100644 index 0000000..90c1788 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/config/init.lua @@ -0,0 +1,108 @@ +local utils = require "lvim.utils" +local Log = require "lvim.core.log" + +local M = {} +local user_config_dir = get_config_dir() +local user_config_file = utils.join_paths(user_config_dir, "config.lua") + +---Get the full path to the user configuration file +---@return string +function M:get_user_config_path() + return user_config_file +end + +--- Initialize lvim default configuration and variables +function M:init() + lvim = vim.deepcopy(require "lvim.config.defaults") + + require("lvim.keymappings").load_defaults() + + local builtins = require "lvim.core.builtins" + builtins.config { user_config_file = user_config_file } + + local settings = require "lvim.config.settings" + settings.load_defaults() + + local autocmds = require "lvim.core.autocmds" + autocmds.load_defaults() + + local lvim_lsp_config = require "lvim.lsp.config" + lvim.lsp = vim.deepcopy(lvim_lsp_config) + + lvim.builtin.luasnip = { + sources = { + friendly_snippets = true, + }, + } + + lvim.builtin.bigfile = { + active = true, + config = {}, + } + + require("lvim.config._deprecated").handle() +end + +--- Override the configuration with a user provided one +-- @param config_path The path to the configuration overrides +function M:load(config_path) + local autocmds = reload "lvim.core.autocmds" + config_path = config_path or self:get_user_config_path() + local ok, err = pcall(dofile, config_path) + if not ok then + if utils.is_file(user_config_file) then + vim.schedule(function() + Log:warn("Invalid configuration: " .. err) + end) + else + vim.schedule(function() + vim.notify_once( + string.format("User-configuration not found. Creating an example configuration in %s", config_path) + ) + end) + local config_name = vim.loop.os_uname().version:match "Windows" and "config_win" or "config" + local example_config = join_paths(get_lvim_base_dir(), "utils", "installer", config_name .. ".example.lua") + vim.fn.mkdir(user_config_dir, "p") + vim.loop.fs_copyfile(example_config, config_path) + end + end + + Log:set_level(lvim.log.level) + + require("lvim.config._deprecated").post_load() + + autocmds.define_autocmds(lvim.autocommands) + + vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader + + reload("lvim.keymappings").load(lvim.keys) + + if lvim.transparent_window then + autocmds.enable_transparent_mode() + end + + if lvim.reload_config_on_save then + autocmds.enable_reload_config_on_save() + end +end + +--- Override the configuration with a user provided one +-- @param config_path The path to the configuration overrides +function M:reload() + vim.schedule(function() + reload("lvim.utils.hooks").run_pre_reload() + + M:load() + + reload("lvim.core.autocmds").configure_format_on_save() + + local plugins = reload "lvim.plugins" + local plugin_loader = reload "lvim.plugin-loader" + + plugin_loader.reload { plugins, lvim.plugins } + reload("lvim.core.theme").setup() + reload("lvim.utils.hooks").run_post_reload() + end) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/config/settings.lua b/mac/.config/LunarVim/lua/lvim/config/settings.lua new file mode 100644 index 0000000..2492f1d --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/config/settings.lua @@ -0,0 +1,120 @@ +local M = {} + +M.load_default_options = function() + local utils = require "lvim.utils" + local join_paths = utils.join_paths + + local undodir = join_paths(get_cache_dir(), "undo") + + if not utils.is_directory(undodir) then + vim.fn.mkdir(undodir, "p") + end + + local default_options = { + backup = false, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 1, -- more space in the neovim command line for displaying messages + completeopt = { "menuone", "noselect" }, + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a file + foldmethod = "manual", -- folding, set to "expr" for treesitter based folding + foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding + hidden = true, -- required to keep multiple buffers and open multiple buffers + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + smartcase = true, -- smart case + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = false, -- creates a swapfile + termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 1000, -- time to wait for a mapped sequence to complete (in milliseconds) + title = true, -- set the title of window to the value of the titlestring + -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to + undodir = undodir, -- set an undo directory + undofile = true, -- enable persistent undo + updatetime = 100, -- faster completion + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = true, -- convert tabs to spaces + shiftwidth = 2, -- the number of spaces inserted for each indentation + tabstop = 2, -- insert 2 spaces for a tab + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + shadafile = join_paths(get_cache_dir(), "lvim.shada"), + scrolloff = 8, -- minimal number of screen lines to keep above and below the cursor. + sidescrolloff = 8, -- minimal number of screen lines to keep left and right of the cursor. + showcmd = false, + ruler = false, + laststatus = 3, + } + + --- SETTINGS --- + vim.opt.spelllang:append "cjk" -- disable spellchecking for asian characters (VIM algorithm does not support it) + vim.opt.shortmess:append "c" -- don't show redundant messages from ins-completion-menu + vim.opt.shortmess:append "I" -- don't show the default intro message + vim.opt.whichwrap:append "<,>,[,],h,l" + + for k, v in pairs(default_options) do + vim.opt[k] = v + end + + vim.filetype.add { + extension = { + tex = "tex", + zir = "zir", + cr = "crystal", + }, + pattern = { + ["[jt]sconfig.*.json"] = "jsonc", + }, + } + + local default_diagnostic_config = { + signs = { + active = true, + values = { + { name = "DiagnosticSignError", text = lvim.icons.diagnostics.Error }, + { name = "DiagnosticSignWarn", text = lvim.icons.diagnostics.Warning }, + { name = "DiagnosticSignHint", text = lvim.icons.diagnostics.Hint }, + { name = "DiagnosticSignInfo", text = lvim.icons.diagnostics.Information }, + }, + }, + virtual_text = true, + update_in_insert = false, + underline = true, + severity_sort = true, + float = { + focusable = true, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(default_diagnostic_config) +end + +M.load_headless_options = function() + vim.opt.shortmess = "" -- try to prevent echom from cutting messages off or prompting + vim.opt.more = false -- don't pause listing when screen is filled + vim.opt.cmdheight = 9999 -- helps avoiding |hit-enter| prompts. + vim.opt.columns = 9999 -- set the widest screen possible + vim.opt.swapfile = false -- don't use a swap file +end + +M.load_defaults = function() + if #vim.api.nvim_list_uis() == 0 then + M.load_headless_options() + return + end + M.load_default_options() +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/alpha.lua b/mac/.config/LunarVim/lua/lvim/core/alpha.lua new file mode 100644 index 0000000..13642c2 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/alpha.lua @@ -0,0 +1,85 @@ +local M = {} + +function M.config() + local lvim_dashboard = require "lvim.core.alpha.dashboard" + local lvim_startify = require "lvim.core.alpha.startify" + lvim.builtin.alpha = { + dashboard = { + config = {}, + section = lvim_dashboard.get_sections(), + opts = { autostart = true }, + }, + startify = { + config = {}, + section = lvim_startify.get_sections(), + opts = { autostart = true }, + }, + active = true, + mode = "dashboard", + } +end + +local function resolve_buttons(theme_name, button_section) + if button_section.val and #button_section.val > 0 then + return button_section.val + end + + local selected_theme = require("alpha.themes." .. theme_name) + local val = {} + for _, entry in pairs(button_section.entries) do + local on_press = function() + local sc_ = entry[1]:gsub("%s", ""):gsub("SPC", "<leader>") + local key = vim.api.nvim_replace_termcodes(sc_, true, false, true) + vim.api.nvim_feedkeys(key, "normal", false) + end + local button_element = selected_theme.button(entry[1], entry[2], entry[3]) + -- this became necessary after recent changes in alpha.nvim (06ade3a20ca9e79a7038b98d05a23d7b6c016174) + button_element.on_press = on_press + + button_element.opts = vim.tbl_extend("force", button_element.opts, entry[4] or button_section.opts or {}) + + table.insert(val, button_element) + end + return val +end + +local function resolve_config(theme_name) + local selected_theme = require("alpha.themes." .. theme_name) + local resolved_section = selected_theme.section + local section = lvim.builtin.alpha[theme_name].section + + for name, el in pairs(section) do + for k, v in pairs(el) do + if name:match "buttons" and k == "entries" then + resolved_section[name].val = resolve_buttons(theme_name, el) + elseif v then + resolved_section[name][k] = v + end + end + + resolved_section[name].opts = el.opts or {} + end + + local opts = lvim.builtin.alpha[theme_name].opts or {} + selected_theme.config.opts = vim.tbl_extend("force", selected_theme.config.opts, opts) + + return selected_theme.config +end + +function M.setup() + local status_ok, alpha = pcall(require, "alpha") + if not status_ok then + return + end + local mode = lvim.builtin.alpha.mode + local config = lvim.builtin.alpha[mode].config + + -- this makes it easier to use a completely custom configuration + if vim.tbl_isempty(config) then + config = resolve_config(mode) + end + + alpha.setup(config) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/alpha/dashboard.lua b/mac/.config/LunarVim/lua/lvim/core/alpha/dashboard.lua new file mode 100644 index 0000000..07a5ecc --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/alpha/dashboard.lua @@ -0,0 +1,148 @@ +local M = {} + +local banner = { + " ⢀⣀⣤⣤⣤⣶⣶⣶⣶⣶⣶⣤⣤⣤⣀⡀ ", + " ⣀⣤⣶⣿⠿⠟⠛⠉⠉⠉⠁⠈⠉⠉⠉⠛⠛⠿⣿⣷⣦⣀ ", + " ⢀⣤⣾⡿⠛⠉ ⠉⠛⢿⣷⣤⡀ ", + " ⣴⣿⡿⠃ ⠙⠻⣿⣦ ", + " ⢀⣠⣤⣤⣤⣤⣤⣾⣿⣉⣀⡀ ⠙⢻⣷⡄ ", + "⣼⠋⠁ ⢠⣿⡟ ⠉⠉⠉⠛⠛⠶⠶⣤⣄⣀ ⣀⣀ ⢠⣤⣤⡄ ⢻⣿⣆ ", + "⢻⡄ ⢰⣿⡟ ⢠⣿⣿⣿⠉⠛⠲⣾⣿⣿⣷ ⢀⣾⣿⣿⠁ ⢻⣿⡆ ", + " ⠹⣦⡀ ⣿⣿⠁ ⢸⣿⣿⡇ ⠻⣿⣿⠟⠳⠶⣤⣀⣸⣿⣿⠇ ⣿⣷ ", + " ⠙⢷⣿⡇ ⣸⣿⣿⠃ ⢸⣿⣿⢷⣤⡀ ⢸⣿⡆ ", + " ⢸⣿⠇ ⣿⣿⣿ ⣿⣿⣷ ⢠⣿⣿⡏ ⠈⠙⠳⢦⣄ ⠈⣿⡇ ", + " ⢸⣿⡆ ⢸⣿⣿⡇ ⣿⣿⣿ ⢀⣿⣿⡟ ⠈⠙⠷⣤⣿⡇ ", + " ⠘⣿⡇ ⣼⣿⣿⠁ ⣿⣿⣿ ⣼⣿⣿⠃ ⢸⣿⠷⣄⡀ ", + " ⣿⣿ ⣿⣿⡿ ⣿⣿⣿⢸⣿⣿⠃ ⣾⡿ ⠈⠻⣆ ", + " ⠸⣿⣧ ⢸⣿⣿⣇⣀⣀⣀⣀⣀⣀⣸⣿⣿⣿⣿⠇ ⣼⣿⠇ ⠘⣧", + " ⠹⣿⣧ ⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏ ⣼⣿⠏ ⣠⡿", + " ⠘⢿⣷⣄ ⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉ ⢠⣼⡿⠛⠛⠛⠛⠛⠛⠉ ", + " ⠻⣿⣦⣄ ⣀⣴⣿⠟ ", + " ⠈⠛⢿⣶⣤⣀ ⣀⣤⣶⡿⠛⠁ ", + " ⠉⠻⢿⣿⣶⣤⣤⣀⣀⡀ ⢀⣀⣀⣠⣤⣶⣿⡿⠟⠋ ", + " ⠈⠉⠙⠛⠻⠿⠿⠿⠿⠿⠿⠟⠛⠋⠉⠁ ", +} + +M.banner_small = { + " ⢀⣀ ⣰⣶ ⢀⣤⣄ ", + " ⢸⣿ ⣀⡀ ⣰⣿⠏ ⠘⠿⠟ ", + " ⣿⡟ ⣤⡄ ⣠⣤ ⢠⣤⣀⣤⣤⣤⡀ ⢀⣤⣤⣤⣤⡀ ⢠⣤⢀⣤⣤⣄ ⣿⣿ ⢰⣿⠏ ⣶⣶⣶⣶⡦ ⢠⣶⣦⣴⣦⣠⣴⣦⡀ ", + " ⢠⣿⡇ ⢠⣿⠇ ⣿⡇ ⣿⡿⠉ ⠈⣿⣧ ⠰⠿⠋ ⢹⣿ ⣿⡿⠋ ⠹⠿ ⢻⣿⡇⢠⣿⡟ ⠈⠉⢹⣿⡇ ⢸⣿⡏⢹⣿⡏⢹⣿⡇ ", + " ⢸⣿ ⢸⣿ ⢰⣿⠃ ⢠⣿⡇ ⣿⡇ ⣠⣴⡶⠶⠶⣿⣿ ⢠⣿⡇ ⢸⣿⣇⣿⡿ ⣿⣿⠁ ⣿⣿ ⣾⣿ ⣾⣿⠁ ", + " ⣿⣟ ⢻⣿⡀ ⢀⣼⣿ ⢸⣿ ⢰⣿⠇ ⢰⣿⣇ ⣠⣿⡏ ⢸⣿ ⢸⣿⣿⣿⠁ ⣀⣀⣠⣿⣿⣀⡀ ⢠⣿⡟⢠⣿⡟⢀⣿⡿ ", + " ⠛⠛⠛⠛⠛⠛⠁ ⠈⠛⠿⠟⠋⠛⠃ ⠛⠛ ⠘⠛ ⠙⠿⠿⠛⠙⠛⠃ ⠚⠛ ⠘⠿⠿⠃ ⠿⠿⠿⠿⠿⠿⠿ ⠸⠿⠇⠸⠿⠇⠸⠿⠇ ", +} + +M.banner_alt_1 = { + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣤⣶⣶⣶⣶⣶⣶⣶⣦⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⣾⣿⠿⠛⠛⠉⠉⠉⠉⠉⠉⠉⠙⠛⠻⢿⣿⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠻⢿⣷⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠒⠈⠉⠉⠉⠉⠉⣹⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⡀⠀⠀⠀⠀⠀⠀⣰⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⢰⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⡀⠀⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢺⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠉⠑⠢⢄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡇⠀⠀⠀⠈⠑⠢⠄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠢⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣇⠀⠀⠀⠀⠀⠀⠀⠀⠉⠐⠢⠄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⡟⠀⠈⠑⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⢀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⠒⠠⠤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⠁⠀⠀⢀⣼⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠒⠂⠤⠤⠀⣀⡀⠀⠀⠀⣼⣿⠇⠀⠀⢀⣸⣿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⣿⡟⠀⠀⠀⠀⠀⠀⣤⡄⠀⠀⠀⣠⣤⠀⠀⢠⣭⣀⣤⣤⣤⡀⠀⠀⠀⢀⣤⣤⣤⣤⡀⠀⠀⠀⢠⣤⢀⣤⣤⣄⠀⠀⣿⣿⠀⠉⣹⣿⠏⠉⠉⢱⣶⣶⣶⡦⠀⠀⠀⢠⣶⣦⣴⣦⣠⣴⣦⡀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⢠⣿⡇⠀⠀⠀⠀⠀⢠⣿⠇⠀⠀⠀⣿⡇⠀⠀⣿⡿⠉⠀⠈⣿⣧⠀⠀⠰⠿⠋⠀⠀⢹⣿⠀⠀⠀⣿⡿⠋⠀⠹⠿⠀⠀⢻⣿⡇⢠⣿⡟⠀⠀⠀⠈⠉⢹⣿⡇⠀⠀⠀⢸⣿⡏⢹⣿⡏⢹⣿⡇⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⢰⣿⠃⠀⢠⣿⡇⠀⠀⠀⣿⡇⠀⠀⣠⣴⡶⠶⠶⣿⣿⠀⠀⢠⣿⡇⠀⠀⠀⠀⠀⠀⢸⣿⣇⣿⡿⠀⠀⠀⠀⠀⠀⣿⣿⠁⠀⠀⠀⣿⣿⠀⣾⣿⠀⣾⣿⠁⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⣿⣟⠀⠀⠀⠀⠀⠀⢻⣿⡀⠀⢀⣼⣿⠀⠀⢸⣿⠀⠀⠀⢰⣿⠇⠀⢰⣿⣇⠀⠀⣠⣿⡏⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⠁⠀⠀⠀⣀⣀⣠⣿⣿⣀⡀⠀⢠⣿⡟⢠⣿⡟⢀⣿⡿⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠛⠛⠛⠛⠛⠛⠁⠀⠈⠛⠿⠟⠋⠛⠃⠀⠀⠛⠛⠀⠀⠀⠘⠛⠀⠀⠀⠙⠿⠿⠛⠙⠛⠃⠀⠀⠚⠛⠀⠀⠀⠀⠀⠀⠀⠘⠿⠿⠃⠀⠀⠀⠀⠿⠿⠿⠿⠿⠿⠿⠀⠸⠿⠇⠸⠿⠇⠸⠿⠇⠀⠀⠀⠀⠀", + " ", +} + +M.banner_alt_2 = { + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠟⠛⠛⠉⠉⠉⠉⠉⠉⠛⠛⠻⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠀⣀⣤⣴⣶⣶⣾⣿⣿⣷⣶⣶⣦⣤⣀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⢀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠈⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⠿⠟⠛⠛⠛⠛⠛⠁⠀⠾⠿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⠁⣴⣾⣿⣿⣿⡟⠀⣰⣿⣶⣶⣶⣤⣤⣉⣉⠛⠛⠿⠿⣿⣿⡿⠿⠿⣿⣿⣿⣿⣿⣿⡟⠛⠛⢛⣿⣿⣿⣆⠀⢻⣿⣿⣿⣿⣿⣿⣿", + "⣿⡄⠻⣿⣿⣿⡟⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⣦⣤⡈⠀⠀⠀⠈⣿⣿⣿⣿⡿⠁⠀⠀⣾⣿⣿⣿⣿⡄⠀⢻⣿⣿⣿⣿⣿⣿", + "⣿⣿⣄⠙⠿⣿⠁⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣄⠀⠀⣠⣄⣉⠛⠻⠃⠀⠀⣼⣿⣿⣿⣿⣿⣿⡀⠈⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣷⣦⡈⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠆⠀⠀⡀⠛⠿⣿⣿⣿⣿⣿⡇⠀⢻⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⡇⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⢀⣿⣿⣿⣿⡇⠀⠀⠘⣿⣿⡟⠀⠀⢰⣿⣷⣦⣌⡙⠻⢿⣿⣷⠀⢸⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⡇⠀⢿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⠀⠀⠀⣿⡿⠀⠀⢀⣿⣿⣿⣿⣿⣿⣷⣤⣈⠛⠀⢸⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣧⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⠀⣾⣿⣿⣿⣿⣿⠀⠀⠀⣿⠁⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⡈⠻⢿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⡀⠈⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⢀⣿⣿⣿⣿⣿⣿⠀⠀⠀⠃⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⢀⣿⣶⣄⠙⣿⣿", + "⣿⣿⣿⣿⣿⣿⣧⠀⠘⣿⣿⣿⣿⣿⣿⡇⠀⠀⠸⠿⠿⠿⠿⠿⠿⠇⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⣼⣿⣿⣿⣦⠘⣿", + "⣿⣿⣿⣿⣿⣿⣿⣧⠀⠹⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⣼⣿⣿⣿⡿⠟⢀⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣧⡀⠈⢿⣿⣿⣿⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⢀⣤⣤⣤⣤⣤⣴⣶⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠈⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⢀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣀⠀⠉⠛⠻⠿⠿⢿⣿⣿⡿⠿⠿⠟⠛⠉⠀⣀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣦⣤⣤⣀⣀⣀⣀⣀⣀⣤⣤⣴⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", + "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", +} + +function M.get_sections() + local header = { + type = "text", + val = function() + local alpha_wins = vim.tbl_filter(function(win) + local buf = vim.api.nvim_win_get_buf(win) + return vim.api.nvim_get_option_value("filetype", { buf = buf }) == "alpha" + end, vim.api.nvim_list_wins()) + + if vim.api.nvim_win_get_height(alpha_wins[#alpha_wins]) < 36 then + return M.banner_small + end + return banner + end, + opts = { + position = "center", + hl = "Label", + }, + } + + local text = require "lvim.interface.text" + local lvim_version = require("lvim.utils.git").get_lvim_version() + + local footer = { + type = "text", + val = text.align_center({ width = 0 }, { + "", + "lunarvim.org", + lvim_version, + }, 0.5), + opts = { + position = "center", + hl = "Number", + }, + } + + local buttons = { + opts = { + hl_shortcut = "Include", + spacing = 1, + }, + entries = { + { "f", lvim.icons.ui.FindFile .. " Find File", "<CMD>Telescope find_files<CR>" }, + { "n", lvim.icons.ui.NewFile .. " New File", "<CMD>ene!<CR>" }, + { "p", lvim.icons.ui.Project .. " Projects ", "<CMD>Telescope projects<CR>" }, + { "r", lvim.icons.ui.History .. " Recent files", ":Telescope oldfiles <CR>" }, + { "t", lvim.icons.ui.FindText .. " Find Text", "<CMD>Telescope live_grep<CR>" }, + { + "c", + lvim.icons.ui.Gear .. " Configuration", + "<CMD>edit " .. require("lvim.config"):get_user_config_path() .. " <CR>", + }, + { "q", lvim.icons.ui.Close .. " Quit", "<CMD>quit<CR>" }, + }, + } + return { + header = header, + buttons = buttons, + footer = footer, + } +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/alpha/startify.lua b/mac/.config/LunarVim/lua/lvim/core/alpha/startify.lua new file mode 100644 index 0000000..e9d10a0 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/alpha/startify.lua @@ -0,0 +1,45 @@ +local M = {} + +function M.get_sections() + local header = { + type = "text", + val = { + [[ __ _ ___ ]], + [[ / / __ ______ ____ _____| | / (_)___ ___ ]], + [[ / / / / / / __ \/ __ `/ ___/ | / / / __ `__ \]], + [[ / /___/ /_/ / / / / /_/ / / | |/ / / / / / / /]], + [[/_____/\__,_/_/ /_/\__,_/_/ |___/_/_/ /_/ /_/ ]], + }, + opts = { + hl = "Label", + shrink_margin = false, + -- wrap = "overflow"; + }, + } + + local top_buttons = { + entries = { + { "e", lvim.icons.ui.NewFile .. " New File", "<CMD>ene!<CR>" }, + }, + } + + local bottom_buttons = { + entries = { + { "q", "Quit", "<CMD>quit<CR>" }, + }, + } + + local footer = { + type = "group", + } + + return { + header = header, + top_buttons = top_buttons, + bottom_buttons = bottom_buttons, + -- this is probably broken + footer = footer, + } +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/autocmds.lua b/mac/.config/LunarVim/lua/lvim/core/autocmds.lua new file mode 100644 index 0000000..f7ec7eb --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/autocmds.lua @@ -0,0 +1,281 @@ +local M = {} +local Log = require "lvim.core.log" + +--- Load the default set of autogroups and autocommands. +function M.load_defaults() + local definitions = { + { + "TextYankPost", + { + group = "_general_settings", + pattern = "*", + desc = "Highlight text on yank", + callback = function() + vim.highlight.on_yank { higroup = "Search", timeout = 100 } + end, + }, + }, + { + "FileType", + { + group = "_hide_dap_repl", + pattern = "dap-repl", + command = "set nobuflisted", + }, + }, + { + "FileType", + { + group = "_filetype_settings", + pattern = { "lua" }, + desc = "fix gf functionality inside .lua files", + callback = function() + ---@diagnostic disable: assign-type-mismatch + -- credit: https://github.com/sam4llis/nvim-lua-gf + vim.opt_local.include = [[\v<((do|load)file|require|reload)[^''"]*[''"]\zs[^''"]+]] + vim.opt_local.includeexpr = "substitute(v:fname,'\\.','/','g')" + vim.opt_local.suffixesadd:prepend ".lua" + vim.opt_local.suffixesadd:prepend "init.lua" + + for _, path in pairs(vim.api.nvim_list_runtime_paths()) do + vim.opt_local.path:append(path .. "/lua") + end + end, + }, + }, + { + "FileType", + { + group = "_buffer_mappings", + pattern = { + "qf", + "help", + "man", + "floaterm", + "lspinfo", + "lir", + "lsp-installer", + "null-ls-info", + "tsplayground", + "DressingSelect", + "Jaq", + }, + callback = function() + vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = true }) + vim.opt_local.buflisted = false + end, + }, + }, + { + "VimResized", + { + group = "_auto_resize", + pattern = "*", + command = [[ + let _auto_resize_current_tab = tabpagenr() + tabdo wincmd = + execute 'tabnext' _auto_resize_current_tab + ]], + }, + }, + { + "FileType", + { + group = "_filetype_settings", + pattern = "alpha", + callback = function() + vim.cmd [[ + set nobuflisted + ]] + end, + }, + }, + { + "FileType", + { + group = "_filetype_settings", + pattern = "lir", + callback = function() + vim.opt_local.number = false + vim.opt_local.relativenumber = false + end, + }, + }, + { + "ColorScheme", + { + group = "_lvim_colorscheme", + callback = function() + if lvim.builtin.breadcrumbs.active then + require("lvim.core.breadcrumbs").get_winbar() + end + local statusline_hl = vim.api.nvim_get_hl(0, { name = "StatusLine" }) + local cursorline_hl = vim.api.nvim_get_hl(0, { name = "CursorLine" }) + local normal_hl = vim.api.nvim_get_hl(0, { name = "Normal" }) + vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" }) + vim.api.nvim_set_hl(0, "CmpItemKindTabnine", { fg = "#CA42F0" }) + vim.api.nvim_set_hl(0, "CmpItemKindCrate", { fg = "#F64D00" }) + vim.api.nvim_set_hl(0, "CmpItemKindEmoji", { fg = "#FDE030" }) + vim.api.nvim_set_hl(0, "SLCopilot", { fg = "#6CC644", bg = statusline_hl.bg }) + vim.api.nvim_set_hl(0, "SLGitIcon", { fg = "#E8AB53", bg = cursorline_hl.bg }) + vim.api.nvim_set_hl(0, "SLBranchName", { fg = normal_hl.fg, bg = cursorline_hl.bg }) + vim.api.nvim_set_hl(0, "SLSeparator", { fg = cursorline_hl.fg, bg = statusline_hl.bg }) + end, + }, + }, + { -- taken from AstroNvim + "BufEnter", + { + group = "_dir_opened", + nested = true, + callback = function(args) + local bufname = vim.api.nvim_buf_get_name(args.buf) + if require("lvim.utils").is_directory(bufname) then + vim.api.nvim_del_augroup_by_name "_dir_opened" + vim.cmd "do User DirOpened" + vim.api.nvim_exec_autocmds(args.event, { buffer = args.buf, data = args.data }) + end + end, + }, + }, + { -- taken from AstroNvim + { "BufRead", "BufWinEnter", "BufNewFile" }, + { + group = "_file_opened", + nested = true, + callback = function(args) + local buftype = vim.api.nvim_get_option_value("buftype", { buf = args.buf }) + if not (vim.fn.expand "%" == "" or buftype == "nofile") then + vim.api.nvim_del_augroup_by_name "_file_opened" + vim.api.nvim_exec_autocmds("User", { pattern = "FileOpened" }) + require("lvim.lsp").setup() + end + end, + }, + }, + } + + M.define_autocmds(definitions) +end + +local get_format_on_save_opts = function() + local defaults = require("lvim.config.defaults").format_on_save + -- accept a basic boolean `lvim.format_on_save=true` + if type(lvim.format_on_save) ~= "table" then + return defaults + end + + return { + pattern = lvim.format_on_save.pattern or defaults.pattern, + timeout = lvim.format_on_save.timeout or defaults.timeout, + } +end + +function M.enable_format_on_save() + local opts = get_format_on_save_opts() + vim.api.nvim_create_augroup("lsp_format_on_save", {}) + vim.api.nvim_create_autocmd("BufWritePre", { + group = "lsp_format_on_save", + pattern = opts.pattern, + callback = function() + require("lvim.lsp.utils").format { timeout_ms = opts.timeout, filter = opts.filter } + end, + }) + Log:debug "enabled format-on-save" +end + +function M.disable_format_on_save() + M.clear_augroup "lsp_format_on_save" + Log:debug "disabled format-on-save" +end + +function M.configure_format_on_save() + if type(lvim.format_on_save) == "table" and lvim.format_on_save.enabled then + M.enable_format_on_save() + elseif lvim.format_on_save == true then + M.enable_format_on_save() + else + M.disable_format_on_save() + end +end + +function M.toggle_format_on_save() + local exists, autocmds = pcall(vim.api.nvim_get_autocmds, { + group = "lsp_format_on_save", + event = "BufWritePre", + }) + if not exists or #autocmds == 0 then + M.enable_format_on_save() + else + M.disable_format_on_save() + end +end + +function M.enable_reload_config_on_save() + -- autocmds require forward slashes (even on windows) + local pattern = get_config_dir():gsub("\\", "/") .. "/*.lua" + + vim.api.nvim_create_augroup("lvim_reload_config_on_save", {}) + vim.api.nvim_create_autocmd("BufWritePost", { + group = "lvim_reload_config_on_save", + pattern = pattern, + desc = "Trigger LvimReload on saving config.lua", + callback = function() + require("lvim.config"):reload() + end, + }) +end + +function M.enable_transparent_mode() + vim.api.nvim_create_autocmd("ColorScheme", { + pattern = "*", + callback = function() + local hl_groups = { + "Normal", + "SignColumn", + "NormalNC", + "TelescopeBorder", + "NvimTreeNormal", + "NvimTreeNormalNC", + "EndOfBuffer", + "MsgArea", + } + for _, name in ipairs(hl_groups) do + vim.cmd(string.format("highlight %s ctermbg=none guibg=none", name)) + end + end, + }) + vim.opt.fillchars = "eob: " +end + +--- Clean autocommand in a group if it exists +--- This is safer than trying to delete the augroup itself +---@param name string the augroup name +function M.clear_augroup(name) + -- defer the function in case the autocommand is still in-use + Log:debug("request to clear autocmds " .. name) + vim.schedule(function() + pcall(function() + vim.api.nvim_clear_autocmds { group = name } + end) + end) +end + +--- Create autocommand groups based on the passed definitions +--- Also creates the augroup automatically if it doesn't exist +---@param definitions table contains a tuple of event, opts, see `:h nvim_create_autocmd` +function M.define_autocmds(definitions) + for _, entry in ipairs(definitions) do + local event = entry[1] + local opts = entry[2] + if type(opts.group) == "string" and opts.group ~= "" then + local exists, _ = pcall(vim.api.nvim_get_autocmds, { group = opts.group }) + if not exists then + vim.api.nvim_create_augroup(opts.group, {}) + end + end + vim.api.nvim_create_autocmd(event, opts) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/autopairs.lua b/mac/.config/LunarVim/lua/lvim/core/autopairs.lua new file mode 100644 index 0000000..439de09 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/autopairs.lua @@ -0,0 +1,91 @@ +local M = {} + +function M.config() + lvim.builtin.autopairs = { + active = true, + on_config_done = nil, + ---@usage modifies the function or method delimiter by filetypes + map_char = { + all = "(", + tex = "{", + }, + ---@usage check bracket in same line + enable_check_bracket_line = false, + ---@usage check treesitter + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + ---@usage disable when recording or executing a macro + disable_in_macro = false, + ---@usage disable when insert after visual block mode + disable_in_visualblock = false, + disable_in_replace_mode = true, + ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]], "%s+", ""), + enable_moveright = true, + ---@usage add bracket pairs after quote + enable_afterquote = true, + ---@usage trigger abbreviation + enable_abbr = false, + ---@usage switch for basic rule break undo sequence + break_undo = true, + map_cr = true, + ---@usage map the <BS> key + map_bs = true, + ---@usage map <c-w> to delete a pair if possible + map_c_w = false, + ---@usage Map the <C-h> key to delete a pair + map_c_h = false, + ---@usage change default fast_wrap + fast_wrap = { + map = "<M-e>", + chars = { "{", "[", "(", '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "Search", + highlight_grey = "Comment", + }, + } +end + +M.setup = function() + local status_ok, autopairs = pcall(require, "nvim-autopairs") + if not status_ok then + return + end + + autopairs.setup { + check_ts = lvim.builtin.autopairs.check_ts, + enable_check_bracket_line = lvim.builtin.autopairs.enable_check_bracket_line, + ts_config = lvim.builtin.autopairs.ts_config, + disable_filetype = lvim.builtin.autopairs.disable_filetype, + disable_in_macro = lvim.builtin.autopairs.disable_in_macro, + ignored_next_char = lvim.builtin.autopairs.ignored_next_char, + enable_moveright = lvim.builtin.autopairs.enable_moveright, + enable_afterquote = lvim.builtin.autopairs.enable_afterquote, + map_c_w = lvim.builtin.autopairs.map_c_w, + map_bs = lvim.builtin.autopairs.map_bs, + disable_in_visualblock = lvim.builtin.autopairs.disable_in_visualblock, + fast_wrap = lvim.builtin.autopairs.fast_wrap, + } + + if lvim.builtin.autopairs.on_config_done then + lvim.builtin.autopairs.on_config_done(autopairs) + end + + pcall(function() + local function on_confirm_done(...) + require("nvim-autopairs.completion.cmp").on_confirm_done()(...) + end + require("cmp").event:off("confirm_done", on_confirm_done) + require("cmp").event:on("confirm_done", on_confirm_done) + end) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/breadcrumbs.lua b/mac/.config/LunarVim/lua/lvim/core/breadcrumbs.lua new file mode 100644 index 0000000..485458f --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/breadcrumbs.lua @@ -0,0 +1,236 @@ +local M = {} + +-- local Log = require "lvim.core.log" +local icons = lvim.icons.kind + +M.config = function() + lvim.builtin.breadcrumbs = { + active = true, + on_config_done = nil, + winbar_filetype_exclude = { + "help", + "startify", + "dashboard", + "lazy", + "neo-tree", + "neogitstatus", + "NvimTree", + "Trouble", + "alpha", + "lir", + "Outline", + "spectre_panel", + "toggleterm", + "DressingSelect", + "Jaq", + "harpoon", + "dap-repl", + "dap-terminal", + "dapui_console", + "dapui_hover", + "lab", + "notify", + "noice", + "neotest-summary", + "", + }, + options = { + icons = { + Array = icons.Array .. " ", + Boolean = icons.Boolean .. " ", + Class = icons.Class .. " ", + Color = icons.Color .. " ", + Constant = icons.Constant .. " ", + Constructor = icons.Constructor .. " ", + Enum = icons.Enum .. " ", + EnumMember = icons.EnumMember .. " ", + Event = icons.Event .. " ", + Field = icons.Field .. " ", + File = icons.File .. " ", + Folder = icons.Folder .. " ", + Function = icons.Function .. " ", + Interface = icons.Interface .. " ", + Key = icons.Key .. " ", + Keyword = icons.Keyword .. " ", + Method = icons.Method .. " ", + Module = icons.Module .. " ", + Namespace = icons.Namespace .. " ", + Null = icons.Null .. " ", + Number = icons.Number .. " ", + Object = icons.Object .. " ", + Operator = icons.Operator .. " ", + Package = icons.Package .. " ", + Property = icons.Property .. " ", + Reference = icons.Reference .. " ", + Snippet = icons.Snippet .. " ", + String = icons.String .. " ", + Struct = icons.Struct .. " ", + Text = icons.Text .. " ", + TypeParameter = icons.TypeParameter .. " ", + Unit = icons.Unit .. " ", + Value = icons.Value .. " ", + Variable = icons.Variable .. " ", + }, + highlight = true, + separator = " " .. lvim.icons.ui.ChevronRight .. " ", + depth_limit = 0, + depth_limit_indicator = "..", + }, + } +end + +M.setup = function() + local status_ok, navic = pcall(require, "nvim-navic") + if not status_ok then + return + end + + M.create_winbar() + navic.setup(lvim.builtin.breadcrumbs.options) + + if lvim.builtin.breadcrumbs.on_config_done then + lvim.builtin.breadcrumbs.on_config_done() + end +end + +local function isempty(s) + return s == nil or s == "" +end + +M.get_filename = function() + local filename = vim.fn.expand "%:t" + local extension = vim.fn.expand "%:e" + + if not isempty(filename) then + local file_icon, hl_group + local devicons_ok, devicons = pcall(require, "nvim-web-devicons") + if lvim.use_icons and devicons_ok then + file_icon, hl_group = devicons.get_icon(filename, extension, { default = true }) + + if isempty(file_icon) then + file_icon = lvim.icons.kind.File + end + else + file_icon = "" + hl_group = "Normal" + end + + local buf_ft = vim.bo.filetype + + if buf_ft == "dapui_breakpoints" then + file_icon = lvim.icons.ui.Bug + end + + if buf_ft == "dapui_stacks" then + file_icon = lvim.icons.ui.Stacks + end + + if buf_ft == "dapui_scopes" then + file_icon = lvim.icons.ui.Scopes + end + + if buf_ft == "dapui_watches" then + file_icon = lvim.icons.ui.Watches + end + + -- if buf_ft == "dapui_console" then + -- file_icon = lvim.icons.ui.DebugConsole + -- end + + local navic_text_hl = vim.api.nvim_get_hl(0, { name = "Normal" }) + vim.api.nvim_set_hl(0, "Winbar", { fg = navic_text_hl.fg }) + + return " " .. "%#" .. hl_group .. "#" .. file_icon .. "%*" .. " " .. "%#Winbar#" .. filename .. "%*" + end +end + +local get_gps = function() + local status_gps_ok, gps = pcall(require, "nvim-navic") + if not status_gps_ok then + return "" + end + + local status_ok, gps_location = pcall(gps.get_location, {}) + if not status_ok then + return "" + end + + if not gps.is_available() or gps_location == "error" then + return "" + end + + if not isempty(gps_location) then + return "%#NavicSeparator#" .. lvim.icons.ui.ChevronRight .. "%* " .. gps_location + else + return "" + end +end + +local excludes = function() + return vim.tbl_contains(lvim.builtin.breadcrumbs.winbar_filetype_exclude or {}, vim.bo.filetype) +end + +M.get_winbar = function() + if excludes() then + return + end + local value = M.get_filename() + + local gps_added = false + if not isempty(value) then + local gps_value = get_gps() + value = value .. " " .. gps_value + if not isempty(gps_value) then + gps_added = true + end + end + + if not isempty(value) and vim.api.nvim_get_option_value("mod", { buf = 0 }) then + -- TODO: replace with circle + local mod = "%#LspCodeLens#" .. lvim.icons.ui.Circle .. "%*" + if gps_added then + value = value .. " " .. mod + else + value = value .. mod + end + end + + local num_tabs = #vim.api.nvim_list_tabpages() + + if num_tabs > 1 and not isempty(value) then + local tabpage_number = tostring(vim.api.nvim_tabpage_get_number(0)) + value = value .. "%=" .. tabpage_number .. "/" .. tostring(num_tabs) + end + + local status_ok, _ = pcall(vim.api.nvim_set_option_value, "winbar", value, { scope = "local" }) + if not status_ok then + return + end +end + +M.create_winbar = function() + vim.api.nvim_create_augroup("_winbar", {}) + vim.api.nvim_create_autocmd({ + "CursorHoldI", + "CursorHold", + "BufWinEnter", + "BufFilePost", + "InsertEnter", + "BufWritePost", + "TabClosed", + "TabEnter", + }, { + group = "_winbar", + callback = function() + if lvim.builtin.breadcrumbs.active then + local status_ok, _ = pcall(vim.api.nvim_buf_get_var, 0, "lsp_floating_window") + if not status_ok then + -- TODO: + require("lvim.core.breadcrumbs").get_winbar() + end + end + end, + }) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/bufferline.lua b/mac/.config/LunarVim/lua/lvim/core/bufferline.lua new file mode 100644 index 0000000..057e7ca --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/bufferline.lua @@ -0,0 +1,256 @@ +local M = {} + +local function is_ft(b, ft) + return vim.bo[b].filetype == ft +end + +local function diagnostics_indicator(num, _, diagnostics, _) + local result = {} + local symbols = { + error = lvim.icons.diagnostics.Error, + warning = lvim.icons.diagnostics.Warning, + info = lvim.icons.diagnostics.Information, + } + if not lvim.use_icons then + return "(" .. num .. ")" + end + for name, count in pairs(diagnostics) do + if symbols[name] and count > 0 then + table.insert(result, symbols[name] .. " " .. count) + end + end + result = table.concat(result, " ") + return #result > 0 and result or "" +end + +local function custom_filter(buf, buf_nums) + local logs = vim.tbl_filter(function(b) + return is_ft(b, "log") + end, buf_nums or {}) + if vim.tbl_isempty(logs) then + return true + end + local tab_num = vim.fn.tabpagenr() + local last_tab = vim.fn.tabpagenr "$" + local is_log = is_ft(buf, "log") + if last_tab == 1 then + return true + end + -- only show log buffers in secondary tabs + return (tab_num == last_tab and is_log) or (tab_num ~= last_tab and not is_log) +end + +M.config = function() + lvim.builtin.bufferline = { + active = true, + on_config_done = nil, + keymap = { + normal_mode = {}, + }, + highlights = { + background = { + italic = true, + }, + buffer_selected = { + bold = true, + }, + }, + options = { + themable = true, -- whether or not bufferline highlights can be overridden externally + -- style_preset = preset, + get_element_icon = nil, + show_duplicate_prefix = true, + duplicates_across_groups = true, + auto_toggle_bufferline = true, + move_wraps_at_ends = false, + groups = { items = {}, options = { toggle_hidden_on_enter = true } }, + mode = "buffers", -- set to "tabs" to only show tabpages instead + numbers = "none", -- can be "none" | "ordinal" | "buffer_id" | "both" | function + close_command = function(bufnr) -- can be a string | function, see "Mouse actions" + M.buf_kill("bd", bufnr, false) + end, + right_mouse_command = "vert sbuffer %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + indicator = { + icon = lvim.icons.ui.BoldLineLeft, -- this should be omitted if indicator style is not 'icon' + style = "icon", -- can also be 'underline'|'none', + }, + buffer_close_icon = lvim.icons.ui.Close, + modified_icon = lvim.icons.ui.Circle, + close_icon = lvim.icons.ui.BoldClose, + left_trunc_marker = lvim.icons.ui.ArrowCircleLeft, + right_trunc_marker = lvim.icons.ui.ArrowCircleRight, + --- name_formatter can be used to change the buffer's label in the bufferline. + --- Please note some names can/will break the + --- bufferline so use this at your discretion knowing that it has + --- some limitations that will *NOT* be fixed. + name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr" + -- remove extension from markdown files for example + if buf.name:match "%.md" then + return vim.fn.fnamemodify(buf.name, ":t:r") + end + end, + max_name_length = 18, + max_prefix_length = 15, -- prefix used when a buffer is de-duplicated + truncate_names = true, -- whether or not tab names should be truncated + tab_size = 18, + diagnostics = "nvim_lsp", + diagnostics_update_in_insert = false, + diagnostics_indicator = diagnostics_indicator, + -- NOTE: this will be called a lot so don't do any heavy processing here + custom_filter = custom_filter, + offsets = { + { + filetype = "undotree", + text = "Undotree", + highlight = "PanelHeading", + padding = 1, + }, + { + filetype = "NvimTree", + text = "Explorer", + highlight = "PanelHeading", + padding = 1, + }, + { + filetype = "DiffviewFiles", + text = "Diff View", + highlight = "PanelHeading", + padding = 1, + }, + { + filetype = "flutterToolsOutline", + text = "Flutter Outline", + highlight = "PanelHeading", + }, + { + filetype = "lazy", + text = "Lazy", + highlight = "PanelHeading", + padding = 1, + }, + }, + color_icons = true, -- whether or not to add the filetype icon highlights + show_buffer_icons = lvim.use_icons, -- disable filetype icons for buffers + show_buffer_close_icons = lvim.use_icons, + show_close_icon = false, + show_tab_indicators = true, + persist_buffer_sort = true, -- whether or not custom sorted buffers should persist + -- can also be a table containing 2 custom separators + -- [focused and unfocused]. eg: { '|', '|' } + separator_style = "thin", + enforce_regular_tabs = false, + always_show_bufferline = false, + hover = { + enabled = false, -- requires nvim 0.8+ + delay = 200, + reveal = { "close" }, + }, + sort_by = "id", + debug = { logging = false }, + }, + } +end + +M.setup = function() + require("lvim.keymappings").load(lvim.builtin.bufferline.keymap) + + local status_ok, bufferline = pcall(require, "bufferline") + if not status_ok then + return + end + + -- can't be set in settings.lua because default tabline would flash before bufferline is loaded + vim.opt.showtabline = 2 + + bufferline.setup { + options = lvim.builtin.bufferline.options, + highlights = lvim.builtin.bufferline.highlights, + } + + if lvim.builtin.bufferline.on_config_done then + lvim.builtin.bufferline.on_config_done() + end +end + +--stylua: ignore + +-- Common kill function for bdelete and bwipeout +-- credits: based on bbye and nvim-bufdel +---@param kill_command? string defaults to "bd" +---@param bufnr? number defaults to the current buffer +---@param force? boolean defaults to false +function M.buf_kill(kill_command, bufnr, force) + kill_command = kill_command or "bd" + + local bo = vim.bo + local api = vim.api + local fmt = string.format + local fn = vim.fn + + if bufnr == 0 or bufnr == nil then + bufnr = api.nvim_get_current_buf() + end + + local bufname = api.nvim_buf_get_name(bufnr) + + if not force then + local choice + if bo[bufnr].modified then + choice = fn.confirm(fmt([[Save changes to "%s"?]], bufname), "&Yes\n&No\n&Cancel") + if choice == 1 then + vim.api.nvim_buf_call(bufnr, function() + vim.cmd("w") + end) + elseif choice == 2 then + force = true + else return + end + elseif api.nvim_get_option_value("buftype", { buf = 0 }) == "terminal" then + choice = fn.confirm(fmt([[Close "%s"?]], bufname), "&Yes\n&No\n&Cancel") + if choice == 1 then + force = true + else + return + end + end + end + + -- Get list of windows IDs with the buffer to close + local windows = vim.tbl_filter(function(win) + return api.nvim_win_get_buf(win) == bufnr + end, api.nvim_list_wins()) + + if force then + kill_command = kill_command .. "!" + end + + -- Get list of active buffers + local buffers = vim.tbl_filter(function(buf) + return api.nvim_buf_is_valid(buf) and bo[buf].buflisted + end, api.nvim_list_bufs()) + + -- If there is only one buffer (which has to be the current one), vim will + -- create a new buffer on :bd. + -- For more than one buffer, pick the previous buffer (wrapping around if necessary) + if #buffers > 1 and #windows > 0 then + for i, v in ipairs(buffers) do + if v == bufnr then + local prev_buf_idx = i == 1 and #buffers or (i - 1) + local prev_buffer = buffers[prev_buf_idx] + for _, win in ipairs(windows) do + api.nvim_win_set_buf(win, prev_buffer) + end + end + end + end + + -- Check if buffer still exists, to ensure the target buffer wasn't killed + -- due to options like bufhidden=wipe. + if api.nvim_buf_is_valid(bufnr) and bo[bufnr].buflisted then + vim.cmd(string.format("%s %d", kill_command, bufnr)) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/builtins/init.lua b/mac/.config/LunarVim/lua/lvim/core/builtins/init.lua new file mode 100644 index 0000000..4764ff7 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/builtins/init.lua @@ -0,0 +1,34 @@ +local M = {} + +local builtins = { + "lvim.core.theme", + "lvim.core.which-key", + "lvim.core.gitsigns", + "lvim.core.cmp", + "lvim.core.dap", + "lvim.core.terminal", + "lvim.core.telescope", + "lvim.core.treesitter", + "lvim.core.nvimtree", + "lvim.core.lir", + "lvim.core.illuminate", + "lvim.core.indentlines", + "lvim.core.breadcrumbs", + "lvim.core.project", + "lvim.core.bufferline", + "lvim.core.autopairs", + "lvim.core.comment", + "lvim.core.lualine", + "lvim.core.alpha", + "lvim.core.mason", +} + +function M.config(config) + for _, builtin_path in ipairs(builtins) do + local builtin = reload(builtin_path) + + builtin.config(config) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/cmp.lua b/mac/.config/LunarVim/lua/lvim/core/cmp.lua new file mode 100644 index 0000000..38da87a --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/cmp.lua @@ -0,0 +1,390 @@ +local M = {} +M.methods = {} + +local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil +end +M.methods.has_words_before = has_words_before + +---@deprecated use M.methods.has_words_before instead +M.methods.check_backspace = function() + return not has_words_before() +end + +local T = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local function feedkeys(key, mode) + vim.api.nvim_feedkeys(T(key), mode, true) +end + +M.methods.feedkeys = feedkeys + +---when inside a snippet, seeks to the nearest luasnip field if possible, and checks if it is jumpable +---@param dir number 1 for forward, -1 for backward; defaults to 1 +---@return boolean true if a jumpable luasnip field is found while inside a snippet +local function jumpable(dir) + local luasnip_ok, luasnip = pcall(require, "luasnip") + if not luasnip_ok then + return false + end + + local win_get_cursor = vim.api.nvim_win_get_cursor + local get_current_buf = vim.api.nvim_get_current_buf + + ---sets the current buffer's luasnip to the one nearest the cursor + ---@return boolean true if a node is found, false otherwise + local function seek_luasnip_cursor_node() + -- TODO(kylo252): upstream this + -- for outdated versions of luasnip + if not luasnip.session.current_nodes then + return false + end + + local node = luasnip.session.current_nodes[get_current_buf()] + if not node then + return false + end + + local snippet = node.parent.snippet + local exit_node = snippet.insert_nodes[0] + + local pos = win_get_cursor(0) + pos[1] = pos[1] - 1 + + -- exit early if we're past the exit node + if exit_node then + local exit_pos_end = exit_node.mark:pos_end() + if (pos[1] > exit_pos_end[1]) or (pos[1] == exit_pos_end[1] and pos[2] > exit_pos_end[2]) then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + node = snippet.inner_first:jump_into(1, true) + while node ~= nil and node.next ~= nil and node ~= snippet do + local n_next = node.next + local next_pos = n_next and n_next.mark:pos_begin() + local candidate = n_next ~= snippet and next_pos and (pos[1] < next_pos[1]) + or (pos[1] == next_pos[1] and pos[2] < next_pos[2]) + + -- Past unmarked exit node, exit early + if n_next == nil or n_next == snippet.next then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + + if candidate then + luasnip.session.current_nodes[get_current_buf()] = node + return true + end + + local ok + ok, node = pcall(node.jump_from, node, 1, true) -- no_move until last stop + if not ok then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + -- No candidate, but have an exit node + if exit_node then + -- to jump to the exit node, seek to snippet + luasnip.session.current_nodes[get_current_buf()] = snippet + return true + end + + -- No exit node, exit from snippet + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + return false + end + + if dir == -1 then + return luasnip.in_snippet() and luasnip.jumpable(-1) + else + return luasnip.in_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable(1) + end +end + +M.methods.jumpable = jumpable + +M.config = function() + local status_cmp_ok, cmp_types = pcall(require, "cmp.types.cmp") + if not status_cmp_ok then + return + end + local ConfirmBehavior = cmp_types.ConfirmBehavior + local SelectBehavior = cmp_types.SelectBehavior + + local cmp = require("lvim.utils.modules").require_on_index "cmp" + local luasnip = require("lvim.utils.modules").require_on_index "luasnip" + local cmp_window = require "cmp.config.window" + local cmp_mapping = require "cmp.config.mapping" + + lvim.builtin.cmp = { + active = true, + on_config_done = nil, + enabled = function() + local buftype = vim.api.nvim_get_option_value("buftype", { buf = 0 }) + if buftype == "prompt" then + return false + end + return lvim.builtin.cmp.active + end, + confirm_opts = { + behavior = ConfirmBehavior.Replace, + select = false, + }, + completion = { + ---@usage The minimum length of a word to complete on. + keyword_length = 1, + }, + experimental = { + ghost_text = false, + native_menu = false, + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + max_width = 0, + kind_icons = lvim.icons.kind, + source_names = { + nvim_lsp = "(LSP)", + emoji = "(Emoji)", + path = "(Path)", + calc = "(Calc)", + cmp_tabnine = "(Tabnine)", + vsnip = "(Snippet)", + luasnip = "(Snippet)", + buffer = "(Buffer)", + tmux = "(TMUX)", + copilot = "(Copilot)", + codeium = "(Codeium)", + treesitter = "(TreeSitter)", + }, + duplicates = { + buffer = 1, + path = 1, + nvim_lsp = 0, + luasnip = 1, + }, + duplicates_default = 0, + format = function(entry, vim_item) + local max_width = lvim.builtin.cmp.formatting.max_width + if max_width ~= 0 and #vim_item.abbr > max_width then + vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. lvim.icons.ui.Ellipsis + end + if lvim.use_icons then + vim_item.kind = lvim.builtin.cmp.formatting.kind_icons[vim_item.kind] + + if entry.source.name == "copilot" then + vim_item.kind = lvim.icons.git.Octoface + vim_item.kind_hl_group = "CmpItemKindCopilot" + end + + if entry.source.name == "codeium" then + vim_item.kind = lvim.icons.misc.Watch + vim_item.kind_hl_group = "CmpItemKindCopilot" + end + + if entry.source.name == "cmp_tabnine" then + vim_item.kind = lvim.icons.misc.Robot + vim_item.kind_hl_group = "CmpItemKindTabnine" + end + + if entry.source.name == "crates" then + vim_item.kind = lvim.icons.misc.Package + vim_item.kind_hl_group = "CmpItemKindCrate" + end + + if entry.source.name == "lab.quick_data" then + vim_item.kind = lvim.icons.misc.CircuitBoard + vim_item.kind_hl_group = "CmpItemKindConstant" + end + + if entry.source.name == "emoji" then + vim_item.kind = lvim.icons.misc.Smiley + vim_item.kind_hl_group = "CmpItemKindEmoji" + end + end + vim_item.menu = lvim.builtin.cmp.formatting.source_names[entry.source.name] + vim_item.dup = lvim.builtin.cmp.formatting.duplicates[entry.source.name] + or lvim.builtin.cmp.formatting.duplicates_default + return vim_item + end, + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + window = { + completion = cmp_window.bordered(), + documentation = cmp_window.bordered(), + }, + sources = { + { + name = "copilot", + -- keyword_length = 0, + max_item_count = 3, + trigger_characters = { + { + ".", + ":", + "(", + "'", + '"', + "[", + ",", + "#", + "*", + "@", + "|", + "=", + "-", + "{", + "/", + "\\", + "+", + "?", + " ", + -- "\t", + -- "\n", + }, + }, + }, + { + name = "nvim_lsp", + entry_filter = function(entry, ctx) + local kind = require("cmp.types.lsp").CompletionItemKind[entry:get_kind()] + if kind == "Snippet" and ctx.prev_context.filetype == "java" then + return false + end + return true + end, + }, + + { name = "codeium" }, -- for codeium completion + { name = "path" }, + { name = "luasnip" }, + { name = "cmp_tabnine" }, + { name = "nvim_lua" }, + { name = "buffer" }, + { name = "calc" }, + { name = "emoji" }, + { name = "treesitter" }, + { name = "crates" }, + { name = "tmux" }, + }, + mapping = cmp_mapping.preset.insert { + ["<C-k>"] = cmp_mapping(cmp_mapping.select_prev_item(), { "i", "c" }), + ["<C-j>"] = cmp_mapping(cmp_mapping.select_next_item(), { "i", "c" }), + ["<Down>"] = cmp_mapping(cmp_mapping.select_next_item { behavior = SelectBehavior.Select }, { "i" }), + ["<Up>"] = cmp_mapping(cmp_mapping.select_prev_item { behavior = SelectBehavior.Select }, { "i" }), + ["<C-d>"] = cmp_mapping.scroll_docs(-4), + ["<C-f>"] = cmp_mapping.scroll_docs(4), + ["<C-y>"] = cmp_mapping { + i = cmp_mapping.confirm { behavior = ConfirmBehavior.Replace, select = false }, + c = function(fallback) + if cmp.visible() then + cmp.confirm { behavior = ConfirmBehavior.Replace, select = false } + else + fallback() + end + end, + }, + ["<Tab>"] = cmp_mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + elseif jumpable(1) then + luasnip.jump(1) + elseif has_words_before() then + -- cmp.complete() + fallback() + else + fallback() + end + end, { "i", "s" }), + ["<S-Tab>"] = cmp_mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + ["<C-Space>"] = cmp_mapping.complete(), + ["<C-e>"] = cmp_mapping.abort(), + ["<CR>"] = cmp_mapping(function(fallback) + if cmp.visible() then + local confirm_opts = vim.deepcopy(lvim.builtin.cmp.confirm_opts) -- avoid mutating the original opts below + local is_insert_mode = function() + return vim.api.nvim_get_mode().mode:sub(1, 1) == "i" + end + if is_insert_mode() then -- prevent overwriting brackets + confirm_opts.behavior = ConfirmBehavior.Insert + end + local entry = cmp.get_selected_entry() + local is_copilot = entry and entry.source.name == "copilot" + if is_copilot then + confirm_opts.behavior = ConfirmBehavior.Replace + confirm_opts.select = true + end + if cmp.confirm(confirm_opts) then + return -- success, exit early + end + end + fallback() -- if not exited early, always fallback + end), + }, + cmdline = { + enable = false, + options = { + { + type = ":", + sources = { + { name = "path" }, + { name = "cmdline" }, + }, + }, + { + type = { "/", "?" }, + sources = { + { name = "buffer" }, + }, + }, + }, + }, + } +end + +function M.setup() + local cmp = require "cmp" + cmp.setup(lvim.builtin.cmp) + + if lvim.builtin.cmp.cmdline.enable then + for _, option in ipairs(lvim.builtin.cmp.cmdline.options) do + cmp.setup.cmdline(option.type, { + mapping = cmp.mapping.preset.cmdline(), + sources = option.sources, + }) + end + end + + if lvim.builtin.cmp.on_config_done then + lvim.builtin.cmp.on_config_done(cmp) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/commands.lua b/mac/.config/LunarVim/lua/lvim/core/commands.lua new file mode 100644 index 0000000..9f5d004 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/commands.lua @@ -0,0 +1,99 @@ +local M = {} + +vim.cmd [[ + function! QuickFixToggle() + if empty(filter(getwininfo(), 'v:val.quickfix')) + copen + else + cclose + endif + endfunction +]] + +M.defaults = { + { + name = "BufferKill", + fn = function() + require("lvim.core.bufferline").buf_kill "bd" + end, + }, + { + name = "LvimToggleFormatOnSave", + fn = function() + require("lvim.core.autocmds").toggle_format_on_save() + end, + }, + { + name = "LvimInfo", + fn = function() + require("lvim.core.info").toggle_popup(vim.bo.filetype) + end, + }, + { + name = "LvimDocs", + fn = function() + local documentation_url = "https://www.lunarvim.org/docs/beginners-guide" + if vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1 then + vim.fn.execute("!open " .. documentation_url) + elseif vim.fn.has "win32" == 1 or vim.fn.has "win64" == 1 then + vim.fn.execute("!start " .. documentation_url) + elseif vim.fn.has "unix" == 1 then + vim.fn.execute("!xdg-open " .. documentation_url) + else + vim.notify "Opening docs in a browser is not supported on your OS" + end + end, + }, + { + name = "LvimCacheReset", + fn = function() + require("lvim.utils.hooks").reset_cache() + end, + }, + { + name = "LvimReload", + fn = function() + require("lvim.config"):reload() + end, + }, + { + name = "LvimUpdate", + fn = function() + require("lvim.bootstrap"):update() + end, + }, + { + name = "LvimSyncCorePlugins", + fn = function() + require("lvim.plugin-loader").sync_core_plugins() + end, + }, + { + name = "LvimChangelog", + fn = function() + require("lvim.core.telescope.custom-finders").view_lunarvim_changelog() + end, + }, + { + name = "LvimVersion", + fn = function() + print(require("lvim.utils.git").get_lvim_version()) + end, + }, + { + name = "LvimOpenlog", + fn = function() + vim.fn.execute("edit " .. require("lvim.core.log").get_path()) + end, + }, +} + +function M.load(collection) + local common_opts = { force = true } + for _, cmd in pairs(collection) do + local opts = vim.tbl_deep_extend("force", common_opts, cmd.opts or {}) + vim.api.nvim_create_user_command(cmd.name, cmd.fn, opts) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/comment.lua b/mac/.config/LunarVim/lua/lvim/core/comment.lua new file mode 100644 index 0000000..f07929c --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/comment.lua @@ -0,0 +1,86 @@ +local M = {} + +function M.config() + lvim.builtin.comment = { + active = true, + on_config_done = nil, + ---Add a space b/w comment and the line + ---@type boolean + padding = true, + + ---Whether cursor should stay at the + ---same position. Only works in NORMAL + ---mode mappings + sticky = true, + + ---Lines to be ignored while comment/uncomment. + ---Could be a regex string or a function that returns a regex string. + ---Example: Use '^$' to ignore empty lines + ---@type string|function + ignore = "^$", + + ---Whether to create basic (operator-pending) and extra mappings for NORMAL/VISUAL mode + ---@type table + mappings = { + ---operator-pending mapping + ---Includes `gcc`, `gcb`, `gc[count]{motion}` and `gb[count]{motion}` + basic = true, + ---Extra mapping + ---Includes `gco`, `gcO`, `gcA` + extra = true, + }, + + ---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode + ---@type table + toggler = { + ---line-comment toggle + line = "gcc", + ---block-comment toggle + block = "gbc", + }, + + ---LHS of line and block comment operator-mode mapping in NORMAL/VISUAL mode + ---@type table + opleader = { + ---line-comment opfunc mapping + line = "gc", + ---block-comment opfunc mapping + block = "gb", + }, + + ---LHS of extra mappings + ---@type table + extra = { + ---Add comment on the line above + above = "gcO", + ---Add comment on the line below + below = "gco", + ---Add comment at the end of line + eol = "gcA", + }, + + ---Pre-hook, called before commenting the line + ---@type function|nil + pre_hook = function(...) + local loaded, ts_comment = pcall(require, "ts_context_commentstring.integrations.comment_nvim") + if loaded and ts_comment then + return ts_comment.create_pre_hook()(...) + end + end, + + ---Post-hook, called after commenting is done + ---@type function|nil + post_hook = nil, + } +end + +function M.setup() + local nvim_comment = require "Comment" + + nvim_comment.setup(lvim.builtin.comment) + if lvim.builtin.comment.on_config_done then + lvim.builtin.comment.on_config_done(nvim_comment) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/dap.lua b/mac/.config/LunarVim/lua/lvim/core/dap.lua new file mode 100644 index 0000000..1c563e3 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/dap.lua @@ -0,0 +1,177 @@ +local M = {} + +M.config = function() + lvim.builtin.dap = { + active = true, + on_config_done = nil, + breakpoint = { + text = lvim.icons.ui.Bug, + texthl = "DiagnosticSignError", + linehl = "", + numhl = "", + }, + breakpoint_rejected = { + text = lvim.icons.ui.Bug, + texthl = "DiagnosticSignError", + linehl = "", + numhl = "", + }, + stopped = { + text = lvim.icons.ui.BoldArrowRight, + texthl = "DiagnosticSignWarn", + linehl = "Visual", + numhl = "DiagnosticSignWarn", + }, + log = { + level = "info", + }, + ui = { + auto_open = true, + notify = { + threshold = vim.log.levels.INFO, + }, + config = { + icons = { expanded = "", collapsed = "", circular = "" }, + mappings = { + -- Use a table to apply multiple mappings + expand = { "<CR>", "<2-LeftMouse>" }, + open = "o", + remove = "d", + edit = "e", + repl = "r", + toggle = "t", + }, + -- Use this to override mappings for specific elements + element_mappings = {}, + expand_lines = true, + layouts = { + { + elements = { + { id = "scopes", size = 0.33 }, + { id = "breakpoints", size = 0.17 }, + { id = "stacks", size = 0.25 }, + { id = "watches", size = 0.25 }, + }, + size = 0.33, + position = "right", + }, + { + elements = { + { id = "repl", size = 0.45 }, + { id = "console", size = 0.55 }, + }, + size = 0.27, + position = "bottom", + }, + }, + controls = { + enabled = true, + -- Display controls in this element + element = "repl", + icons = { + pause = "", + play = "", + step_into = "", + step_over = "", + step_out = "", + step_back = "", + run_last = "", + terminate = "", + }, + }, + floating = { + max_height = 0.9, + max_width = 0.5, -- Floats will be treated as percentage of your screen. + border = "rounded", + mappings = { + close = { "q", "<Esc>" }, + }, + }, + windows = { indent = 1 }, + render = { + max_type_length = nil, -- Can be integer or nil. + max_value_lines = 100, -- Can be integer or nil. + }, + }, + }, + } +end + +M.setup = function() + local status_ok, dap = pcall(require, "dap") + if not status_ok then + return + end + + if lvim.use_icons then + vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) + vim.fn.sign_define("DapBreakpointRejected", lvim.builtin.dap.breakpoint_rejected) + vim.fn.sign_define("DapStopped", lvim.builtin.dap.stopped) + end + + dap.set_log_level(lvim.builtin.dap.log.level) + + if lvim.builtin.dap.on_config_done then + lvim.builtin.dap.on_config_done(dap) + end +end + +M.setup_ui = function() + local status_ok, dap = pcall(require, "dap") + if not status_ok then + return + end + local dapui = require "dapui" + dapui.setup(lvim.builtin.dap.ui.config) + + if lvim.builtin.dap.ui.auto_open then + dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open() + end + -- dap.listeners.before.event_terminated["dapui_config"] = function() + -- dapui.close() + -- end + -- dap.listeners.before.event_exited["dapui_config"] = function() + -- dapui.close() + -- end + end + + local Log = require "lvim.core.log" + + -- until rcarriga/nvim-dap-ui#164 is fixed + local function notify_handler(msg, level, opts) + if level >= lvim.builtin.dap.ui.notify.threshold then + return vim.notify(msg, level, opts) + end + + opts = vim.tbl_extend("keep", opts or {}, { + title = "dap-ui", + icon = "", + on_open = function(win) + vim.api.nvim_set_option_value("filetype", "markdown", { buf = vim.api.nvim_win_get_buf(win) }) + end, + }) + + -- vim_log_level can be omitted + if level == nil then + level = Log.levels["INFO"] + elseif type(level) == "string" then + level = Log.levels[(level):upper()] or Log.levels["INFO"] + else + -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5 + level = level + 1 + end + + msg = string.format("%s: %s", opts.title, msg) + Log:add_entry(level, msg) + end + + local dapui_ok, _ = xpcall(function() + require("dapui.util").notify = notify_handler + end, debug.traceback) + if not dapui_ok then + Log:debug "Unable to override dap-ui logging level" + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/gitsigns.lua b/mac/.config/LunarVim/lua/lvim/core/gitsigns.lua new file mode 100644 index 0000000..1c8619c --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/gitsigns.lua @@ -0,0 +1,83 @@ +local M = {} + +M.config = function() + lvim.builtin.gitsigns = { + active = true, + on_config_done = nil, + opts = { + signs = { + add = { + hl = "GitSignsAdd", + text = lvim.icons.ui.BoldLineLeft, + numhl = "GitSignsAddNr", + linehl = "GitSignsAddLn", + }, + change = { + hl = "GitSignsChange", + text = lvim.icons.ui.BoldLineLeft, + numhl = "GitSignsChangeNr", + linehl = "GitSignsChangeLn", + }, + delete = { + hl = "GitSignsDelete", + text = lvim.icons.ui.Triangle, + numhl = "GitSignsDeleteNr", + linehl = "GitSignsDeleteLn", + }, + topdelete = { + hl = "GitSignsDelete", + text = lvim.icons.ui.Triangle, + numhl = "GitSignsDeleteNr", + linehl = "GitSignsDeleteLn", + }, + changedelete = { + hl = "GitSignsChange", + text = lvim.icons.ui.BoldLineLeft, + numhl = "GitSignsChangeNr", + linehl = "GitSignsChangeLn", + }, + }, + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + watch_gitdir = { + interval = 1000, + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter = "<author>, <author_time:%Y-%m-%d> - <summary>", + sign_priority = 6, + status_formatter = nil, -- Use default + update_debounce = 200, + max_file_length = 40000, + preview_config = { + -- Options passed to nvim_open_win + border = "rounded", + style = "minimal", + relative = "cursor", + row = 0, + col = 1, + }, + yadm = { enable = false }, + }, + } +end + +M.setup = function() + local gitsigns = reload "gitsigns" + + gitsigns.setup(lvim.builtin.gitsigns.opts) + if lvim.builtin.gitsigns.on_config_done then + lvim.builtin.gitsigns.on_config_done(gitsigns) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/illuminate.lua b/mac/.config/LunarVim/lua/lvim/core/illuminate.lua new file mode 100644 index 0000000..7264710 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/illuminate.lua @@ -0,0 +1,72 @@ +local M = {} + +M.config = function() + lvim.builtin.illuminate = { + active = true, + on_config_done = nil, + options = { + -- providers: provider used to get references in the buffer, ordered by priority + providers = { + "lsp", + "treesitter", + "regex", + }, + -- delay: delay in milliseconds + delay = 120, + -- filetype_overrides: filetype specific overrides. + -- The keys are strings to represent the filetype while the values are tables that + -- supports the same keys passed to .configure except for filetypes_denylist and filetypes_allowlist + filetype_overrides = {}, + -- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist + filetypes_denylist = { + "dirvish", + "fugitive", + "alpha", + "NvimTree", + "lazy", + "neogitstatus", + "Trouble", + "lir", + "Outline", + "spectre_panel", + "toggleterm", + "DressingSelect", + "TelescopePrompt", + }, + -- filetypes_allowlist: filetypes to illuminate, this is overridden by filetypes_denylist + filetypes_allowlist = {}, + -- modes_denylist: modes to not illuminate, this overrides modes_allowlist + modes_denylist = {}, + -- modes_allowlist: modes to illuminate, this is overridden by modes_denylist + modes_allowlist = {}, + -- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist + -- Only applies to the 'regex' provider + -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') + providers_regex_syntax_denylist = {}, + -- providers_regex_syntax_allowlist: syntax to illuminate, this is overridden by providers_regex_syntax_denylist + -- Only applies to the 'regex' provider + -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') + providers_regex_syntax_allowlist = {}, + -- under_cursor: whether or not to illuminate under the cursor + under_cursor = true, + }, + } +end + +M.setup = function() + local status_ok, illuminate = pcall(require, "illuminate") + if not status_ok then + return + end + + local config_ok, _ = pcall(illuminate.configure, lvim.builtin.illuminate.options) + if not config_ok then + return + end + + if lvim.builtin.illuminate.on_config_done then + lvim.builtin.illuminate.on_config_done() + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/indentlines.lua b/mac/.config/LunarVim/lua/lvim/core/indentlines.lua new file mode 100644 index 0000000..ad82753 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/indentlines.lua @@ -0,0 +1,43 @@ +local M = {} + +M.config = function() + lvim.builtin.indentlines = { + active = true, + on_config_done = nil, + options = { + enabled = true, + buftype_exclude = { "terminal", "nofile" }, + filetype_exclude = { + "help", + "startify", + "dashboard", + "lazy", + "neogitstatus", + "NvimTree", + "Trouble", + "text", + }, + char = lvim.icons.ui.LineLeft, + context_char = lvim.icons.ui.LineLeft, + show_trailing_blankline_indent = false, + show_first_indent_level = true, + use_treesitter = true, + show_current_context = true, + }, + } +end + +M.setup = function() + local status_ok, indent_blankline = pcall(require, "indent_blankline") + if not status_ok then + return + end + + indent_blankline.setup(lvim.builtin.indentlines.options) + + if lvim.builtin.indentlines.on_config_done then + lvim.builtin.indentlines.on_config_done() + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/info.lua b/mac/.config/LunarVim/lua/lvim/core/info.lua new file mode 100644 index 0000000..c12edc3 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/info.lua @@ -0,0 +1,222 @@ +local M = { + banner = { + "", + [[ __ _ ___ ]], + [[ / / __ ______ ____ _____| | / (_)___ ___ ]], + [[ / / / / / / __ \/ __ `/ ___/ | / / / __ `__ \]], + [[ / /___/ /_/ / / / / /_/ / / | |/ / / / / / / /]], + [[/_____/\__,_/_/ /_/\__,_/_/ |___/_/_/ /_/ /_/ ]], + }, +} + +local fmt = string.format +local text = require "lvim.interface.text" +local lsp_utils = require "lvim.lsp.utils" + +local function str_list(list) + return #list == 1 and list[1] or fmt("[%s]", table.concat(list, ", ")) +end + +local function make_formatters_info(ft) + local null_formatters = require "lvim.lsp.null-ls.formatters" + local registered_formatters = null_formatters.list_registered(ft) + local supported_formatters = null_formatters.list_supported(ft) + local section = { + "Formatters info", + fmt( + "* Active: %s%s", + table.concat(registered_formatters, " " .. lvim.icons.ui.BoxChecked .. " , "), + vim.tbl_count(registered_formatters) > 0 and " " .. lvim.icons.ui.BoxChecked .. " " or "" + ), + fmt("* Supported: %s", str_list(supported_formatters)), + } + + return section +end + +local function make_code_actions_info(ft) + local null_actions = require "lvim.lsp.null-ls.code_actions" + local registered_actions = null_actions.list_registered(ft) + local section = { + "Code actions info", + fmt( + "* Active: %s%s", + table.concat(registered_actions, " " .. lvim.icons.ui.BoxChecked .. " , "), + vim.tbl_count(registered_actions) > 0 and " " .. lvim.icons.ui.BoxChecked .. " " or "" + ), + } + + return section +end + +local function make_linters_info(ft) + local null_linters = require "lvim.lsp.null-ls.linters" + local supported_linters = null_linters.list_supported(ft) + local registered_linters = null_linters.list_registered(ft) + local section = { + "Linters info", + fmt( + "* Active: %s%s", + table.concat(registered_linters, " " .. lvim.icons.ui.BoxChecked .. " , "), + vim.tbl_count(registered_linters) > 0 and " " .. lvim.icons.ui.BoxChecked .. " " or "" + ), + fmt("* Supported: %s", str_list(supported_linters)), + } + + return section +end + +local function tbl_set_highlight(terms, highlight_group) + for _, v in pairs(terms) do + vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. "[ ,│']\")") + vim.cmd('let m=matchadd("' .. highlight_group .. '", ", ' .. v .. '")') + end +end + +local function make_client_info(client) + if client.name == "null-ls" then + return + end + local client_enabled_caps = lsp_utils.get_client_capabilities(client.id) + local name = client.name + local id = client.id + local filetypes = lsp_utils.get_supported_filetypes(name) + local attached_buffers_list = str_list(vim.lsp.get_buffers_by_client_id(client.id)) + local client_info = { + fmt("* name: %s", name), + fmt("* id: %s", tostring(id)), + fmt("* supported filetype(s): %s", str_list(filetypes)), + fmt("* attached buffers: %s", tostring(attached_buffers_list)), + fmt("* root_dir pattern: %s", tostring(attached_buffers_list)), + } + if not vim.tbl_isempty(client_enabled_caps) then + local caps_text = "* capabilities: " + local caps_text_len = caps_text:len() + local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") + enabled_caps = text.shift_right(enabled_caps, caps_text_len) + enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) + vim.list_extend(client_info, enabled_caps) + end + + return client_info +end + +local function make_auto_lsp_info(ft) + local skipped_filetypes = lvim.lsp.automatic_configuration.skipped_filetypes + local skipped_servers = lvim.lsp.automatic_configuration.skipped_servers + local info_lines = { "Automatic LSP info" } + + if vim.tbl_contains(skipped_filetypes, ft) then + vim.list_extend(info_lines, { "* Status: disabled for " .. ft }) + return info_lines + end + + local supported = lsp_utils.get_supported_servers(ft) + local skipped = vim.tbl_filter(function(name) + return vim.tbl_contains(supported, name) + end, skipped_servers) + + if #skipped == 0 then + return { "" } + end + + vim.list_extend(info_lines, { fmt("* Skipped servers: %s", str_list(skipped)) }) + + return info_lines +end + +function M.toggle_popup(ft) + local clients = vim.lsp.get_clients() + local client_names = {} + local bufnr = vim.api.nvim_get_current_buf() + local ts_active_buffers = vim.tbl_keys(vim.treesitter.highlighter.active) + local is_treesitter_active = function() + local status = "inactive" + if vim.tbl_contains(ts_active_buffers, bufnr) then + status = "active" + end + return status + end + local header = { + "Buffer info", + fmt("* filetype: %s", ft), + fmt("* bufnr: %s", bufnr), + fmt("* treesitter status: %s", is_treesitter_active()), + } + + local lsp_info = { + "Active client(s)", + } + + for _, client in pairs(clients) do + local client_info = make_client_info(client) + if client_info then + vim.list_extend(lsp_info, client_info) + end + table.insert(client_names, client.name) + end + + local auto_lsp_info = make_auto_lsp_info(ft) + + local formatters_info = make_formatters_info(ft) + + local linters_info = make_linters_info(ft) + + local code_actions_info = make_code_actions_info(ft) + + local content_provider = function(popup) + local content = {} + + for _, section in ipairs { + M.banner, + { "" }, + { "" }, + header, + { "" }, + lsp_info, + { "" }, + auto_lsp_info, + { "" }, + formatters_info, + { "" }, + linters_info, + { "" }, + code_actions_info, + } do + vim.list_extend(content, section) + end + + return text.align_left(popup, content, 0.5) + end + + local function set_syntax_hl() + vim.cmd [[highlight LvimInfoIdentifier gui=bold]] + vim.cmd [[highlight link LvimInfoHeader Type]] + vim.fn.matchadd("LvimInfoHeader", "Buffer info") + vim.fn.matchadd("LvimInfoHeader", "Active client(s)") + vim.fn.matchadd("LvimInfoHeader", fmt("Overridden %s server(s)", ft)) + vim.fn.matchadd("LvimInfoHeader", "Formatters info") + vim.fn.matchadd("LvimInfoHeader", "Linters info") + vim.fn.matchadd("LvimInfoHeader", "Code actions info") + vim.fn.matchadd("LvimInfoHeader", "Automatic LSP info") + vim.fn.matchadd("LvimInfoIdentifier", " " .. ft .. "$") + vim.fn.matchadd("string", "true") + vim.fn.matchadd("string", "active") + vim.fn.matchadd("string", lvim.icons.ui.BoxChecked) + vim.fn.matchadd("boolean", "inactive") + vim.fn.matchadd("error", "false") + tbl_set_highlight(require("lvim.lsp.null-ls.formatters").list_registered(ft), "LvimInfoIdentifier") + tbl_set_highlight(require("lvim.lsp.null-ls.linters").list_registered(ft), "LvimInfoIdentifier") + tbl_set_highlight(require("lvim.lsp.null-ls.code_actions").list_registered(ft), "LvimInfoIdentifier") + end + + local Popup = require("lvim.interface.popup"):new { + win_opts = { number = false }, + buf_opts = { modifiable = false, filetype = "lspinfo" }, + } + Popup:display(content_provider) + set_syntax_hl() + + return Popup +end +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/lir.lua b/mac/.config/LunarVim/lua/lvim/core/lir.lua new file mode 100644 index 0000000..a8ed42c --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/lir.lua @@ -0,0 +1,120 @@ +local M = {} + +M.config = function() + local utils = require "lvim.utils.modules" + local actions = utils.require_on_exported_call "lir.actions" + local clipboard_actions = utils.require_on_exported_call "lir.clipboard.actions" + + lvim.builtin.lir = { + active = true, + on_config_done = nil, + icon = "", + show_hidden_files = false, + ignore = {}, -- { ".DS_Store" "node_modules" } etc. + devicons = { + enable = true, + highlight_dirname = true, + }, + mappings = { + ["l"] = actions.edit, + ["<CR>"] = actions.edit, + ["<C-s>"] = actions.split, + ["v"] = actions.vsplit, + ["<C-t>"] = actions.tabedit, + + ["h"] = actions.up, + ["q"] = actions.quit, + + ["A"] = actions.mkdir, + ["a"] = actions.newfile, + ["r"] = actions.rename, + ["@"] = actions.cd, + ["Y"] = actions.yank_path, + ["i"] = actions.toggle_show_hidden, + ["d"] = actions.delete, + + ["J"] = function() + require("lir.mark.actions").toggle_mark() + vim.cmd "normal! j" + end, + ["c"] = clipboard_actions.copy, + ["x"] = clipboard_actions.cut, + ["p"] = clipboard_actions.paste, + }, + float = { + winblend = 0, + curdir_window = { + enable = false, + highlight_dirname = true, + }, + + -- You can define a function that returns a table to be passed as the third + -- argument of nvim_open_win(). + win_opts = function() + local width = math.floor(vim.o.columns * 0.7) + local height = math.floor(vim.o.lines * 0.7) + return { + border = "rounded", + width = width, + height = height, + } + end, + }, + hide_cursor = false, + on_init = function() + -- use visual mode + vim.api.nvim_buf_set_keymap( + 0, + "x", + "J", + ':<C-u>lua require"lir.mark.actions".toggle_mark("v")<CR>', + { noremap = true, silent = true } + ) + end, + } +end + +function M.icon_setup() + local devicons_ok, devicons = pcall(require, "nvim-web-devicons") + if not devicons_ok then + return + end + + local function get_hl_by_name(name) + local ret = vim.api.nvim_get_hl(0, { name = name.group }) + return string.format("#%06x", ret[name.property]) + end + + local found, icon_color = pcall(get_hl_by_name, { group = "NvimTreeFolderIcon", property = "fg" }) + if not found then + icon_color = "#42A5F5" + end + + devicons.set_icon { + lir_folder_icon = { + icon = lvim.builtin.lir.icon, + color = icon_color, + name = "LirFolderNode", + }, + } +end + +function M.setup() + local status_ok, lir = pcall(require, "lir") + if not status_ok then + return + end + + if not lvim.use_icons then + lvim.builtin.lir.devicons.enable = false + end + + lir.setup(lvim.builtin.lir) + M.icon_setup() + + if lvim.builtin.lir.on_config_done then + lvim.builtin.lir.on_config_done(lir) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/log.lua b/mac/.config/LunarVim/lua/lvim/core/log.lua new file mode 100644 index 0000000..ba92462 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/log.lua @@ -0,0 +1,203 @@ +local Log = {} + +Log.levels = { + TRACE = 1, + DEBUG = 2, + INFO = 3, + WARN = 4, + ERROR = 5, +} + +local notify_opts = {} +local log_notify_as_notification = false + +function Log:set_level(level) + if + not pcall(function() + local logger_ok, logger = pcall(function() + return require("structlog").get_logger "lvim" + end) + local log_level = Log.levels[level:upper()] + if logger_ok and logger and log_level then + for _, pipeline in ipairs(logger.pipelines) do + pipeline.level = log_level + end + end + end) + then + vim.notify "structlog version too old, run `:Lazy sync`" + end +end + +function Log:init() + local status_ok, structlog = pcall(require, "structlog") + if not status_ok then + return nil + end + + local log_level = Log.levels[(lvim.log.level):upper() or "WARN"] + structlog.configure { + lvim = { + pipelines = { + { + level = log_level, + processors = { + structlog.processors.StackWriter({ "line", "file" }, { max_parents = 0, stack_level = 2 }), + structlog.processors.Timestamper "%H:%M:%S", + }, + formatter = structlog.formatters.FormatColorizer( + "%s [%-5s] %s: %-30s", + { "timestamp", "level", "logger_name", "msg" }, + { level = structlog.formatters.FormatColorizer.color_level() } + ), + sink = structlog.sinks.Console(false), -- async=false + }, + { + level = log_level, + processors = { + structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3, stack_level = 2 }), + structlog.processors.Timestamper "%F %H:%M:%S", + }, + formatter = structlog.formatters.Format( + "%s [%-5s] %s: %-30s", + { "timestamp", "level", "logger_name", "msg" } + ), + sink = structlog.sinks.File(self:get_path()), + }, + }, + }, + } + + local logger = structlog.get_logger "lvim" + + -- Overwrite `vim.notify` to use the logger + if lvim.log.override_notify then + vim.notify = function(msg, vim_log_level, opts) + notify_opts = opts or {} + + -- vim_log_level can be omitted + if vim_log_level == nil then + vim_log_level = Log.levels["INFO"] + elseif type(vim_log_level) == "string" then + vim_log_level = Log.levels[(vim_log_level):upper()] or Log.levels["INFO"] + else + -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5 + vim_log_level = vim_log_level + 1 + end + + self:add_entry(vim_log_level, msg) + end + end + + return logger +end + +--- Configure the sink in charge of logging notifications +---@param nvim_notify table The nvim-notify instance +function Log:configure_notifications(nvim_notify) + local status_ok, structlog = pcall(require, "structlog") + if not status_ok then + return + end + + local function log_writer(log) + local opts = { title = log.logger_name } + opts = vim.tbl_deep_extend("force", opts, notify_opts) + notify_opts = {} + + if log_notify_as_notification then + nvim_notify(log.msg, log.level, opts) + end + end + + local notif_pipeline = structlog.Pipeline( + structlog.level.INFO, + {}, + structlog.formatters.Format("%s", { "msg" }, { blacklist_all = true }), + structlog.sinks.Adapter(log_writer) + ) + self.__handle:add_pipeline(notif_pipeline) +end + +--- Adds a log entry using Plenary.log +---@param level integer [same as vim.log.levels] +---@param msg any +---@param event any +function Log:add_entry(level, msg, event) + if + not pcall(function() + local logger = self:get_logger() + if not logger then + return + end + logger:log(level, vim.inspect(msg), event) + end) + then + vim.notify "structlog version too old, run `:Lazy sync`" + end +end + +---Retrieves the handle of the logger object +---@return table|nil logger handle if found +function Log:get_logger() + local logger_ok, logger = pcall(function() + return require("structlog").get_logger "lvim" + end) + if logger_ok and logger then + return logger + end + + logger = self:init() + + if not logger then + return + end + + self.__handle = logger + return logger +end + +---Retrieves the path of the logfile +---@return string path of the logfile +function Log:get_path() + return string.format("%s/%s.log", get_cache_dir(), "lvim") +end + +---Add a log entry at TRACE level +---@param msg any +---@param event any +function Log:trace(msg, event) + self:add_entry(self.levels.TRACE, msg, event) +end + +---Add a log entry at DEBUG level +---@param msg any +---@param event any +function Log:debug(msg, event) + self:add_entry(self.levels.DEBUG, msg, event) +end + +---Add a log entry at INFO level +---@param msg any +---@param event any +function Log:info(msg, event) + self:add_entry(self.levels.INFO, msg, event) +end + +---Add a log entry at WARN level +---@param msg any +---@param event any +function Log:warn(msg, event) + self:add_entry(self.levels.WARN, msg, event) +end + +---Add a log entry at ERROR level +---@param msg any +---@param event any +function Log:error(msg, event) + self:add_entry(self.levels.ERROR, msg, event) +end + +setmetatable({}, Log) + +return Log diff --git a/mac/.config/LunarVim/lua/lvim/core/lualine/colors.lua b/mac/.config/LunarVim/lua/lvim/core/lualine/colors.lua new file mode 100644 index 0000000..4984cd1 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/lualine/colors.lua @@ -0,0 +1,16 @@ +local colors = { + bg = "#202328", + fg = "#bbc2cf", + yellow = "#ECBE7B", + cyan = "#008080", + darkblue = "#081633", + green = "#98be65", + orange = "#FF8800", + violet = "#a9a1e1", + magenta = "#c678dd", + purple = "#c678dd", + blue = "#51afef", + red = "#ec5f67", +} + +return colors diff --git a/mac/.config/LunarVim/lua/lvim/core/lualine/components.lua b/mac/.config/LunarVim/lua/lvim/core/lualine/components.lua new file mode 100644 index 0000000..afcce6b --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/lualine/components.lua @@ -0,0 +1,174 @@ +local conditions = require "lvim.core.lualine.conditions" +local colors = require "lvim.core.lualine.colors" + +local function diff_source() + local gitsigns = vim.b.gitsigns_status_dict + if gitsigns then + return { + added = gitsigns.added, + modified = gitsigns.changed, + removed = gitsigns.removed, + } + end +end + +local branch = lvim.icons.git.Branch + +if lvim.colorscheme == "lunar" then + branch = "%#SLGitIcon#" .. lvim.icons.git.Branch .. "%*" .. "%#SLBranchName#" +end + +return { + mode = { + function() + return " " .. lvim.icons.ui.Target .. " " + end, + padding = { left = 0, right = 0 }, + color = {}, + cond = nil, + }, + branch = { + "b:gitsigns_head", + icon = branch, + color = { gui = "bold" }, + }, + filename = { + "filename", + color = {}, + cond = nil, + }, + diff = { + "diff", + source = diff_source, + symbols = { + added = lvim.icons.git.LineAdded .. " ", + modified = lvim.icons.git.LineModified .. " ", + removed = lvim.icons.git.LineRemoved .. " ", + }, + padding = { left = 2, right = 1 }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.yellow }, + removed = { fg = colors.red }, + }, + cond = nil, + }, + python_env = { + function() + local utils = require "lvim.core.lualine.utils" + if vim.bo.filetype == "python" then + local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV" + if venv then + local icons = require "nvim-web-devicons" + local py_icon, _ = icons.get_icon ".py" + return string.format(" " .. py_icon .. " (%s)", utils.env_cleanup(venv)) + end + end + return "" + end, + color = { fg = colors.green }, + cond = conditions.hide_in_width, + }, + diagnostics = { + "diagnostics", + sources = { "nvim_diagnostic" }, + symbols = { + error = lvim.icons.diagnostics.BoldError .. " ", + warn = lvim.icons.diagnostics.BoldWarning .. " ", + info = lvim.icons.diagnostics.BoldInformation .. " ", + hint = lvim.icons.diagnostics.BoldHint .. " ", + }, + -- cond = conditions.hide_in_width, + }, + treesitter = { + function() + return lvim.icons.ui.Tree + end, + color = function() + local buf = vim.api.nvim_get_current_buf() + local ts = vim.treesitter.highlighter.active[buf] + return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red } + end, + cond = conditions.hide_in_width, + }, + lsp = { + function() + local buf_clients = vim.lsp.get_clients { bufnr = 0 } + if #buf_clients == 0 then + return "LSP Inactive" + end + + local buf_ft = vim.bo.filetype + local buf_client_names = {} + local copilot_active = false + + -- add client + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" and client.name ~= "copilot" then + table.insert(buf_client_names, client.name) + end + + if client.name == "copilot" then + copilot_active = true + end + end + + -- add formatter + local formatters = require "lvim.lsp.null-ls.formatters" + local supported_formatters = formatters.list_registered(buf_ft) + vim.list_extend(buf_client_names, supported_formatters) + + -- add linter + local linters = require "lvim.lsp.null-ls.linters" + local supported_linters = linters.list_registered(buf_ft) + vim.list_extend(buf_client_names, supported_linters) + + local unique_client_names = table.concat(buf_client_names, ", ") + local language_servers = string.format("[%s]", unique_client_names) + + if copilot_active then + language_servers = language_servers .. "%#SLCopilot#" .. " " .. lvim.icons.git.Octoface .. "%*" + end + + return language_servers + end, + color = { gui = "bold" }, + cond = conditions.hide_in_width, + }, + location = { "location" }, + progress = { + "progress", + fmt = function() + return "%P/%L" + end, + color = {}, + }, + + spaces = { + function() + local shiftwidth = vim.api.nvim_get_option_value("shiftwidth", { buf = 0 }) + return lvim.icons.ui.Tab .. " " .. shiftwidth + end, + padding = 1, + }, + encoding = { + "o:encoding", + fmt = string.upper, + color = {}, + cond = conditions.hide_in_width, + }, + filetype = { "filetype", cond = nil, padding = { left = 1, right = 1 } }, + scrollbar = { + function() + local current_line = vim.fn.line "." + local total_lines = vim.fn.line "$" + local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" } + local line_ratio = current_line / total_lines + local index = math.ceil(line_ratio * #chars) + return chars[index] + end, + padding = { left = 0, right = 0 }, + color = "SLProgress", + cond = nil, + }, +} diff --git a/mac/.config/LunarVim/lua/lvim/core/lualine/conditions.lua b/mac/.config/LunarVim/lua/lvim/core/lualine/conditions.lua new file mode 100644 index 0000000..42d52a8 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/lualine/conditions.lua @@ -0,0 +1,17 @@ +local window_width_limit = 100 + +local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand "%:t") ~= 1 + end, + hide_in_width = function() + return vim.o.columns > window_width_limit + end, + -- check_git_workspace = function() + -- local filepath = vim.fn.expand "%:p:h" + -- local gitdir = vim.fn.finddir(".git", filepath .. ";") + -- return gitdir and #gitdir > 0 and #gitdir < #filepath + -- end, +} + +return conditions diff --git a/mac/.config/LunarVim/lua/lvim/core/lualine/init.lua b/mac/.config/LunarVim/lua/lvim/core/lualine/init.lua new file mode 100644 index 0000000..fa4cf82 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/lualine/init.lua @@ -0,0 +1,57 @@ +local M = {} +M.config = function() + lvim.builtin.lualine = { + active = true, + style = "lvim", + options = { + icons_enabled = nil, + component_separators = nil, + section_separators = nil, + theme = nil, + disabled_filetypes = { statusline = { "alpha" } }, + globalstatus = true, + }, + sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + inactive_sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + tabline = nil, + extensions = nil, + on_config_done = nil, + } +end + +M.setup = function() + if #vim.api.nvim_list_uis() == 0 then + local Log = require "lvim.core.log" + Log:debug "headless mode detected, skipping running setup for lualine" + return + end + + local status_ok, lualine = pcall(require, "lualine") + if not status_ok then + return + end + + require("lvim.core.lualine.styles").update() + + lualine.setup(lvim.builtin.lualine) + + if lvim.builtin.lualine.on_config_done then + lvim.builtin.lualine.on_config_done(lualine) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/lualine/styles.lua b/mac/.config/LunarVim/lua/lvim/core/lualine/styles.lua new file mode 100644 index 0000000..81dbbab --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/lualine/styles.lua @@ -0,0 +1,165 @@ +local M = {} +local components = require "lvim.core.lualine.components" + +local styles = { + lvim = nil, + default = nil, + none = nil, +} + +styles.none = { + style = "none", + options = { + theme = "auto", + globalstatus = true, + icons_enabled = lvim.use_icons, + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = {}, + }, + sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.default = { + style = "default", + options = { + theme = "auto", + globalstatus = true, + icons_enabled = lvim.use_icons, + component_separators = { + left = lvim.icons.ui.DividerRight, + right = lvim.icons.ui.DividerLeft, + }, + section_separators = { + left = lvim.icons.ui.BoldDividerRight, + right = lvim.icons.ui.BoldDividerLeft, + }, + disabled_filetypes = {}, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.lvim = { + style = "lvim", + options = { + theme = "auto", + globalstatus = true, + icons_enabled = lvim.use_icons, + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = { "alpha" }, + }, + sections = { + lualine_a = { + components.mode, + }, + lualine_b = { + components.branch, + }, + lualine_c = { + components.diff, + components.python_env, + }, + lualine_x = { + components.diagnostics, + components.lsp, + components.spaces, + components.filetype, + }, + lualine_y = { components.location }, + lualine_z = { + components.progress, + }, + }, + inactive_sections = { + lualine_a = { + components.mode, + }, + lualine_b = { + components.branch, + }, + lualine_c = { + components.diff, + components.python_env, + }, + lualine_x = { + components.diagnostics, + components.lsp, + components.spaces, + components.filetype, + }, + lualine_y = { components.location }, + lualine_z = { + components.progress, + }, + }, + tabline = {}, + extensions = {}, +} + +function M.get_style(style) + local style_keys = vim.tbl_keys(styles) + if not vim.tbl_contains(style_keys, style) then + local Log = require "lvim.core.log" + Log:error( + "Invalid lualine style" + .. string.format('"%s"', style) + .. "options are: " + .. string.format('"%s"', table.concat(style_keys, '", "')) + ) + Log:debug '"lvim" style is applied.' + style = "lvim" + end + + return vim.deepcopy(styles[style]) +end + +function M.update() + local style = M.get_style(lvim.builtin.lualine.style) + + lvim.builtin.lualine = vim.tbl_deep_extend("keep", lvim.builtin.lualine, style) + + local color_template = vim.g.colors_name or lvim.colorscheme + local theme_supported, template = pcall(function() + require("lualine.utils.loader").load_theme(color_template) + end) + if theme_supported and template then + lvim.builtin.lualine.options.theme = color_template + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/lualine/utils.lua b/mac/.config/LunarVim/lua/lvim/core/lualine/utils.lua new file mode 100644 index 0000000..3fd3c2d --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/lualine/utils.lua @@ -0,0 +1,14 @@ +local M = {} + +function M.env_cleanup(venv) + if string.find(venv, "/") then + local final_venv = venv + for w in venv:gmatch "([^/]+)" do + final_venv = w + end + venv = final_venv + end + return venv +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/mason.lua b/mac/.config/LunarVim/lua/lvim/core/mason.lua new file mode 100644 index 0000000..a8816a3 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/mason.lua @@ -0,0 +1,120 @@ +local M = {} + +local join_paths = require("lvim.utils").join_paths + +function M.config() + lvim.builtin.mason = { + ui = { + check_outdated_packages_on_open = true, + width = 0.8, + height = 0.9, + border = "rounded", + keymaps = { + toggle_package_expand = "<CR>", + install_package = "i", + update_package = "u", + check_package_version = "c", + update_all_packages = "U", + check_outdated_packages = "C", + uninstall_package = "X", + cancel_installation = "<C-c>", + apply_language_filter = "<C-f>", + }, + }, + + icons = { + package_installed = "◍", + package_pending = "◍", + package_uninstalled = "◍", + }, + + -- NOTE: should be available in $PATH + install_root_dir = join_paths(vim.fn.stdpath "data", "mason"), + + -- NOTE: already handled in the bootstrap stage + PATH = "skip", + + pip = { + upgrade_pip = false, + -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior + -- and is not recommended. + -- + -- Example: { "--proxy", "https://proxyserver" } + install_args = {}, + }, + + -- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when + -- debugging issues with package installations. + log_level = vim.log.levels.INFO, + + -- Limit for the maximum amount of packages to be installed at the same time. Once this limit is reached, any further + -- packages that are requested to be installed will be put in a queue. + max_concurrent_installers = 4, + + -- [Advanced setting] + -- The registries to source packages from. Accepts multiple entries. Should a package with the same name exist in + -- multiple registries, the registry listed first will be used. + registries = { + "lua:mason-registry.index", + "github:mason-org/mason-registry", + }, + + -- The provider implementations to use for resolving supplementary package metadata (e.g., all available versions). + -- Accepts multiple entries, where later entries will be used as fallback should prior providers fail. + providers = { + "mason.providers.registry-api", + "mason.providers.client", + }, + + github = { + -- The template URL to use when downloading assets from GitHub. + -- The placeholders are the following (in order): + -- 1. The repository (e.g. "rust-lang/rust-analyzer") + -- 2. The release version (e.g. "v0.3.0") + -- 3. The asset name (e.g. "rust-analyzer-v0.3.0-x86_64-unknown-linux-gnu.tar.gz") + download_url_template = "https://github.com/%s/releases/download/%s/%s", + }, + + on_config_done = nil, + } +end + +function M.get_prefix() + local default_prefix = join_paths(vim.fn.stdpath "data", "mason") + return vim.tbl_get(lvim.builtin, "mason", "install_root_dir") or default_prefix +end + +---@param append boolean|nil whether to append to prepend to PATH +local function add_to_path(append) + local p = join_paths(M.get_prefix(), "bin") + if vim.env.PATH:match(p) then + return + end + local string_separator = vim.loop.os_uname().version:match "Windows" and ";" or ":" + if append then + vim.env.PATH = vim.env.PATH .. string_separator .. p + else + vim.env.PATH = p .. string_separator .. vim.env.PATH + end +end + +function M.bootstrap() + add_to_path() +end + +function M.setup() + local status_ok, mason = pcall(require, "mason") + if not status_ok then + return + end + + add_to_path(lvim.builtin.mason.PATH == "append") + + mason.setup(lvim.builtin.mason) + + if lvim.builtin.mason.on_config_done then + lvim.builtin.mason.on_config_done(mason) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/nvimtree.lua b/mac/.config/LunarVim/lua/lvim/core/nvimtree.lua new file mode 100644 index 0000000..d1aaff4 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/nvimtree.lua @@ -0,0 +1,344 @@ +local M = {} +local Log = require "lvim.core.log" + +function M.config() + lvim.builtin.nvimtree = { + active = true, + on_config_done = nil, + setup = { + experimental = {}, + auto_reload_on_write = false, + disable_netrw = false, + hijack_cursor = false, + hijack_netrw = true, + hijack_unnamed_buffer_when_opening = false, + sort = { + sorter = "name", + folders_first = true, + files_first = false, + }, + root_dirs = {}, + prefer_startup_root = false, + sync_root_with_cwd = true, + reload_on_bufenter = false, + respect_buf_cwd = false, + on_attach = "default", + select_prompts = false, + view = { + adaptive_size = false, + centralize_selection = true, + width = 30, + cursorline = true, + debounce_delay = 15, + side = "left", + preserve_window_proportions = false, + number = false, + relativenumber = false, + signcolumn = "yes", + float = { + enable = false, + quit_on_focus_loss = true, + open_win_config = { + relative = "editor", + border = "rounded", + width = 30, + height = 30, + row = 1, + col = 1, + }, + }, + }, + renderer = { + add_trailing = false, + group_empty = false, + highlight_git = "name", + highlight_opened_files = "none", + root_folder_label = ":t", + full_name = false, + indent_width = 2, + special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" }, + symlink_destination = true, + highlight_diagnostics = "none", + highlight_modified = "none", + highlight_bookmarks = "none", + highlight_clipboard = "name", + indent_markers = { + enable = false, + inline_arrows = true, + icons = { + corner = "└", + edge = "│", + item = "│", + bottom = "─", + none = " ", + }, + }, + icons = { + webdev_colors = lvim.use_icons, + + web_devicons = { + file = { + enable = lvim.use_icons, + color = lvim.use_icons, + }, + folder = { + enable = false, + color = lvim.use_icons, + }, + }, + git_placement = "before", + padding = " ", + symlink_arrow = " ➛ ", + modified_placement = "after", + diagnostics_placement = "signcolumn", + bookmarks_placement = "signcolumn", + show = { + file = lvim.use_icons, + folder = lvim.use_icons, + folder_arrow = lvim.use_icons, + git = lvim.use_icons, + modified = lvim.use_icons, + diagnostics = lvim.use_icons, + bookmarks = lvim.use_icons, + }, + glyphs = { + default = lvim.icons.ui.Text, + symlink = lvim.icons.ui.FileSymlink, + bookmark = lvim.icons.ui.BookMark, + modified = lvim.icons.ui.Circle, + folder = { + arrow_closed = lvim.icons.ui.TriangleShortArrowRight, + arrow_open = lvim.icons.ui.TriangleShortArrowDown, + default = lvim.icons.ui.Folder, + open = lvim.icons.ui.FolderOpen, + empty = lvim.icons.ui.EmptyFolder, + empty_open = lvim.icons.ui.EmptyFolderOpen, + symlink = lvim.icons.ui.FolderSymlink, + symlink_open = lvim.icons.ui.FolderOpen, + }, + git = { + unstaged = lvim.icons.git.FileUnstaged, + staged = lvim.icons.git.FileStaged, + unmerged = lvim.icons.git.FileUnmerged, + renamed = lvim.icons.git.FileRenamed, + untracked = lvim.icons.git.FileUntracked, + deleted = lvim.icons.git.FileDeleted, + ignored = lvim.icons.git.FileIgnored, + }, + }, + }, + }, + hijack_directories = { + enable = false, + auto_open = true, + }, + update_focused_file = { + enable = true, + update_root = { + enable = true, + ignore_list = {}, + }, + exclude = false, + }, + diagnostics = { + enable = lvim.use_icons, + show_on_dirs = false, + show_on_open_dirs = true, + debounce_delay = 50, + severity = { + min = vim.diagnostic.severity.HINT, + max = vim.diagnostic.severity.ERROR, + }, + icons = { + hint = lvim.icons.diagnostics.BoldHint, + info = lvim.icons.diagnostics.BoldInformation, + warning = lvim.icons.diagnostics.BoldWarning, + error = lvim.icons.diagnostics.BoldError, + }, + }, + filters = { + enable = true, + dotfiles = false, + git_clean = false, + git_ignored = false, + no_bookmark = false, + no_buffer = false, + custom = { "node_modules", "\\.cache" }, + exclude = {}, + }, + filesystem_watchers = { + enable = true, + debounce_delay = 50, + ignore_dirs = {}, + }, + git = { + enable = true, + show_on_dirs = true, + show_on_open_dirs = true, + disable_for_dirs = {}, + timeout = 400, + cygwin_support = false, + }, + actions = { + use_system_clipboard = true, + change_dir = { + enable = true, + global = false, + restrict_above_cwd = false, + }, + expand_all = { + max_folder_discovery = 300, + exclude = {}, + }, + file_popup = { + open_win_config = { + col = 1, + row = 1, + relative = "cursor", + border = "shadow", + style = "minimal", + }, + }, + open_file = { + quit_on_open = false, + eject = true, + resize_window = false, + window_picker = { + enable = true, + picker = "default", + chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", + exclude = { + filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" }, + buftype = { "nofile", "terminal", "help" }, + }, + }, + }, + remove_file = { + close_window = true, + }, + }, + trash = { + cmd = "gio trash", + }, + live_filter = { + prefix = "[FILTER]: ", + always_show_folders = true, + }, + tab = { + sync = { + open = false, + close = false, + ignore = {}, + }, + }, + notify = { + threshold = vim.log.levels.INFO, + absolute_path = true, + }, + ui = { + confirm = { + remove = true, + trash = true, + default_yes = false, + }, + }, + modified = { + enable = false, + show_on_dirs = true, + show_on_open_dirs = true, + }, + help = { + sort_by = "key", + }, + log = { + enable = false, + truncate = false, + types = { + all = false, + config = false, + copy_paste = false, + dev = false, + diagnostics = false, + git = false, + profile = false, + watcher = false, + }, + }, + system_open = { + cmd = nil, + args = {}, + }, + }, + } +end + +function M.start_telescope(telescope_mode) + local node = require("nvim-tree.lib").get_node_at_cursor() + local abspath = node.link_to or node.absolute_path + local is_folder = node.open ~= nil + local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h") + require("telescope.builtin")[telescope_mode] { + cwd = basedir, + } +end + +local function on_attach(bufnr) + local api = require "nvim-tree.api" + + local function telescope_find_files(_) + require("lvim.core.nvimtree").start_telescope "find_files" + end + + local function telescope_live_grep(_) + require("lvim.core.nvimtree").start_telescope "live_grep" + end + + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + api.config.mappings.default_on_attach(bufnr) + + local useful_keys = { + ["l"] = { api.node.open.edit, opts "Open" }, + ["o"] = { api.node.open.edit, opts "Open" }, + ["<CR>"] = { api.node.open.edit, opts "Open" }, + ["v"] = { api.node.open.vertical, opts "Open: Vertical Split" }, + ["h"] = { api.node.navigate.parent_close, opts "Close Directory" }, + ["C"] = { api.tree.change_root_to_node, opts "CD" }, + ["gtg"] = { telescope_live_grep, opts "Telescope Live Grep" }, + ["gtf"] = { telescope_find_files, opts "Telescope Find File" }, + } + + require("lvim.keymappings").load_mode("n", useful_keys) +end + +function M.setup() + local status_ok, nvim_tree = pcall(require, "nvim-tree") + + if not status_ok then + Log:error "Failed to load nvim-tree" + return + end + + -- Implicitly update nvim-tree when project module is active + if lvim.builtin.project.active then + lvim.builtin.nvimtree.setup.respect_buf_cwd = true + lvim.builtin.nvimtree.setup.update_cwd = true + lvim.builtin.nvimtree.setup.update_focused_file.enable = true + lvim.builtin.nvimtree.setup.update_focused_file.update_cwd = true + end + + -- Add useful keymaps + if lvim.builtin.nvimtree.setup.on_attach == "default" then + lvim.builtin.nvimtree.setup.on_attach = on_attach + end + + nvim_tree.setup(lvim.builtin.nvimtree.setup) + + if lvim.builtin.nvimtree.on_config_done then + lvim.builtin.nvimtree.on_config_done(nvim_tree) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/project.lua b/mac/.config/LunarVim/lua/lvim/core/project.lua new file mode 100644 index 0000000..17473c5 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/project.lua @@ -0,0 +1,67 @@ +local M = {} + +function M.config() + lvim.builtin.project = { + ---@usage set to false to disable project.nvim. + --- This is on by default since it's currently the expected behavior. + active = true, + + on_config_done = nil, + + ---@usage set to true to disable setting the current-woriking directory + --- Manual mode doesn't automatically change your root directory, so you have + --- the option to manually do so using `:ProjectRoot` command. + manual_mode = false, + + ---@usage Methods of detecting the root directory + --- Allowed values: **"lsp"** uses the native neovim lsp + --- **"pattern"** uses vim-rooter like glob pattern matching. Here + --- order matters: if one is not detected, the other is used as fallback. You + --- can also delete or rearangne the detection methods. + -- detection_methods = { "lsp", "pattern" }, -- NOTE: lsp detection will get annoying with multiple langs in one project + detection_methods = { "pattern" }, + + -- All the patterns used to detect root dir, when **"pattern"** is in + -- detection_methods + patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json", "pom.xml" }, + + -- Table of lsp clients to ignore by name + -- eg: { "efm", ... } + ignore_lsp = {}, + + -- Don't calculate root dir on specific directories + -- Ex: { "~/.cargo/*", ... } + exclude_dirs = {}, + + -- Show hidden files in telescope + show_hidden = false, + + -- When set to false, you will get a message when project.nvim changes your + -- directory. + silent_chdir = true, + + -- What scope to change the directory, valid options are + -- * global (default) + -- * tab + -- * win + scope_chdir = "global", + + ---@type string + ---@usage path to store the project history for use in telescope + datapath = get_cache_dir(), + } +end + +function M.setup() + local status_ok, project = pcall(require, "project_nvim") + if not status_ok then + return + end + + project.setup(lvim.builtin.project) + if lvim.builtin.project.on_config_done then + lvim.builtin.project.on_config_done(project) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/telescope.lua b/mac/.config/LunarVim/lua/lvim/core/telescope.lua new file mode 100644 index 0000000..b701f7e --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/telescope.lua @@ -0,0 +1,150 @@ +local M = {} + +---@alias telescope_themes +---| "cursor" # see `telescope.themes.get_cursor()` +---| "dropdown" # see `telescope.themes.get_dropdown()` +---| "ivy" # see `telescope.themes.get_ivy()` +---| "center" # retain the default telescope theme + +function M.config() + local actions = require("lvim.utils.modules").require_on_exported_call "telescope.actions" + lvim.builtin.telescope = { + ---@usage disable telescope completely [not recommended] + active = true, + on_config_done = nil, + theme = "dropdown", ---@type telescope_themes + defaults = { + prompt_prefix = lvim.icons.ui.Telescope .. " ", + selection_caret = lvim.icons.ui.Forward .. " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = nil, + layout_strategy = nil, + layout_config = {}, + vimgrep_arguments = { + "rg", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + "--hidden", + "--glob=!.git/", + }, + ---@usage Mappings are fully customizable. Many familiar mapping patterns are setup as defaults. + mappings = { + i = { + ["<C-n>"] = actions.move_selection_next, + ["<C-p>"] = actions.move_selection_previous, + ["<C-c>"] = actions.close, + ["<C-j>"] = actions.cycle_history_next, + ["<C-k>"] = actions.cycle_history_prev, + ["<C-q>"] = function(...) + actions.smart_send_to_qflist(...) + actions.open_qflist(...) + end, + ["<CR>"] = actions.select_default, + }, + n = { + ["<C-n>"] = actions.move_selection_next, + ["<C-p>"] = actions.move_selection_previous, + ["<C-q>"] = function(...) + actions.smart_send_to_qflist(...) + actions.open_qflist(...) + end, + }, + }, + file_ignore_patterns = {}, + path_display = { "smart" }, + winblend = 0, + border = {}, + borderchars = nil, + color_devicons = true, + set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, + }, + pickers = { + find_files = { + hidden = true, + }, + live_grep = { + --@usage don't include the filename in the search results + only_sort_text = true, + }, + grep_string = { + only_sort_text = true, + }, + buffers = { + initial_mode = "normal", + mappings = { + i = { + ["<C-d>"] = actions.delete_buffer, + }, + n = { + ["dd"] = actions.delete_buffer, + }, + }, + }, + planets = { + show_pluto = true, + show_moon = true, + }, + git_files = { + hidden = true, + show_untracked = true, + }, + colorscheme = { + enable_preview = true, + }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + }, + }, + } +end + +function M.setup() + local previewers = require "telescope.previewers" + local sorters = require "telescope.sorters" + + lvim.builtin.telescope = vim.tbl_extend("keep", { + file_previewer = previewers.vim_buffer_cat.new, + grep_previewer = previewers.vim_buffer_vimgrep.new, + qflist_previewer = previewers.vim_buffer_qflist.new, + file_sorter = sorters.get_fuzzy_file, + generic_sorter = sorters.get_generic_fuzzy_sorter, + }, lvim.builtin.telescope) + + local telescope = require "telescope" + + local theme = require("telescope.themes")["get_" .. (lvim.builtin.telescope.theme or "")] + if theme then + lvim.builtin.telescope.defaults = theme(lvim.builtin.telescope.defaults) + end + + telescope.setup(lvim.builtin.telescope) + + if lvim.builtin.project.active then + pcall(function() + require("telescope").load_extension "projects" + end) + end + + if lvim.builtin.telescope.on_config_done then + lvim.builtin.telescope.on_config_done(telescope) + end + + if lvim.builtin.telescope.extensions and lvim.builtin.telescope.extensions.fzf then + pcall(function() + require("telescope").load_extension "fzf" + end) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/telescope/custom-finders.lua b/mac/.config/LunarVim/lua/lvim/core/telescope/custom-finders.lua new file mode 100644 index 0000000..f433f35 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/telescope/custom-finders.lua @@ -0,0 +1,98 @@ +local M = {} + +local _, builtin = pcall(require, "telescope.builtin") +local _, finders = pcall(require, "telescope.finders") +local _, pickers = pcall(require, "telescope.pickers") +local _, sorters = pcall(require, "telescope.sorters") +local _, themes = pcall(require, "telescope.themes") +local _, actions = pcall(require, "telescope.actions") +local _, previewers = pcall(require, "telescope.previewers") +local _, make_entry = pcall(require, "telescope.make_entry") + +function M.find_lunarvim_files(opts) + opts = opts or {} + local theme_opts = themes.get_ivy { + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + prompt_prefix = ">> ", + prompt_title = "~ LunarVim files ~", + cwd = get_runtime_dir(), + search_dirs = { get_lvim_base_dir(), lvim.lsp.templates_dir }, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + builtin.find_files(opts) +end + +function M.grep_lunarvim_files(opts) + opts = opts or {} + local theme_opts = themes.get_ivy { + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + prompt_prefix = ">> ", + prompt_title = "~ search LunarVim ~", + cwd = get_runtime_dir(), + search_dirs = { get_lvim_base_dir(), lvim.lsp.templates_dir }, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + builtin.live_grep(opts) +end + +local copy_to_clipboard_action = function(prompt_bufnr) + local _, action_state = pcall(require, "telescope.actions.state") + local entry = action_state.get_selected_entry() + local version = entry.value + vim.fn.setreg("+", version) + vim.fn.setreg('"', version) + vim.notify("Copied " .. version .. " to clipboard", vim.log.levels.INFO) + actions.close(prompt_bufnr) +end + +function M.view_lunarvim_changelog() + local opts = themes.get_ivy { + cwd = get_lvim_base_dir(), + } + opts.entry_maker = make_entry.gen_from_git_commits(opts) + + pickers + .new(opts, { + prompt_title = "~ LunarVim Changelog ~", + + finder = finders.new_oneshot_job( + vim.tbl_flatten { + "git", + "log", + "--pretty=oneline", + "--abbrev-commit", + }, + opts + ), + previewer = { + previewers.git_commit_diff_as_was.new(opts), + }, + + --TODO: consider opening a diff view when pressing enter + attach_mappings = function(_, map) + map("i", "<enter>", copy_to_clipboard_action) + map("n", "<enter>", copy_to_clipboard_action) + map("i", "<esc>", actions.close) + map("n", "<esc>", actions.close) + map("n", "q", actions.close) + return true + end, + sorter = sorters.generic_sorter, + }) + :find() +end + +-- Smartly opens either git_files or find_files, depending on whether the working directory is +-- contained in a Git repo. +function M.find_project_files(opts) + opts = opts or {} + local ok = pcall(builtin.git_files, opts) + + if not ok then + builtin.find_files(opts) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/terminal.lua b/mac/.config/LunarVim/lua/lvim/core/terminal.lua new file mode 100644 index 0000000..5270dda --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/terminal.lua @@ -0,0 +1,174 @@ +local M = {} +local Log = require "lvim.core.log" + +M.config = function() + lvim.builtin["terminal"] = { + active = true, + on_config_done = nil, + -- size can be a number or function which is passed the current terminal + size = 20, + open_mapping = [[<c-\>]], + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_filetypes = {}, + shade_terminals = true, + shading_factor = 2, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + start_in_insert = true, + insert_mappings = true, -- whether or not the open mapping applies in insert mode + persist_size = false, + -- direction = 'vertical' | 'horizontal' | 'window' | 'float', + direction = "float", + close_on_exit = true, -- close the terminal window when the process exits + auto_scroll = true, -- automatically scroll to the bottom on terminal output + shell = nil, -- change the default shell + -- This field is only relevant if direction is set to 'float' + float_opts = { + -- The border key is *almost* the same as 'nvim_win_open' + -- see :h nvim_win_open for details on borders however + -- the 'curved' border is a custom border type + -- not natively supported but implemented in this plugin. + -- border = 'single' | 'double' | 'shadow' | 'curved' | ... other options supported by win open + border = "curved", + -- width = <value>, + -- height = <value>, + winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + }, + }, + winbar = { + enabled = false, + }, + -- Add executables on the config.lua + -- { cmd, keymap, description, direction, size } + -- lvim.builtin.terminal.execs = {...} to overwrite + -- lvim.builtin.terminal.execs[#lvim.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"} + -- TODO: pls add mappings in which key and refactor this + execs = { + { nil, "<M-1>", "Horizontal Terminal", "horizontal", 0.3 }, + { nil, "<M-2>", "Vertical Terminal", "vertical", 0.4 }, + { nil, "<M-3>", "Float Terminal", "float", nil }, + }, + } +end + +--- Get current buffer size +---@return {width: number, height: number} +local function get_buf_size() + local cbuf = vim.api.nvim_get_current_buf() + local bufinfo = vim.tbl_filter(function(buf) + return buf.bufnr == cbuf + end, vim.fn.getwininfo(vim.api.nvim_get_current_win()))[1] + if bufinfo == nil then + return { width = -1, height = -1 } + end + return { width = bufinfo.width, height = bufinfo.height } +end + +--- Get the dynamic terminal size in cells +---@param direction number +---@param size number +---@return integer +local function get_dynamic_terminal_size(direction, size) + size = size or lvim.builtin.terminal.size + if direction ~= "float" and tostring(size):find(".", 1, true) then + size = math.min(size, 1.0) + local buf_sizes = get_buf_size() + local buf_size = direction == "horizontal" and buf_sizes.height or buf_sizes.width + return buf_size * size + else + return size + end +end + +M.init = function() + for i, exec in pairs(lvim.builtin.terminal.execs) do + local direction = exec[4] or lvim.builtin.terminal.direction + + local opts = { + cmd = exec[1] or lvim.builtin.terminal.shell or vim.o.shell, + keymap = exec[2], + label = exec[3], + -- NOTE: unable to consistently bind id/count <= 9, see #2146 + count = i + 100, + direction = direction, + size = function() + return get_dynamic_terminal_size(direction, exec[5]) + end, + } + + M.add_exec(opts) + end +end + +M.setup = function() + local terminal = require "toggleterm" + terminal.setup(lvim.builtin.terminal) + if lvim.builtin.terminal.on_config_done then + lvim.builtin.terminal.on_config_done(terminal) + end +end + +M.add_exec = function(opts) + local binary = opts.cmd:match "(%S+)" + if vim.fn.executable(binary) ~= 1 then + Log:debug("Skipping configuring executable " .. binary .. ". Please make sure it is installed properly.") + return + end + + vim.keymap.set({ "n", "t" }, opts.keymap, function() + M._exec_toggle { cmd = opts.cmd, count = opts.count, direction = opts.direction, size = opts.size() } + end, { desc = opts.label, noremap = true, silent = true }) +end + +M._exec_toggle = function(opts) + local Terminal = require("toggleterm.terminal").Terminal + local term = Terminal:new { cmd = opts.cmd, count = opts.count, direction = opts.direction } + term:toggle(opts.size, opts.direction) +end + +---Toggles a log viewer according to log.viewer.layout_config +---@param logfile string the fullpath to the logfile +M.toggle_log_view = function(logfile) + local log_viewer = lvim.log.viewer.cmd + if vim.fn.executable(log_viewer) ~= 1 then + log_viewer = "less +F" + end + Log:debug("attempting to open: " .. logfile) + log_viewer = log_viewer .. " " .. logfile + local term_opts = vim.tbl_deep_extend("force", lvim.builtin.terminal, { + cmd = log_viewer, + open_mapping = lvim.log.viewer.layout_config.open_mapping, + direction = lvim.log.viewer.layout_config.direction, + -- TODO: this might not be working as expected + size = lvim.log.viewer.layout_config.size, + float_opts = lvim.log.viewer.layout_config.float_opts, + }) + + local Terminal = require("toggleterm.terminal").Terminal + local log_view = Terminal:new(term_opts) + log_view:toggle() +end + +M.lazygit_toggle = function() + local Terminal = require("toggleterm.terminal").Terminal + local lazygit = Terminal:new { + cmd = "lazygit", + hidden = true, + direction = "float", + float_opts = { + border = "none", + width = 100000, + height = 100000, + zindex = 200, + }, + on_open = function(_) + vim.cmd "startinsert!" + end, + on_close = function(_) end, + count = 99, + } + lazygit:toggle() +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/theme.lua b/mac/.config/LunarVim/lua/lvim/core/theme.lua new file mode 100644 index 0000000..5a39f04 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/theme.lua @@ -0,0 +1,96 @@ +local Log = require "lvim.core.log" + +local M = {} + +M.config = function() + lvim.builtin.theme = { + name = "lunar", + lunar = { + options = { -- currently unused + }, + }, + tokyonight = { + options = { + on_highlights = function(hl, c) + hl.IndentBlanklineContextChar = { + fg = c.dark5, + } + hl.TSConstructor = { + fg = c.blue1, + } + hl.TSTagDelimiter = { + fg = c.dark5, + } + end, + style = "night", -- The theme comes in three styles, `storm`, a darker variant `night` and `day` + transparent = lvim.transparent_window, -- Enable this to disable setting the background color + terminal_colors = true, -- Configure the colors used when opening a `:terminal` in Neovim + styles = { + -- Style to be applied to different syntax groups + -- Value is any valid attr-list value for `:help nvim_set_hl` + comments = { italic = true }, + keywords = { italic = true }, + functions = {}, + variables = {}, + -- Background styles. Can be "dark", "transparent" or "normal" + sidebars = "dark", -- style for sidebars, see below + floats = "dark", -- style for floating windows + }, + -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]` + sidebars = { + "qf", + "vista_kind", + "terminal", + "packer", + "spectre_panel", + "NeogitStatus", + "help", + }, + day_brightness = 0.3, -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors + hide_inactive_statusline = false, -- Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**. + dim_inactive = false, -- dims inactive windows + lualine_bold = false, -- When `true`, section headers in the lualine theme will be bold + use_background = true, -- can be light/dark/auto. When auto, background will be set to vim.o.background + }, + }, + } +end + +M.setup = function() + -- avoid running in headless mode since it's harder to detect failures + if #vim.api.nvim_list_uis() == 0 then + Log:debug "headless mode detected, skipping running setup for lualine" + return + end + + local selected_theme = lvim.builtin.theme.name + + if vim.startswith(lvim.colorscheme, selected_theme) then + local status_ok, plugin = pcall(require, selected_theme) + if not status_ok then + return + end + pcall(function() + plugin.setup(lvim.builtin.theme[selected_theme].options) + end) + end + + -- ref: https://github.com/neovim/neovim/issues/18201#issuecomment-1104754564 + local colors = vim.api.nvim_get_runtime_file(("colors/%s.*"):format(lvim.colorscheme), false) + if #colors == 0 then + Log:debug(string.format("Could not find '%s' colorscheme", lvim.colorscheme)) + return + end + + vim.g.colors_name = lvim.colorscheme + vim.cmd("colorscheme " .. lvim.colorscheme) + + if package.loaded.lualine then + require("lvim.core.lualine").setup() + end + if package.loaded.lir then + require("lvim.core.lir").icon_setup() + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/treesitter.lua b/mac/.config/LunarVim/lua/lvim/core/treesitter.lua new file mode 100644 index 0000000..bdb127c --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/treesitter.lua @@ -0,0 +1,135 @@ +local M = {} +local Log = require "lvim.core.log" + +function M.config() + lvim.builtin.treesitter = { + on_config_done = nil, + + -- A list of parser names, or "all" + ensure_installed = { "comment", "markdown_inline", "regex" }, + + -- List of parsers to ignore installing (for "all") + ignore_install = {}, + + -- A directory to install the parsers into. + -- By default parsers are installed to either the package dir, or the "site" dir. + -- If a custom path is used (not nil) it must be added to the runtimepath. + parser_install_dir = nil, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + auto_install = true, + + matchup = { + enable = false, -- mandatory, false will disable the whole extension + -- disable = { "c", "ruby" }, -- optional, list of language that will be disabled + }, + highlight = { + enable = true, -- false will disable the whole extension + additional_vim_regex_highlighting = false, + disable = function(lang, buf) + if vim.tbl_contains({ "latex" }, lang) then + return true + end + + local status_ok, big_file_detected = pcall(vim.api.nvim_buf_get_var, buf, "bigfile_disable_treesitter") + return status_ok and big_file_detected + end, + }, + context_commentstring = { + enable = true, + enable_autocmd = false, + config = { + -- Languages that have a single comment style + typescript = "// %s", + css = "/* %s */", + scss = "/* %s */", + html = "<!-- %s -->", + svelte = "<!-- %s -->", + vue = "<!-- %s -->", + json = "", + }, + }, + indent = { enable = true, disable = { "yaml", "python" } }, + autotag = { enable = false }, + textobjects = { + swap = { + enable = false, + -- swap_next = textobj_swap_keymaps, + }, + -- move = textobj_move_keymaps, + select = { + enable = false, + -- keymaps = textobj_sel_keymaps, + }, + }, + textsubjects = { + enable = false, + keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" }, + }, + playground = { + enable = false, + disable = {}, + updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code + persist_queries = false, -- Whether the query persists across vim sessions + keybindings = { + toggle_query_editor = "o", + toggle_hl_groups = "i", + toggle_injected_languages = "t", + toggle_anonymous_nodes = "a", + toggle_language_display = "I", + focus_language = "f", + unfocus_language = "F", + update = "R", + goto_node = "<cr>", + show_help = "?", + }, + }, + rainbow = { + enable = false, + extended_mode = true, -- Highlight also non-parentheses delimiters, boolean or table: lang -> boolean + max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int + }, + } +end + +function M.setup() + -- avoid running in headless mode since it's harder to detect failures + if #vim.api.nvim_list_uis() == 0 then + Log:debug "headless mode detected, skipping running setup for treesitter" + return + end + + local ts_status_ok, treesitter_configs = pcall(require, "nvim-treesitter.configs") + if not ts_status_ok then + Log:error "Failed to load nvim-treesitter.configs" + return + end + + local status_ok, ts_context_commentstring = pcall(require, "ts_context_commentstring") + if not status_ok then + Log:error "Failed to load ts_context_commentstring" + return + end + + local opts = vim.deepcopy(lvim.builtin.treesitter) + + -- handle deprecated API, https://github.com/JoosepAlviste/nvim-ts-context-commentstring/issues/82 + ts_context_commentstring.setup(opts.context_commentstring) + opts.context_commentstring = nil + + treesitter_configs.setup(opts) + + if lvim.builtin.treesitter.on_config_done then + lvim.builtin.treesitter.on_config_done(treesitter_configs) + end + + -- handle deprecated API, https://github.com/windwp/nvim-autopairs/pull/324 + local ts_utils = require "nvim-treesitter.ts_utils" + ts_utils.is_in_node_range = vim.treesitter.is_in_node_range + ts_utils.get_node_range = vim.treesitter.get_node_range +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/core/which-key.lua b/mac/.config/LunarVim/lua/lvim/core/which-key.lua new file mode 100644 index 0000000..ab548d9 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/core/which-key.lua @@ -0,0 +1,333 @@ +local M = {} +M.config = function() + lvim.builtin.which_key = { + ---@usage disable which-key completely [not recommended] + active = true, + on_config_done = nil, + setup = { + plugins = { + marks = false, -- shows a list of your marks on ' and ` + registers = false, -- shows your registers on " in NORMAL or <C-r> in INSERT mode + spelling = { + enabled = true, + suggestions = 20, + }, -- use which-key for spelling hints + -- the presets plugin, adds help for a bunch of default keybindings in Neovim + -- No actual key bindings are created + presets = { + operators = false, -- adds help for operators like d, y, ... + motions = false, -- adds help for motions + text_objects = false, -- help for text objects triggered after entering an operator + windows = false, -- default bindings on <c-w> + nav = false, -- misc bindings to work with windows + z = false, -- bindings for folds, spelling and others prefixed with z + g = false, -- bindings for prefixed with g + }, + }, + -- add operators that will trigger motion and text object completion + -- to enable all native operators, set the preset / operators plugin above + operators = { gc = "Comments" }, + key_labels = { + -- override the label used to display some keys. It doesn't effect WK in any other way. + -- For example: + -- ["<space>"] = "SPC", + -- ["<cr>"] = "RET", + -- ["<tab>"] = "TAB", + }, + icons = { + breadcrumb = lvim.icons.ui.DoubleChevronRight, -- symbol used in the command line area that shows your active key combo + separator = lvim.icons.ui.BoldArrowRight, -- symbol used between a key and it's label + group = lvim.icons.ui.Plus, -- symbol prepended to a group + }, + popup_mappings = { + scroll_down = "<c-d>", -- binding to scroll down inside the popup + scroll_up = "<c-u>", -- binding to scroll up inside the popup + }, + window = { + border = "single", -- none, single, double, shadow + position = "bottom", -- bottom, top + margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] + padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] + winblend = 0, + }, + layout = { + height = { min = 4, max = 25 }, -- min and max height of the columns + width = { min = 20, max = 50 }, -- min and max width of the columns + spacing = 3, -- spacing between columns + align = "left", -- align columns left, center or right + }, + ignore_missing = true, -- enable this to hide mappings for which you didn't specify a label + hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate + show_help = true, -- show help message on the command line when the popup is visible + show_keys = true, -- show the currently pressed key and its label as a message in the command line + triggers = "auto", -- automatically setup triggers + -- triggers = {"<leader>"} -- or specify a list manually + triggers_blacklist = { + -- list of mode / prefixes that should never be hooked by WhichKey + -- this is mostly relevant for key maps that start with a native binding + -- most people should not need to change this + i = { "j", "k" }, + v = { "j", "k" }, + }, + -- disable the WhichKey popup for certain buf types and file types. + -- Disabled by default for Telescope + disable = { + buftypes = {}, + filetypes = { "TelescopePrompt" }, + }, + }, + + opts = { + mode = "n", -- NORMAL mode + prefix = "<leader>", + buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings + silent = true, -- use `silent` when creating keymaps + noremap = true, -- use `noremap` when creating keymaps + nowait = true, -- use `nowait` when creating keymaps + }, + vopts = { + mode = "v", -- VISUAL mode + prefix = "<leader>", + buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings + silent = true, -- use `silent` when creating keymaps + noremap = true, -- use `noremap` when creating keymaps + nowait = true, -- use `nowait` when creating keymaps + }, + -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode. + -- see https://neovim.io/doc/user/map.html#:map-cmd + vmappings = { + ["/"] = { "<Plug>(comment_toggle_linewise_visual)", "Comment toggle linewise (visual)" }, + l = { + name = "LSP", + a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" }, + }, + g = { + name = "Git", + r = { "<cmd>Gitsigns reset_hunk<cr>", "Reset Hunk" }, + s = { "<cmd>Gitsigns stage_hunk<cr>", "Stage Hunk" }, + }, + }, + mappings = { + [";"] = { "<cmd>Alpha<CR>", "Dashboard" }, + ["w"] = { "<cmd>w!<CR>", "Save" }, + ["q"] = { "<cmd>confirm q<CR>", "Quit" }, + ["/"] = { "<Plug>(comment_toggle_linewise_current)", "Comment toggle current line" }, + ["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" }, + ["f"] = { + function() + require("lvim.core.telescope.custom-finders").find_project_files { previewer = false } + end, + "Find File", + }, + ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" }, + ["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }, + b = { + name = "Buffers", + j = { "<cmd>BufferLinePick<cr>", "Jump" }, + f = { "<cmd>Telescope buffers previewer=false<cr>", "Find" }, + b = { "<cmd>BufferLineCyclePrev<cr>", "Previous" }, + n = { "<cmd>BufferLineCycleNext<cr>", "Next" }, + W = { "<cmd>noautocmd w<cr>", "Save without formatting (noautocmd)" }, + -- w = { "<cmd>BufferWipeout<cr>", "Wipeout" }, -- TODO: implement this for bufferline + e = { + "<cmd>BufferLinePickClose<cr>", + "Pick which buffer to close", + }, + h = { "<cmd>BufferLineCloseLeft<cr>", "Close all to the left" }, + l = { + "<cmd>BufferLineCloseRight<cr>", + "Close all to the right", + }, + D = { + "<cmd>BufferLineSortByDirectory<cr>", + "Sort by directory", + }, + L = { + "<cmd>BufferLineSortByExtension<cr>", + "Sort by language", + }, + }, + d = { + name = "Debug", + t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" }, + b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" }, + c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" }, + C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" }, + d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" }, + g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" }, + i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" }, + o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" }, + u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" }, + p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" }, + r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" }, + s = { "<cmd>lua require'dap'.continue()<cr>", "Start" }, + q = { "<cmd>lua require'dap'.close()<cr>", "Quit" }, + U = { "<cmd>lua require'dapui'.toggle({reset = true})<cr>", "Toggle UI" }, + }, + p = { + name = "Plugins", + i = { "<cmd>Lazy install<cr>", "Install" }, + s = { "<cmd>Lazy sync<cr>", "Sync" }, + S = { "<cmd>Lazy clear<cr>", "Status" }, + c = { "<cmd>Lazy clean<cr>", "Clean" }, + u = { "<cmd>Lazy update<cr>", "Update" }, + p = { "<cmd>Lazy profile<cr>", "Profile" }, + l = { "<cmd>Lazy log<cr>", "Log" }, + d = { "<cmd>Lazy debug<cr>", "Debug" }, + }, + + -- " Available Debug Adapters: + -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/ + -- " Adapter configuration and installation instructions: + -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation + -- " Debug Adapter protocol: + -- " https://microsoft.github.io/debug-adapter-protocol/ + -- " Debugging + g = { + name = "Git", + g = { "<cmd>lua require 'lvim.core.terminal'.lazygit_toggle()<cr>", "Lazygit" }, + j = { "<cmd>lua require 'gitsigns'.nav_hunk('next', {navigation_message = false})<cr>", "Next Hunk" }, + k = { "<cmd>lua require 'gitsigns'.nav_hunk('prev', {navigation_message = false})<cr>", "Prev Hunk" }, + l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" }, + L = { "<cmd>lua require 'gitsigns'.blame_line({full=true})<cr>", "Blame Line (full)" }, + p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" }, + r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" }, + R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" }, + s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" }, + u = { + "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>", + "Undo Stage Hunk", + }, + o = { "<cmd>Telescope git_status<cr>", "Open changed file" }, + b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" }, + c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" }, + C = { + "<cmd>Telescope git_bcommits<cr>", + "Checkout commit(for current file)", + }, + d = { + "<cmd>Gitsigns diffthis HEAD<cr>", + "Git Diff", + }, + }, + l = { + name = "LSP", + a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" }, + d = { "<cmd>Telescope diagnostics bufnr=0 theme=get_ivy<cr>", "Buffer Diagnostics" }, + w = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" }, + f = { "<cmd>lua require('lvim.lsp.utils').format()<cr>", "Format" }, + i = { "<cmd>LspInfo<cr>", "Info" }, + I = { "<cmd>Mason<cr>", "Mason Info" }, + j = { + "<cmd>lua vim.diagnostic.goto_next()<cr>", + "Next Diagnostic", + }, + k = { + "<cmd>lua vim.diagnostic.goto_prev()<cr>", + "Prev Diagnostic", + }, + l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" }, + q = { "<cmd>lua vim.diagnostic.setloclist()<cr>", "Quickfix" }, + r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" }, + s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" }, + S = { + "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>", + "Workspace Symbols", + }, + e = { "<cmd>Telescope quickfix<cr>", "Telescope Quickfix" }, + }, + L = { + name = "+LunarVim", + c = { + "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>", + "Edit config.lua", + }, + d = { "<cmd>LvimDocs<cr>", "View LunarVim's docs" }, + f = { + "<cmd>lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()<cr>", + "Find LunarVim files", + }, + g = { + "<cmd>lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()<cr>", + "Grep LunarVim files", + }, + k = { "<cmd>Telescope keymaps<cr>", "View LunarVim's keymappings" }, + i = { + "<cmd>lua require('lvim.core.info').toggle_popup(vim.bo.filetype)<cr>", + "Toggle LunarVim Info", + }, + I = { + "<cmd>lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()<cr>", + "View LunarVim's changelog", + }, + l = { + name = "+logs", + d = { + "<cmd>lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())<cr>", + "view default log", + }, + D = { + "<cmd>lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())<cr>", + "Open the default logfile", + }, + l = { + "<cmd>lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>", + "view lsp log", + }, + L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" }, + n = { + "<cmd>lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>", + "view neovim log", + }, + N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" }, + }, + r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" }, + u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" }, + }, + s = { + name = "Search", + b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" }, + c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" }, + f = { "<cmd>Telescope find_files<cr>", "Find File" }, + h = { "<cmd>Telescope help_tags<cr>", "Find Help" }, + H = { "<cmd>Telescope highlights<cr>", "Find highlight groups" }, + M = { "<cmd>Telescope man_pages<cr>", "Man Pages" }, + r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" }, + R = { "<cmd>Telescope registers<cr>", "Registers" }, + t = { "<cmd>Telescope live_grep<cr>", "Text" }, + k = { "<cmd>Telescope keymaps<cr>", "Keymaps" }, + C = { "<cmd>Telescope commands<cr>", "Commands" }, + l = { "<cmd>Telescope resume<cr>", "Resume last search" }, + p = { + "<cmd>lua require('telescope.builtin').colorscheme({enable_preview = true})<cr>", + "Colorscheme with Preview", + }, + }, + T = { + name = "Treesitter", + i = { ":TSConfigInfo<cr>", "Info" }, + }, + }, + } +end + +M.setup = function() + local which_key = require "which-key" + + which_key.setup(lvim.builtin.which_key.setup) + + local opts = lvim.builtin.which_key.opts + local vopts = lvim.builtin.which_key.vopts + + local mappings = lvim.builtin.which_key.mappings + local vmappings = lvim.builtin.which_key.vmappings + + which_key.register(mappings, opts) + which_key.register(vmappings, vopts) + + if lvim.builtin.which_key.on_config_done then + lvim.builtin.which_key.on_config_done(which_key) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/icons.lua b/mac/.config/LunarVim/lua/lvim/icons.lua new file mode 100644 index 0000000..d9fb4cd --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/icons.lua @@ -0,0 +1,154 @@ +return { + kind = { + Array = "", + Boolean = "", + Class = "", + Color = "", + Constant = "", + Constructor = "", + Enum = "", + EnumMember = "", + Event = "", + Field = "", + File = "", + Folder = "", + Function = "", + Interface = "", + Key = "", + Keyword = "", + Method = "", + Module = "", + Namespace = "", + Null = "", + Number = "", + Object = "", + Operator = "", + Package = "", + Property = "", + Reference = "", + Snippet = "", + String = "", + Struct = "", + Text = "", + TypeParameter = "", + Unit = "", + Value = "", + Variable = "", + }, + git = { + LineAdded = "", + LineModified = "", + LineRemoved = "", + FileDeleted = "", + FileIgnored = "◌", + FileRenamed = "", + FileStaged = "S", + FileUnmerged = "", + FileUnstaged = "", + FileUntracked = "U", + Diff = "", + Repo = "", + Octoface = "", + Branch = "", + }, + ui = { + ArrowCircleDown = "", + ArrowCircleLeft = "", + ArrowCircleRight = "", + ArrowCircleUp = "", + BoldArrowDown = "", + BoldArrowLeft = "", + BoldArrowRight = "", + BoldArrowUp = "", + BoldClose = "", + BoldDividerLeft = "", + BoldDividerRight = "", + BoldLineLeft = "▎", + BookMark = "", + BoxChecked = "", + Bug = "", + Stacks = "", + Scopes = "", + Watches = "", + DebugConsole = "", + Calendar = "", + Check = "", + ChevronRight = "", + ChevronShortDown = "", + ChevronShortLeft = "", + ChevronShortRight = "", + ChevronShortUp = "", + Circle = " ", + Close = "", + CloudDownload = "", + Code = "", + Comment = "", + Dashboard = "", + DividerLeft = "", + DividerRight = "", + DoubleChevronRight = "»", + Ellipsis = "", + EmptyFolder = "", + EmptyFolderOpen = "", + File = "", + FileSymlink = "", + Files = "", + FindFile = "", + FindText = "", + Fire = "", + Folder = "", + FolderOpen = "", + FolderSymlink = "", + Forward = "", + Gear = "", + History = "", + Lightbulb = "", + LineLeft = "▏", + LineMiddle = "│", + List = "", + Lock = "", + NewFile = "", + Note = "", + Package = "", + Pencil = "", + Plus = "", + Project = "", + Search = "", + SignIn = "", + SignOut = "", + Tab = "", + Table = "", + Target = "", + Telescope = "", + Text = "", + Tree = "", + Triangle = "", + TriangleShortArrowDown = "", + TriangleShortArrowLeft = "", + TriangleShortArrowRight = "", + TriangleShortArrowUp = "", + }, + diagnostics = { + BoldError = "", + Error = "", + BoldWarning = "", + Warning = "", + BoldInformation = "", + Information = "", + BoldQuestion = "", + Question = "", + BoldHint = "", + Hint = "", + Debug = "", + Trace = "✎", + }, + misc = { + Robot = "", + Squirrel = "", + Tag = "", + Watch = "", + Smiley = "", + Package = "", + CircuitBoard = "", + }, +} diff --git a/mac/.config/LunarVim/lua/lvim/interface/popup.lua b/mac/.config/LunarVim/lua/lvim/interface/popup.lua new file mode 100644 index 0000000..84a27e1 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/interface/popup.lua @@ -0,0 +1,64 @@ +local Popup = {} + +--- Create a new floating window +-- @param config The configuration passed to vim.api.nvim_open_win +-- @param win_opts The options registered with vim.api.nvim_win_set_option +-- @param buf_opts The options registered with vim.api.nvim_buf_set_option +-- @return A new popup +function Popup:new(opts) + opts = opts or {} + opts.layout = opts.layout or {} + opts.win_opts = opts.win_opts or {} + opts.buf_opts = opts.buf_opts or {} + + Popup.__index = Popup + + local editor_layout = { + height = vim.o.lines - vim.o.cmdheight - 2, -- Add margin for status and buffer line + width = vim.o.columns, + } + local popup_layout = { + relative = "editor", + height = math.floor(editor_layout.height * 0.9), + width = math.floor(editor_layout.width * 0.8), + style = "minimal", + border = "rounded", + } + popup_layout.row = math.floor((editor_layout.height - popup_layout.height) / 2) + popup_layout.col = math.floor((editor_layout.width - popup_layout.width) / 2) + + local obj = { + buffer = vim.api.nvim_create_buf(false, true), + layout = vim.tbl_deep_extend("force", popup_layout, opts.layout), + win_opts = opts.win_opts, + buf_opts = opts.buf_opts, + } + + setmetatable(obj, Popup) + + return obj +end + +--- Display the popup with the provided content +-- @param content_provider A function accepting the popup's layout and returning the content to display +function Popup:display(content_provider) + self.win_id = vim.api.nvim_open_win(self.buffer, true, self.layout) + vim.api.nvim_command( + string.format("autocmd BufHidden,BufLeave <buffer> ++once lua pcall(vim.api.nvim_win_close, %d, true)", self.win_id) + ) + + local lines = content_provider(self.layout) + vim.api.nvim_buf_set_lines(self.bufnr or 0, 0, -1, false, lines) + + -- window options + for key, value in pairs(self.win_opts) do + vim.api.nvim_set_option_value(key, value, { win = self.win_id or 0, scope = "local" }) + end + + -- buffer options + for key, value in pairs(self.buf_opts) do + vim.api.nvim_set_option_value(key, value, { buf = self.buffer }) + end +end + +return Popup diff --git a/mac/.config/LunarVim/lua/lvim/interface/text.lua b/mac/.config/LunarVim/lua/lvim/interface/text.lua new file mode 100644 index 0000000..0266d52 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/interface/text.lua @@ -0,0 +1,95 @@ +local M = {} + +local function max_len_line(lines) + local max_len = 0 + + for _, line in ipairs(lines) do + local line_len = line:len() + if line_len > max_len then + max_len = line_len + end + end + + return max_len +end + +--- Left align lines relatively to the parent container +-- @param container The container where lines will be displayed +-- @param lines The text to align +-- @param alignment The alignment value, range: [0-1] +function M.align_left(container, lines, alignment) + local max_len = max_len_line(lines) + local indent_amount = math.ceil(math.max(container.width - max_len, 0) * alignment) + return M.shift_right(lines, indent_amount) +end + +--- Center align lines relatively to the parent container +-- @param container The container where lines will be displayed +-- @param lines The text to align +-- @param alignment The alignment value, range: [0-1] +function M.align_center(container, lines, alignment) + local output = {} + local max_len = max_len_line(lines) + + for _, line in ipairs(lines) do + local padding = string.rep(" ", (math.max(container.width, max_len) - line:len()) * alignment) + table.insert(output, padding .. line) + end + + return output +end + +--- Shift lines by a given amount +-- @params lines The lines the shift +-- @param amount The amount of spaces to add +function M.shift_right(lines, amount) + local output = {} + local padding = string.rep(" ", amount) + + for _, line in ipairs(lines) do + table.insert(output, padding .. line) + end + + return output +end + +--- Pretty format tables +-- @param entries The table to format +-- @param col_count The number of column to span the table on +-- @param col_sep The separator between each column, default: " " +function M.format_table(entries, col_count, col_sep) + col_sep = col_sep or " " + + local col_rows = math.ceil(vim.tbl_count(entries) / col_count) + local cols = {} + local count = 0 + + for i, entry in ipairs(entries) do + if ((i - 1) % col_rows) == 0 then + table.insert(cols, {}) + count = count + 1 + end + table.insert(cols[count], entry) + end + + local col_max_len = {} + for _, col in ipairs(cols) do + table.insert(col_max_len, max_len_line(col)) + end + + local output = {} + for i, col in ipairs(cols) do + for j, entry in ipairs(col) do + if not output[j] then + output[j] = entry + else + local padding = string.rep(" ", col_max_len[i - 1] - cols[i - 1][j]:len()) + output[j] = output[j] .. padding .. col_sep .. entry + end + end + end + + return output +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/keymappings.lua b/mac/.config/LunarVim/lua/lvim/keymappings.lua new file mode 100644 index 0000000..e7010a3 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/keymappings.lua @@ -0,0 +1,177 @@ +local M = {} +local Log = require "lvim.core.log" + +local generic_opts_any = { noremap = true, silent = true } + +local generic_opts = { + insert_mode = generic_opts_any, + normal_mode = generic_opts_any, + visual_mode = generic_opts_any, + visual_block_mode = generic_opts_any, + command_mode = generic_opts_any, + operator_pending_mode = generic_opts_any, + term_mode = { silent = true }, +} + +local mode_adapters = { + insert_mode = "i", + normal_mode = "n", + term_mode = "t", + visual_mode = "v", + visual_block_mode = "x", + command_mode = "c", + operator_pending_mode = "o", +} + +---@class Keys +---@field insert_mode table +---@field normal_mode table +---@field terminal_mode table +---@field visual_mode table +---@field visual_block_mode table +---@field command_mode table +---@field operator_pending_mode table + +local defaults = { + insert_mode = { + -- Move current line / block with Alt-j/k ala vscode. + ["<A-j>"] = "<Esc>:m .+1<CR>==gi", + -- Move current line / block with Alt-j/k ala vscode. + ["<A-k>"] = "<Esc>:m .-2<CR>==gi", + -- navigation + ["<A-Up>"] = "<C-\\><C-N><C-w>k", + ["<A-Down>"] = "<C-\\><C-N><C-w>j", + ["<A-Left>"] = "<C-\\><C-N><C-w>h", + ["<A-Right>"] = "<C-\\><C-N><C-w>l", + }, + + normal_mode = { + -- Better window movement + ["<C-h>"] = "<C-w>h", + ["<C-j>"] = "<C-w>j", + ["<C-k>"] = "<C-w>k", + ["<C-l>"] = "<C-w>l", + + -- Resize with arrows + ["<C-Up>"] = ":resize -2<CR>", + ["<C-Down>"] = ":resize +2<CR>", + ["<C-Left>"] = ":vertical resize -2<CR>", + ["<C-Right>"] = ":vertical resize +2<CR>", + + -- Move current line / block with Alt-j/k a la vscode. + ["<A-j>"] = ":m .+1<CR>==", + ["<A-k>"] = ":m .-2<CR>==", + + -- QuickFix + ["]q"] = ":cnext<CR>", + ["[q"] = ":cprev<CR>", + ["<C-q>"] = ":call QuickFixToggle()<CR>", + }, + + term_mode = { + -- Terminal window navigation + ["<C-h>"] = "<C-\\><C-N><C-w>h", + ["<C-j>"] = "<C-\\><C-N><C-w>j", + ["<C-k>"] = "<C-\\><C-N><C-w>k", + ["<C-l>"] = "<C-\\><C-N><C-w>l", + }, + + visual_mode = { + -- Better indenting + ["<"] = "<gv", + [">"] = ">gv", + + -- ["p"] = '"0p', + -- ["P"] = '"0P', + }, + + visual_block_mode = { + -- Move current line / block with Alt-j/k ala vscode. + ["<A-j>"] = ":m '>+1<CR>gv-gv", + ["<A-k>"] = ":m '<-2<CR>gv-gv", + }, + + command_mode = { + -- navigate tab completion with <c-j> and <c-k> + -- runs conditionally + ["<C-j>"] = { 'pumvisible() ? "\\<C-n>" : "\\<C-j>"', { expr = true, noremap = true } }, + ["<C-k>"] = { 'pumvisible() ? "\\<C-p>" : "\\<C-k>"', { expr = true, noremap = true } }, + }, +} + +if vim.fn.has "mac" == 1 then + defaults.normal_mode["<A-Up>"] = defaults.normal_mode["<C-Up>"] + defaults.normal_mode["<A-Down>"] = defaults.normal_mode["<C-Down>"] + defaults.normal_mode["<A-Left>"] = defaults.normal_mode["<C-Left>"] + defaults.normal_mode["<A-Right>"] = defaults.normal_mode["<C-Right>"] + Log:debug "Activated mac keymappings" +end + +-- Unsets all keybindings defined in keymaps +-- @param keymaps The table of key mappings containing a list per mode (normal_mode, insert_mode, ..) +function M.clear(keymaps) + local default = M.get_defaults() + for mode, mappings in pairs(keymaps) do + local translated_mode = mode_adapters[mode] and mode_adapters[mode] or mode + for key, _ in pairs(mappings) do + -- some plugins may override default bindings that the user hasn't manually overriden + if default[mode][key] ~= nil or (default[translated_mode] ~= nil and default[translated_mode][key] ~= nil) then + pcall(vim.api.nvim_del_keymap, translated_mode, key) + end + end + end +end + +-- Set key mappings individually +-- @param mode The keymap mode, can be one of the keys of mode_adapters +-- @param key The key of keymap +-- @param val Can be form as a mapping or tuple of mapping and user defined opt +function M.set_keymaps(mode, key, val) + local opt = generic_opts[mode] or generic_opts_any + if type(val) == "table" then + opt = val[2] + val = val[1] + end + if val then + vim.keymap.set(mode, key, val, opt) + else + pcall(vim.api.nvim_del_keymap, mode, key) + end +end + +-- Load key mappings for a given mode +-- @param mode The keymap mode, can be one of the keys of mode_adapters +-- @param keymaps The list of key mappings +function M.load_mode(mode, keymaps) + mode = mode_adapters[mode] or mode + for k, v in pairs(keymaps) do + M.set_keymaps(mode, k, v) + end +end + +-- Load key mappings for all provided modes +-- @param keymaps A list of key mappings for each mode +function M.load(keymaps) + keymaps = keymaps or {} + for mode, mapping in pairs(keymaps) do + M.load_mode(mode, mapping) + end +end + +-- Load the default keymappings +function M.load_defaults() + M.load(M.get_defaults()) + lvim.keys = lvim.keys or {} + for idx, _ in pairs(defaults) do + if not lvim.keys[idx] then + lvim.keys[idx] = {} + end + end +end + +-- Get the default keymappings +function M.get_defaults() + return defaults +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/config.lua b/mac/.config/LunarVim/lua/lvim/lsp/config.lua new file mode 100644 index 0000000..55f7d64 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/config.lua @@ -0,0 +1,164 @@ +local skipped_servers = { + "angularls", + "ansiblels", + "antlersls", + "ast_grep", + "azure_pipelines_ls", + "basedpyright", + "biome", + "bzl", + "ccls", + "css_variables", + "cssmodules_ls", + "custom_elements_ls", + "denols", + "docker_compose_language_service", + "dprint", + "elp", + "ember", + "emmet_language_server", + "emmet_ls", + "eslint", + "eslintls", + "fennel_language_server", + "gitlab_ci_ls", + "glint", + "glslls", + "golangci_lint_ls", + "gradle_ls", + "graphql", + "harper_ls", + "hdl_checker", + "hydra_lsp", + "htmx", + "java_language_server", + "jedi_language_server", + "lexical", + "ltex", + "lwc_ls", + "mdx_analyzer", + "neocmake", + "nim_langserver", + "ocamlls", + "omnisharp", + "phpactor", + "psalm", + "pylsp", + "pylyzer", + "pyre", + "quick_lint_js", + "reason_ls", + "rnix", + "rome", + "rubocop", + "ruby_ls", + "ruby_lsp", + "ruff_lsp", + "scry", + "snyk_ls", + "solang", + "solc", + "solidity_ls", + "solidity_ls_nomicfoundation", + "sorbet", + "sourcekit", + "somesass_ls", + "sourcery", + "spectral", + "sqlls", + "sqls", + "standardrb", + "stimulus_ls", + "stylelint_lsp", + "svlangserver", + "swift_mesonls", + "templ", + "tflint", + "tinymist", + "unocss", + "vale_ls", + "vacuum", + "verible", + "v_analyzer", + "vtsls", + "vuels", +} + +local skipped_filetypes = { "markdown", "rst", "plaintext", "toml", "proto" } + +local join_paths = require("lvim.utils").join_paths + +return { + templates_dir = join_paths(get_runtime_dir(), "site", "after", "ftplugin"), + ---@deprecated use vim.diagnostic.config({ ... }) instead + diagnostics = {}, + document_highlight = false, + code_lens_refresh = true, + on_attach_callback = nil, + on_init_callback = nil, + automatic_configuration = { + ---@usage list of servers that the automatic installer will skip + skipped_servers = skipped_servers, + ---@usage list of filetypes that the automatic installer will skip + skipped_filetypes = skipped_filetypes, + }, + buffer_mappings = { + normal_mode = { + ["K"] = { "<cmd>lua vim.lsp.buf.hover()<cr>", "Show hover" }, + ["gd"] = { "<cmd>lua vim.lsp.buf.definition()<cr>", "Goto definition" }, + ["gD"] = { "<cmd>lua vim.lsp.buf.declaration()<cr>", "Goto Declaration" }, + ["gr"] = { "<cmd>lua vim.lsp.buf.references()<cr>", "Goto references" }, + ["gI"] = { "<cmd>lua vim.lsp.buf.implementation()<cr>", "Goto Implementation" }, + ["gs"] = { "<cmd>lua vim.lsp.buf.signature_help()<cr>", "show signature help" }, + ["gl"] = { + function() + local float = vim.diagnostic.config().float + + if float then + local config = type(float) == "table" and float or {} + config.scope = "line" + + vim.diagnostic.open_float(config) + end + end, + "Show line diagnostics", + }, + }, + insert_mode = {}, + visual_mode = {}, + }, + buffer_options = { + --- enable completion triggered by <c-x><c-o> + omnifunc = "v:lua.vim.lsp.omnifunc", + --- use gq for formatting + formatexpr = "v:lua.vim.lsp.formatexpr(#{timeout_ms:500})", + }, + ---@usage list of settings of nvim-lsp-installer + installer = { + setup = { + ensure_installed = {}, + automatic_installation = { + exclude = {}, + }, + }, + }, + nlsp_settings = { + setup = { + config_home = join_paths(get_config_dir(), "lsp-settings"), + -- set to false to overwrite schemastore.nvim + append_default_schemas = true, + ignored_servers = {}, + loader = "json", + }, + }, + null_ls = { + setup = { + debug = false, + }, + config = {}, + }, + ---@deprecated use lvim.lsp.automatic_configuration.skipped_servers instead + override = {}, + ---@deprecated use lvim.lsp.installer.setup.automatic_installation instead + automatic_servers_installation = nil, +} diff --git a/mac/.config/LunarVim/lua/lvim/lsp/init.lua b/mac/.config/LunarVim/lua/lvim/lsp/init.lua new file mode 100644 index 0000000..d59b29a --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/init.lua @@ -0,0 +1,128 @@ +local M = {} +local Log = require "lvim.core.log" +local utils = require "lvim.utils" +local autocmds = require "lvim.core.autocmds" + +local function add_lsp_buffer_options(bufnr) + for k, v in pairs(lvim.lsp.buffer_options) do + vim.api.nvim_set_option_value(k, v, { buf = bufnr }) + end +end + +local function add_lsp_buffer_keybindings(bufnr) + local mappings = { + normal_mode = "n", + insert_mode = "i", + visual_mode = "v", + } + + for mode_name, mode_char in pairs(mappings) do + for key, remap in pairs(lvim.lsp.buffer_mappings[mode_name]) do + local opts = { buffer = bufnr, desc = remap[2], noremap = true, silent = true } + vim.keymap.set(mode_char, key, remap[1], opts) + end + end +end + +function M.common_capabilities() + local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") + if status_ok then + return cmp_nvim_lsp.default_capabilities() + end + + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, + } + + return capabilities +end + +function M.common_on_exit(_, _) + if lvim.lsp.document_highlight then + autocmds.clear_augroup "lsp_document_highlight" + end + if lvim.lsp.code_lens_refresh then + autocmds.clear_augroup "lsp_code_lens_refresh" + end +end + +function M.common_on_init(client, bufnr) + if lvim.lsp.on_init_callback then + lvim.lsp.on_init_callback(client, bufnr) + Log:debug "Called lsp.on_init_callback" + return + end +end + +function M.common_on_attach(client, bufnr) + if lvim.lsp.on_attach_callback then + lvim.lsp.on_attach_callback(client, bufnr) + Log:debug "Called lsp.on_attach_callback" + end + local lu = require "lvim.lsp.utils" + if lvim.lsp.document_highlight then + lu.setup_document_highlight(client, bufnr) + end + if lvim.lsp.code_lens_refresh then + lu.setup_codelens_refresh(client, bufnr) + end + add_lsp_buffer_keybindings(bufnr) + add_lsp_buffer_options(bufnr) + lu.setup_document_symbols(client, bufnr) +end + +function M.get_common_opts() + return { + on_attach = M.common_on_attach, + on_init = M.common_on_init, + on_exit = M.common_on_exit, + capabilities = M.common_capabilities(), + } +end + +function M.setup() + Log:debug "Setting up LSP support" + + local lsp_status_ok, _ = pcall(require, "lspconfig") + if not lsp_status_ok then + return + end + + if lvim.use_icons then + for _, sign in ipairs(vim.tbl_get(vim.diagnostic.config(), "signs", "values") or {}) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) + end + end + + if not utils.is_directory(lvim.lsp.templates_dir) then + require("lvim.lsp.templates").generate_templates() + end + + pcall(function() + require("nlspsettings").setup(lvim.lsp.nlsp_settings.setup) + end) + + require("lvim.lsp.null-ls").setup() + + autocmds.configure_format_on_save() + + local function set_handler_opts_if_not_set(name, handler, opts) + if debug.getinfo(vim.lsp.handlers[name], "S").source:find(vim.env.VIMRUNTIME, 1, true) then + vim.lsp.handlers[name] = vim.lsp.with(handler, opts) + end + end + + set_handler_opts_if_not_set("textDocument/hover", vim.lsp.handlers.hover, { border = "rounded" }) + set_handler_opts_if_not_set("textDocument/signatureHelp", vim.lsp.handlers.signature_help, { border = "rounded" }) + + -- Enable rounded borders in :LspInfo window. + require("lspconfig.ui.windows").default_options.border = "rounded" +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/manager.lua b/mac/.config/LunarVim/lua/lvim/lsp/manager.lua new file mode 100644 index 0000000..5e695ec --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/manager.lua @@ -0,0 +1,141 @@ +local M = {} + +local Log = require "lvim.core.log" +local fmt = string.format +local lvim_lsp_utils = require "lvim.lsp.utils" +local is_windows = vim.loop.os_uname().version:match "Windows" + +local function resolve_mason_config(server_name) + local found, mason_config = pcall(require, "mason-lspconfig.server_configurations." .. server_name) + if not found then + Log:debug(fmt("mason configuration not found for %s", server_name)) + return {} + end + local server_mapping = require "mason-lspconfig.mappings.server" + local path = require "mason-core.path" + local pkg_name = server_mapping.lspconfig_to_package[server_name] + local install_dir = path.package_prefix(pkg_name) + local conf = mason_config(install_dir) + if is_windows and conf.cmd and conf.cmd[1] then + local exepath = vim.fn.exepath(conf.cmd[1]) + if exepath ~= "" then + conf.cmd[1] = exepath + end + end + Log:debug(fmt("resolved mason configuration for %s, got %s", server_name, vim.inspect(conf))) + return conf or {} +end + +---Resolve the configuration for a server by merging with the default config +---@param server_name string +---@vararg any config table [optional] +---@return table +local function resolve_config(server_name, ...) + local defaults = { + on_attach = require("lvim.lsp").common_on_attach, + on_init = require("lvim.lsp").common_on_init, + on_exit = require("lvim.lsp").common_on_exit, + capabilities = require("lvim.lsp").common_capabilities(), + } + + local has_custom_provider, custom_config = pcall(require, "lvim/lsp/providers/" .. server_name) + if has_custom_provider then + Log:debug("Using custom configuration for requested server: " .. server_name) + defaults = vim.tbl_deep_extend("force", defaults, custom_config) + end + + defaults = vim.tbl_deep_extend("force", defaults, ...) + + return defaults +end + +-- manually start the server and don't wait for the usual filetype trigger from lspconfig +local function buf_try_add(server_name, bufnr) + bufnr = bufnr or vim.api.nvim_get_current_buf() + require("lspconfig")[server_name].manager:try_add_wrapper(bufnr) +end + +-- check if the manager autocomd has already been configured since some servers can take a while to initialize +-- this helps guarding against a data-race condition where a server can get configured twice +-- which seems to occur only when attaching to single-files +local function client_is_configured(server_name, ft) + ft = ft or vim.bo.filetype + local active_autocmds = vim.api.nvim_get_autocmds { event = "FileType", pattern = ft } + for _, result in ipairs(active_autocmds) do + if result.desc ~= nil and result.desc:match("server " .. server_name .. " ") then + Log:debug(string.format("[%q] is already configured", server_name)) + return true + end + end + return false +end + +local function launch_server(server_name, config) + pcall(function() + local command = config.cmd + or (function() + local default_config = require("lspconfig.server_configurations." .. server_name).default_config + return default_config.cmd + end)() + -- some servers have dynamic commands defined with on_new_config + if type(command) == "table" and type(command[1]) == "string" and vim.fn.executable(command[1]) ~= 1 then + Log:debug(string.format("[%q] is either not installed, missing from PATH, or not executable.", server_name)) + return + end + require("lspconfig")[server_name].setup(config) + buf_try_add(server_name) + end) +end + +---Setup a language server by providing a name +---@param server_name string name of the language server +---@param user_config table? when available it will take predence over any default configurations +function M.setup(server_name, user_config) + vim.validate { name = { server_name, "string" } } + user_config = user_config or {} + + if lvim_lsp_utils.is_client_active(server_name) or client_is_configured(server_name) then + return + end + + local server_mapping = require "mason-lspconfig.mappings.server" + local registry = require "mason-registry" + + local pkg_name = server_mapping.lspconfig_to_package[server_name] + if not pkg_name then + local config = resolve_config(server_name, user_config) + launch_server(server_name, config) + return + end + + local should_auto_install = function(name) + local installer_settings = lvim.lsp.installer.setup + return installer_settings.automatic_installation + and not vim.tbl_contains(installer_settings.automatic_installation.exclude, name) + end + + if not registry.is_installed(pkg_name) then + if should_auto_install(server_name) then + Log:debug "Automatic server installation detected" + vim.notify_once(string.format("Installation in progress for [%s]", server_name), vim.log.levels.INFO) + local pkg = registry.get_package(pkg_name) + pkg:install():once("closed", function() + if pkg:is_installed() then + vim.schedule(function() + vim.notify_once(string.format("Installation complete for [%s]", server_name), vim.log.levels.INFO) + -- mason config is only available once the server has been installed + local config = resolve_config(server_name, resolve_mason_config(server_name), user_config) + launch_server(server_name, config) + end) + end + end) + else + Log:debug(server_name .. " is not managed by the automatic installer") + end + end + + local config = resolve_config(server_name, resolve_mason_config(server_name), user_config) + launch_server(server_name, config) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/null-ls/code_actions.lua b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/code_actions.lua new file mode 100644 index 0000000..50f4cfb --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/code_actions.lua @@ -0,0 +1,26 @@ +local M = {} + +local Log = require "lvim.core.log" + +local null_ls = require "null-ls" +local services = require "lvim.lsp.null-ls.services" +local method = null_ls.methods.CODE_ACTION + +function M.list_registered(filetype) + local registered_providers = services.list_registered_providers_names(filetype) + return registered_providers[method] or {} +end + +function M.setup(actions_configs) + if vim.tbl_isempty(actions_configs) then + return + end + + local registered = services.register_sources(actions_configs, method) + + if #registered > 0 then + Log:debug("Registered the following action-handlers: " .. unpack(registered)) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/null-ls/formatters.lua b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/formatters.lua new file mode 100644 index 0000000..b4fb2f3 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/formatters.lua @@ -0,0 +1,33 @@ +local M = {} + +local Log = require "lvim.core.log" + +local null_ls = require "null-ls" +local services = require "lvim.lsp.null-ls.services" +local method = null_ls.methods.FORMATTING + +function M.list_registered(filetype) + local registered_providers = services.list_registered_providers_names(filetype) + return registered_providers[method] or {} +end + +function M.list_supported(filetype) + local s = require "null-ls.sources" + local supported_formatters = s.get_supported(filetype, "formatting") + table.sort(supported_formatters) + return supported_formatters +end + +function M.setup(formatter_configs) + if vim.tbl_isempty(formatter_configs) then + return + end + + local registered = services.register_sources(formatter_configs, method) + + if #registered > 0 then + Log:debug("Registered the following formatters: " .. unpack(registered)) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/null-ls/init.lua b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/init.lua new file mode 100644 index 0000000..51a200f --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/init.lua @@ -0,0 +1,16 @@ +local M = {} + +local Log = require "lvim.core.log" + +function M.setup() + local status_ok, null_ls = pcall(require, "null-ls") + if not status_ok then + Log:error "Missing null-ls dependency" + return + end + + local default_opts = require("lvim.lsp").get_common_opts() + null_ls.setup(vim.tbl_deep_extend("force", default_opts, lvim.lsp.null_ls.setup)) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/null-ls/linters.lua b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/linters.lua new file mode 100644 index 0000000..ba7670d --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/linters.lua @@ -0,0 +1,43 @@ +local M = {} + +local Log = require "lvim.core.log" + +local null_ls = require "null-ls" +local services = require "lvim.lsp.null-ls.services" +local method = null_ls.methods.DIAGNOSTICS + +local alternative_methods = { + null_ls.methods.DIAGNOSTICS, + null_ls.methods.DIAGNOSTICS_ON_OPEN, + null_ls.methods.DIAGNOSTICS_ON_SAVE, +} + +function M.list_registered(filetype) + local registered_providers = services.list_registered_providers_names(filetype) + local providers_for_methods = vim.tbl_flatten(vim.tbl_map(function(m) + return registered_providers[m] or {} + end, alternative_methods)) + + return providers_for_methods +end + +function M.list_supported(filetype) + local s = require "null-ls.sources" + local supported_linters = s.get_supported(filetype, "diagnostics") + table.sort(supported_linters) + return supported_linters +end + +function M.setup(linter_configs) + if vim.tbl_isempty(linter_configs) then + return + end + + local registered = services.register_sources(linter_configs, method) + + if #registered > 0 then + Log:debug("Registered the following linters: " .. unpack(registered)) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/null-ls/services.lua b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/services.lua new file mode 100644 index 0000000..7dc0bb6 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/null-ls/services.lua @@ -0,0 +1,104 @@ +local M = {} + +local Log = require "lvim.core.log" + +local function find_root_dir() + local util = require "lspconfig/util" + local lsp_utils = require "lvim.lsp.utils" + + local ts_client = lsp_utils.is_client_active "typescript" + if ts_client then + return ts_client.config.root_dir + end + local dirname = vim.fn.expand "%:p:h" + return util.root_pattern "package.json"(dirname) +end + +local function from_node_modules(command) + local root_dir = find_root_dir() + + if not root_dir then + return nil + end + + local join_paths = require("lvim.utils").join_paths + return join_paths(root_dir, "node_modules", ".bin", command) +end + +local local_providers = { + prettier = { find = from_node_modules }, + prettierd = { find = from_node_modules }, + prettier_d_slim = { find = from_node_modules }, + eslint_d = { find = from_node_modules }, + eslint = { find = from_node_modules }, + stylelint = { find = from_node_modules }, +} + +function M.find_command(command) + if local_providers[command] then + local local_command = local_providers[command].find(command) + if local_command and vim.fn.executable(local_command) == 1 then + return local_command + end + end + + if command and vim.fn.executable(command) == 1 then + return command + end + return nil +end + +function M.list_registered_providers_names(filetype) + local s = require "null-ls.sources" + local available_sources = s.get_available(filetype) + local registered = {} + for _, source in ipairs(available_sources) do + for method in pairs(source.methods) do + registered[method] = registered[method] or {} + table.insert(registered[method], source.name) + end + end + return registered +end + +function M.register_sources(configs, method) + local null_ls = require "null-ls" + local is_registered = require("null-ls.sources").is_registered + + local sources, registered_names = {}, {} + + for _, config in ipairs(configs) do + local cmd = config.exe or config.command + local name = config.name or cmd:gsub("-", "_") + local type = method == null_ls.methods.CODE_ACTION and "code_actions" or null_ls.methods[method]:lower() + local source = type and null_ls.builtins[type][name] + Log:debug(string.format("Received request to register [%s] as a %s source", name, type)) + if not source then + Log:error("Not a valid source: " .. name) + elseif is_registered { name = source.name or name, method = method } then + Log:trace(string.format("Skipping registering [%s] more than once", name)) + else + local command = M.find_command(source._opts.command) or source._opts.command + + -- treat `args` as `extra_args` for backwards compatibility. Can otherwise use `generator_opts.args` + local compat_opts = vim.deepcopy(config) + if config.args then + compat_opts.extra_args = config.args or config.extra_args + compat_opts.args = nil + end + + local opts = vim.tbl_deep_extend("keep", { command = command }, compat_opts) + Log:debug("Registering source " .. name) + Log:trace(vim.inspect(opts)) + table.insert(sources, source.with(opts)) + vim.list_extend(registered_names, { source.name }) + end + end + + if #sources > 0 then + null_ls.register { sources = sources } + end + return registered_names +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/providers/jsonls.lua b/mac/.config/LunarVim/lua/lvim/lsp/providers/jsonls.lua new file mode 100644 index 0000000..76aea25 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/providers/jsonls.lua @@ -0,0 +1,18 @@ +local opts = { + settings = { + json = { + schemas = require("schemastore").json.schemas(), + }, + }, + setup = { + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + end, + }, + }, + }, +} + +return opts diff --git a/mac/.config/LunarVim/lua/lvim/lsp/providers/lua_ls.lua b/mac/.config/LunarVim/lua/lvim/lsp/providers/lua_ls.lua new file mode 100644 index 0000000..952e04d --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/providers/lua_ls.lua @@ -0,0 +1,64 @@ +local default_workspace = { + library = { + vim.fn.expand "$VIMRUNTIME", + get_lvim_base_dir(), + require("neodev.config").types(), + "${3rd}/busted/library", + "${3rd}/luassert/library", + "${3rd}/luv/library", + }, + + maxPreload = 5000, + preloadFileSize = 10000, +} + +local add_packages_to_workspace = function(packages, config) + -- config.settings.Lua = config.settings.Lua or { workspace = default_workspace } + local runtimedirs = vim.api.nvim__get_runtime({ "lua" }, true, { is_lua = true }) + local workspace = config.settings.Lua.workspace + for _, v in pairs(runtimedirs) do + for _, pack in ipairs(packages) do + if v:match(pack) and not vim.tbl_contains(workspace.library, v) then + table.insert(workspace.library, v) + end + end + end +end + +local lspconfig = require "lspconfig" + +local make_on_new_config = function(on_new_config, _) + return lspconfig.util.add_hook_before(on_new_config, function(new_config, _) + local server_name = new_config.name + + if server_name ~= "lua_ls" then + return + end + local plugins = { "plenary.nvim", "telescope.nvim", "nvim-treesitter", "LuaSnip" } + add_packages_to_workspace(plugins, new_config) + end) +end + +lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, { + on_new_config = make_on_new_config(lspconfig.util.default_config.on_new_config), +}) + +local opts = { + settings = { + Lua = { + telemetry = { enable = false }, + runtime = { + version = "LuaJIT", + special = { + reload = "require", + }, + }, + diagnostics = { + globals = { "vim", "lvim", "reload" }, + }, + workspace = default_workspace, + }, + }, +} + +return opts diff --git a/mac/.config/LunarVim/lua/lvim/lsp/providers/tailwindcss.lua b/mac/.config/LunarVim/lua/lvim/lsp/providers/tailwindcss.lua new file mode 100644 index 0000000..ebf0a1c --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/providers/tailwindcss.lua @@ -0,0 +1,15 @@ +local opts = { + root_dir = function(fname) + local util = require "lspconfig/util" + return util.root_pattern( + "tailwind.config.js", + "tailwind.config.ts", + "tailwind.config.cjs", + "tailwind.js", + "tailwind.ts", + "tailwind.cjs" + )(fname) + end, +} + +return opts diff --git a/mac/.config/LunarVim/lua/lvim/lsp/providers/vuels.lua b/mac/.config/LunarVim/lua/lvim/lsp/providers/vuels.lua new file mode 100644 index 0000000..326363f --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/providers/vuels.lua @@ -0,0 +1,26 @@ +local opts = { + setup = { + root_dir = function(fname) + local util = require "lvim.lspconfig/util" + return util.root_pattern "package.json"(fname) or util.root_pattern "vue.config.js"(fname) or vim.fn.getcwd() + end, + init_options = { + config = { + vetur = { + completion = { + autoImport = true, + tagCasing = "kebab", + useScaffoldSnippets = true, + }, + useWorkspaceDependencies = true, + validation = { + script = true, + style = true, + template = true, + }, + }, + }, + }, + }, +} +return opts diff --git a/mac/.config/LunarVim/lua/lvim/lsp/providers/yamlls.lua b/mac/.config/LunarVim/lua/lvim/lsp/providers/yamlls.lua new file mode 100644 index 0000000..c9764fc --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/providers/yamlls.lua @@ -0,0 +1,16 @@ +local opts = { + settings = { + yaml = { + hover = true, + completion = true, + validate = true, + schemaStore = { + enable = true, + url = "https://www.schemastore.org/api/json/catalog.json", + }, + schemas = require("schemastore").yaml.schemas(), + }, + }, +} + +return opts diff --git a/mac/.config/LunarVim/lua/lvim/lsp/templates.lua b/mac/.config/LunarVim/lua/lvim/lsp/templates.lua new file mode 100644 index 0000000..4a65fac --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/templates.lua @@ -0,0 +1,76 @@ +local M = {} + +local Log = require "lvim.core.log" +local utils = require "lvim.utils" +local lvim_lsp_utils = require "lvim.lsp.utils" + +local ftplugin_dir = lvim.lsp.templates_dir + +local join_paths = _G.join_paths + +function M.remove_template_files() + -- remove any outdated files + for _, file in ipairs(vim.fn.glob(ftplugin_dir .. "/*.lua", 1, 1)) do + vim.fn.delete(file) + vim.wait(10) + end +end + +local skipped_filetypes = lvim.lsp.automatic_configuration.skipped_filetypes +local skipped_servers = lvim.lsp.automatic_configuration.skipped_servers + +---Check if we should skip generating an ftplugin file based on the server_name +---@param server_name string name of a valid language server +local function should_skip(server_name) + return vim.tbl_contains(skipped_servers, server_name) +end + +---Generates an ftplugin file based on the server_name in the selected directory +---@param server_name string name of a valid language server, e.g. pyright, gopls, tsserver, etc. +---@param dir string the full path to the desired directory +function M.generate_ftplugin(server_name, dir) + if should_skip(server_name) then + return + end + + -- get the supported filetypes and remove any ignored ones + local filetypes = vim.tbl_filter(function(ft) + return not vim.tbl_contains(skipped_filetypes, ft) + end, lvim_lsp_utils.get_supported_filetypes(server_name) or {}) + + if not filetypes then + return + end + + for _, filetype in ipairs(filetypes) do + filetype = filetype:match "%.([^.]*)$" or filetype + local filename = join_paths(dir, filetype .. ".lua") + local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name) + -- print("using setup_cmd: " .. setup_cmd) + -- overwrite the file completely + utils.write_file(filename, setup_cmd .. "\n", "a") + end +end + +---Generates ftplugin files based on a list of server_names +---The files are generated to a runtimepath: "$LUNARVIM_RUNTIME_DIR/site/after/ftplugin/template.lua" +---@param servers_names? table list of servers to be enabled. Will add all by default +function M.generate_templates(servers_names) + servers_names = servers_names or lvim_lsp_utils.get_supported_servers() + + Log:debug "Templates installation in progress" + + M.remove_template_files() + + -- create the directory if it didn't exist + if not utils.is_directory(lvim.lsp.templates_dir) then + vim.fn.mkdir(ftplugin_dir, "p") + end + + for _, server in ipairs(servers_names) do + M.generate_ftplugin(server, ftplugin_dir) + end + Log:debug "Templates installation is complete" +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/lsp/utils.lua b/mac/.config/LunarVim/lua/lvim/lsp/utils.lua new file mode 100644 index 0000000..0d9bcd7 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/lsp/utils.lua @@ -0,0 +1,185 @@ +local M = {} + +local tbl = require "lvim.utils.table" +local Log = require "lvim.core.log" + +function M.is_client_active(name) + local clients = vim.lsp.get_clients() + return tbl.find_first(clients, function(client) + return client.name == name + end) +end + +function M.get_active_clients_by_ft(filetype) + local matches = {} + local clients = vim.lsp.get_clients() + for _, client in pairs(clients) do + local supported_filetypes = client.config.filetypes or {} + if client.name ~= "null-ls" and vim.tbl_contains(supported_filetypes, filetype) then + table.insert(matches, client) + end + end + return matches +end + +function M.get_client_capabilities(client_id) + local client = vim.lsp.get_client_by_id(tonumber(client_id)) + if not client then + Log:warn("Unable to determine client from client_id: " .. client_id) + return + end + + local enabled_caps = {} + for capability, status in pairs(client.server_capabilities) do + if status == true then + table.insert(enabled_caps, capability) + end + end + + return enabled_caps +end + +---Get supported filetypes per server +---@param server_name string can be any server supported by nvim-lsp-installer +---@return string[] supported filestypes as a list of strings +function M.get_supported_filetypes(server_name) + local status_ok, config = pcall(require, ("lspconfig.server_configurations.%s"):format(server_name)) + if not status_ok then + return {} + end + + return config.default_config.filetypes or {} +end + +---Get supported servers per filetype +---@param filter { filetype: string | string[] }?: (optional) Used to filter the list of server names. +---@return string[] list of names of supported servers +function M.get_supported_servers(filter) + -- force synchronous mode, see: |mason-registry.refresh()| + require("mason-registry").refresh() + require("mason-registry").get_all_packages() + + local _, supported_servers = pcall(function() + return require("mason-lspconfig").get_available_servers(filter) + end) + return supported_servers or {} +end + +---Get all supported filetypes by nvim-lsp-installer +---@return string[] supported filestypes as a list of strings +function M.get_all_supported_filetypes() + local status_ok, filetype_server_map = pcall(require, "mason-lspconfig.mappings.filetype") + if not status_ok then + return {} + end + return vim.tbl_keys(filetype_server_map or {}) +end + +function M.setup_document_highlight(client, bufnr) + if lvim.builtin.illuminate.active then + Log:debug "skipping setup for document_highlight, illuminate already active" + return + end + local status_ok, highlight_supported = pcall(function() + return client.supports_method "textDocument/documentHighlight" + end) + if not status_ok or not highlight_supported then + return + end + local group = "lsp_document_highlight" + local hl_events = { "CursorHold", "CursorHoldI" } + + local ok, hl_autocmds = pcall(vim.api.nvim_get_autocmds, { + group = group, + buffer = bufnr, + event = hl_events, + }) + + if ok and #hl_autocmds > 0 then + return + end + + vim.api.nvim_create_augroup(group, { clear = false }) + vim.api.nvim_create_autocmd(hl_events, { + group = group, + buffer = bufnr, + callback = vim.lsp.buf.document_highlight, + }) + vim.api.nvim_create_autocmd("CursorMoved", { + group = group, + buffer = bufnr, + callback = vim.lsp.buf.clear_references, + }) +end + +function M.setup_document_symbols(client, bufnr) + vim.g.navic_silence = false -- can be set to true to suppress error + local symbols_supported = client.supports_method "textDocument/documentSymbol" + if not symbols_supported then + Log:debug("skipping setup for document_symbols, method not supported by " .. client.name) + return + end + local status_ok, navic = pcall(require, "nvim-navic") + if status_ok then + navic.attach(client, bufnr) + end +end + +function M.setup_codelens_refresh(client, bufnr) + local status_ok, codelens_supported = pcall(function() + return client.supports_method "textDocument/codeLens" + end) + if not status_ok or not codelens_supported then + return + end + local group = "lsp_code_lens_refresh" + local cl_events = { "BufEnter", "InsertLeave" } + local ok, cl_autocmds = pcall(vim.api.nvim_get_autocmds, { + group = group, + buffer = bufnr, + event = cl_events, + }) + + if ok and #cl_autocmds > 0 then + return + end + vim.api.nvim_create_augroup(group, { clear = false }) + vim.api.nvim_create_autocmd(cl_events, { + group = group, + buffer = bufnr, + callback = function() + vim.lsp.codelens.refresh { bufnr = bufnr } + end, + }) +end + +---filter passed to vim.lsp.buf.format +---always selects null-ls if it's available and caches the value per buffer +---@param client table client attached to a buffer +---@return boolean if client matches +function M.format_filter(client) + local filetype = vim.bo.filetype + local n = require "null-ls" + local s = require "null-ls.sources" + local method = n.methods.FORMATTING + local available_formatters = s.get_available(filetype, method) + + if #available_formatters > 0 then + return client.name == "null-ls" + elseif client.supports_method "textDocument/formatting" then + return true + else + return false + end +end + +---Simple wrapper for vim.lsp.buf.format() to provide defaults +---@param opts table|nil +function M.format(opts) + opts = opts or {} + opts.filter = opts.filter or M.format_filter + + return vim.lsp.buf.format(opts) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/plugin-loader.lua b/mac/.config/LunarVim/lua/lvim/plugin-loader.lua new file mode 100644 index 0000000..485b8b3 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/plugin-loader.lua @@ -0,0 +1,138 @@ +local plugin_loader = {} + +local utils = require "lvim.utils" +local Log = require "lvim.core.log" +local join_paths = utils.join_paths + +local plugins_dir = join_paths(get_runtime_dir(), "site", "pack", "lazy", "opt") + +function plugin_loader.init(opts) + opts = opts or {} + + local lazy_install_dir = opts.install_path + or join_paths(vim.fn.stdpath "data", "site", "pack", "lazy", "opt", "lazy.nvim") + + if not utils.is_directory(lazy_install_dir) then + print "Initializing first time setup" + local core_plugins_dir = join_paths(get_lvim_base_dir(), "plugins") + if utils.is_directory(core_plugins_dir) then + vim.fn.mkdir(plugins_dir, "p") + vim.fn.delete(plugins_dir, "rf") + require("lvim.utils").fs_copy(core_plugins_dir, plugins_dir) + else + vim.fn.system { + "git", + "clone", + "--branch=stable", + "https://github.com/folke/lazy.nvim.git", + lazy_install_dir, + } + + local default_snapshot_path = join_paths(get_lvim_base_dir(), "snapshots", "default.json") + local snapshot = assert(vim.fn.json_decode(vim.fn.readfile(default_snapshot_path))) + vim.fn.system { + "git", + "-C", + lazy_install_dir, + "checkout", + snapshot["lazy.nvim"].commit, + } + end + + vim.api.nvim_create_autocmd("User", { pattern = "LazyDone", callback = require("lvim.lsp").setup }) + end + + local rtp = vim.opt.rtp:get() + local base_dir = (vim.env.LUNARVIM_BASE_DIR or get_runtime_dir() .. "/lvim"):gsub("\\", "/") + local idx_base = #rtp + 1 + for i, path in ipairs(rtp) do + path = path:gsub("\\", "/") + if path == base_dir then + idx_base = i + 1 + break + end + end + table.insert(rtp, idx_base, lazy_install_dir) + table.insert(rtp, idx_base + 1, join_paths(plugins_dir, "*")) + vim.opt.rtp = rtp + + pcall(function() + -- set a custom path for lazy's cache + local lazy_cache = require "lazy.core.cache" + lazy_cache.path = join_paths(get_cache_dir(), "lazy", "luac") + end) +end + +function plugin_loader.reload(spec) + local Config = require "lazy.core.config" + local lazy = require "lazy" + + -- TODO: reset cache? and unload plugins? + + Config.spec = spec + + require("lazy.core.plugin").load(true) + require("lazy.core.plugin").update_state() + + local not_installed_plugins = vim.tbl_filter(function(plugin) + return not plugin._.installed + end, Config.plugins) + + require("lazy.manage").clear() + + if #not_installed_plugins > 0 then + lazy.install { wait = true } + end + + if #Config.to_clean > 0 then + -- TODO: set show to true when lazy shows something useful on clean + lazy.clean { wait = true, show = false } + end +end + +function plugin_loader.load(configurations) + Log:debug "loading plugins configuration" + local lazy_available, lazy = pcall(require, "lazy") + if not lazy_available then + Log:warn "skipping loading plugins until lazy.nvim is installed" + return + end + + -- remove plugins from rtp before loading lazy, so that all plugins won't be loaded on startup + vim.opt.runtimepath:remove(join_paths(plugins_dir, "*")) + + local status_ok = xpcall(function() + table.insert(lvim.lazy.opts.install.colorscheme, 1, lvim.colorscheme) + lazy.setup(configurations, lvim.lazy.opts) + end, debug.traceback) + + if not status_ok then + Log:warn "problems detected while loading plugins' configurations" + Log:trace(debug.traceback()) + end +end + +function plugin_loader.get_core_plugins() + local names = {} + local plugins = require "lvim.plugins" + local get_name = require("lazy.core.plugin").Spec.get_name + for _, spec in pairs(plugins) do + if spec.enabled == true or spec.enabled == nil then + table.insert(names, get_name(spec[1])) + end + end + return names +end + +function plugin_loader.sync_core_plugins() + local core_plugins = plugin_loader.get_core_plugins() + Log:trace(string.format("Syncing core plugins: [%q]", table.concat(core_plugins, ", "))) + require("lazy").update { wait = true, plugins = core_plugins } +end + +function plugin_loader.ensure_plugins() + Log:debug "calling lazy.install()" + require("lazy").install { wait = true } +end + +return plugin_loader diff --git a/mac/.config/LunarVim/lua/lvim/plugins.lua b/mac/.config/LunarVim/lua/lvim/plugins.lua new file mode 100644 index 0000000..4f76399 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/plugins.lua @@ -0,0 +1,385 @@ +-- local require = require("lvim.utils.require").require +local core_plugins = { + { "folke/lazy.nvim", tag = "stable" }, + { + "neovim/nvim-lspconfig", + lazy = true, + dependencies = { "mason-lspconfig.nvim", "nlsp-settings.nvim" }, + }, + { + "williamboman/mason-lspconfig.nvim", + cmd = { "LspInstall", "LspUninstall" }, + config = function() + require("mason-lspconfig").setup(lvim.lsp.installer.setup) + + -- automatic_installation is handled by lsp-manager + local settings = require "mason-lspconfig.settings" + settings.current.automatic_installation = false + end, + lazy = true, + event = "User FileOpened", + dependencies = "mason.nvim", + }, + { "tamago324/nlsp-settings.nvim", cmd = "LspSettings", lazy = true }, + { "nvimtools/none-ls.nvim", lazy = true }, + { + "williamboman/mason.nvim", + config = function() + require("lvim.core.mason").setup() + end, + cmd = { "Mason", "MasonInstall", "MasonUninstall", "MasonUninstallAll", "MasonLog" }, + build = function() + pcall(function() + require("mason-registry").refresh() + end) + end, + event = "User FileOpened", + lazy = true, + }, + { + "folke/tokyonight.nvim", + lazy = not vim.startswith(lvim.colorscheme, "tokyonight"), + }, + { + "lunarvim/lunar.nvim", + lazy = lvim.colorscheme ~= "lunar", + }, + { "Tastyep/structlog.nvim", lazy = true }, + { "nvim-lua/plenary.nvim", cmd = { "PlenaryBustedFile", "PlenaryBustedDirectory" }, lazy = true }, + -- Telescope + { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + config = function() + require("lvim.core.telescope").setup() + end, + dependencies = { "telescope-fzf-native.nvim" }, + lazy = true, + cmd = "Telescope", + enabled = lvim.builtin.telescope.active, + }, + { "nvim-telescope/telescope-fzf-native.nvim", build = "make", lazy = true, enabled = lvim.builtin.telescope.active }, + -- Install nvim-cmp, and buffer source as a dependency + { + "hrsh7th/nvim-cmp", + config = function() + if lvim.builtin.cmp then + require("lvim.core.cmp").setup() + end + end, + event = { "InsertEnter", "CmdlineEnter" }, + dependencies = { + "cmp-nvim-lsp", + "cmp_luasnip", + "cmp-buffer", + "cmp-path", + "cmp-cmdline", + }, + }, + { "hrsh7th/cmp-nvim-lsp", lazy = true }, + { "saadparwaiz1/cmp_luasnip", lazy = true }, + { "hrsh7th/cmp-buffer", lazy = true }, + { "hrsh7th/cmp-path", lazy = true }, + { + "hrsh7th/cmp-cmdline", + lazy = true, + enabled = lvim.builtin.cmp and lvim.builtin.cmp.cmdline.enable or false, + }, + { + "L3MON4D3/LuaSnip", + config = function() + local utils = require "lvim.utils" + local paths = {} + if lvim.builtin.luasnip.sources.friendly_snippets then + paths[#paths + 1] = utils.join_paths(get_runtime_dir(), "site", "pack", "lazy", "opt", "friendly-snippets") + end + local user_snippets = utils.join_paths(get_config_dir(), "snippets") + if utils.is_directory(user_snippets) then + paths[#paths + 1] = user_snippets + end + require("luasnip.loaders.from_lua").lazy_load() + require("luasnip.loaders.from_vscode").lazy_load { + paths = paths, + } + require("luasnip.loaders.from_snipmate").lazy_load() + end, + event = "InsertEnter", + dependencies = { + "friendly-snippets", + }, + }, + { "rafamadriz/friendly-snippets", lazy = true, cond = lvim.builtin.luasnip.sources.friendly_snippets }, + { + "folke/neodev.nvim", + lazy = true, + }, + + -- Autopairs + { + "windwp/nvim-autopairs", + event = "InsertEnter", + config = function() + require("lvim.core.autopairs").setup() + end, + enabled = lvim.builtin.autopairs.active, + dependencies = { "nvim-treesitter/nvim-treesitter", "hrsh7th/nvim-cmp" }, + }, + + -- Treesitter + { + "nvim-treesitter/nvim-treesitter", + -- run = ":TSUpdate", + config = function() + local utils = require "lvim.utils" + local path = utils.join_paths(get_runtime_dir(), "site", "pack", "lazy", "opt", "nvim-treesitter") + vim.opt.rtp:prepend(path) -- treesitter needs to be before nvim's runtime in rtp + require("lvim.core.treesitter").setup() + end, + cmd = { + "TSInstall", + "TSUninstall", + "TSUpdate", + "TSUpdateSync", + "TSInstallInfo", + "TSInstallSync", + "TSInstallFromGrammar", + }, + event = "User FileOpened", + }, + { + -- Lazy loaded by Comment.nvim pre_hook + "JoosepAlviste/nvim-ts-context-commentstring", + lazy = true, + }, + + -- NvimTree + { + "nvim-tree/nvim-tree.lua", + config = function() + require("lvim.core.nvimtree").setup() + end, + enabled = lvim.builtin.nvimtree.active, + cmd = { "NvimTreeToggle", "NvimTreeOpen", "NvimTreeFocus", "NvimTreeFindFileToggle" }, + event = "User DirOpened", + }, + -- Lir + { + "tamago324/lir.nvim", + config = function() + require("lvim.core.lir").setup() + end, + enabled = lvim.builtin.lir.active, + event = "User DirOpened", + }, + { + "lewis6991/gitsigns.nvim", + config = function() + require("lvim.core.gitsigns").setup() + end, + event = "User FileOpened", + cmd = "Gitsigns", + enabled = lvim.builtin.gitsigns.active, + }, + + -- Whichkey + { + "folke/which-key.nvim", + config = function() + require("lvim.core.which-key").setup() + end, + cmd = "WhichKey", + event = "VeryLazy", + enabled = lvim.builtin.which_key.active, + }, + + -- Comments + { + "numToStr/Comment.nvim", + config = function() + require("lvim.core.comment").setup() + end, + keys = { { "gc", mode = { "n", "v" } }, { "gb", mode = { "n", "v" } } }, + event = "User FileOpened", + enabled = lvim.builtin.comment.active, + }, + + -- project.nvim + { + "ahmedkhalf/project.nvim", + config = function() + require("lvim.core.project").setup() + end, + enabled = lvim.builtin.project.active, + event = "VimEnter", + cmd = "Telescope projects", + }, + + -- Icons + { + "nvim-tree/nvim-web-devicons", + enabled = lvim.use_icons, + lazy = true, + }, + + -- Status Line and Bufferline + { + -- "hoob3rt/lualine.nvim", + "nvim-lualine/lualine.nvim", + -- "Lunarvim/lualine.nvim", + config = function() + require("lvim.core.lualine").setup() + end, + event = "VimEnter", + enabled = lvim.builtin.lualine.active, + }, + + -- breadcrumbs + { + "SmiteshP/nvim-navic", + config = function() + require("lvim.core.breadcrumbs").setup() + end, + event = "User FileOpened", + enabled = lvim.builtin.breadcrumbs.active, + }, + + { + "akinsho/bufferline.nvim", + config = function() + require("lvim.core.bufferline").setup() + end, + branch = "main", + event = "User FileOpened", + enabled = lvim.builtin.bufferline.active, + }, + + -- Debugging + { + "mfussenegger/nvim-dap", + config = function() + require("lvim.core.dap").setup() + end, + lazy = true, + dependencies = { + "rcarriga/nvim-dap-ui", + }, + enabled = lvim.builtin.dap.active, + }, + + -- Debugger user interface + { + "rcarriga/nvim-dap-ui", + config = function() + require("lvim.core.dap").setup_ui() + end, + lazy = true, + enabled = lvim.builtin.dap.active, + }, + + -- alpha + { + "goolord/alpha-nvim", + config = function() + require("lvim.core.alpha").setup() + end, + enabled = lvim.builtin.alpha.active, + event = "VimEnter", + }, + + -- Terminal + { + "akinsho/toggleterm.nvim", + branch = "main", + init = function() + require("lvim.core.terminal").init() + end, + config = function() + require("lvim.core.terminal").setup() + end, + cmd = { + "ToggleTerm", + "TermExec", + "ToggleTermToggleAll", + "ToggleTermSendCurrentLine", + "ToggleTermSendVisualLines", + "ToggleTermSendVisualSelection", + }, + keys = lvim.builtin.terminal.open_mapping, + enabled = lvim.builtin.terminal.active, + }, + + -- SchemaStore + { + "b0o/schemastore.nvim", + lazy = true, + }, + + { + "RRethy/vim-illuminate", + config = function() + require("lvim.core.illuminate").setup() + end, + event = "User FileOpened", + enabled = lvim.builtin.illuminate.active, + }, + + { + "lukas-reineke/indent-blankline.nvim", + config = function() + require("lvim.core.indentlines").setup() + end, + event = "User FileOpened", + enabled = lvim.builtin.indentlines.active, + }, + + { + "lunarvim/onedarker.nvim", + branch = "freeze", + config = function() + pcall(function() + if lvim and lvim.colorscheme == "onedarker" then + require("onedarker").setup() + lvim.builtin.lualine.options.theme = "onedarker" + end + end) + end, + lazy = lvim.colorscheme ~= "onedarker", + }, + + { + "lunarvim/bigfile.nvim", + config = function() + pcall(function() + require("bigfile").setup(lvim.builtin.bigfile.config) + end) + end, + enabled = lvim.builtin.bigfile.active, + dependencies = { "nvim-treesitter/nvim-treesitter" }, + event = { "FileReadPre", "BufReadPre", "User FileOpened" }, + }, +} + +local default_snapshot_path = join_paths(get_lvim_base_dir(), "snapshots", "default.json") +local content = vim.fn.readfile(default_snapshot_path) +local default_sha1 = assert(vim.fn.json_decode(content)) + +-- taken from <https://github.com/folke/lazy.nvim/blob/c7122d64cdf16766433588486adcee67571de6d0/lua/lazy/core/plugin.lua#L27> +local get_short_name = function(long_name) + local name = long_name:sub(-4) == ".git" and long_name:sub(1, -5) or long_name + local slash = name:reverse():find("/", 1, true) --[[@as number?]] + return slash and name:sub(#name - slash + 2) or long_name:gsub("%W+", "_") +end + +local get_default_sha1 = function(spec) + local short_name = get_short_name(spec[1]) + return default_sha1[short_name] and default_sha1[short_name].commit +end + +if not vim.env.LVIM_DEV_MODE then + -- Manually lock the commit hashes of core plugins + for _, spec in ipairs(core_plugins) do + spec["commit"] = get_default_sha1(spec) + end +end + +return core_plugins diff --git a/mac/.config/LunarVim/lua/lvim/utils.lua b/mac/.config/LunarVim/lua/lvim/utils.lua new file mode 100644 index 0000000..5e49906 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/utils.lua @@ -0,0 +1,132 @@ +local M = {} +local uv = vim.loop + +-- recursive Print (structure, limit, separator) +local function r_inspect_settings(structure, limit, separator) + limit = limit or 100 -- default item limit + separator = separator or "." -- indent string + if limit < 1 then + print "ERROR: Item limit reached." + return limit - 1 + end + if structure == nil then + io.write("-- O", separator:sub(2), " = nil\n") + return limit - 1 + end + local ts = type(structure) + + if ts == "table" then + for k, v in pairs(structure) do + -- replace non alpha keys with ["key"] + if tostring(k):match "[^%a_]" then + k = '["' .. tostring(k) .. '"]' + end + limit = r_inspect_settings(v, limit, separator .. "." .. tostring(k)) + if limit < 0 then + break + end + end + return limit + end + + if ts == "string" then + -- escape sequences + structure = string.format("%q", structure) + end + separator = separator:gsub("%.%[", "%[") + if type(structure) == "function" then + -- don't print functions + io.write("-- lvim", separator:sub(2), " = function ()\n") + else + io.write("lvim", separator:sub(2), " = ", tostring(structure), "\n") + end + return limit - 1 +end + +function M.generate_settings() + -- Opens a file in append mode + local file = io.open("lv-settings.lua", "w") + + -- sets the default output file as test.lua + io.output(file) + + -- write all `lvim` related settings to `lv-settings.lua` file + r_inspect_settings(lvim, 10000, ".") + + -- closes the open file + io.close(file) +end + +--- Returns a table with the default values that are missing. +--- either parameter can be empty. +--@param config (table) table containing entries that take priority over defaults +--@param default_config (table) table contatining default values if found +function M.apply_defaults(config, default_config) + config = config or {} + default_config = default_config or {} + local new_config = vim.tbl_deep_extend("keep", vim.empty_dict(), config) + new_config = vim.tbl_deep_extend("keep", new_config, default_config) + return new_config +end + +--- Checks whether a given path exists and is a file. +--@param path (string) path to check +--@returns (bool) +function M.is_file(path) + local stat = uv.fs_stat(path) + return stat and stat.type == "file" or false +end + +--- Checks whether a given path exists and is a directory +--@param path (string) path to check +--@returns (bool) +function M.is_directory(path) + local stat = uv.fs_stat(path) + return stat and stat.type == "directory" or false +end + +M.join_paths = _G.join_paths + +---Write data to a file +---@param path string can be full or relative to `cwd` +---@param txt string|table text to be written, uses `vim.inspect` internally for tables +---@param flag string used to determine access mode, common flags: "w" for `overwrite` or "a" for `append` +function M.write_file(path, txt, flag) + local data = type(txt) == "string" and txt or vim.inspect(txt) + uv.fs_open(path, flag, 438, function(open_err, fd) + assert(not open_err, open_err) + uv.fs_write(fd, data, -1, function(write_err) + assert(not write_err, write_err) + uv.fs_close(fd, function(close_err) + assert(not close_err, close_err) + end) + end) + end) +end + +---Copies a file or directory recursively +---@param source string +---@param destination string +function M.fs_copy(source, destination) + local source_stats = assert(vim.loop.fs_stat(source)) + + if source_stats.type == "file" then + assert(vim.loop.fs_copyfile(source, destination)) + return + elseif source_stats.type == "directory" then + local handle = assert(vim.loop.fs_scandir(source)) + + assert(vim.loop.fs_mkdir(destination, source_stats.mode)) + + while true do + local name = vim.loop.fs_scandir_next(handle) + if not name then + break + end + + M.fs_copy(M.join_paths(source, name), M.join_paths(destination, name)) + end + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/utils/git.lua b/mac/.config/LunarVim/lua/lvim/utils/git.lua new file mode 100644 index 0000000..d5f1d92 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/utils/git.lua @@ -0,0 +1,152 @@ +local M = {} + +local Log = require "lvim.core.log" +local fmt = string.format +local if_nil = vim.F.if_nil + +local function git_cmd(opts) + local plenary_loaded, Job = pcall(require, "plenary.job") + if not plenary_loaded then + return 1, { "" } + end + + opts = opts or {} + opts.cwd = opts.cwd or get_lvim_base_dir() + + local stderr = {} + local stdout, ret = Job:new({ + command = "git", + args = opts.args, + cwd = opts.cwd, + on_stderr = function(_, data) + table.insert(stderr, data) + end, + }):sync(10000) + + if not vim.tbl_isempty(stderr) then + Log:debug(stderr) + end + + if not vim.tbl_isempty(stdout) then + Log:debug(stdout) + end + + return ret, stdout, stderr +end + +local function safe_deep_fetch() + local ret, result, error = git_cmd { args = { "rev-parse", "--is-shallow-repository" } } + if ret ~= 0 then + Log:error(vim.inspect(error)) + return + end + -- git fetch --unshallow will cause an error on a complete clone + local fetch_mode = result[1] == "true" and "--unshallow" or "--all" + ret = git_cmd { args = { "fetch", fetch_mode } } + if ret ~= 0 then + Log:error(fmt "Git fetch %s failed! Please pull the changes manually in %s", fetch_mode, get_lvim_base_dir()) + return + end + if fetch_mode == "--unshallow" then + ret = git_cmd { args = { "remote", "set-branches", "origin", "*" } } + if ret ~= 0 then + Log:error(fmt "Git fetch %s failed! Please pull the changes manually in %s", fetch_mode, get_lvim_base_dir()) + return + end + end + return true +end + +---pulls the latest changes from github +function M.update_base_lvim() + Log:info "Checking for updates" + + if not vim.loop.fs_access(get_lvim_base_dir(), "w") then + Log:warn(fmt("Lunarvim update aborted! cannot write to %s", get_lvim_base_dir())) + return + end + + if not safe_deep_fetch() then + return + end + + local ret + + ret = git_cmd { args = { "diff", "--quiet", "@{upstream}" } } + if ret == 0 then + Log:info "LunarVim is already up-to-date" + return + end + + ret = git_cmd { args = { "merge", "--ff-only", "--progress" } } + if ret ~= 0 then + Log:error("Update failed! Please pull the changes manually in " .. get_lvim_base_dir()) + return + end + + return true +end + +---Switch Lunarvim to the specified development branch +---@param branch string +function M.switch_lvim_branch(branch) + if not safe_deep_fetch() then + return + end + local args = { "switch", branch } + + if branch:match "^[0-9]" then + -- avoids producing an error for tags + vim.list_extend(args, { "--detach" }) + end + + local ret = git_cmd { args = args } + if ret ~= 0 then + Log:error "Unable to switch branches! Check the log for further information" + return + end + return true +end + +---Get the current Lunarvim development branch +---@return string|nil +function M.get_lvim_branch() + local _, results = git_cmd { args = { "rev-parse", "--abbrev-ref", "HEAD" } } + local branch = if_nil(results[1], "") + return branch +end + +---Get currently checked-out tag of Lunarvim +---@return string +function M.get_lvim_tag() + local args = { "describe", "--tags", "--abbrev=0" } + + local _, results = git_cmd { args = args } + local tag = if_nil(results[1], "") + return tag +end + +---Get the description of currently checked-out commit of Lunarvim +---@return string|nil +function M.get_lvim_description() + local _, results = git_cmd { args = { "describe", "--dirty", "--always" } } + + local description = if_nil(results[1], M.get_lvim_branch()) + return description +end + +---Get currently running version of Lunarvim +---@return string +function M.get_lvim_version() + local current_branch = M.get_lvim_branch() + + local lvim_version + if current_branch ~= "HEAD" or "" then + lvim_version = current_branch .. "-" .. M.get_lvim_description() + else + lvim_version = "v" .. M.get_lvim_tag() + end + return lvim_version +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/utils/hooks.lua b/mac/.config/LunarVim/lua/lvim/utils/hooks.lua new file mode 100644 index 0000000..2bf2ff0 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/utils/hooks.lua @@ -0,0 +1,76 @@ +local M = {} + +local Log = require "lvim.core.log" +local in_headless = #vim.api.nvim_list_uis() == 0 +local plugin_loader = require "lvim.plugin-loader" + +function M.run_pre_update() + Log:debug "Starting pre-update hook" +end + +function M.run_pre_reload() + Log:debug "Starting pre-reload hook" +end + +-- TODO: convert to lazy.nvim +-- function M.run_on_packer_complete() +-- -- FIXME(kylo252): nvim-tree.lua/lua/nvim-tree/view.lua:442: Invalid window id +-- vim.g.colors_name = lvim.colorscheme +-- pcall(vim.cmd.colorscheme, lvim.colorscheme) +-- end + +function M.run_post_reload() + Log:debug "Starting post-reload hook" +end + +---Reset any startup cache files used by lazy.nvim +---It also forces regenerating any template ftplugin files +---Tip: Useful for clearing any outdated settings +function M.reset_cache() + local lvim_modules = {} + for module, _ in pairs(package.loaded) do + if module:match "lvim.core" or module:match "lvim.lsp" then + package.loaded[module] = nil + table.insert(lvim_modules, module) + end + end + Log:trace(string.format("Cache invalidated for core modules: { %s }", table.concat(lvim_modules, ", "))) + require("lvim.lsp.templates").generate_templates() +end + +function M.run_post_update() + Log:debug "Starting post-update hook" + + if vim.fn.has "nvim-0.9" ~= 1 then + local compat_tag = "1.2.0" + vim.notify( + "Please upgrade your Neovim base installation. Newer version of Lunarvim requires v0.9+", + vim.log.levels.WARN + ) + vim.wait(1000) + local ret = reload("lvim.utils.git").switch_lvim_branch(compat_tag) + if ret then + vim.notify("Reverted to the last known compatible version: " .. compat_tag, vim.log.levels.WARN) + end + return + end + + M.reset_cache() + + Log:debug "Syncing core plugins" + plugin_loader.reload { reload "lvim.plugins", lvim.plugins } + plugin_loader.sync_core_plugins() + M.reset_cache() -- force cache clear and templates regen once more + + if not in_headless then + vim.schedule(function() + if package.loaded["nvim-treesitter"] then + vim.cmd [[ TSUpdateSync ]] + end + -- TODO: add a changelog + vim.notify("Update complete", vim.log.levels.INFO) + end) + end +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/utils/modules.lua b/mac/.config/LunarVim/lua/lvim/utils/modules.lua new file mode 100644 index 0000000..45cacfa --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/utils/modules.lua @@ -0,0 +1,122 @@ +local M = {} + +local Log = require "lvim.core.log" +-- revisit this +-- function prequire(package) +-- local status, lib = pcall(require, package) +-- if status then +-- return lib +-- else +-- vim.notify("Failed to require '" .. package .. "' from " .. debug.getinfo(2).source) +-- return nil +-- end +-- end + +local function _assign(old, new, k) + local otype = type(old[k]) + local ntype = type(new[k]) + -- print("hi") + if (otype == "thread" or otype == "userdata") or (ntype == "thread" or ntype == "userdata") then + vim.notify(string.format("warning: old or new attr %s type be thread or userdata", k)) + end + old[k] = new[k] +end + +local function _replace(old, new, repeat_tbl) + if repeat_tbl[old] then + return + end + repeat_tbl[old] = true + + local dellist = {} + for k, _ in pairs(old) do + if not new[k] then + table.insert(dellist, k) + end + end + for _, v in ipairs(dellist) do + old[v] = nil + end + + for k, _ in pairs(new) do + if not old[k] then + old[k] = new[k] + else + if type(old[k]) ~= type(new[k]) then + Log:debug( + string.format("Reloader: mismatch between old [%s] and new [%s] type for [%s]", type(old[k]), type(new[k]), k) + ) + _assign(old, new, k) + else + if type(old[k]) == "table" then + _replace(old[k], new[k], repeat_tbl) + else + _assign(old, new, k) + end + end + end + end +end + +M.require_clean = function(m) + package.loaded[m] = nil + _G[m] = nil + local _, module = pcall(require, m) + return module +end + +M.require_safe = function(mod) + local status_ok, module = pcall(require, mod) + if not status_ok then + local trace = debug.getinfo(2, "SL") + local shorter_src = trace.short_src + local lineinfo = shorter_src .. ":" .. (trace.currentline or trace.linedefined) + local msg = string.format("%s : skipped loading [%s]", lineinfo, mod) + Log:debug(msg) + end + return module +end + +M.reload = function(mod) + if not package.loaded[mod] then + return M.require_safe(mod) + end + + local old = package.loaded[mod] + package.loaded[mod] = nil + local new = M.require_safe(mod) + + if type(old) == "table" and type(new) == "table" then + local repeat_tbl = {} + _replace(old, new, repeat_tbl) + end + + package.loaded[mod] = old + return old +end + +-- code from <https://github.com/tjdevries/lazy-require.nvim/blob/bb626818ebc175b8c595846925fd96902b1ce02b/lua/lazy-require.lua#L25> +function M.require_on_index(require_path) + return setmetatable({}, { + __index = function(_, key) + return require(require_path)[key] + end, + + __newindex = function(_, key, value) + require(require_path)[key] = value + end, + }) +end + +-- code from <https://github.com/tjdevries/lazy-require.nvim/blob/bb626818ebc175b8c595846925fd96902b1ce02b/lua/lazy-require.lua#L25> +function M.require_on_exported_call(require_path) + return setmetatable({}, { + __index = function(_, k) + return function(...) + return require(require_path)[k](...) + end + end, + }) +end + +return M diff --git a/mac/.config/LunarVim/lua/lvim/utils/table.lua b/mac/.config/LunarVim/lua/lvim/utils/table.lua new file mode 100644 index 0000000..1ac5949 --- /dev/null +++ b/mac/.config/LunarVim/lua/lvim/utils/table.lua @@ -0,0 +1,24 @@ +local Table = {} + +--- Find the first entry for which the predicate returns true. +-- @param t The table +-- @param predicate The function called for each entry of t +-- @return The entry for which the predicate returned True or nil +function Table.find_first(t, predicate) + for _, entry in pairs(t) do + if predicate(entry) then + return entry + end + end + return nil +end + +--- Check if the predicate returns True for at least one entry of the table. +-- @param t The table +-- @param predicate The function called for each entry of t +-- @return True if predicate returned True at least once, false otherwise +function Table.contains(t, predicate) + return Table.find_first(t, predicate) ~= nil +end + +return Table |
