Skip to content

Commit

Permalink
docs: update docs site
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Jan 11, 2025
1 parent afb2dd0 commit 75c091a
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 31 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ luac.out
# Macos
.DS_Store

# vitepress
doc/.vitepress/dist
doc/.vitepress/cache

.direnv/
.testenv/
.repro/
Expand Down
4 changes: 4 additions & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# vitepress
doc/.vitepress/dist
doc/.vitepress/cache

13 changes: 8 additions & 5 deletions doc/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,21 @@ export default defineConfig({
collapsed: false,
items: [
{ text: "Adapters", link: "/configuration/adapters" },
{ text: "Chat Buffer", link: "/configuration/chat" },
{ text: "Chat Buffer", link: "/configuration/chat-buffer" },
{ text: "Inline Assistant", link: "/configuration/inline-assistant" },
{ text: "Action Palette", link: "/configuration/action-palette" },
{ text: "Prompt Library", link: "/configuration/prompt-library" },
{ text: "System Prompt", link: "/configuration/system-prompt" },
{ text: "UI", link: "/configuration/ui" },
{ text: "Others", link: "/configuration/others" },
],
},
{
text: "Usage",
collapsed: false,
collapsed: true,
items: [
{ text: "General", link: "/usage/general" },
{ text: "Chat Buffer", link: "/usage/chat" },
{ text: "Inline Assistant", link: "/usage/inline" },
{ text: "Chat Buffer", link: "/usage/chat-buffer" },
{ text: "Inline Assistant", link: "/usage/inline-assistant" },
{ text: "Commands", link: "/usage/commands" },
{ text: "Action Palette", link: "/usage/action-palette" },
{ text: "Adapters", link: "/usage/adapters" },
Expand All @@ -71,6 +73,7 @@ export default defineConfig({
items: [
{ text: "Creating Adapters", link: "/extending/adapters" },
{ text: "Creating Prompts", link: "/extending/prompts" },
{ text: "Creating Tools", link: "/extending/tools" },
],
},
],
Expand Down
31 changes: 31 additions & 0 deletions doc/configuration/action-palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Configuring the Action Palette

<p align="center">
<img src="https://github.com/user-attachments/assets/0d427d6d-aa5f-405c-ba14-583830251740" alt="Action Palette">
</p>

The Action Palette holds plugin specific items like the ability to launch a chat buffer and the currently open chat buffers. It also displays the prompts from the [Prompt Library](prompt-library).

## Layout

> [!NOTE]
> The Action Palette also supports [Telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) and [mini.pick](https://github.com/echasnovski/mini.pick)
You can change the appearance of the chat buffer by changing the `display.action_palette` table in your configuration:

```lua
require("codecompanion").setup({
display = {
action_palette = {
width = 95,
height = 10,
prompt = "Prompt ", -- Prompt used for interactive LLM calls
provider = "default", -- default|telescope|mini_pick
opts = {
show_default_actions = true, -- Show the default actions in the action palette?
show_default_prompt_library = true, -- Show the default prompt library in the action palette?
},
},
},
}),
```
31 changes: 24 additions & 7 deletions doc/configuration/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ An adapter is what connects Neovim to an LLM. It's the interface that allows dat

## Changing the Default Adapter

Use the `adapter` field in each strategy:
You can change the default adapter as follows:

```lua
require("codecompanion").setup({
Expand All @@ -16,7 +16,7 @@ require("codecompanion").setup({
adapter = "copilot",
},
},
})
}),
```

## Extending an Adapter
Expand All @@ -34,7 +34,7 @@ require("codecompanion").setup({
})
end,
},
})
}),
```

If you do not want to store secrets in plain text, prefix commands with `cmd:`:
Expand All @@ -50,7 +50,24 @@ require("codecompanion").setup({
})
end,
},
})
}),
```

## Adding a Custom Adapter

> [!NOTE]
> See the [Creating Adapters](extending/adapters) section to learn how to create custom adapters
Custom adapters can be added to the plugin as follows:

```lua
require("codecompanion").setup({
adapters = {
my_custom_adapter = function()
return {} -- My adapter logic
end,
},
}),
```

## Setting a Proxy
Expand All @@ -65,7 +82,7 @@ require("codecompanion").setup({
proxy = "socks5://127.0.0.1:9999",
},
},
})
}),
```

## Changing a Model
Expand All @@ -85,7 +102,7 @@ require("codecompanion").setup({
})
end,
},
})
}),
```
## Example: Azure OpenAI

Expand Down Expand Up @@ -116,6 +133,6 @@ require("codecompanion").setup({
adapter = "azure_openai",
},
},
})
}),
```

226 changes: 226 additions & 0 deletions doc/configuration/chat-buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
# Configuring the Chat Buffer

<p align="center">
<img src="https://github.com/user-attachments/assets/597299d2-36b3-469e-b69c-4d8fd14838f8" alt="Chat buffer">
</p>

By default, CodeCompanion provides a "chat" strategy that uses a dedicated Neovim buffer for conversational interaction with your chosen LLM. This buffer can be customized according to your preferences.

## Keymaps

You can define or override the default keymaps to send messages, regenerate responses, close the buffer, etc. Example:

```lua
require("codecompanion").setup({
strategies = {
chat = {
keymaps = {
send = {
modes = { n = "<C-s>", i = "<C-s>" },
},
close = {
modes = { n = "<C-c>", i = "<C-c>" },
},
-- Add further custom keymaps here
},
},
},
})
```

The keymaps are mapped to `<C-s>` for sending a message and `<C-c>` for closing in both normal and insert modes.

## Variables

Variables are placeholders inserted into the chat buffer (using `#`). They provide contextual code or information about the current Neovim state. For instance, the built-in `#buffer` variable sends the current buffer’s contents to the LLM.

You can even define your own variables to share specific content:

```lua
require("codecompanion").setup({
strategies = {
chat = {
variables = {
["my_var"] = {
callback = function()
return "Your custom content here."
end,
description = "Explain what my_var does",
opts = {
contains_code = false,
},
},
},
},
},
})
```

## Slash Commands

Slash Commands (invoked with `/`) let you dynamically insert context into the chat buffer, such as file contents or date/time.

The plugin supports providers like `telescope`, `mini_pick`, or `fzf_lua` (please see the [Chat Buffer](/usage/chat-buffer) usage section for full details):

```lua
require("codecompanion").setup({
strategies = {
chat = {
slash_commands = {
["file"] = {
callback = "strategies.chat.slash_commands.file",
description = "Select a file using Telescope",
opts = {
provider = "telescope", -- Other options include 'default', 'mini_pick', 'fzf_lua'
contains_code = true,
},
},
},
},
},
})
```

You can also add your own slash commands:

```lua
require("codecompanion").setup({
strategies = {
chat = {
slash_commands = {
["mycmd"] = {
description = "Describe what mycmd inserts",
callback = function()
return "Custom context or data"
end,
opts = {
contains_code = true,
},
},
},
},
},
})
```

## Agents and Tools

Tools perform specific tasks (e.g., running shell commands, editing buffers, etc.) when invoked by an LLM. You can group them into an Agent and both can be referenced with `@` when in the chat buffer:

```lua
require("codecompanion").setup({
strategies = {
chat = {
agents = {
["my_agent"] = {
description = "A custom agent combining tools",
system_prompt = "Describe what the agent should do",
tools = {
"cmd_runner",
"editor",
-- Add your own tools or reuse existing ones
},
},
},
tools = {
["my_tool"] = {
description = "Run a custom task",
callback = function(command)
-- Perform the custom task here
return "Tool result"
end,
},
},
},
},
})
```

When users introduce the agent `@my_agent` in the chat buffer, it can call the tools you listed (like `@my_tool`) to perform tasks on your code.

## Layout

You can change the appearance of the chat buffer by changing the `display.chat.window` table in your configuration:

```lua
require("codecompanion").setup({
display = {
chat = {
-- Options to customize the UI of the chat buffer
window = {
layout = "vertical", -- float|vertical|horizontal|buffer
position = nil, -- left|right|top|bottom (nil will default depending on vim.opt.splitright|vim.opt.splitbelow)
border = "single",
height = 0.8,
width = 0.45,
relative = "editor",
opts = {
breakindent = true,
cursorcolumn = false,
cursorline = false,
foldcolumn = "0",
linebreak = true,
list = false,
numberwidth = 1,
signcolumn = "no",
spell = false,
wrap = true,
},
},

---Customize how tokens are displayed
---@param tokens number
---@param adapter CodeCompanion.Adapter
---@return string
token_count = function(tokens, adapter)
return " (" .. tokens .. " tokens)"
end,
},
}
}),
```

## Diff

> [!NOTE]
> Currently the plugin only supports native Neovim diff or [mini.diff](https://github.com/echasnovski/mini.diff)
If you utilize the `@editor` tool, then the plugin can update a given chat buffer. A diff will be created so you can see the changes made by the LLM.

There are a number of diff settings available to you:

```lua
require("codecompanion").setup({
display = {
chat = {
diff = {
enabled = true,
close_chat_at = 240, -- Close an open chat buffer if the total columns of your display are less than...
layout = "vertical", -- vertical|horizontal split for default provider
opts = { "internal", "filler", "closeoff", "algorithm:patience", "followwrap", "linematch:120" },
provider = "default", -- default|mini_diff
},
},
},
}),
```

## Additional Options

There are also a number of other options that you can customize:

```lua
require("codecompanion").setup({
display = {
chat = {
intro_message = "Welcome to CodeCompanion ✨! Press ? for options",
show_header_separator = false, -- Show header separators in the chat buffer? Set this to false if you're using an exteral markdown formatting plugin
separator = "", -- The separator between the different messages in the chat buffer
show_references = true, -- Show references (from slash commands and variables) in the chat buffer?
show_settings = false, -- Show LLM settings at the top of the chat buffer?
show_token_count = true, -- Show the token count for each response?
start_in_insert_mode = false, -- Open the chat buffer in insert mode?
},
},
}),
```
Loading

0 comments on commit 75c091a

Please sign in to comment.