### Vim-Plug Installation for CopilotChat.nvim Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Install CopilotChat.nvim using vim-plug. Includes 'nvim-lua/plenary.nvim' as a dependency and requires calling require("CopilotChat").setup() in Lua. ```vim call plug#begin() Plug 'nvim-lua/plenary.nvim' Plug 'CopilotC-Nvim/CopilotChat.nvim' call plug#end() lua << EOF require("CopilotChat").setup() EOF ``` -------------------------------- ### Lazy.nvim Installation for CopilotChat.nvim Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Install CopilotChat.nvim using lazy.nvim. Ensure 'nvim-lua/plenary.nvim' is a dependency and 'make tiktoken' is run during the build process. ```lua return { { "CopilotC-Nvim/CopilotChat.nvim", dependencies = { { "nvim-lua/plenary.nvim", branch = "master" }, }, build = "make tiktoken", opts = { -- See Configuration section for options }, }, } ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Installs pre-commit hooks and other development dependencies required for contributing to the project. ```bash make install-pre-commit ``` -------------------------------- ### Show Help Actions with Telescope Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/MIGRATION.md Use this to display available help actions within Copilot Chat using the Telescope plugin. Ensure `copilot.nvim` and `plenary.nvim` are installed. ```lua local actions = require("CopilotChat.actions") require("CopilotChat.integrations.telescope").pick(actions.help_actions()) ``` -------------------------------- ### Setup Trusted Tools Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Configures CopilotChat.nvim to automatically trust a predefined set of small, read-only tools for specific operations. ```lua require('CopilotChat').setup({ trusted_tools = { 'file', 'glob', 'grep' }, }) ``` -------------------------------- ### Custom AI Provider Configuration Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Example of how to add a custom AI provider to CopilotChat.nvim. This involves defining a table with provider-specific functions like getting the URL, headers, and models. ```lua { providers = { my_provider = { get_url = function(opts) return 'https://api.example.com/chat' end, get_headers = function() return { ['Authorization'] = 'Bearer ' .. api_key } end, get_models = function() return { { id = 'gpt-5-mini', name = 'GPT-5 mini model' } } end, prepare_input = require('CopilotChat.config.providers').copilot.prepare_input, prepare_output = require('CopilotChat.config.providers').copilot.prepare_output, } } } ``` -------------------------------- ### Trusted Tools Setup Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Configures the plugin to automatically trust a predefined set of small, read-only tools for use in chat interactions. ```lua -- Automatically trust a small read-only tool set require('CopilotChat').setup({ trusted_tools = { 'file', 'glob', 'grep' }, }) ``` -------------------------------- ### Create a new feature branch Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/CONTRIBUTING.md When starting work on an issue, create a new branch with a descriptive name. This helps in tracking changes related to specific issues. ```bash git checkout -b 325-add-japanese-localization ``` -------------------------------- ### Provider Interface Definition Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Defines the interface for custom AI providers in CopilotChat.nvim. It outlines optional functions for disabling, getting info, headers, URL, input/output preparation, models, and model resolution. ```lua { -- Optional: Disable provider disabled?: boolean, -- Optional: Extra info about the provider displayed in info panel get_info?(headers: table): string[] -- Optional: Get extra request headers with optional expiration time get_headers?(): table, number?, -- Optional: Get API endpoint URL get_url?(opts: CopilotChat.Provider.options): string, -- Optional: Prepare request input prepare_input?(inputs: table, opts: CopilotChat.Provider.options): table, -- Optional: Prepare response output prepare_output?(output: table, opts: CopilotChat.Provider.options): CopilotChat.Provider.output, -- Optional: Get available models get_models?(headers: table): table, -- Optional: Resolve a user-facing model id to a provider model id resolve_model?(headers: table, model: string): string, } ``` -------------------------------- ### Set Up Quick Chat Keybinding Source: https://github.com/copilotc-nvim/copilotchat.nvim/wiki/Examples-and-Tips Configures a keybinding to initiate a quick chat using the entire buffer content. Requires user input for the chat prompt. ```lua -- Quick chat keybinding vim.keymap.set('n', 'ccq', function() local input = vim.fn.input("Quick Chat: ") if input ~= "" then require("CopilotChat").ask(input, { resources = { 'buffer' }, }) end end, { desc = "CopilotChat - Quick chat" }) ``` -------------------------------- ### CopilotChat.nvim Configuration Options Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Configure AI model, temperature, trusted tools, window layout, and auto-insert mode for copilotchat.nvim. ```lua { model = 'gpt-5-mini', temperature = 0.1, trusted_tools = nil, window = { layout = 'vertical', width = 0.5, }, auto_insert_mode = true, } ``` -------------------------------- ### Basic CopilotChat Configuration Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Sets the AI model, temperature, and basic window layout for CopilotChat. ```lua { model = 'gpt-5-mini', -- AI model to use temperature = 0.1, -- Lower = focused, higher = creative trusted_tools = nil, -- Require approval for all tool calls window = { layout = 'vertical', width = 0.5, -- 50% of screen width }, auto_insert_mode = true, -- Enter insert mode when opening } ``` -------------------------------- ### Run Tests with make test Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/AGENTS.md Execute the test suite using the provided make command. This command runs Neovim in headless mode with the plenary test harness. ```bash make test ``` -------------------------------- ### Sticky Context with Tools Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Combine buffer content with tool access using `> #buffer:listed` and `@copilot` to provide context for LLM actions like refactoring code. ```markdown # Sticky context with tools > #buffer:listed > @copilot > Refactor the authentication code ``` -------------------------------- ### Project Structure Overview Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/AGENTS.md Provides a detailed breakdown of the copilotchat.nvim project directory and file structure. Understanding this layout is crucial for navigation and development. ```text plugin/CopilotChat.lua — Neovim plugin entry: commands, highlights, autocmds lua/CopilotChat/ init.lua — Main module: setup(), ask(), open/close/toggle, save/load client.lua — Copilot API client (auth, streaming, tool calls) config.lua — Default configuration schema config/ — Sub-configs: functions, mappings, prompts, providers constants.lua — Shared constants (roles, etc.) completion.lua — Completion source functions.lua — Built-in functions/tools exposed to the LLM prompts.lua — Built-in prompt definitions resources.lua — Resource handling select.lua — Selection strategies (visual, buffer, diagnostics, git diff) tiktoken.lua — Token counting via native tiktoken lib health.lua — :checkhealth integration notify.lua — Notification utilities instructions/ — System prompt templates injected into LLM conversations (not agent guidance) ui/ — Chat window, overlay, spinner utils.lua — General utilities utils/ — Utility modules: class, curl, diff, files, orderedmap, stringbuffer queries/ — Treesitter queries for copilot-chat filetype tests/ — Plenary busted-style specs (*_spec.lua) scripts/ test.lua — Test runner bootstrap (sets up plenary) minimal.lua — Minimal reproduction config doc/CopilotChat.txt — Auto-generated vimdoc (do NOT edit; generated from README by panvimdoc in CI) ``` -------------------------------- ### Run Tests Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Executes the test suite for CopilotChat.nvim. ```bash make test ``` -------------------------------- ### Show Prompt Actions with Telescope Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/MIGRATION.md This snippet demonstrates how to display prompt actions in Copilot Chat using Telescope, with options to select visual or buffer content. Requires `copilot.nvim` and `plenary.nvim`. ```lua local actions = require("CopilotChat.actions") local select = require("CopilotChat.select") require("CopilotChat.integrations.telescope").pick(actions.prompt_actions({ selection = select.visual, })) ``` -------------------------------- ### Basic Chat Interaction and History Management Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Demonstrates how to open the chat interface, ask a question with a callback for handling the response, and save/load chat history. The response content is trimmed and truncated for display. ```lua -- Open chat, ask a question and handle response require('CopilotChat').open() require('CopilotChat').ask('#buffer Explain this code', { callback = function(response) vim.notify('Got response: ' .. vim.trim(response.content):sub(1, 50) .. '...') end, }) -- Save and load chat history require('CopilotChat').save('my_debugging_session') require('CopilotChat').load('my_debugging_session') ``` -------------------------------- ### Defining Custom Prompts Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Allows users to define custom prompts with specific instructions, system prompts, key mappings, and descriptions. ```lua { prompts = { MyCustomPrompt = { prompt = 'Explain how it works.', system_prompt = 'You are very good at explaining stuff', mapping = 'ccmc', description = 'My custom prompt description', }, Yarrr = { system_prompt = 'You are fascinated by pirates, so please respond in pirate speak.', }, NiceInstructions = { system_prompt = 'You are a nice coding tutor, so please respond in a friendly and helpful manner.', } } } ``` -------------------------------- ### Custom Chat Configuration Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Shows how to specify a custom AI model and define custom sticky context for a chat query. Sticky context can include buffer content and staged Git diffs. ```lua -- Use custom sticky and model require('CopilotChat').ask('How can I optimize this?', { model = 'gpt-5-mini', sticky = { '#buffer', '#gitdiff:staged' }, }) ``` -------------------------------- ### Clone Repository Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Clones the CopilotChat.nvim repository to your local machine. ```bash git clone https://github.com/CopilotC-Nvim/CopilotChat.nvim cd CopilotChat.nvim ``` -------------------------------- ### Advanced Window and Appearance Settings Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Configures detailed window properties like layout, size, borders, titles, and headers for the chat interface. ```lua { window = { layout = 'float', width = 80, -- Fixed width in columns height = 20, -- Fixed height in rows border = 'rounded', -- 'single', 'double', 'rounded', 'solid' title = '🤖 AI Assistant', zindex = 100, -- Ensure window stays on top }, headers = { user = '👤 You', assistant = '🤖 Copilot', tool = '🔧 Tool', }, separator = '━━', auto_fold = true, -- Automatically folds non-assistant messages } ``` -------------------------------- ### Accessing All Open Buffers Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Use the `#buffer:listed` predefined function to include content from all currently open buffers. This replaces the older `#buffers` syntax. ```markdown # All open buffers (replaces old #buffers) #buffer:listed ``` -------------------------------- ### Open Chat and Ask a Question Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Opens the chat interface and sends a question about the current buffer's code. Handles the response using a callback function. ```lua require('CopilotChat').open() require('CopilotChat').ask('#buffer Explain this code', { callback = function(response) vim.notify('Got response: ' .. vim.trim(response.content):sub(1, 50) .. '...') end, }) ``` -------------------------------- ### Ask Question with Custom Model and Sticky Context Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Asks a question using a specified AI model and includes custom sticky contexts like the current buffer and staged Git diff. ```lua require('CopilotChat').ask('How can I optimize this?', { model = 'gpt-5-mini', sticky = { '#buffer', '#gitdiff:staged' }, }) ``` -------------------------------- ### Fetching Content from a URL Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Use the `#url:` predefined function to fetch and include content from a specified HTTPS URL. ```markdown # URL content #url:https://example.com/docs ``` -------------------------------- ### Core API Functions Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Provides essential functions for interacting with CopilotChat.nvim. Includes methods for asking questions, managing the chat window, prompts, models, and history. ```lua local chat = require('CopilotChat') -- Basic Chat Functions chat.ask(prompt, config) -- Ask a question with optional config -- Window Management chat.open(config) -- Open chat window with optional config chat.close() -- Close chat window chat.toggle(config) -- Toggle chat window visibility with optional config chat.reset() -- Reset the chat chat.stop() -- Stop current output -- Prompt & Model Management chat.select_prompt(config) -- Open prompt selector with optional config chat.select_model() -- Open model selector -- History Management chat.load(name, history_path) -- Load chat history chat.save(name, history_path) -- Save chat history -- Configuration chat.setup(config) -- Update configuration chat.log_level(level) -- Set log level (debug, info, etc.) ``` -------------------------------- ### Accessing All Visible Buffers Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Use the `#buffer:visible` predefined function to include content from all visible buffers. ```markdown # All visible buffers #buffer:visible ``` -------------------------------- ### Configure Inline Chat Window Source: https://github.com/copilotc-nvim/copilotchat.nvim/wiki/Examples-and-Tips Sets up the chat window to appear inline near the cursor. Adjusts layout, relative positioning, and dimensions. ```lua require("CopilotChat").setup({ window = { layout = 'float', relative = 'cursor', width = 1, height = 0.4, row = 1 } }) ``` -------------------------------- ### Enable Markdown Rendering for Chat Source: https://github.com/copilotc-nvim/copilotchat.nvim/wiki/Examples-and-Tips Registers the 'copilot-chat' filetype with render-markdown.nvim for improved chat display and adjusts CopilotChat's display settings. ```lua -- Register copilot-chat filetype require('render-markdown').setup({ file_types = { 'markdown', 'copilot-chat' }, }) -- Adjust chat display settings require('CopilotChat').setup({ highlight_headers = false, separator = '---', error_header = '> [!ERROR] Error', }) ``` -------------------------------- ### Accessing Specific File Content Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Use the `#file:` predefined function to include the content of a specific file. Use Tab for path completion. ```markdown # Specific file #file:src/main.lua ``` -------------------------------- ### Save and Load Chat History Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Demonstrates how to save the current chat session to a named file and load a previously saved session. ```lua require('CopilotChat').save('my_debugging_session') require('CopilotChat').load('my_debugging_session') ``` -------------------------------- ### Chat Window UI Methods Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Methods for controlling and querying the state of the chat window UI. ```APIDOC ## Chat Window UI Methods ### Description Methods to interact with and query the state of the chat window's user interface. ### Methods - `window:visible()`: Check if the chat window is currently visible. - `window:focused()`: Check if the chat window currently has focus. - `window:get_message(role, cursor)`: Retrieve a chat message based on its role and proximity to a cursor position. - `window:add_message({ role, content }, replace)`: Add a new message or replace an existing one in the chat. - `window:remove_message(role, cursor)`: Remove a chat message based on its role and proximity to a cursor position. - `window:get_block(role, cursor)`: Retrieve a code block from the chat based on its role and proximity to a cursor position. - `window:append(text)`: Append text content to the chat window. - `window:clear()`: Clear all content from the chat window. - `window:start()`: Indicate the start of writing content to the chat window. - `window:finish()`: Indicate the completion of writing content to the chat window. - `window:get_source()`: Get the current source buffer and window associated with the chat. - `window:set_source(winnr)`: Set the source window for the chat. - `window:follow()`: Move the cursor to the end of the chat content. - `window:focus()`: Set focus to the chat window. - `window:overlay(opts)`: Display an overlay with specified options. ``` -------------------------------- ### Chat Window UI Methods Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Exposes methods for controlling and interacting with the chat window's user interface. These functions manage visibility, message content, source buffer linking, and navigation within the chat. ```lua local window = require('CopilotChat').chat -- Chat UI State window:visible() -- Check if chat window is visible window:focused() -- Check if chat window is focused -- Message Management window:get_message(role, cursor) -- Get chat message by role, either last or closest to cursor window:add_message({ role, content }, replace) -- Add or replace a message in chat window:remove_message(role, cursor) -- Remove chat message by role, either last or closest to cursor window:get_block(role, cursor) -- Get code block by role, either last or closest to cursor -- Content Management window:append(text) -- Append text to chat window window:clear() -- Clear chat window content window:start() -- Start writing to chat window window:finish() -- Finish writing to chat window -- Source Management window:get_source() -- Get the current source buffer and window window:set_source(winnr) -- Set the source window -- Navigation window:follow() -- Move cursor to end of chat content window:focus() -- Focus the chat window -- Advanced Features window:overlay(opts) -- Show overlay with specified options ``` -------------------------------- ### Granting LLM Access to Workspace Tools Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Use `@copilot` to allow the LLM to call functions from the `copilot` group, such as bash, edit, file, glob, grep, and gitdiff. This enables the LLM to interact with your project files and environment. ```markdown # Give LLM access to workspace tools @copilot What files are in this project? ``` -------------------------------- ### Check Formatting Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Runs the stylua formatter check to ensure code adheres to project formatting standards, mimicking the CI check. ```bash stylua --check . ``` -------------------------------- ### Core API Functions Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Provides essential functions for interacting with the chat, managing windows, prompts, models, and history. ```APIDOC ## Core API Functions ### Description Core functions for initiating chats, managing the chat window, handling prompts and models, and managing chat history. ### Functions - `chat.ask(prompt, config)`: Ask a question with optional configuration. - `chat.open(config)`: Open the chat window with optional configuration. - `chat.close()`: Close the chat window. - `chat.toggle(config)`: Toggle the chat window's visibility with optional configuration. - `chat.reset()`: Reset the chat state. - `chat.stop()`: Stop the current output generation. - `chat.select_prompt(config)`: Open the prompt selector with optional configuration. - `chat.select_model()`: Open the model selector. - `chat.load(name, history_path)`: Load chat history from a specified path. - `chat.save(name, history_path)`: Save the current chat history to a specified path. - `chat.setup(config)`: Update the plugin's configuration. - `chat.log_level(level)`: Set the logging level (e.g., 'debug', 'info'). ``` -------------------------------- ### Prompt Parser Functions Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt These functions from the CopilotChat.prompts module are used to resolve various references within prompts, including prompt references, tools, and manual function references. Note that resolving the model is an asynchronous operation. ```lua local parser = require('CopilotChat.prompts') parser.resolve_prompt() -- Resolve prompt references parser.resolve_tools() -- Resolve tools shared with the model via @... parser.resolve_functions() -- Resolve manual function/resource references via #... parser.resolve_model() -- Resolve model from prompt (WARN: async, requires plenary.async.run) ``` -------------------------------- ### Customizing Chat Buffer Behavior Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Sets up an autocommand to disable relative and absolute line numbers, and reset conceallevel when entering the chat buffer. ```lua -- Auto-command to customize chat buffer behavior vim.api.nvim_create_autocmd('BufEnter', { pattern = 'copilot-chat', callback = function() vim.opt_local.relativenumber = false vim.opt_local.number = false vim.opt_local.conceallevel = 0 end, }) ``` -------------------------------- ### Chat Window Management Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Methods for controlling and querying the state and content of the chat window UI. ```APIDOC ## Chat Window API ### Description Methods for controlling and querying the state and content of the chat window UI. ### Functions - **window:visible()**: Check if chat window is visible. - **window:focused()**: Check if chat window is focused. - **window:get_message(role, cursor)**: Get chat message by role, either last or closest to cursor. - **window:add_message({ role, content }, replace)**: Add or replace a message in chat. - **window:remove_message(role, cursor)**: Remove chat message by role, either last or closest to cursor. - **window:get_block(role, cursor)**: Get code block by role, either last or closest to cursor. - **window:append(text)**: Append text to chat window. - **window:clear()**: Clear chat window content. - **window:start()**: Start writing to chat window. - **window:finish()**: Finish writing to chat window. - **window:get_source()**: Get the current source buffer and window. - **window:set_source(winnr)**: Set the source window. - **window:follow()**: Move cursor to end of chat content. ``` -------------------------------- ### Customizing Highlight Groups Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Applies custom colors and styles to CopilotChat UI elements by setting highlight groups. ```lua -- In your colorscheme or init.lua vim.api.nvim_set_hl(0, 'CopilotChatHeader', { fg = '#7C3AED', bold = true }) vim.api.nvim_set_hl(0, 'CopilotChatSeparator', { fg = '#374151' }) ``` -------------------------------- ### Custom Provider Configuration Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Defines the interface for adding and configuring custom AI providers. ```APIDOC ## Custom Provider Interface ### Description Defines the interface for adding and configuring custom AI providers. ### Provider Options - **disabled?**: boolean - Optional: Disable provider. - **get_info?(headers: table)**: string[] - Optional: Get extra info about the provider displayed in info panel. - **get_headers?()**: table, number? - Optional: Get extra request headers with optional expiration time. - **get_url?(opts: CopilotChat.Provider.options)**: string - Optional: Get API endpoint URL. - **prepare_input?(inputs: table, opts: CopilotChat.Provider.options)**: table - Optional: Prepare request input. - **prepare_output?(output: table, opts: CopilotChat.Provider.options)**: CopilotChat.Provider.output - Optional: Prepare response output. - **get_models?(headers: table)**: table - Optional: Get available models. - **resolve_model?(headers: table, model: string)**: string - Optional: Resolve a user-facing model id to a provider model id. ``` -------------------------------- ### Format Check with stylua Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/AGENTS.md Perform a format check on the project files using stylua. This command is used in CI to ensure code style consistency. ```bash stylua --check . ``` -------------------------------- ### Configuring Trusted Tools Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Sets the trust level for tool calls, controlling whether they execute automatically or require user approval. ```lua { trusted_tools = nil, -- default: require approval for all tool calls -- trust all functions in a group -- trusted_tools = 'copilot', -- trust specific functions by name or groups by name -- trusted_tools = { 'file', 'glob', 'grep' }, -- trust every enabled tool call -- trusted_tools = true, } ``` -------------------------------- ### Core Chat Functions Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Provides essential functions for interacting with the chat functionality, such as asking questions, managing the chat window, and selecting prompts or models. ```APIDOC ## Core API Functions ### Description Provides essential functions for interacting with the chat functionality, such as asking questions, managing the chat window, and selecting prompts or models. ### Functions - **chat.ask(prompt, config)**: Ask a question with optional configuration. - **chat.open(config)**: Open chat window with optional configuration. - **chat.close()**: Close chat window. - **chat.toggle(config)**: Toggle chat window visibility with optional configuration. - **chat.reset()**: Reset the chat. - **chat.stop()**: Stop current output. - **chat.select_prompt(config)**: Open prompt selector with optional configuration. - **chat.select_model()**: Open model selector. - **chat.load(name, history_path)**: Load chat history. - **chat.save(name, history_path)**: Save chat history. - **chat.setup(config)**: Update configuration. - **chat.log_level(level)**: Set log level (debug, info, etc.). ``` -------------------------------- ### Define Custom Functions for Tool Calls Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Define custom functions with descriptions, URIs, trust settings, schemas, and resolution logic. These can be used by the model or manually invoked. ```lua { functions = { birthday = { description = 'Retrieves birthday information for a person', uri = 'birthday://{name}', trusted = false, schema = { type = 'object', required = { 'name' }, properties = { name = { type = 'string', enum = { 'Alice', 'Bob', 'Charlie' }, description = "Person's name", }, }, }, resolve = function(input) return { { uri = 'birthday://' .. input.name, mimetype = 'text/plain', data = input.name .. ' birthday info', }, } end, }, } } ``` -------------------------------- ### Defining Custom Functions with Schema Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Defines a custom function 'birthday' with a description, URI, trust setting, and a JSON schema for input validation. ```lua { functions = { birthday = { description = 'Retrieves birthday information for a person', uri = 'birthday://{name}', trusted = false, schema = { type = 'object', required = { 'name' }, properties = { name = { type = 'string', }, }, }, }, }, } ``` -------------------------------- ### Chat Window UI Methods Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Accesses chat window UI methods via the `chat.chat` object. Allows checking visibility and focus, managing messages and code blocks, and controlling content display. ```lua local window = require('CopilotChat').chat -- Chat UI State window:visible() -- Check if chat window is visible window:focused() -- Check if chat window is focused -- Message Management window:get_message(role, cursor) -- Get chat message by role, either last or closest to cursor window:add_message({ role, content }, replace) -- Add or replace a message in chat window:remove_message(role, cursor) -- Remove chat message by role, either last or closest to cursor window:get_block(role, cursor) -- Get code block by role, either last or closest to cursor -- Content Management window:append(text) -- Append text to chat window window:clear() -- Clear chat window content window:start() -- Start writing to chat window window:finish() -- Finish writing to chat window -- Source Management window:get_source() -- Get the current source buffer and window window:set_source(winnr) -- Set the source window -- Navigation window:follow() -- Move cursor to end of chat content ``` -------------------------------- ### Restore Legacy Copilot Chat Behavior Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/MIGRATION.md Configure Copilot Chat to restore legacy behaviors such as using the unnamed register by default, custom headers, and recreating deprecated commands like `CopilotChatVisual`, `CopilotChatInPlace`, `CopilotChatBuffer`, and `CopilotChatVsplitToggle`. ```lua local chat = require('CopilotChat') local select = require('CopilotChat.select') chat.setup { -- Restore the behaviour for CopilotChat to use unnamed register by default selection = select.unnamed, -- Restore the format with ## headers as prefixes, question_header = '## User ', answer_header = '## Copilot ', error_header = '## Error ', } -- Restore CopilotChatVisual vim.api.nvim_create_user_command('CopilotChatVisual', function(args) chat.ask(args.args, { selection = select.visual }) end, { nargs = '*', range = true }) -- Restore CopilotChatInPlace (sort of) vim.api.nvim_create_user_command('CopilotChatInPlace', function(args) chat.ask(args.args, { selection = select.visual, window = { layout = 'float' } }) end, { nargs = '*', range = true }) -- Restore CopilotChatBuffer vim.api.nvim_create_user_command('CopilotChatBuffer', function(args) chat.ask(args.args, { selection = select.buffer }) end, { nargs = '*', range = true }) -- Restore CopilotChatVsplitToggle vim.api.nvim_create_user_command('CopilotChatVsplitToggle', chat.toggle, {}) ``` -------------------------------- ### Accessing Current Buffer Content Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Use the `#buffer:active` predefined function to include the content of the current buffer in your message. ```markdown # Current buffer #buffer:active ``` -------------------------------- ### Accessing Staged Git Changes Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt Use the `#gitdiff:staged` predefined function to include staged Git diff information in your message. ```markdown # Git changes #gitdiff:staged ``` -------------------------------- ### Prompt Parser Functions Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Functions for resolving various elements within prompts, such as tool references, function calls, and model identifiers. ```APIDOC ## Prompt Parser Functions ### Description Functions for resolving different types of references and information within prompts. ### Functions - `parser.resolve_prompt()`: Resolve prompt references. - `parser.resolve_tools()`: Resolve tools shared with the model via `@...` syntax. - `parser.resolve_functions()`: Resolve manual function or resource references via `#...` syntax. - `parser.resolve_model()`: Resolve the model from the prompt (Note: This is an asynchronous operation and requires `plenary.async.run`). ``` -------------------------------- ### Update local main branch and push feature branch Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/CONTRIBUTING.md Before submitting a pull request, ensure your local main branch is up-to-date with the upstream repository. Then, rebase your feature branch onto the updated main branch and push it to your GitHub account. ```bash git remote add upstream git@github.com:CopilotC-Nvim/CopilotChat.nvim.git git checkout main git pull upstream main ``` ```bash git checkout 325-add-japanese-localization git rebase main git push --set-upstream origin 325-add-japanese-localization ``` -------------------------------- ### Disable copilot.vim Tab Mapping Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/doc/CopilotChat.txt If the Tab key is not working as expected, disable the tab mapping in copilot.vim to resolve conflicts. Alternatively, customize CopilotChat keymaps. ```lua vim.g.copilot_no_tab_map = true vim.keymap.set('i', '', 'copilot#Accept("\")', { expr = true, replace_keycodes = false }) ``` -------------------------------- ### Resolve Tab Key Conflicts with copilot.vim Source: https://github.com/copilotc-nvim/copilotchat.nvim/blob/main/README.md Disable the default tab key mapping in copilot.vim to prevent conflicts with CopilotChat.nvim's tab completion. This configuration is for Lua environments. ```lua -- For copilot.vim vim.g.copilot_no_tab_map = true vim.keymap.set('i', '', 'copilot#Accept("\")', { expr = true, replace_keycodes = false }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.