Skip to content

Commit f580992

Browse files
authored
chore(commons): upgrade logging api (#228)
1 parent a5e0d3e commit f580992

File tree

8 files changed

+118
-118
lines changed

8 files changed

+118
-118
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ There're several **router types**:
127127
> - `browse` generate the `/src` url (default): https://bitbucket.org/gitlinkernvim/gitlinker.nvim/src/dbf3922382576391fbe50b36c55066c1768b08b6/.gitignore#lines-9:14.
128128
> - `blame` generate the `/annotate` url: https://bitbucket.org/gitlinkernvim/gitlinker.nvim/annotate/dbf3922382576391fbe50b36c55066c1768b08b6/.gitignore#lines-9:14.
129129
> - `default_branch` generate the `/main` or `/master` url: https://bitbucket.org/gitlinkernvim/gitlinker.nvim/src/master/.gitignore#lines-9:14.
130-
> - `current_branch` generate the current branch url: https://bitbucket.org/gitlinkernvim/gitlinker.nvim/src/master/.gitignore#lines-9:14.
130+
> - `current_branch` generate the current branch url: https://bitbucket.org/gitlinkernvim/gitlinker.nvim/src/feat-dev/.gitignore#lines-9:14.
131131
132132
To specify the remote when there're multiple git remotes, add `remote=xxx` parameter, for example:
133133

@@ -408,9 +408,7 @@ For complete default options, please see `Defaults` in [configs.lua](https://git
408408
>
409409
> Please refer to `Defaults.router` in [configs.lua](https://github.com/linrongbin16/gitlinker.nvim/blob/master/lua/gitlinker/configs.lua) for more examples about string template.
410410
411-
To create customized urls for other git hosts, please bind the target git host name with a new router.
412-
413-
A router simply constructs the url string from below components (upper case with prefix `_A.`):
411+
To create customized urls for other git hosts, please bind the target git host name with a new router. A router simply constructs the url string from below components (upper case with prefix `_A.`):
414412

415413
- `_A.PROTOCOL`: Network protocol before `://` delimiter, for example:
416414
- `https` in `https://github.com`.
@@ -476,15 +474,15 @@ require("gitlinker").setup({
476474
})
477475
```
478476

479-
The template string use curly braces `{}` to contain lua scripts, and evaluate via [luaeval()](https://neovim.io/doc/user/lua.html#lua-eval) (while the error message can be confusing if there's any syntax issue).
477+
The template string use curly braces `{}` to contain lua scripts, and evaluate via [luaeval()](https://neovim.io/doc/user/lua.html#lua-eval), while the error message can be confusing if there's any syntax issue.
480478

481479
#### Lua Function
482480

483481
> [!NOTE]
484482
>
485-
> Please refer to [routers.lua](https://github.com/linrongbin16/gitlinker.nvim/blob/master/lua/gitlinker/routers.lua) for builtin routers implementation.
483+
> Please refer to [routers.lua](https://github.com/linrongbin16/gitlinker.nvim/blob/master/lua/gitlinker/routers.lua) for more examples about function-based routers.
486484
487-
You can also bind a lua function to it, which accepts a lua table parameter that contains the same fields, but in lower case, without the prefix `_A.`:
485+
You can also bind a lua function to the git host, the function accepts only 1 lua table as its parameter, which contains the same fields as string template, but in lower case, without the prefix `_A.`:
488486

489487
- `protocol`
490488
- `username`
@@ -506,7 +504,7 @@ The 2 branch components are:
506504
- `default_branch`
507505
- `current_branch`
508506

509-
Thus you can use below lua function to implement your router:
507+
Thus you can implement your router with below lua function:
510508

511509
```lua
512510
--- @param s string

lua/gitlinker.lua

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ local function _url_template_engine(lk, template)
3838
local close_pos = str.find(template, CLOSE_BRACE, open_pos + string.len(OPEN_BRACE))
3939
logger:ensure(
4040
type(close_pos) == "number" and close_pos > open_pos,
41-
"failed to evaluate url template(%s) at pos %d",
42-
vim.inspect(template),
43-
open_pos + string.len(OPEN_BRACE)
41+
string.format(
42+
"failed to evaluate url template(%s) at pos %d",
43+
vim.inspect(template),
44+
open_pos + string.len(OPEN_BRACE)
45+
)
4446
)
4547
table.insert(exprs, {
4648
plain = false,
@@ -81,10 +83,12 @@ local function _url_template_engine(lk, template)
8183
CURRENT_BRANCH = str.not_empty(lk.current_branch) and lk.current_branch or "",
8284
})
8385
logger:debug(
84-
"|_url_template_engine| exp:%s, lk:%s, evaluated:%s",
85-
vim.inspect(exp.body),
86-
vim.inspect(lk),
87-
vim.inspect(evaluated)
86+
string.format(
87+
"|_url_template_engine| exp:%s, lk:%s, evaluated:%s",
88+
vim.inspect(exp.body),
89+
vim.inspect(lk),
90+
vim.inspect(evaluated)
91+
)
8892
)
8993
table.insert(results, evaluated)
9094
end
@@ -121,18 +125,15 @@ local function _router(router_type, lk)
121125
local confs = configs.get()
122126
logger:ensure(
123127
type(confs._routers[router_type]) == "table",
124-
"unknown router type %s!",
125-
vim.inspect(router_type)
128+
string.format("unknown router type %s!", vim.inspect(router_type))
126129
)
127130
logger:ensure(
128131
type(confs._routers[router_type].list_routers) == "table",
129-
"invalid router type %s! 'list_routers' missing.",
130-
vim.inspect(router_type)
132+
string.format("invalid router type %s! 'list_routers' missing.", vim.inspect(router_type))
131133
)
132134
logger:ensure(
133135
type(confs._routers[router_type].map_routers) == "table",
134-
"invalid router type %s! 'map_routers' missing.",
135-
vim.inspect(router_type)
136+
string.format("invalid router type %s! 'map_routers' missing.", vim.inspect(router_type))
136137
)
137138

138139
for i, tuple in ipairs(confs._routers[router_type].list_routers) do
@@ -180,7 +181,10 @@ local function _router(router_type, lk)
180181
end
181182
end
182183
end
183-
logger:ensure(false, "%s not support, please bind it in 'router'!", vim.inspect(lk.host))
184+
logger:ensure(
185+
false,
186+
string.format("%s not support, please bind it in 'router'!", vim.inspect(lk.host))
187+
)
184188
return nil
185189
end
186190

@@ -219,9 +223,11 @@ local _link = function(opts)
219223
-- )
220224
logger:ensure(
221225
ok and str.not_empty(url),
222-
"fatal: failed to generate permanent url from remote (%s): %s",
223-
vim.inspect(lk.remote_url),
224-
vim.inspect(url)
226+
string.format(
227+
"fatal: failed to generate permanent url from remote (%s): %s",
228+
vim.inspect(lk.remote_url),
229+
vim.inspect(url)
230+
)
225231
)
226232

227233
if opts.action then
@@ -242,10 +248,12 @@ local _link = function(opts)
242248
message = opts.message
243249
end
244250
logger:debug(
245-
"|_link| message:%s, opts:%s, confs:%s",
246-
vim.inspect(message),
247-
vim.inspect(opts),
248-
vim.inspect(confs)
251+
string.format(
252+
"|_link| message:%s, opts:%s, confs:%s",
253+
vim.inspect(message),
254+
vim.inspect(opts),
255+
vim.inspect(confs)
256+
)
249257
)
250258
if message then
251259
local msg = lk.file_changed and url .. " (lines can be wrong due to file change)" or url --[[@as string]]
@@ -295,10 +303,6 @@ local function setup(opts)
295303
file_log_name = "gitlinker.log",
296304
})
297305

298-
local logger = logging.get("gitlinker")
299-
300-
-- logger:debug("|setup| confs:%s", vim.inspect(confs))
301-
302306
-- command
303307
vim.api.nvim_create_user_command(confs.command.name, function(command_opts)
304308
local r = range.make_range()

0 commit comments

Comments
 (0)