Skip to content

Commit

Permalink
chore!: upgrade commons.nvim library (#251)
Browse files Browse the repository at this point in the history
docs: remove code coverage badge (#251)
  • Loading branch information
linrongbin16 authored Nov 22, 2024
1 parent a221c13 commit 606060e
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 824 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: JohnnyMorganz/stylua-action@v3
- uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --config-path .stylua.toml ./lua ./spec
- uses: mrcjkb/lua-typecheck-action@v0
- uses: stevearc/nvim-typecheck-action@v2
with:
directories: lua
path: lua
configpath: ".luarc.json"
- uses: cargo-bins/cargo-binstall@main
- name: Selene
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
echo $PWD
git clone --depth=1 https://github.com/linrongbin16/giturlparser.lua.git ~/.giturlparser.lua
cp ~/.giturlparser.lua/src/giturlparser.lua ./lua/gitlinker/giturlparser.lua
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ github.ref != 'refs/heads/master' }}
with:
commit_message: "chore(pr): auto-commit"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# gitlinker.nvim

<p>
<a href="https://github.com/neovim/neovim/releases/v0.9.0"><img alt="Neovim" src="https://img.shields.io/badge/require-0.9%2B-blue" /></a>
<a href="https://github.com/neovim/neovim/releases/"><img alt="Neovim" src="https://img.shields.io/badge/require-stable-blue" /></a>
<a href="https://github.com/linrongbin16/commons.nvim"><img alt="commons.nvim" src="https://img.shields.io/badge/power_by-commons.nvim-pink" /></a>
<a href="https://luarocks.org/modules/linrongbin16/gitlinker.nvim"><img alt="luarocks" src="https://img.shields.io/luarocks/v/linrongbin16/gitlinker.nvim" /></a>
<a href="https://github.com/linrongbin16/gitlinker.nvim/actions/workflows/ci.yml"><img alt="ci.yml" src="https://img.shields.io/github/actions/workflow/status/linrongbin16/gitlinker.nvim/ci.yml?label=ci" /></a>
<a href="https://app.codecov.io/github/linrongbin16/gitlinker.nvim"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/gitlinker.nvim/main?label=codecov" /></a>
<!-- <a href="https://app.codecov.io/github/linrongbin16/gitlinker.nvim"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/gitlinker.nvim/main?label=codecov" /></a> -->
</p>

> Maintained fork of [ruifm's gitlinker](https://github.com/ruifm/gitlinker.nvim), refactored with bug fixes, ssh host alias, blame support and other improvements.
Expand Down Expand Up @@ -66,9 +66,9 @@ PRs are welcomed for other git host websites!

> [!NOTE]
>
> This plugin keeps update with the latest stable Neovim version, supports until the last legacy version, while earlier versions are dropped for maintenance reason. For example at the time of writing (2024-08-20), stable is 0.10, last legacy is 0.9. Thus this plugin supports 0.9+.
> This plugin always supports the latest stable and (possible) nightly version.
- Neovim &ge; 0.9.
- Neovim &ge; 0.10.
- [git](https://git-scm.com/).
- [ssh](https://www.openssh.com/) (optional for resolve ssh host alias).
- [wslview](https://github.com/wslutilities/wslu) (optional for open browser from Windows wsl2).
Expand Down
2 changes: 1 addition & 1 deletion lua/gitlinker.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local tbl = require("gitlinker.commons.tbl")
local str = require("gitlinker.commons.str")
local num = require("gitlinker.commons.num")
local async = require("gitlinker.commons.async")
local LogLevels = require("gitlinker.commons.logging").LogLevels
local logging = require("gitlinker.commons.logging")

local async = require("gitlinker.async")
local configs = require("gitlinker.configs")
local range = require("gitlinker.range")
local linker = require("gitlinker.linker")
Expand Down
79 changes: 41 additions & 38 deletions lua/gitlinker/commons/async.lua → lua/gitlinker/async.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- Store all the async threads in a weak table so we don't prevent them from
-- being garbage collected
local handles = setmetatable({}, { __mode = 'k' })
local handles = setmetatable({}, { __mode = "k" })

local M = {}

Expand All @@ -28,10 +28,12 @@ function M.running()
end

local function is_Async_T(handle)
if handle
and type(handle) == 'table'
if
handle
and type(handle) == "table"
and vim.is_callable(handle.cancel)
and vim.is_callable(handle.is_cancelled) then
and vim.is_callable(handle.is_cancelled)
then
return true
end
end
Expand Down Expand Up @@ -63,35 +65,36 @@ end
--- @tparam any ... Arguments for func
--- @treturn async_t Handle
function M.run(func, callback, ...)
vim.validate {
func = { func, 'function' },
callback = { callback, 'function', true }
}
vim.validate({
func = { func, "function" },
callback = { callback, "function", true },
})

local co = coroutine.create(func)
local handle = Async_T.new(co)

local function step(...)
local ret = {coroutine.resume(co, ...)}
local ret = { coroutine.resume(co, ...) }
local ok = ret[1]

if not ok then
local err = ret[2]
error(string.format("The coroutine failed with this message:\n%s\n%s",
err, debug.traceback(co)))
error(
string.format("The coroutine failed with this message:\n%s\n%s", err, debug.traceback(co))
)
end

if coroutine.status(co) == 'dead' then
if coroutine.status(co) == "dead" then
if callback then
callback(unpack(ret, 4, table.maxn(ret)))
end
return
end

local nargs, fn = ret[2], ret[3]
local args = {select(4, unpack(ret))}
local args = { select(4, unpack(ret)) }

assert(type(fn) == 'function', "type error :: expected func")
assert(type(fn) == "function", "type error :: expected func")

args[nargs] = step

Expand All @@ -106,10 +109,10 @@ function M.run(func, callback, ...)
end

local function wait(argc, func, ...)
vim.validate {
argc = { argc, 'number' },
func = { func, 'function' },
}
vim.validate({
argc = { argc, "number" },
func = { func, "function" },
})

-- Always run the wrapped functions in xpcall and re-raise the error in the
-- coroutine. This makes pcall work as normal.
Expand All @@ -124,7 +127,7 @@ local function wait(argc, func, ...)
end, unpack(args, 1, argc))
end

local ret = {coroutine.yield(argc, pfunc, ...)}
local ret = { coroutine.yield(argc, pfunc, ...) }

local ok = ret[1]
if not ok then
Expand All @@ -141,12 +144,12 @@ end
--- @tparam function func callback style function to execute
--- @tparam any ... Arguments for func
function M.wait(...)
if type(select(1, ...)) == 'number' then
if type(select(1, ...)) == "number" then
return wait(...)
end

-- Assume argc is equal to the number of passed arguments.
return wait(select('#', ...) - 1, ...)
return wait(select("#", ...) - 1, ...)
end

--- Use this to create a function which executes in an async context but
Expand All @@ -157,20 +160,20 @@ end
--- @tparam boolean strict Error when called in non-async context
--- @treturn function(...):async_t
function M.create(func, argc, strict)
vim.validate {
func = { func, 'function' },
argc = { argc, 'number', true }
}
vim.validate({
func = { func, "function" },
argc = { argc, "number", true },
})
argc = argc or 0
return function(...)
if M.running() then
if strict then
error('This function must run in a non-async context')
error("This function must run in a non-async context")
end
return func(...)
end
local callback = select(argc + 1, ...)
return M.run(func, callback, unpack({...}, 1, argc))
return M.run(func, callback, unpack({ ... }, 1, argc))
end
end

Expand All @@ -179,11 +182,11 @@ end
--- @tparam function func
--- @tparam boolean strict Error when called in non-async context
function M.void(func, strict)
vim.validate { func = { func, 'function' } }
vim.validate({ func = { func, "function" } })
return function(...)
if M.running() then
if strict then
error('This function must run in a non-async context')
error("This function must run in a non-async context")
end
return func(...)
end
Expand All @@ -198,13 +201,13 @@ end
--- @tparam boolean strict Error when called in non-async context
--- @treturn function Returns an async function
function M.wrap(func, argc, strict)
vim.validate {
argc = { argc, 'number' },
}
vim.validate({
argc = { argc, "number" },
})
return function(...)
if not M.running() then
if strict then
error('This function must run in an async context')
error("This function must run in an async context")
end
return func(...)
end
Expand All @@ -229,7 +232,7 @@ function M.join(thunks, n, interrupt_check)
local ret = {}

local function cb(...)
ret[#ret + 1] = {...}
ret[#ret + 1] = { ... }
to_go = to_go - 1
if to_go == 0 then
finish(ret)
Expand All @@ -256,11 +259,11 @@ end
--- @tparam function fn
--- @param ... arguments to apply to `fn`
function M.curry(fn, ...)
local args = {...}
local nargs = select('#', ...)
local args = { ... }
local nargs = select("#", ...)
return function(...)
local other = {...}
for i = 1, select('#', ...) do
local other = { ... }
for i = 1, select("#", ...) do
args[nargs + i] = other[i]
end
fn(unpack(args))
Expand Down
Loading

0 comments on commit 606060e

Please sign in to comment.