Skip to content

Commit

Permalink
format lua
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 6, 2021
1 parent 75de462 commit 3fdea07
Show file tree
Hide file tree
Showing 18 changed files with 1,319 additions and 794 deletions.
370 changes: 228 additions & 142 deletions lua/packer.lua

Large diffs are not rendered by default.

36 changes: 23 additions & 13 deletions lua/packer/async.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Adapted from https://ms-jpq.github.io/neovim-async-tutorial/
local log = require('packer.log')
local log = require 'packer.log'
local yield = coroutine.yield
local resume = coroutine.resume
local thread_create = coroutine.create
Expand Down Expand Up @@ -27,7 +27,7 @@ end

local function wrap(func)
return function(...)
local params = {...}
local params = { ... }
return function(tick)
params[#params + 1] = tick
return func(unpack(params))
Expand All @@ -36,14 +36,16 @@ local function wrap(func)
end

local function join(...)
local thunks = {...}
local thunks = { ... }
local thunk_all = function(s)
if #thunks == 0 then return s() end
if #thunks == 0 then
return s()
end
local to_go = #thunks
local results = {}
for i, thunk in ipairs(thunks) do
local callback = function(...)
results[i] = {...}
results[i] = { ... }
if to_go == 1 then
s(unpack(results))
else
Expand All @@ -58,20 +60,24 @@ local function join(...)
return thunk_all
end

local function wait_all(...) return yield(join(...)) end
local function wait_all(...)
return yield(join(...))
end

local function pool(n, interrupt_check, ...)
local thunks = {...}
local thunks = { ... }
return function(s)
if #thunks == 0 then return s() end
local remaining = {select(n + 1, unpack(thunks))}
if #thunks == 0 then
return s()
end
local remaining = { select(n + 1, unpack(thunks)) }
local results = {}
local to_go = #thunks
local make_callback = nil
make_callback = function(idx, left)
local i = (left == nil) and idx or (idx + left)
return function(...)
results[i] = {...}
results[i] = { ... }
to_go = to_go - 1
if to_go == 0 then
s(unpack(results))
Expand All @@ -91,13 +97,17 @@ local function pool(n, interrupt_check, ...)
end
end

local function wait_pool(limit, ...) return yield(pool(limit, false, ...)) end
local function wait_pool(limit, ...)
return yield(pool(limit, false, ...))
end

local function interruptible_wait_pool(limit, interrupt_check, ...)
return yield(pool(limit, interrupt_check, ...))
end

local function main(f) vim.schedule(f) end
local function main(f)
vim.schedule(f)
end

local M = {
--- Wrapper for functions that do not take a callback to make async functions
Expand All @@ -116,7 +126,7 @@ local M = {
wrap = wrap,
--- Convenience function to ensure a function runs on the main "thread" (i.e. for functions which
-- use Neovim functions, etc.)
main = main
main = main,
}

return M
37 changes: 22 additions & 15 deletions lua/packer/clean.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local plugin_utils = require('packer.plugin_utils')
local a = require('packer.async')
local display = require('packer.display')
local log = require('packer.log')
local util = require('packer.util')
local plugin_utils = require 'packer.plugin_utils'
local a = require 'packer.async'
local display = require 'packer.display'
local log = require 'packer.log'
local util = require 'packer.util'

local await = a.wait
local async = a.sync
Expand All @@ -13,14 +13,13 @@ local PLUGIN_OPTIONAL_LIST = 1
local PLUGIN_START_LIST = 2

local function is_dirty(plugin, typ)
return (plugin.opt and typ == PLUGIN_START_LIST)
or (not plugin.opt and typ == PLUGIN_OPTIONAL_LIST)
return (plugin.opt and typ == PLUGIN_START_LIST) or (not plugin.opt and typ == PLUGIN_OPTIONAL_LIST)
end

-- Find and remove any plugins not currently configured for use
local clean_plugins = function(_, plugins, fs_state, results)
return async(function()
log.debug('Starting clean')
log.debug 'Starting clean'
local dirty_plugins = {}
results = results or {}
results.removals = results.removals or {}
Expand Down Expand Up @@ -54,32 +53,40 @@ local clean_plugins = function(_, plugins, fs_state, results)

-- Any path which was not set to `nil` above will be set to dirty here
local function mark_remaining_as_dirty(plugin_list)
for path, _ in pairs(plugin_list) do dirty_plugins[#dirty_plugins + 1] = path end
for path, _ in pairs(plugin_list) do
dirty_plugins[#dirty_plugins + 1] = path
end
end

mark_remaining_as_dirty(opt_plugins)
mark_remaining_as_dirty(start_plugins)
if next(dirty_plugins) then
local lines = {}
for _, path in ipairs(dirty_plugins) do table.insert(lines, ' - ' .. path) end
for _, path in ipairs(dirty_plugins) do
table.insert(lines, ' - ' .. path)
end
await(a.main)
if await(display.ask_user('Removing the following directories. OK? (y/N)', lines)) then
results.removals = dirty_plugins
log.debug('Removed ' .. vim.inspect(dirty_plugins))
for _, path in ipairs(dirty_plugins) do
local result = vim.fn.delete(path, 'rf')
if result == -1 then log.warn('Could not remove ' .. path) end
if result == -1 then
log.warn('Could not remove ' .. path)
end
end
else
log.warn('Cleaning cancelled!')
log.warn 'Cleaning cancelled!'
end
else
log.info('Already clean!')
log.info 'Already clean!'
end
end)
end

local function cfg(_config) config = _config end
local function cfg(_config)
config = _config
end

local clean = setmetatable({cfg = cfg}, {__call = clean_plugins})
local clean = setmetatable({ cfg = cfg }, { __call = clean_plugins })
return clean
Loading

1 comment on commit 3fdea07

@wbthomason
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge diff because of the first time running stylua since switching from lua-format.

Please sign in to comment.