Skip to content

Commit

Permalink
perf(refactor): use 'commons.nvim' library (#173)
Browse files Browse the repository at this point in the history
fix(windows): fix file path for Windows (#173)
  • Loading branch information
linrongbin16 committed Dec 14, 2023
1 parent e2a2b6a commit 3f8cfa5
Show file tree
Hide file tree
Showing 36 changed files with 2,378 additions and 798 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --config-path .stylua.toml ./lua ./test
- name: Install commons.nvim
if: ${{ github.ref != 'refs/heads/master' }}
shell: bash
run: |
echo "pwd"
echo $PWD
git clone --depth=1 https://github.com/linrongbin16/commons.nvim.git ~/.commons.nvim
mkdir -p ./lua/gitlinker/commons
cp -rf ~/.commons.nvim/lua/commons/*.lua ./lua/gitlinker/commons
cd ./lua/gitlinker/commons
find . -type f -name '*.lua' -exec sed -i 's/require("commons/require("gitlinker.commons/g' {} \;
- uses: stefanzweifel/git-auto-commit-action@v4
if: ${{ github.ref != 'refs/heads/master' }}
with:
Expand Down
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ globals = { "vim", "describe", "before_each", "it", "assert" }
max_line_length = 500
unused = false
unused_args = false
exclude_files =
{ "lua/gitlinker/commons/_system.lua", "lua/gitlinker/commons/_json.lua" }
4 changes: 4 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ modules = {
["gitlinker"] = "lua/gitlinker.lua",
["gitlinker.*"] = "lua",
}

exclude = {
"lua/gitlinker/commons/*.lua",
}
2 changes: 1 addition & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"diagnostics.globals": ["vim", "describe", "before_each", "it"],
"diagnostics.globals": ["vim", "describe", "before_each", "it", "jit"],
"workspace.checkThirdParty": false
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# gitlinker.nvim

<p align="center">
<a href="https://github.com/neovim/neovim/releases/v0.7.0"><img alt="Neovim" src="https://img.shields.io/badge/Neovim-v0.7-57A143?logo=neovim&logoColor=57A143" /></a>
<a href="https://github.com/neovim/neovim/releases/v0.7.0"><img alt="Neovim" src="https://img.shields.io/badge/Neovim-v0.7+-57A143?logo=neovim&logoColor=57A143" /></a>
<a href="https://github.com/linrongbin16/commons.nvim"><img alt="commons.nvim" src="https://custom-icon-badges.demolab.com/badge/Powered_by-commons.nvim-42b883?logo=heart&logoColor=fff&labelColor=e4002b" /></a>
<a href="https://luarocks.org/modules/linrongbin16/gitlinker.nvim"><img alt="luarocks" src="https://custom-icon-badges.demolab.com/luarocks/v/linrongbin16/gitlinker.nvim?label=LuaRocks&labelColor=063B70&logo=tag&logoColor=fff&color=008B8B" /></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=GitHub%20CI&labelColor=181717&logo=github&logoColor=fff" /></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?logo=codecov&logoColor=F01F7A&label=Codecov" /></a>
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage:
patch:
default:
threshold: 90%
ignore:
- "lua/gitlinker/commons/*.lua"
45 changes: 6 additions & 39 deletions lua/gitlinker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ local LogLevels = require("gitlinker.logger").LogLevels
local logger = require("gitlinker.logger")
local linker = require("gitlinker.linker")
local highlight = require("gitlinker.highlight")
local deprecation = require("gitlinker.deprecation")
local utils = require("gitlinker.utils")
local strings = require("gitlinker.commons.strings")

--- @alias gitlinker.Options table<any, any>
--- @type gitlinker.Options
Expand Down Expand Up @@ -119,25 +118,6 @@ local Defaults = {
--- @type gitlinker.Options
local Configs = {}

--- @param opts gitlinker.Options
local function deprecated_notification(opts)
if type(opts) == "table" and opts.pattern_rules ~= nil then
deprecation.notify(
"'pattern_rules' option is deprecated! please migrate to latest configs."
)
end
if type(opts) == "table" and opts.override_rules ~= nil then
deprecation.notify(
"'override_rules' option is deprecated! please migrate to latest configs."
)
end
if type(opts) == "table" and opts.custom_rules ~= nil then
deprecation.notify(
"'custom_rules' option is deprecated! please migrate to latest configs."
)
end
end

--- @param lk gitlinker.Linker
--- @param template string
--- @return string
Expand All @@ -155,7 +135,7 @@ local function _url_template_engine(lk, template)
local i = 1
local n = string.len(template)
while i <= n do
local open_pos = utils.string_find(template, OPEN_BRACE, i)
local open_pos = strings.find(template, OPEN_BRACE, i)
if not open_pos then
table.insert(exprs, { plain = true, body = string.sub(template, i) })
break
Expand All @@ -164,11 +144,8 @@ local function _url_template_engine(lk, template)
exprs,
{ plain = true, body = string.sub(template, i, open_pos - 1) }
)
local close_pos = utils.string_find(
template,
CLOSE_BRACE,
open_pos + string.len(OPEN_BRACE)
)
local close_pos =
strings.find(template, CLOSE_BRACE, open_pos + string.len(OPEN_BRACE))
assert(
type(close_pos) == "number" and close_pos > open_pos,
string.format(
Expand Down Expand Up @@ -207,7 +184,7 @@ local function _url_template_engine(lk, template)
PROTOCOL = lk.protocol,
HOST = lk.host,
USER = lk.user,
REPO = utils.string_endswith(lk.repo, ".git")
REPO = strings.endswith(lk.repo, ".git")
and lk.repo:sub(1, #lk.repo - 4)
or lk.repo,
REV = lk.rev,
Expand Down Expand Up @@ -511,7 +488,7 @@ local function _parse_args(args)
local args_splits = vim.split(args, " ", { plain = true, trimempty = true })
for _, a in ipairs(args_splits) do
if string.len(a) > 0 then
if utils.string_startswith(a, "remote=") then
if strings.startswith(a, "remote=") then
remote = a:sub(8)
else
router_type = a
Expand Down Expand Up @@ -583,23 +560,13 @@ local function setup(opts)
end,
})

if type(Configs.mapping) == "table" then
deprecation.notify(
"'mapping' option is deprecated! please migrate to 'GitLink' command."
)
end

-- Configure highlight group
if Configs.highlight_duration > 0 then
local hl_group = "NvimGitLinkerHighlightTextObject"
if not highlight.hl_group_exists(hl_group) then
vim.api.nvim_set_hl(0, hl_group, { link = "Search" })
end
end

-- logger.debug("|setup| Configs:%s", vim.inspect(Configs))

deprecated_notification(Configs)
end

local M = {
Expand Down
Loading

0 comments on commit 3f8cfa5

Please sign in to comment.