Skip to content

Commit

Permalink
Add documentation for selections to README
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
  • Loading branch information
deathbeam committed Nov 18, 2024
1 parent 7890192 commit 6a2d8ae
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,47 @@ You can define custom contexts like this:
}
```

### Selections

Selections are used to determine the source of the chat (so basically what to chat about).
Selections are configurable either by default or by prompt.
Default selection is `visual` or `buffer` (if no visual selection).
Default supported selections that live in `local select = require("CopilotChat.select")` are:

- `select.visual` - Current visual selection. Works well with diffs.
- `select.buffer` - Current buffer content. Works well with diffs.
- `select.line` - Current line content. Works decently with diffs.
- `select.unnamed` - Content from the unnamed register.
- `select.clipboard` - Content from system clipboard.

You can define custom selection functions like this:

```lua
{
selection = function()
-- Get content from * register
local lines = vim.fn.getreg('*')
if not lines or lines == '' then
return nil
end

return {
lines = lines,
}
end
}
```

Or chain multiple selections like this:

```lua
{
selection = function(source)
return select.visual(source) or select.buffer(source)
end
}
```

### API

```lua
Expand Down

0 comments on commit 6a2d8ae

Please sign in to comment.