### Install Opencode.nvim with lazy.nvim Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Basic setup configuration for opencode.nvim using the lazy.nvim package manager. Includes optional integration with snacks.nvim for enhanced input and picker experiences. Ensure vim.o.autoread is set to true for automatic buffer reloads. ```lua { "nickjvandyke/opencode.nvim", version = "*", -- Latest stable release dependencies = { { "folke/snacks.nvim", optional = true, opts = { input = {}, -- Enhances `ask()` picker = { actions = { opencode_send = function(...) return require("opencode").snacks_picker_send(...) end, }, win = { input = { keys = { [""] = { "opencode_send", mode = { "n", "i" } }, }, }, }, }, }, }, }, config = function() --@type opencode.Opts vim.g.opencode_opts = { server = { port = nil, -- Auto-detect, or set specific port like 12345 }, prompts = { custom_review = { prompt = "Review @this for security vulnerabilities", submit = true, }, }, } vim.o.autoread = true -- Required for automatic buffer reload on edits -- Recommended keymaps vim.keymap.set({ "n", "x" }, "", function() require("opencode").ask("@this: ", { submit = true }) end) vim.keymap.set({ "n", "x" }, "", function() require("opencode").select() end) vim.keymap.set({ "n", "t" }, "", function() require("opencode").toggle() end) vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { expr = true }) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { expr = true }) end, } ``` -------------------------------- ### Install opencode.nvim with nixvim Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md Add the plugin to your nixvim configuration via extraPlugins. ```nix programs.nixvim = { extraPlugins = [ pkgs.vimPlugins.opencode-nvim ]; }; ``` -------------------------------- ### Install opencode.nvim with lazy.nvim Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md Configure the plugin using lazy.nvim, including optional snacks.nvim integration and recommended keybindings. ```lua { "nickjvandyke/opencode.nvim", version = "*", -- Latest stable release dependencies = { { -- `snacks.nvim` integration is recommended, but optional ---@module "snacks" <- Loads `snacks.nvim` types for configuration intellisense "folke/snacks.nvim", optional = true, opts = { input = {}, -- Enhances `ask()` picker = { -- Enhances `select()` actions = { opencode_send = function(...) return require("opencode").snacks_picker_send(...) end, }, win = { input = { keys = { [""] = { "opencode_send", mode = { "n", "i" } }, }, }, }, }, }, }, }, config = function() ---@type opencode.Opts vim.g.opencode_opts = { -- Your configuration, if any; goto definition on the type or field for details } vim.o.autoread = true -- Required for `opts.events.reload` -- Recommended/example keymaps vim.keymap.set({ "n", "x" }, "", function() require("opencode").ask("@this: ", { submit = true }) end, { desc = "Ask opencode…" }) vim.keymap.set({ "n", "x" }, "", function() require("opencode").select() end, { desc = "Execute opencode action…" }) vim.keymap.set({ "n", "t" }, "", function() require("opencode").toggle() end, { desc = "Toggle opencode" }) vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { desc = "Add range to opencode", expr = true }) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { desc = "Add line to opencode", expr = true }) vim.keymap.set("n", "", function() require("opencode").command("session.half.page.up") end, { desc = "Scroll opencode up" }) vim.keymap.set("n", "", function() require("opencode").command("session.half.page.down") end, { desc = "Scroll opencode down" }) -- You may want these if you use the opinionated `` and `` keymaps above — otherwise consider `o…` (and remove terminal mode from the `toggle` keymap) vim.keymap.set("n", "+", "", { desc = "Increment under cursor", noremap = true }) vim.keymap.set("n", "-", "", { desc = "Decrement under cursor", noremap = true }) end, } ``` -------------------------------- ### Customize opencode server with snacks.terminal Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md Configure opencode.nvim to use snacks.terminal for server management, including custom keymap setup for the terminal window. ```lua local opencode_cmd = 'opencode --port' ---@type snacks.terminal.Opts local snacks_terminal_opts = { win = { position = 'right', enter = false, on_win = function(win) -- Set up keymaps and cleanup for an arbitrary terminal require('opencode.terminal').setup(win.win) end, }, } ---@type opencode.Opts vim.g.opencode_opts = { server = { start = function() require('snacks.terminal').open(opencode_cmd, snacks_terminal_opts) end, stop = function() require('snacks.terminal').get(opencode_cmd, snacks_terminal_opts):close() end, toggle = function() require('snacks.terminal').toggle(opencode_cmd, snacks_terminal_opts) end, }, } ``` -------------------------------- ### Execute OpenCode Commands Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Sends commands directly to the OpenCode TUI for session management, navigation, and control. Includes examples for session management, navigation, and prompt/agent commands. ```lua -- Session management commands require("opencode").command("session.new") -- Start new session require("opencode").command("session.interrupt") -- Stop current response require("opencode").command("session.compact") -- Reduce context size require("opencode").command("session.share") -- Share session URL require("opencode").command("session.undo") -- Undo last action require("opencode").command("session.redo") -- Redo last action ``` ```lua -- Navigation commands require("opencode").command("session.page.up") -- Scroll up full page require("opencode").command("session.page.down") -- Scroll down full page require("opencode").command("session.half.page.up") -- Scroll up half page require("opencode").command("session.half.page.down") -- Scroll down half page require("opencode").command("session.first") -- Jump to first message require("opencode").command("session.last") -- Jump to last message ``` ```lua -- Prompt and agent commands require("opencode").command("prompt.submit") -- Submit current input require("opencode").command("prompt.clear") -- Clear input field require("opencode").command("agent.cycle") -- Switch AI agent ``` ```lua -- Example keymaps for scrolling vim.keymap.set("n", "", function() require("opencode").command("session.half.page.up") end, { desc = "Scroll opencode up" }) vim.keymap.set("n", "", function() require("opencode").command("session.half.page.down") end, { desc = "Scroll opencode down" }) ``` -------------------------------- ### Server Control Functions Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Functions to manage the OpenCode server lifecycle including starting, stopping, and toggling visibility. ```APIDOC ## Server Control Functions ### Description Functions to manage the OpenCode server lifecycle including starting, stopping, and toggling visibility. ### Methods - `require("opencode").toggle()` - Toggle server visibility (show/hide terminal) - `require("opencode").start()` - Start the configured server - `require("opencode").stop()` - Stop the configured server - `require("opencode").select_server()` - Select from multiple running servers - `require("opencode").select_session()` - Select a specific session ``` -------------------------------- ### Context Placeholders Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Context placeholders that get replaced with actual editor content when prompts are sent. ```APIDOC ## Context Placeholders ### Description Context placeholders that get replaced with actual editor content when prompts are sent. These can be used in any prompt string. ### Available Placeholders - `@this` - Operator range, visual selection, or cursor position - `@buffer` - Current buffer contents - `@buffers` - All open buffer paths - `@visible` - Visible text in all windows - `@diagnostics` - Current buffer diagnostics - `@quickfix` - Quickfix list contents - `@diff` - Git diff output - `@marks` - Global marks - `@grapple` - grapple.nvim tags (if installed) ``` -------------------------------- ### Vim Operator Integration with OpenCode Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Wraps prompt functionality as a Vim operator, supporting ranges and dot-repeat. Returns a string for use with `operatorfunc`. Examples demonstrate setting up mappings for various actions. ```lua -- Define operator mapping (must use expr = true) vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { expr = true, desc = "Send range to opencode" }) ``` ```lua -- Line-wise operator (double key like yy, dd) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { expr = true, desc = "Send line to opencode" }) ``` ```lua -- Usage examples after setting up the keymaps: -- goiw - Send inner word to opencode -- goap - Send paragraph to opencode -- go3j - Send current line and 3 lines below -- goo - Send current line -- V3jgo - Visual select 3 lines and send ``` ```lua -- Custom operator with specific prompt vim.keymap.set({ "n", "x" }, "goe", function() return require("opencode").operator("Explain @this: ") end, { expr = true, desc = "Explain with opencode" }) ``` ```lua vim.keymap.set({ "n", "x" }, "gor", function() return require("opencode").operator("Review @this for issues: ") end, { expr = true, desc = "Review with opencode" }) ``` -------------------------------- ### Handle OpenCode Events Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Subscribe to real-time SSE events using Neovim autocommands and configure event settings via global options. ```lua -- Listen for all opencode events vim.api.nvim_create_autocmd("User", { pattern = "OpencodeEvent:*", callback = function(args) local event = args.data.event -- Event data local port = args.data.port -- Server port vim.notify("Event: " .. event.type) end, }) -- Listen for specific event types vim.api.nvim_create_autocmd("User", { pattern = "OpencodeEvent:session.idle", callback = function(args) vim.notify("OpenCode finished responding") end, }) vim.api.nvim_create_autocmd("User", { pattern = "OpencodeEvent:session.error", callback = function(args) vim.notify("OpenCode error: " .. vim.inspect(args.data.event.properties)) end, }) vim.api.nvim_create_autocmd("User", { pattern = "OpencodeEvent:permission.updated", callback = function(args) vim.notify("Permission requested") end, }) -- Event types available: -- server.connected, server.instance.disposed -- session.idle, session.diff, session.heartbeat, session.error -- message.updated, message.part.updated -- permission.updated, permission.replied -- Events configuration vim.g.opencode_opts = { events = { enabled = true, -- Enable SSE subscription reload = true, -- Auto-reload buffers edited by opencode permissions = { enabled = true, idle_delay_ms = 1000, edits = { enabled = true, -- Show diff view for edit permissions }, }, }, } ``` -------------------------------- ### Configure Built-in Prompts Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Define and invoke reusable prompts via the global configuration table. ```lua -- Default prompts configuration vim.g.opencode_opts = { prompts = { -- Opens ask dialog with empty prompt ask = { prompt = "", ask = true, submit = true }, -- Code review and analysis diagnostics = { prompt = "Explain @diagnostics", submit = true }, diff = { prompt = "Review the following git diff for correctness and readability: @diff", submit = true }, explain = { prompt = "Explain @this and its context", submit = true }, review = { prompt = "Review @this for correctness and readability", submit = true }, -- Code modification document = { prompt = "Add comments documenting @this", submit = true }, fix = { prompt = "Fix @diagnostics", submit = true }, implement = { prompt = "Implement @this", submit = true }, optimize = { prompt = "Optimize @this for performance and readability", submit = true }, test = { prompt = "Add tests for @this", submit = true }, -- Custom prompts refactor = { prompt = "Refactor @this to be more maintainable", submit = true, }, security = { prompt = "Review @this for security vulnerabilities", submit = true, }, typescript = { prompt = "Convert @this to TypeScript with proper types", submit = true, }, debug = { prompt = "Add debug logging to @this", ask = true, -- Opens input for additional instructions submit = false, }, }, } -- Use prompts by name require("opencode").prompt("review") -- Uses configured review prompt require("opencode").prompt("explain") -- Uses configured explain prompt require("opencode").prompt("fix") -- Uses configured fix prompt ``` -------------------------------- ### Utilize Context Placeholders Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Inject editor state into prompts using placeholders and define custom context providers. ```lua -- Available context placeholders: -- @this - Operator range, visual selection, or cursor position -- @buffer - Current buffer contents -- @buffers - All open buffer paths -- @visible - Visible text in all windows -- @diagnostics - Current buffer diagnostics -- @quickfix - Quickfix list contents -- @diff - Git diff output -- @marks - Global marks -- @grapple - grapple.nvim tags (if installed) -- Examples using context placeholders require("opencode").prompt("Explain @this and its context", { submit = true }) require("opencode").prompt("Fix @diagnostics in the current file", { submit = true }) require("opencode").prompt("Review @diff for potential issues", { submit = true }) require("opencode").prompt("Document @this with JSDoc comments", { submit = true }) -- Custom context function in configuration vim.g.opencode_opts = { contexts = { ["@this"] = function(context) return context:this() end, ["@buffer"] = function(context) return context:buffer() end, ["@custom"] = function(context) -- Return custom context string return "Project: MyApp\nVersion: 1.0.0" end, }, } -- Context methods available on context object: -- context:this() - Range or cursor position -- context:buffer() - Current buffer path -- context:buffers() - All buffer paths (comma-separated) -- context:visible_text() - Visible lines in all windows -- context:diagnostics() - Formatted diagnostic messages -- context:quickfix() - Quickfix entries -- context:git_diff() - Git diff output -- context:marks() - Global marks -- context:grapple_tags() - Grapple tags ``` -------------------------------- ### Configure OpenCode LSP Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Set the global configuration table to enable LSP features, specify filetypes, and define handler settings. ```lua -- Enable experimental LSP features vim.g.opencode_opts = { lsp = { enabled = true, filetypes = nil, -- All filetypes, or specify: { "lua", "python", "typescript" } handlers = { hover = { enabled = true, model = nil, -- Use default model, or specify: "gpt-4", "claude-3", etc. }, code_action = { enabled = true, }, }, }, } ``` -------------------------------- ### Configure snacks.nvim Integration Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Add custom actions to snacks.picker and configure a terminal for OpenCode. ```lua -- Configure snacks.nvim with opencode action require("snacks").setup({ picker = { actions = { opencode_send = function(...) return require("opencode").snacks_picker_send(...) end, }, win = { input = { keys = { [""] = { "opencode_send", mode = { "n", "i" } }, }, }, }, }, }) -- Usage: In any snacks picker, press to send selected items to opencode -- Works with file pickers, grep results, LSP references, etc. -- The snacks_picker_send function formats items with file paths and positions: -- - Single file: /path/to/file.lua:L10:C5-L20:C10 -- - Multiple files: Newline-separated list -- - Falls back to item text if no file info available -- Custom snacks terminal for opencode vim.g.opencode_opts = { server = { start = function() require("snacks.terminal").open("opencode --port", { win = { position = "right", enter = false, on_win = function(win) require("opencode.terminal").setup(win.win) end, }, }) end, toggle = function() require("snacks.terminal").toggle("opencode --port", { win = { position = "right" }, }) end, }, } ``` -------------------------------- ### Manage OpenCode Server Lifecycle Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Functions for controlling the server state and configuring custom server behavior via vim.g.opencode_opts. ```lua -- Toggle server visibility (show/hide terminal) require("opencode").toggle() -- Start the configured server require("opencode").start() -- Stop the configured server require("opencode").stop() -- Select from multiple running servers require("opencode").select_server() -- Select a specific session require("opencode").select_session() -- Keymaps for server control vim.keymap.set({ "n", "t" }, "", function() require("opencode").toggle() end, { desc = "Toggle opencode terminal" }) -- Custom server configuration vim.g.opencode_opts = { server = { port = 12345, -- Fixed port instead of auto-detect start = function() require("opencode.terminal").open("opencode --port 12345", { split = "right", width = math.floor(vim.o.columns * 0.4), }) end, stop = function() require("opencode.terminal").close() end, toggle = function() require("opencode.terminal").toggle("opencode --port 12345", { split = "right", width = math.floor(vim.o.columns * 0.4), }) end, }, } ``` -------------------------------- ### Opencode Commands Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md This section details the various commands available through the `require("opencode").command()` function, allowing users to manage sessions, navigate messages, and interact with the prompt and agents. ```APIDOC ## Opencode Commands ### Description Provides access to various opencode functionalities through a command interface. ### Method `require("opencode").command(subcommand) ### Endpoint N/A (Lua function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Subcommands - **session.list**: List available sessions. - **session.new**: Start a new session. - **session.select**: Select an existing session. - **session.share**: Share the current session. - **session.interrupt**: Interrupt the current session. - **session.compact**: Compact the current session to reduce context size. - **session.page.up**: Scroll messages up by one page. - **session.page.down**: Scroll messages down by one page. - **session.half.page.up**: Scroll messages up by half a page. - **session.half.page.down**: Scroll messages down by half a page. - **session.first**: Jump to the first message in the session. - **session.last**: Jump to the last message in the session. - **session.undo**: Undo the last action in the current session. - **session.redo**: Redo the last undone action in the current session. - **prompt.submit**: Submit the text input in the TUI. - **prompt.clear**: Clear the text input in the TUI. - **agent.cycle**: Cycle through available agents. ### Request Example ```lua require("opencode").command("session.list") require("opencode").command("prompt.submit") ``` ### Response None (commands typically trigger actions within the plugin) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Use prompt() for Programmatic Prompts Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Sends a prompt directly to OpenCode without an input dialog. Resolves named prompts from configuration and injects configured contexts. Useful for automated tasks or custom workflows. ```lua -- Direct prompt with immediate submission require("opencode").prompt("Explain the error in this code", { submit = true }) ``` ```lua -- Use a named prompt from configuration require("opencode").prompt("review") -- Uses prompts.review from config ``` ```lua -- Prompt with context injection require("opencode").prompt("Optimize @this for performance", { submit = true }) ``` ```lua -- Prompt with all open buffers require("opencode").prompt("Find potential issues across @buffers") ``` ```lua -- Prompt with git diff context require("opencode").prompt("Review the following changes: @diff", { submit = true }) ``` ```lua -- Prompt with visible text in all windows require("opencode").prompt("Explain what @visible does") ``` ```lua -- Programmatic prompt in a function local function review_current_file() require("opencode").prompt("Review @buffer for bugs and improvements", { submit = true, context = require("opencode.context").new(), }) end ``` -------------------------------- ### Built-in Prompts Configuration Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Pre-configured prompts available via select() or by name reference. ```APIDOC ## Built-in Prompts Configuration ### Description Pre-configured prompts available via `select()` or by name reference. Each prompt can be customized or extended. ### Usage `require("opencode").prompt(name)` - Executes a configured prompt by name. ``` -------------------------------- ### Use ask() for Interactive Prompts Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Opens an interactive input prompt for sending messages to OpenCode. Supports completions, context placeholders, and history browsing. Ending prompts with '\n' appends instead of submitting. ```lua -- Basic ask with pre-filled text require("opencode").ask("Explain this function: ") ``` ```lua -- Ask with context placeholder (replaced with current selection/cursor position) require("opencode").ask("@this: ", { submit = true }) ``` ```lua -- Ask about current buffer require("opencode").ask("Review @buffer for best practices") ``` ```lua -- Ask about diagnostics in the buffer require("opencode").ask("Fix @diagnostics") ``` ```lua -- Ask with visual selection context (in visual mode mapping) vim.keymap.set("x", "ae", function() require("opencode").ask("Explain @this in detail", { submit = false }) end, { desc = "Ask opencode to explain selection" }) ``` ```lua -- Custom ask with snacks.input integration vim.keymap.set("n", "aa", function() require("opencode").ask("", { submit = false, context = require("opencode.context").new(), }) end, { desc = "Open opencode prompt" }) ``` -------------------------------- ### Open Full Selection Menu with OpenCode Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Opens the full selection menu for OpenCode functionality. Can be configured with custom sections for prompts, commands, and server controls. Integrates with snacks.picker for enhanced previews. ```lua -- Open the full selection menu require("opencode").select() ``` ```lua -- Open with custom section configuration require("opencode").select({ sections = { prompts = true, -- Show configured prompts commands = { ["session.new"] = "Start a fresh session", ["session.compact"] = "Reduce context size", ["agent.cycle"] = "Switch AI agent", }, server = true, -- Show server controls }, }) ``` ```lua -- Keymap for quick access vim.keymap.set({ "n", "x" }, "", function() require("opencode").select() end, { desc = "Execute opencode action" }) ``` ```lua -- Select with snacks.picker options require("opencode").select({ snacks = { preview = "preview", layout = { preset = "vscode", }, }, }) ``` -------------------------------- ### Opencode LSP Integration Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md Details on how opencode.nvim integrates with the Language Server Protocol (LSP) to provide features like Hover and Code Actions. ```APIDOC ## Opencode LSP Integration ### Description `opencode.nvim` offers an in-process LSP server that enables interaction with `opencode` using standard LSP client functions. This feature is experimental and requires explicit enabling. ### Method LSP Functions (e.g., `vim.lsp.buf_request_all`) ### Endpoint N/A (In-process LSP) ### Parameters None directly for enabling, but requires configuration. ### Configuration To enable the LSP feature, set the following global variable: ```lua vim.g.opencode_opts.lsp.enabled = true ``` ### Supported LSP Functions - **Hover**: Provides a brief explanation of the symbol located under the cursor. - **Code Actions**: Offers suggestions from `opencode` to explain or fix diagnostics found at the cursor's position. ### Request Example ```lua -- Example for requesting hover information vim.lsp.buf_request_all(0, "textDocument/hover", { textDocument = vim.lsp.util.make_text_document_params() }) -- Example for requesting code actions vim.lsp.buf_request_all(0, "textDocument/codeAction", { context = { diagnostics = vim.diagnostic.get(0) }, textDocument = vim.lsp.util.make_text_document_params() }) ``` ### Response Responses depend on the specific LSP request made. For example, a hover request will return hover information, and a code action request will return a list of available code actions. ``` -------------------------------- ### Opencode Edits and Permissions Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md Explains how opencode.nvim handles file edits and permission requests, including UI interactions and keybindings for managing changes. ```APIDOC ## Opencode Edits and Permissions ### Description This section covers how `opencode.nvim` manages file modifications initiated by `opencode` and handles permission requests. For edits, it uses Neovim's diff capabilities to show changes side-by-side. ### Handling Edits When `opencode` proposes edits to a file, `opencode.nvim` automatically reloads the affected buffer. For visual comparison, it opens the target file in a new tab and utilizes Neovim's `:diffpatch` functionality. Customization of the diff view can be done via `':h "diffopt"'`. ### Handling Permissions When `opencode` requires user permission for an action (e.g., file modification), `opencode.nvim` waits for an idle state before prompting the user to approve or deny the request. ### Edit Request Interface (Diff View) When viewing proposed edits, the following keybindings are available: | Keymap | Function | | ------- | ----------------------------------------------------------------------------- | | `da` | Accept the entire edit request | | `dr` | Reject the entire edit request | | `]c/[c` | Navigate to the next/previous change (hunk) | | `dp` | Accept _only_ the current hunk and reject the rest of the edit request | | `do` | Reject _only_ the current hunk and accept the rest of the edit request | | `q` | Close the diff view without applying any changes | ### Request Example (No direct API calls for this, as it's a UI interaction triggered by `opencode`.) ### Response Actions taken via the keymaps result in the edit being applied or rejected, or the diff view being closed. ``` -------------------------------- ### Define Custom Hover Keymap Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Map a key to trigger built-in LSP hover, falling back to OpenCode's ask function if the LSP fails. ```lua -- Example: Custom hover behavior vim.keymap.set("n", "K", function() -- First try built-in LSP, then fall back to opencode local hover_ok = pcall(vim.lsp.buf.hover) if not hover_ok then require("opencode").ask("Explain the symbol under cursor: @this", { submit = true }) end end, { desc = "Hover documentation" }) ``` -------------------------------- ### select() - Action Picker Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Opens a selection menu with all OpenCode functionality including prompts, commands, and server controls. Integrates with snacks.picker for enhanced previews and highlighting. ```APIDOC ## select() ### Description Opens a selection menu with all OpenCode functionality including prompts, commands, and server controls. Integrates with snacks.picker for enhanced previews and highlighting. ### Parameters #### Request Body - **sections** (table) - Optional - Configuration for sections (prompts, commands, server). - **snacks** (table) - Optional - Configuration for snacks.picker integration (preview, layout). ``` -------------------------------- ### Opencode Statusline Integration Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md Instructions on how to integrate the opencode.nvim statusline component into popular statusline plugins like lualine. ```APIDOC ## Opencode Statusline Integration ### Description This section provides guidance on integrating the `opencode.nvim` statusline component, which displays relevant information about the current `opencode` session, into your Neovim statusline configuration. ### Method Configuration of statusline plugins (e.g., `lualine.nvim`). ### Endpoint N/A (Configuration setting) ### Parameters None ### Example Usage (with lualine.nvim) To add the `opencode` statusline component to `lualine.nvim`, modify your `lualine` setup as follows: ```lua require("lualine").setup({ sections = { lualine_z = { { -- Add the opencode statusline component here require("opencode").statusline, }, }, -- other sections... }, -- other lualine options... }) ``` ### Request Example ```lua -- This is a configuration snippet, not an API request. require("lualine").setup({ sections = { lualine_z = { require("opencode").statusline, } } }) ``` ### Response Displays the `opencode` status information within the configured statusline. ``` -------------------------------- ### command() - Execute OpenCode Commands Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Sends commands directly to the OpenCode TUI for session management, navigation, and control. ```APIDOC ## command(cmd) ### Description Sends commands directly to the OpenCode TUI for session management, navigation, and control. ### Parameters #### Path Parameters - **cmd** (string) - Required - The command string to execute (e.g., "session.new", "session.page.up", "agent.cycle"). ``` -------------------------------- ### Opencode Events Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md Information on how to handle Server-Sent-Events (SSE) forwarded by opencode.nvim as `OpencodeEvent` autocmds. ```APIDOC ## Opencode Events ### Description `opencode.nvim` forwards Server-Sent-Events from `opencode` as Neovim `User` autocmds with the pattern `OpencodeEvent:*`. This allows users to react to various events occurring within `opencode`. ### Method `vim.api.nvim_create_autocmd("User", { ... }) ### Endpoint N/A (Autocmds) ### Parameters - **pattern**: `"OpencodeEvent:*"` (can be filtered further, e.g., `"OpencodeEvent:session.idle"`) - **callback**: A Lua function that receives event data. ### Event Data Structure The callback function receives an `args` table containing: - `args.data.event`: The actual event object from `opencode` (type `opencode.server.Event`). - `args.data.port`: The port number associated with the `opencode` server. ### Example Usage ```lua -- Handle `opencode` events vim.api.nvim_create_autocmd("User", { pattern = "OpencodeEvent:*", -- Optionally filter event types callback = function(args) --@type opencode.server.Event local event = args.data.event --@type number local port = args.data.port -- See the available event types and their properties vim.notify(vim.inspect(event)) -- Do something useful if event.type == "session.idle" then vim.notify("`opencode` finished responding") end end, }) ``` ### Common Event Types - `session.idle`: Indicates that `opencode` has finished responding. (Refer to `opencode` documentation for a full list of event types and their properties.) ### Response Example ```lua -- Example event data structure { type = "session.idle", -- other event-specific fields... } ``` ``` -------------------------------- ### Integrate Statusline Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Display OpenCode connection status and icons in your statusline using built-in helpers or custom components. ```lua -- Basic statusline function require("opencode").statusline() -- Returns icon + port like "󰚩 :3000" -- Lualine integration require("lualine").setup({ sections = { lualine_z = { { require("opencode").statusline, }, }, }, }) -- Custom statusline component local function opencode_status() local status = require("opencode.status") local icon = status.statusline_icon() -- Icons: 󰚩 (idle), 󱜙 (responding), 󱚟 (permission), 󱚡 (error), 󱚧 (disconnected) return icon end -- Status values available: -- "idle" - Ready for input -- "responding" - Processing request -- "requesting_permission" - Awaiting user approval -- "error" - Error occurred -- nil - Not connected -- Example with heirline.nvim local OpencodeComponent = { provider = function() return require("opencode").statusline() end, condition = function() return require("opencode.events").connected_server ~= nil end, } ``` -------------------------------- ### Configure Lualine Statusline Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md This Lua code configures the lualine statusline plugin to include the opencode.nvim statusline component. Ensure lualine is set up before adding this section. ```lua require("lualine").setup({ sections = { lualine_z = { { require("opencode").statusline, }, }, }, }) ``` -------------------------------- ### Handle opencode Events Source: https://github.com/nickjvandyke/opencode.nvim/blob/main/README.md This Lua code sets up an autocommand to handle 'OpencodeEvent' events. It inspects the event data and performs actions based on the event type, such as notifying when a session becomes idle. ```lua vim.api.nvim_create_autocmd("User", { pattern = "OpencodeEvent:*", -- Optionally filter event types callback = function(args) --@type opencode.server.Event local event = args.data.event --@type number local port = args.data.port -- See the available event types and their properties vim.notify(vim.inspect(event)) -- Do something useful if event.type == "session.idle" then vim.notify("`opencode` finished responding") end end, }) ``` -------------------------------- ### operator() - Vim Operator Integration Source: https://context7.com/nickjvandyke/opencode.nvim/llms.txt Wraps prompt functionality as a Vim operator supporting ranges and dot-repeat. Returns "g@" for use with operatorfunc. ```APIDOC ## operator(prompt) ### Description Wraps prompt functionality as a Vim operator supporting ranges and dot-repeat. Returns "g@" for use with operatorfunc. ### Parameters #### Path Parameters - **prompt** (string) - Required - The prompt string to prepend to the selected text. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.