11local 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
55local writters = {}
66
@@ -16,8 +16,8 @@ The diff output:
1616
1717local 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
2323end
@@ -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
4246
4347function 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
6266end
@@ -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 )
8185
8286function 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
0 commit comments