Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/bump-commons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
git clone --depth=1 https://github.com/linrongbin16/commons.nvim.git ~/.commons.nvim
rm -rf ./lua/gitlinker/commons
mkdir -p ./lua/gitlinker/commons
cp -rf ~/.commons.nvim/lua/commons/*.lua ./lua/gitlinker/commons
cp ~/.commons.nvim/version.txt ./lua/gitlinker/commons/version.txt
cp -rf ~/.commons.nvim/lua/commons ./lua/gitlinker
cd ./lua/gitlinker/commons
find . -type f -name '*.lua' -exec sed -i 's/require("commons/require("gitlinker.commons/g' {} \;
find . -type f -name '*.lua' -exec sed -i "s/require('commons/require('gitlinker.commons/g" {} \;
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ github.ref != 'refs/heads/master' }}
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
selene --config selene.toml ./lua
unit_test:
name: Unit Test
needs:
- lint
strategy:
matrix:
nvim_version: [stable, nightly]
Expand Down
5 changes: 4 additions & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"jit",
"utf8"
],
"diagnostics.disable": [],
"diagnostics.disable": [
"luadoc-miss-symbol",
"missing-return"
],
"runtime.version": "LuaJIT",
"workspace.checkThirdParty": "Disable"
}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<p>
<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>
</p>
Expand Down
49 changes: 24 additions & 25 deletions lua/gitlinker.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
local tbl = require("gitlinker.commons.tbl")
local str = require("gitlinker.commons.str")
local num = require("gitlinker.commons.num")
local LogLevels = require("gitlinker.commons.logging").LogLevels
local logging = require("gitlinker.commons.logging")
local log = require("gitlinker.commons.log")
local async = require("gitlinker.commons.async")

local async = require("gitlinker.async")
local configs = require("gitlinker.configs")
local range = require("gitlinker.range")
local linker = require("gitlinker.linker")
Expand All @@ -20,8 +19,6 @@ local function _url_template_engine(lk, template)
return nil
end

local logger = logging.get("gitlinker")

--- @alias gitlinker.UrlTemplateExpr {plain:boolean,body:string}
--- @type gitlinker.UrlTemplateExpr[]
local exprs = {}
Expand All @@ -36,7 +33,7 @@ local function _url_template_engine(lk, template)
end
table.insert(exprs, { plain = true, body = string.sub(template, i, open_pos - 1) })
local close_pos = str.find(template, CLOSE_BRACE, open_pos + string.len(OPEN_BRACE))
logger:ensure(
log.ensure(
type(close_pos) == "number" and close_pos > open_pos,
string.format(
"failed to evaluate url template(%s) at pos %d",
Expand Down Expand Up @@ -82,7 +79,7 @@ local function _url_template_engine(lk, template)
DEFAULT_BRANCH = str.not_empty(lk.default_branch) and lk.default_branch or "",
CURRENT_BRANCH = str.not_empty(lk.current_branch) and lk.current_branch or "",
})
logger:debug(
log.debug(
string.format(
"|_url_template_engine| exp:%s, lk:%s, evaluated:%s",
vim.inspect(exp.body),
Expand All @@ -107,8 +104,7 @@ local function _worker(lk, p, r)
elseif type(r) == "string" then
return _url_template_engine(lk, r)
else
local logger = logging.get("gitlinker")
logger:ensure(
log.ensure(
false,
string.format("unsupported router %s on pattern %s", vim.inspect(r), vim.inspect(p))
)
Expand All @@ -121,17 +117,16 @@ end
--- @param lk gitlinker.Linker
--- @return string?
local function _router(router_type, lk)
local logger = logging.get("gitlinker")
local confs = configs.get()
logger:ensure(
log.ensure(
type(confs._routers[router_type]) == "table",
string.format("unknown router type %s!", vim.inspect(router_type))
)
logger:ensure(
log.ensure(
type(confs._routers[router_type].list_routers) == "table",
string.format("invalid router type %s! 'list_routers' missing.", vim.inspect(router_type))
)
logger:ensure(
log.ensure(
type(confs._routers[router_type].map_routers) == "table",
string.format("invalid router type %s! 'map_routers' missing.", vim.inspect(router_type))
)
Expand Down Expand Up @@ -181,7 +176,7 @@ local function _router(router_type, lk)
end
end
end
logger:ensure(
log.ensure(
false,
string.format("%s not support, please bind it in 'router'!", vim.inspect(lk.host))
)
Expand All @@ -201,9 +196,9 @@ local function _blame(lk)
end

--- @param opts {action:gitlinker.Action|boolean,router:gitlinker.Router,lstart:integer,lend:integer,message:boolean?,highlight_duration:integer?,remote:string?,file:string?,rev:string?}
--- @return string?
local _link = function(opts)
local confs = configs.get()
local logger = logging.get("gitlinker")
-- logger.debug("[link] merged opts: %s", vim.inspect(opts))

local lk = linker.make_linker(opts.remote, opts.file, opts.rev)
Expand All @@ -221,15 +216,16 @@ local _link = function(opts)
lk.rev = opts.rev
end

async.scheduler()
async.await(1, vim.schedule)

local ok, url = pcall(opts.router, lk, true)
-- logger:debug(
-- "|link| ok:%s, url:%s, router:%s",
-- vim.inspect(ok),
-- vim.inspect(url),
-- vim.inspect(opts.router)
-- )
logger:ensure(
log.ensure(
ok and str.not_empty(url),
string.format(
"fatal: failed to generate permanent url from remote (%s): %s",
Expand All @@ -255,7 +251,7 @@ local _link = function(opts)
if type(opts.message) == "boolean" then
message = opts.message
end
logger:debug(
log.debug(
string.format(
"|_link| message:%s, opts:%s, confs:%s",
vim.inspect(message),
Expand All @@ -272,8 +268,11 @@ local _link = function(opts)
return url
end

--- @type fun(opts:{action:gitlinker.Action?,router:gitlinker.Router,lstart:integer,lend:integer,remote:string?,file:string?,rev:string?}):string?
local _void_link = async.void(_link)
--- @param opts {action:gitlinker.Action?,router:gitlinker.Router,lstart:integer,lend:integer,remote:string?,file:string?,rev:string?}
--- @return string?
local _void_link = function(opts)
return async.run(_link, opts)
end

--- @param args string?
--- @return {router_type:string,remote:string?,file:string?,rev:string?}
Expand Down Expand Up @@ -309,12 +308,12 @@ local function setup(opts)
local confs = configs.setup(opts)

-- logger
logging.setup({
log.setup({
name = "gitlinker",
level = confs.debug and LogLevels.DEBUG or LogLevels.INFO,
console_log = confs.console_log,
file_log = confs.file_log,
file_log_name = "gitlinker.log",
level = confs.debug and vim.log.levels.DEBUG or vim.log.levels.INFO,
use_console = confs.console_log,
use_file = confs.file_log,
file_name = "gitlinker.log",
})

-- command
Expand Down
Loading