diff --git a/README.md b/README.md index 4dfa819e..cb5940ec 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ vim.o.autoread = true -- Required for `vim.g.opencode_opts.events.reload` vim.keymap.set({ "n", "x" }, "oa", function() require("opencode").ask("@this: ") end, { desc = "Ask OpenCode…" }) vim.keymap.set({ "n", "x" }, "os", function() require("opencode").select() end, { desc = "Select OpenCode…" }) +vim.keymap.set("n", "oc", function() require("opencode").prompt(require("opencode.config").opts.select.prompts.commit) end, { desc = "Generate conventional commit" }) + vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { desc = "Append range to OpenCode", expr = true }) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { desc = "Append line to OpenCode", expr = true }) @@ -72,6 +74,10 @@ vim.keymap.set("n", "", function() require("opencode").command("session.h vim.keymap.set({ "n", "x" }, "oa", function() require("opencode").ask("@this: ") end, { desc = "Ask OpenCode…" }) vim.keymap.set({ "n", "x" }, "os", function() require("opencode").select() end, { desc = "Select OpenCode…" }) + vim.keymap.set("n", "oc", function() + require("opencode").prompt(require("opencode.config").opts.select.prompts.commit) + end, { desc = "Generate conventional commit" }) + vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { desc = "Append range to OpenCode", expr = true }) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { desc = "Append line to OpenCode", expr = true }) @@ -202,16 +208,20 @@ opencode.nvim replaces placeholders in prompts with the corresponding context: Select prompts to review, explain, and improve your code: -| Name | Prompt | -| ------------- | ------------------------------------------------ | -| `diagnostics` | Explain `@diagnostics` | -| `document` | Add comments documenting `@this` | -| `explain` | Explain `@this` and its context | -| `fix` | Fix `@diagnostics` | -| `implement` | Implement `@this` | -| `optimize` | Optimize `@this` for performance and readability | -| `review` | Review `@this` for correctness and readability | -| `test` | Add tests for `@this` | +| Name | Prompt | +| ------------- | ------------------------------------------------------------------- | +| `commit` | Generate a conventional commit message from staged changes | +| `diagnostics` | Explain `@diagnostics` | +| `document` | Add comments documenting `@this` | +| `explain` | Explain `@this` and its context | +| `fix` | Fix `@diagnostics` | +| `implement` | Implement `@this` | +| `optimize` | Optimize `@this` for performance and readability | +| `review` | Review `@this` for correctness and readability | +| `test` | Add tests for `@this` | + +> [!TIP] +> After generating a commit message, copy it from the OpenCode TUI with `y` (press `ctrl+x` then `y`). ### Server diff --git a/lua/opencode/config.lua b/lua/opencode/config.lua index 4400010b..88af9e11 100644 --- a/lua/opencode/config.lua +++ b/lua/opencode/config.lua @@ -70,6 +70,31 @@ local defaults = { prompt = "OpenCode: ", prompts = { ask = "...", + commit = [[Write a conventional commit message for the staged changes. Follow these steps: + + 1. Run `git status` to review changed files. + 2. Run `git diff --cached` to inspect the staged changes. + 3. Construct a commit message following the Conventional Commits specification. + + Commit message structure: + - type: feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert + - scope: optional, recommended for clarity + - description: required, imperative mood (e.g. "add", not "added") + - body: optional, for additional context + - footer: optional, for breaking changes or issue references + + Format: `(): ` followed by optional body and footer. + + Examples: + - feat(parser): add ability to parse arrays + - fix(ui): correct button alignment + - docs: update README with usage instructions + - refactor: improve performance of data processing + - chore: update dependencies + - feat!: send email on registration (BREAKING CHANGE: email service required) + + Output only the commit message, do not commit. + Do not wrap the output in markdown code fences; respond with the raw commit message only.]], diagnostics = "Explain @diagnostics", document = "Add comments documenting @this", explain = "Explain @this and its context",