nvim: rm orphaned modules psoxizsh.{plugins.bootstrap,diagnostic}

these are superseded by lazy.nvim's superior bootstrap process, and
LazyVim's builtin diagnostic configuration
This commit is contained in:
Paul Stemmet 2024-08-08 12:06:58 +00:00
parent 5e80c28f26
commit ad7f34b624
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
3 changed files with 1 additions and 339 deletions

View File

@ -1,70 +0,0 @@
local au, keys = require 'psoxizsh.autocmd', require 'psoxizsh.key.map'
local D = vim.diagnostic
local M = setmetatable({}, { __call = function(self, args) self.setup(args) end })
local sign = function(o)
vim.fn.sign_define(o.name, {
texthl = o.name,
text = o.text,
numhl = ''
})
end
local DiagnosticFloat = function()
-- current, last diagnostic cursor position
local current = vim.api.nvim_win_get_cursor(0)
local last = vim.w.diagnostics_last_cursor or { nil, nil }
-- Show the popup diagnostics window,
-- but only once for the current cursor location (unless moved afterwards).
if not (current[1] == last[1] and current[2] == last[2]) then
vim.w.diagnostics_last_cursor = current
D.open_float({ focusable = false, scope = 'cursor' })
end
end
function M.config()
-- Setup signs
sign({ name = 'DiagnosticSignError', text = '' })
sign({ name = 'DiagnosticSignWarn', text = '' })
sign({ name = 'DiagnosticSignHint', text = '' })
sign({ name = 'DiagnosticSignInfo', text = '' })
-- Define base diagnostic configuration
D.config({
virtual_text = false,
signs = true,
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
border = 'rounded',
source = 'if_many',
header = '',
prefix = '',
},
})
end
-- Key maps
function M.keymaps()
keys.Global.N.DiagnosticPrev { action = D.goto_prev }
keys.Global.N.DiagnosticNext { action = D.goto_next }
end
function M.autocmds()
au.PsoxDiagnosticHover {
{ 'CursorHold', '*', DiagnosticFloat }
}
end
function M.setup(_)
M.config()
M.keymaps()
M.autocmds()
end
return M

View File

@ -1,24 +0,0 @@
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'
local repo_url = 'https://github.com/wbthomason/packer.nvim'
local strapped = nil
-- Bootstraps our package manager, ensuring it is present on the local system
local function bootstrap()
local should_install = fn.empty(fn.glob(install_path)) > 0
if should_install then
fn.system({'git', 'clone', '--depth', '1', repo_url, install_path})
end
return should_install
end
if not strapped then
strapped = bootstrap()
end
return function()
return strapped
end

View File

@ -1,245 +1 @@
local cmd, bootstrap, util = vim.cmd, require 'psoxizsh.plugins.bootstrap', require 'psoxizsh.util'
local cb_table = {}
local packer = nil
local EARLY, LATE = { early = 1, pre = 1 }, { post = 1, late = 1 }
-- Wrap the provided function in async context that will wait until all plugins have been initialized
local function defer_wrap(fn)
if bootstrap() then return fn end
return function(plugs)
local a = require 'plenary.async'
a.run(function()
-- Yield until packer's global plugin list is available
while _G.packer_plugins == nil do
a.util.sleep(100)
end
end, function()
fn(plugs)
end)
end
end
-- Plugins provides a hook based wrapper around packer.nvim, allowing
-- callers to register hooks at specific lifecycle events such as pre
-- and post plugin load.
--
-- A new, uninitialized one is provided upon requiring this module,
-- See :setup/1 and :init/0 for more on configuring and initializing
-- this object
local Plugins = { mt = {} }
-- Creates a new, uninitialized Plugins
--
-- You must call :init/0 (and likely :setup/1) before using this
-- object, though you can directly invoke the Plugins object as
-- you would :setup/1 as a convenience
function Plugins.new()
local m = {
_list = {},
_hooks = {},
}
setmetatable(m, Plugins.mt)
return m
end
-- Configures this Plugins, with the provided opts
--
-- You can provide a tables of hooks by name or { name, callback }
-- tuples.
--
-- In the former case, Plugins will create User <name> autocmds
-- when the lifecycle stage is hit, which you can register arbitrary
-- code to be invoked on.
--
-- In the latter, the provided callback fn will be invoked at the
-- lifecycle stage, with 'post' and 'late' hooks being provided the
-- current Plugins object as the first argument
--
-- @opts = {
-- hooks = {
-- early = name | { name, callback/0 }
-- pre = name | { name, callback/0 }
-- post = name | { name, callback/1 }
-- late = name | { name, callback/1 }
-- }
-- }
function Plugins.setup(self, opts)
opts = opts or {}
local hooks = opts.hooks or {}
self._hooks = vim.tbl_map(function(hk)
local t = type(hk)
if t == 'string' then return hk end
if t == 'table' then return hk[1] end
end, hooks)
local callbacks = vim.tbl_map(function(hk)
local t = type(hk[2])
if t == 'function' then return hk[2] end
end, hooks)
self:list_regen()
self:register_callbacks(callbacks)
return self
end
-- Invokes the plugin manager, and hooks any provided hooks as they become ready
--
-- Note, you shouldn't rerun this function, use :reload/0 instead if you want to
-- reload an existing Plugins
function Plugins.init(self)
self:do_hook 'early'
if packer == nil then
cmd [[packadd packer.nvim]]
packer = require 'packer'
packer.init {
max_jobs = 32
}
end
packer.reset()
self:do_hook 'pre'
for _, spec in ipairs(self:list()) do
packer.use(spec)
end
self:do_hook 'post'
self:do_hook 'late'
return self
end
-- Regenerate the plugin spec list, reloading the config if it has changed.
--
-- Note that this method *only* reloads the spec list, it does not reload
-- plugins, see :reload/0 for that
function Plugins.list_regen(self)
local plugs = util.mreload('psoxizsh.plugins.plug')
self._list = plugs(util.try_mconfig('plug'))
return self:list()
end
-- Return the current plugin list
function Plugins.list(self)
return self._list
end
-- Get the plugin spec for the provided @id.
--
-- The plugin id will be either the last component of the name, or if redefined by 'as',
-- whatever 'as' is.
--
-- Returns the spec if it exists, nil otherwise
function Plugins.get(self, id)
local needle = function(p)
local plugid = p.as and p.as or p[1] and p[1]:match("^.+/(.+)$")
return plugid == id
end
return vim.tbl_filter(needle, self:list())[1]
end
-- Check if the plugin @id exists in the current spec table
--
-- Returns true if it does, nil otherwise
function Plugins.has(self, id)
return self:get(id) and true or nil
end
-- Reload plugins, and rerun any registered hooks
function Plugins.reload(self)
self:list_regen()
self:init()
packer.compile()
end
-- Request the active Plugins to run the provided lifecycle's hook
--
-- Note that this may not run immediately, depending on current lifecycle
-- of underlying plugin manager
--
-- @name { 'early' | 'pre' | 'post' | 'late' }
function Plugins.do_hook(self, name)
if LATE[name] then
self:_post_hook(self._hooks[name])
elseif EARLY[name] then
self:_pre_hook(self._hooks[name])
end
end
-- Manually (re)register callbacks for any configured lifecycle hooks
--
-- Note that any hooks that were not registered in :setup/1 will be
-- silently ignored.
--
-- You may consider re-initializing the active Plugins via :setup/1:init/0
function Plugins.register_callbacks(self, callbacks)
_G._psoxizsh_plugins_cb = function(id) cb_table[id](self) end
cb_table = {}
cmd [[augroup PsoxConfigCallbacks]]
cmd [[autocmd!]]
for n, fn in pairs(callbacks) do
local id = self._hooks[n]
cb_table[id] = self:_make_callback(n, fn)
cmd(string.format('autocmd User %s call v:lua._psoxizsh_plugins_cb("%s")', id, id))
end
cmd [[augroup END]]
end
function Plugins._pre_hook(self, hook)
self:_dispatch_autocmd(hook)
end
function Plugins._post_hook(self, hook)
if bootstrap() and hook then
cmd [[augroup PsoxConfigBootstrap]]
cmd [[autocmd!]]
cmd [[autocmd VimEnter * ++once PackerSync]]
cmd [[augroup END]]
cmd ('augroup PsoxConfigDeferHook_' .. hook)
cmd ('autocmd!')
cmd ('autocmd User PackerCompileDone doautocmd User ' .. hook)
cmd ('augroup END')
else
self:_dispatch_autocmd(hook)
end
end
function Plugins._dispatch_autocmd(_, hook)
if hook then cmd('doautocmd User ' .. hook) end
end
function Plugins._make_callback(_, name, fn)
if LATE[name] then
return defer_wrap(fn)
else
return fn
end
end
-- Setup a convenience method for setting up + initializing a Plugins object
-- via directly calling the object with the opts that would normally be
-- provided to :setup/1
function Plugins.mt.__call(self, opts)
self:setup(opts):init()
end
-- Allow callers to access the underlying packer object
function Plugins.mt.__index(_, key)
return Plugins[key] or packer[key]
end
return Plugins.new()
return {}