Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ vim.o.autoread = true -- Required for `vim.g.opencode_opts.events.reload`
vim.keymap.set({ "n", "x" }, "<leader>oa", function() require("opencode").ask("@this: ") end, { desc = "Ask OpenCode…" })
vim.keymap.set({ "n", "x" }, "<leader>os", function() require("opencode").select() end, { desc = "Select OpenCode…" })

vim.keymap.set("n", "<leader>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 })

Expand All @@ -72,6 +74,10 @@ vim.keymap.set("n", "<S-C-d>", function() require("opencode").command("session.h
vim.keymap.set({ "n", "x" }, "<leader>oa", function() require("opencode").ask("@this: ") end, { desc = "Ask OpenCode…" })
vim.keymap.set({ "n", "x" }, "<leader>os", function() require("opencode").select() end, { desc = "Select OpenCode…" })

vim.keymap.set("n", "<leader>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 })

Expand Down Expand Up @@ -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 `<leader>y` (press `ctrl+x` then `y`).

### Server

Expand Down
25 changes: 25 additions & 0 deletions lua/opencode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<type>(<scope>): <description>` 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",
Expand Down
Loading