Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit 7293a1a

Browse files
committed
ci: fix format
1 parent cba95bf commit 7293a1a

File tree

8 files changed

+111
-87
lines changed

8 files changed

+111
-87
lines changed

lua/commit-msg-sg/config.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ CommitMsgSg.options = {
1010
auto_setup_gitcommit = true,
1111
auto_setup_command = true,
1212
on_attach = nil,
13-
ghost_text = 'Thinking...',
13+
ghost_text = "Thinking...",
1414
-- customized function to generate prompt string.
1515
prompt_gen = nil,
1616
default_prompt = nil,
1717
-- @private
18-
executor = 'sg',
18+
executor = "sg",
1919
-- Debug
2020
-- @private
2121
debug = false,

lua/commit-msg-sg/executor.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ local executor = nil
44

55
function M.setup(bufnr, config)
66
local executor_name = config.executor
7-
if executor_name ~= 'sg' then
7+
if executor_name ~= "sg" then
88
error("executor must be 'sg', for now.", vim.log.levels.ERROR)
99
end
1010

11-
local ok, executor_ = pcall(require, 'commit-msg-sg.utils.executor_' .. executor_name)
12-
if not ok then error("executor not found", vim.log.levels.ERROR) end
11+
local ok, executor_ = pcall(require, "commit-msg-sg.utils.executor_" .. executor_name)
12+
if not ok then
13+
error("executor not found", vim.log.levels.ERROR)
14+
end
1315
executor = executor_
1416
executor.setup(bufnr, config)
1517
end

lua/commit-msg-sg/init.lua

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
2-
local config = require('commit-msg-sg.config')
3-
local utils = require('commit-msg-sg.utils')
2+
local config = require("commit-msg-sg.config")
3+
local utils = require("commit-msg-sg.utils")
44

55
local writters = {}
66

@@ -16,8 +16,8 @@ The diff output:
1616

1717
local function on_attach(client, bufnr, opts)
1818
if opts.auto_setup_command then
19-
vim.api.nvim_buf_create_user_command(bufnr, 'WriteGitCommitMessage', M.write, {
20-
desc = 'Write git commit with AI',
19+
vim.api.nvim_buf_create_user_command(bufnr, "WriteGitCommitMessage", M.write, {
20+
desc = "Write git commit with AI",
2121
})
2222
end
2323
end
@@ -32,7 +32,11 @@ function M.setup(opts)
3232
end
3333
end
3434
config.setup(opts)
35-
if config.options.default_prompt and config.options.default_prompt and config.options.default_prompt ~= '' then
35+
if
36+
config.options.default_prompt
37+
and config.options.default_prompt
38+
and config.options.default_prompt ~= ""
39+
then
3640
prompt_str = config.options.default_prompt
3741
end
3842
if config.options.auto_setup_gitcommit then
@@ -42,21 +46,21 @@ end
4246

4347
function M.setup_gitcommit(opts)
4448
local setup_ = function(bufnr)
45-
require('commit-msg-sg.executor').setup(bufnr, opts)
49+
require("commit-msg-sg.executor").setup(bufnr, opts)
4650
end
4751

48-
vim.api.nvim_create_augroup('commit-msg-sg', {
52+
vim.api.nvim_create_augroup("commit-msg-sg", {
4953
clear = true,
5054
})
51-
vim.api.nvim_create_autocmd('FileType', {
52-
pattern = 'gitcommit',
53-
group = 'commit-msg-sg',
55+
vim.api.nvim_create_autocmd("FileType", {
56+
pattern = "gitcommit",
57+
group = "commit-msg-sg",
5458
callback = function()
5559
setup_(vim.api.nvim_get_current_buf())
5660
end,
5761
})
5862

59-
if vim.bo.filetype == 'gitcommit' then
63+
if vim.bo.filetype == "gitcommit" then
6064
setup_(vim.api.nvim_get_current_buf())
6165
end
6266
end
@@ -66,7 +70,7 @@ local function gen_snippet(opts, callback)
6670
return opts.prompt_gen(callback)
6771
end
6872

69-
local cwd = type(opts.cwd) == 'function' and opts.cwd() or opts.cwd
73+
local cwd = type(opts.cwd) == "function" and opts.cwd() or opts.cwd
7074
utils.fetch_git_diff_as_text({
7175
cwd = cwd,
7276
callback = function(err, text)
@@ -81,7 +85,7 @@ end
8185

8286
function M.write()
8387
local bufnr = vim.api.nvim_get_current_buf()
84-
local Writter = require('commit-msg-sg.simple_writter')
88+
local Writter = require("commit-msg-sg.simple_writter")
8589
local writter = writters[bufnr]
8690
if writter then
8791
writter:reset()
@@ -95,7 +99,7 @@ function M.write()
9599
utils.update_ghost_text(bufnr, config.options.ghost_text)
96100
end
97101

98-
local executor = require('commit-msg-sg.executor')
102+
local executor = require("commit-msg-sg.executor")
99103
gen_snippet(config.options, function(err, snippet)
100104
print(snippet)
101105
if err then
@@ -104,7 +108,9 @@ function M.write()
104108
end
105109
writter:reset()
106110
executor.execute(bufnr, snippet, function(err_, text)
107-
if writter:invalid() then return end
111+
if writter:invalid() then
112+
return
113+
end
108114
if err_ then
109115
vim.notify(err_, vim.log.levels.ERROR)
110116
return

lua/commit-msg-sg/simple_writter.lua

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local utils = require('commit-msg-sg.utils')
1+
local utils = require("commit-msg-sg.utils")
22

33
local id = 1
44

@@ -15,7 +15,7 @@ SimpleWritter.init = function(bufnr)
1515
error("bufnr is required", vim.log.levels.ERROR)
1616
end
1717

18-
local Mark = require('sg.mark')
18+
local Mark = require("sg.mark")
1919
local mark = Mark.init({
2020
ns = bufnr,
2121
bufnr = bufnr,
@@ -27,34 +27,44 @@ SimpleWritter.init = function(bufnr)
2727
id = id + 1
2828
return setmetatable({
2929
bufnr = bufnr,
30-
text = '',
30+
text = "",
3131
id = id,
3232
marker = mark,
3333
}, { __index = SimpleWritter })
3434
end
3535

3636
function SimpleWritter:update(text)
37-
if self:invalid() then return end
37+
if self:invalid() then
38+
return
39+
end
3840

39-
self.text = text or ''
41+
self.text = text or ""
4042

41-
local lines = vim.split(text, '\n')
43+
local lines = vim.split(text, "\n")
4244
-- iterate the lines, if vim.trim(line) is ```, ignore it
4345
local new_lines = {}
4446
for _, line in ipairs(lines) do
45-
if vim.trim(line) ~= '```' then
47+
if vim.trim(line) ~= "```" then
4648
table.insert(new_lines, line)
4749
end
4850
end
49-
vim.api.nvim_buf_set_lines(self.bufnr, self.marker:start_pos().row, self.marker:end_pos().row, false, new_lines)
51+
vim.api.nvim_buf_set_lines(
52+
self.bufnr,
53+
self.marker:start_pos().row,
54+
self.marker:end_pos().row,
55+
false,
56+
new_lines
57+
)
5058
end
5159

5260
function SimpleWritter:invalid()
5361
return self.id ~= id
5462
end
5563

5664
function SimpleWritter:reset()
57-
if vim.fn.getline(1) == '' then return end
65+
if vim.fn.getline(1) == "" then
66+
return
67+
end
5868
local marker = self.marker
5969
local end_row = marker:end_pos().row - 1
6070
if end_row <= 0 then

lua/commit-msg-sg/utils/debug.lua

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ local D = {}
77
---@param ... any: the arguments of the formatted string.
88
---@private
99
function D.log(scope, str, ...)
10-
if _G.CommitMsgSg.config ~= nil and not _G.CommitMsgSg.config.debug then
11-
return
12-
end
13-
14-
local info = debug.getinfo(2, "Sl")
15-
local line = ""
16-
17-
if info then
18-
line = "L" .. info.currentline
19-
end
20-
21-
print(
22-
string.format(
23-
"[commit-msg-sg:%s %s in %s] > %s",
24-
os.date("%H:%M:%S"),
25-
line,
26-
scope,
27-
string.format(str, ...)
28-
)
10+
if _G.CommitMsgSg.config ~= nil and not _G.CommitMsgSg.config.debug then
11+
return
12+
end
13+
14+
local info = debug.getinfo(2, "Sl")
15+
local line = ""
16+
17+
if info then
18+
line = "L" .. info.currentline
19+
end
20+
21+
print(
22+
string.format(
23+
"[commit-msg-sg:%s %s in %s] > %s",
24+
os.date("%H:%M:%S"),
25+
line,
26+
scope,
27+
string.format(str, ...)
2928
)
29+
)
3030
end
3131

3232
---prints the table if debug is true.
@@ -35,27 +35,27 @@ end
3535
---@param indent number?: the default indent value, starts at 0.
3636
---@private
3737
function D.tprint(table, indent)
38-
if _G.CommitMsgSg.config ~= nil and not _G.CommitMsgSg.config.debug then
39-
return
40-
end
41-
42-
if not indent then
43-
indent = 0
44-
end
45-
46-
for k, v in pairs(table) do
47-
local formatting = string.rep(" ", indent) .. k .. ": "
48-
if type(v) == "table" then
49-
print(formatting)
50-
D.tprint(v, indent + 1)
51-
elseif type(v) == "boolean" then
52-
print(formatting .. tostring(v))
53-
elseif type(v) == "function" then
54-
print(formatting .. "FUNCTION")
55-
else
56-
print(formatting .. v)
57-
end
38+
if _G.CommitMsgSg.config ~= nil and not _G.CommitMsgSg.config.debug then
39+
return
40+
end
41+
42+
if not indent then
43+
indent = 0
44+
end
45+
46+
for k, v in pairs(table) do
47+
local formatting = string.rep(" ", indent) .. k .. ": "
48+
if type(v) == "table" then
49+
print(formatting)
50+
D.tprint(v, indent + 1)
51+
elseif type(v) == "boolean" then
52+
print(formatting .. tostring(v))
53+
elseif type(v) == "function" then
54+
print(formatting .. "FUNCTION")
55+
else
56+
print(formatting .. v)
5857
end
58+
end
5959
end
6060

6161
return D

lua/commit-msg-sg/utils/executor_sg.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local utils = require('commit-msg-sg.utils')
1+
local utils = require("commit-msg-sg.utils")
22

33
local M = {}
44

@@ -7,7 +7,7 @@ local clients = {}
77
--- @param snippet string
88
--- @param callback function
99
function M.execute(bufnr, snippet, callback)
10-
local rpc = require('sg.cody.rpc')
10+
local rpc = require("sg.cody.rpc")
1111
local client = clients[bufnr]
1212
if not client then
1313
error("setup not called", vim.log.levels.ERROR)
@@ -16,20 +16,22 @@ function M.execute(bufnr, snippet, callback)
1616
if not res then
1717
return
1818
end
19-
local text = res.text .. '\n'
19+
local text = res.text .. "\n"
2020
callback(nil, text)
2121
end)
2222
end
2323

2424
function M.setup(bufnr, config)
2525
utils.throws_if_deps_is_missing()
26-
if clients[bufnr] then return end
26+
if clients[bufnr] then
27+
return
28+
end
2729

28-
require('sg.cody.rpc').start({
30+
require("sg.cody.rpc").start({
2931
force = false,
3032
}, function(client_or_nil)
3133
if client_or_nil == nil then
32-
vim.notify('cody client not started successfully');
34+
vim.notify("cody client not started successfully")
3335
return
3436
end
3537

0 commit comments

Comments
 (0)