Skip to content

Commit 0f10333

Browse files
committed
feat(gitcommit): add multi-language and amend support
- introduce multi-language commit message generation and language selection UI - add support for `git commit --amend` workflow in buffer and API - update documentation and examples for new language and amend features - enhance module structure with langs.lua and expanded types.lua - improve generator setup with adapter and model configuration options
1 parent d62580b commit 0f10333

File tree

3 files changed

+153
-40
lines changed

3 files changed

+153
-40
lines changed

README.md

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ A CodeCompanion extension that generates AI-powered git commit messages followin
1010
- 🔍 Automatic git repository detection
1111
- 📝 Support for both user commands and slash commands
1212
- ⌨️ Smart keymap integration for gitcommit buffers
13+
- 🌍 Multi-language support for commit messages
14+
- 🔄 Support for both regular commits and `git commit --amend`
1315

1416
## Installation
1517

@@ -26,7 +28,7 @@ require("codecompanion").setup({
2628
add_slash_command = true, -- Optional: adds /gitcommit slash command
2729
adapter = "openai", -- Optional: specify LLM adapter (defaults to codecompanion chat adapter)
2830
model = "gpt-4", -- Optional: specify model (defaults to codecompanion chat model)
29-
languages = { "English", "Chinese", "Japanese" }, -- Optional: list of languages for commit messages
31+
languages = { "English", "简体中文", "日本語", "Français", "Español" }, -- Optional: list of languages for commit messages
3032
buffer = {
3133
enabled = true, -- Enable gitcommit buffer keymaps
3234
keymap = "<leader>gc", -- Keymap for generating commit message in gitcommit buffer
@@ -60,8 +62,17 @@ In a CodeCompanion chat buffer, use `/gitcommit` to generate a commit message.
6062
```lua
6163
local gitcommit = require("codecompanion").extensions.gitcommit
6264

63-
-- Generate commit message
64-
gitcommit.generate(function(result, error)
65+
-- Generate commit message with language selection
66+
gitcommit.generate("English", function(result, error)
67+
if error then
68+
print("Error:", error)
69+
else
70+
print("Generated:", result)
71+
end
72+
end)
73+
74+
-- Generate commit message without language (uses default)
75+
gitcommit.generate(nil, function(result, error)
6576
if error then
6677
print("Error:", error)
6778
else
@@ -86,44 +97,70 @@ local buffer_config = gitcommit.get_buffer_config()
8697

8798
```
8899
lua/codecompanion/_extensions/gitcommit/
89-
├── init.lua # Main extension entry point
90-
├── git.lua # Git operations (repository detection, diff, commit)
100+
├── init.lua # Main extension entry point and command registration
101+
├── git.lua # Git operations (repository detection, diff, commit, amend support)
91102
├── generator.lua # LLM integration for commit message generation
92103
├── ui.lua # Floating window UI and interactions
93-
└── buffer.lua # GitCommit buffer keymap integration
104+
├── buffer.lua # GitCommit buffer keymap integration
105+
├── langs.lua # Language selection functionality
106+
└── types.lua # Type definitions and TypeScript-style annotations
94107
```
95108

96109
## Module Overview
97110

98111
### `git.lua`
99112
Handles all git-related operations:
100-
- Repository detection
101-
- Staged changes retrieval
102-
- Commit execution
113+
114+
- Repository detection with filesystem and git command fallback
115+
- Staged changes retrieval and contextual diff generation
116+
- Support for both regular commits and `git commit --amend`
117+
- Commit execution with proper error handling
103118

104119
### `generator.lua`
105120
Manages LLM interaction:
106-
- Prompt creation for commit message generation
121+
122+
- Prompt creation for commit message generation with language support
107123
- API communication with CodeCompanion adapters
108-
- Response handling
124+
- Response handling and error management
125+
- Adapter and model configuration
109126

110127
### `ui.lua`
111128
Provides interactive user interface:
112-
- Floating window display
113-
- Keyboard shortcuts
129+
130+
- Floating window display with markdown formatting
131+
- Interactive keyboard shortcuts (`c`, `s`, `Enter`, `q/Esc`)
114132
- Copy to clipboard functionality
133+
- Responsive window sizing
115134

116135
### `buffer.lua`
117136
Handles gitcommit buffer integration:
137+
118138
- Automatic keymap setup for gitcommit filetype
119-
- Smart commit message insertion
120-
- Buffer content management
139+
- Smart commit message insertion at correct position
140+
- Buffer content management and validation
141+
- Language selection integration
142+
143+
### `langs.lua`
144+
Manages language selection:
145+
146+
- Multi-language support configuration
147+
- Interactive language selection UI
148+
- Language preference handling
149+
150+
### `types.lua`
151+
Provides type definitions:
152+
153+
- TypeScript-style type annotations for Lua
154+
- Interface definitions for all modules
155+
- Configuration option types
121156

122157
### `init.lua`
123158
Main extension coordinator:
124-
- Module integration
125-
- Command registration
126-
- Extension exports
159+
160+
- Module integration and dependency management
161+
- Command registration (`:CodeCompanionGitCommit`, `:CCGitCommit`)
162+
- Slash command integration
163+
- Extension exports for programmatic usage
127164

128165
## Requirements
129166

@@ -150,6 +187,14 @@ Main extension coordinator:
150187
4. The AI-generated message will be inserted into the buffer
151188
5. Edit if needed and save to complete the commit
152189

190+
### Amend Workflow
191+
1. Make additional changes to your files
192+
2. Stage changes with `git add` (optional, for new changes)
193+
3. Run `git commit --amend` to open the amend buffer
194+
4. Press `<leader>gc` in normal mode to generate an updated commit message
195+
5. The extension will analyze the full commit changes and generate an appropriate message
196+
6. Edit if needed and save to complete the amend
197+
153198
## Configuration
154199

155200
The extension accepts the following options:
@@ -159,7 +204,7 @@ opts = {
159204
add_slash_command = true, -- Add /gitcommit slash command to chat buffer
160205
adapter = "openai", -- LLM adapter to use (default: codecompanion chat adapter)
161206
model = "gpt-4", -- Model to use (default: codecompanion chat model)
162-
languages = { "English", "Chinese", "Japanese" }, -- Languages for commit messages
207+
languages = { "English", "简体中文", "日本語", "Français", "Español" }, -- Languages for commit messages
163208
buffer = {
164209
enabled = true, -- Enable gitcommit buffer keymaps (default: true)
165210
keymap = "<leader>gc", -- Keymap for generating commit message (default: "<leader>gc")
@@ -179,7 +224,13 @@ The LLM adapter to use for generating commit messages. If not specified, default
179224
The specific model to use with the adapter. If not specified, defaults to the model configured for CodeCompanion's chat strategy.
180225

181226
#### `languages` (table, optional)
182-
A list of languages that can be used for generating commit messages. When specified, the extension will prompt you to select a language before generating the commit message. If not provided, commit messages will be generated in English by default.
227+
A list of languages that can be used for generating commit messages. When specified, the extension will prompt you to select a language before generating the commit message. If not provided or empty, commit messages will be generated in English by default.
228+
229+
Example:
230+
```lua
231+
languages = { "English", "简体中文", "日本語", "Français", "Español" }
232+
```
233+
183234
#### `buffer.enabled` (boolean, default: `true`)
184235
Controls whether gitcommit buffer keymap integration is enabled.
185236

doc/codecompanion-gitcommit.txt

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*codecompanion-gitcommit.txt* For Neovim >= 0.8.0 Last change: 2024 Dec 19
1+
*codecompanion-gitcommit.txt* For Neovim >= 0.8.0 Last change: 2025 Jun 02
22

33
CODECOMPANION GIT COMMIT EXTENSION *codecompanion-gitcommit*
44

@@ -36,6 +36,8 @@ analyze your staged changes and create appropriate commit messages.
3636
• Automatic git repository detection
3737
• Support for both user commands and slash commands
3838
• Smart keymap integration for gitcommit buffers
39+
• Multi-language support for commit messages
40+
• Support for both regular commits and `git commit --amend`
3941

4042
==============================================================================
4143
3. INSTALLATION *codecompanion-gitcommit-install*
@@ -64,11 +66,12 @@ Add this extension to your CodeCompanion configuration:
6466
==============================================================================
6567
4. CONFIGURATION *codecompanion-gitcommit-config*
6668

67-
The extension accepts the following configuration options:
68-
69-
*codecompanion-gitcommit-opts*
69+
The extension accepts the following configuration options: *codecompanion-gitcommit-opts*
7070
opts = {
7171
add_slash_command = false, -- Add /gitcommit slash command to chat buffer
72+
adapter = "openai", -- LLM adapter to use (optional)
73+
model = "gpt-4", -- Model to use (optional)
74+
languages = { "English", "简体中文", "日本語" }, -- Languages for commit messages (optional)
7275
buffer = {
7376
enabled = true, -- Enable gitcommit buffer keymaps
7477
keymap = "<leader>gc", -- Keymap for generating commit message
@@ -83,6 +86,29 @@ add_slash_command *gitcommit-add-slash-command*
8386
When enabled, adds `/gitcommit` slash command to CodeCompanion chat
8487
buffers for generating commit messages within chat sessions.
8588

89+
adapter *gitcommit-adapter*
90+
Type: string
91+
Default: codecompanion chat adapter
92+
The LLM adapter to use for generating commit messages. If not
93+
specified, defaults to the adapter configured for CodeCompanion's
94+
chat strategy.
95+
96+
model *gitcommit-model*
97+
Type: string
98+
Default: codecompanion chat model
99+
The specific model to use with the adapter. If not specified,
100+
defaults to the model configured for CodeCompanion's chat strategy.
101+
102+
languages *gitcommit-languages*
103+
Type: table
104+
Default: nil (English only)
105+
A list of languages that can be used for generating commit messages.
106+
When specified, the extension will prompt you to select a language
107+
before generating the commit message. If not provided or empty,
108+
commit messages will be generated in English by default.
109+
110+
Example: { "English", "简体中文", "日本語", "Français" }
111+
86112
buffer.enabled *gitcommit-buffer-enabled*
87113
Type: boolean
88114
Default: true
@@ -139,6 +165,15 @@ GitCommit Buffer Workflow:~
139165
4. The AI-generated message will be inserted into the buffer
140166
5. Edit if needed and save to complete the commit
141167

168+
Amend Workflow:~
169+
1. Make additional changes to your files
170+
2. Stage changes with `git add` (optional, for new changes)
171+
3. Run `git commit --amend` to open the amend buffer
172+
4. Press `<leader>gc` in normal mode to generate an updated commit message
173+
5. The extension will analyze the full commit changes and generate an
174+
appropriate message
175+
6. Edit if needed and save to complete the amend
176+
142177
==============================================================================
143178
6. COMMANDS *codecompanion-gitcommit-commands*
144179

@@ -155,18 +190,30 @@ GitCommit Buffer Workflow:~
155190

156191
The extension provides a programmatic API for advanced usage:
157192

158-
gitcommit.generate({callback}) *gitcommit.generate()*
159-
Generate a commit message asynchronously.
193+
gitcommit.generate({lang}, {callback}) *gitcommit.generate()*
194+
Generate a commit message asynchronously with optional language support.
160195

161196
Parameters:~
197+
{lang} string|nil: Language to generate commit message in
198+
(optional, uses default if nil)
162199
{callback} function: Callback function that receives
163200
(result, error) parameters
164201

165202
Example:~
166203
>lua
167204
local gitcommit = require("codecompanion").extensions.gitcommit
168205

169-
gitcommit.generate(function(result, error)
206+
-- Generate with specific language
207+
gitcommit.generate("简体中文", function(result, error)
208+
if error then
209+
print("Error:", error)
210+
else
211+
print("Generated:", result)
212+
end
213+
end)
214+
215+
-- Generate with default language
216+
gitcommit.generate(nil, function(result, error)
170217
if error then
171218
print("Error:", error)
172219
else
@@ -208,37 +255,49 @@ gitcommit.get_buffer_config() *gitcommit.get_buffer_config()*
208255
The extension consists of the following modules:
209256

210257
lua/codecompanion/_extensions/gitcommit/
211-
├── init.lua # Main extension entry point
212-
├── git.lua # Git operations (repository detection, diff, commit)
258+
├── init.lua # Main extension entry point and command registration
259+
├── git.lua # Git operations (repository detection, diff, commit, amend support)
213260
├── generator.lua # LLM integration for commit message generation
214261
├── ui.lua # Floating window UI and interactions
215262
├── buffer.lua # GitCommit buffer keymap integration
216-
├── types.lua # Type definitions and constants
217-
└── test.lua # Test utilities and functions
263+
├── langs.lua # Language selection functionality
264+
└── types.lua # Type definitions and TypeScript-style annotations
218265

219266
Module Overview:~
220267

221268
git.lua~
222269
Handles all git-related operations including repository detection,
223-
staged changes retrieval, and commit execution.
270+
staged changes retrieval, commit execution, and `git commit --amend`
271+
support. Includes contextual diff analysis and error handling.
224272

225273
generator.lua~
226274
Manages LLM interaction including prompt creation for commit message
227-
generation, API communication with CodeCompanion adapters, and
228-
response handling.
275+
generation with language support, API communication with CodeCompanion
276+
adapters, response handling, and adapter/model configuration.
229277

230278
ui.lua~
231-
Provides interactive user interface including floating window display,
232-
keyboard shortcuts, and copy to clipboard functionality.
279+
Provides interactive user interface including floating window display
280+
with markdown formatting, interactive keyboard shortcuts, copy to
281+
clipboard functionality, and responsive window sizing.
233282

234283
buffer.lua~
235284
Handles gitcommit buffer integration including automatic keymap setup
236-
for gitcommit filetype, smart commit message insertion, and buffer
237-
content management.
285+
for gitcommit filetype, smart commit message insertion at correct
286+
position, buffer content management, and language selection integration.
287+
288+
langs.lua~
289+
Manages language selection functionality including multi-language
290+
support configuration, interactive language selection UI, and
291+
language preference handling.
292+
293+
types.lua~
294+
Provides TypeScript-style type annotations for Lua including interface
295+
definitions for all modules and configuration option types.
238296

239297
init.lua~
240-
Main extension coordinator that handles module integration, command
241-
registration, and extension exports.
298+
Main extension coordinator that handles module integration, dependency
299+
management, command registration, slash command integration, and
300+
extension exports for programmatic usage.
242301

243302
==============================================================================
244303
9. REQUIREMENTS *codecompanion-gitcommit-requirements*

lua/codecompanion/_extensions/gitcommit/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ return {
5151
setup = function(opts)
5252
opts = opts or {}
5353

54+
-- Setup generator with adapter and model configuration
55+
Generator.setup(opts.adapter, opts.model)
56+
5457
-- Setup buffer keymaps for gitcommit filetype
5558
if opts.buffer then
5659
Buffer.setup(opts.buffer)

0 commit comments

Comments
 (0)