Skip to content

Commit 36f609d

Browse files
authored
feat(context): context bar (#69)
This PR is adding a context bar to manage/view context being sent by the plugin. You can now manage the context via the completion menu with the `#` trigger.
1 parent ad1260e commit 36f609d

33 files changed

+1757
-167
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ require('opencode').setup({
132132
['~'] = { 'mention_file', mode = 'i' }, -- Pick a file and add to context. See File Mentions section
133133
['@'] = { 'mention', mode = 'i' }, -- Insert mention (file/agent)
134134
['/'] = { 'slash_commands', mode = 'i' }, -- Pick a command to run in the input window
135+
['#'] = { 'context_items', mode = 'i' }, -- Manage context items (current file, selection, diagnostics, mentioned files)
136+
['<C-i>'] = { 'focus_input', mode = { 'n', 'i' } }, -- Focus on input window and enter insert mode at the end of the input from the output window
135137
['<tab>'] = { 'toggle_pane', mode = { 'n', 'i' } }, -- Toggle between input and output panes
136138
['<up>'] = { 'prev_prompt_history', mode = { 'n', 'i' } }, -- Navigate to previous prompt in history
137139
['<down>'] = { 'next_prompt_history', mode = { 'n', 'i' } }, -- Navigate to next prompt in history
@@ -425,6 +427,34 @@ The following editor context is automatically captured and included in your conv
425427
You can reference files in your project directly in your conversations with Opencode. This is useful when you want to ask about or provide context about specific files. Type `@` in the input window to trigger the file picker.
426428
Supported pickers include [`fzf-lua`](https://github.com/ibhagwan/fzf-lua), [`telescope`](https://github.com/nvim-telescope/telescope.nvim), [`mini.pick`](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-pick.md), [`snacks`](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md)
427429

430+
### Context bar
431+
432+
You can quiclkly see the current context items in the context bar at the top of the input window:
433+
434+
<div align="center">
435+
<img src="https://i.imgur.com/vGgu6br.png" alt="Opencode.nvim context bar" width="90%" />
436+
</div>
437+
438+
### Context Items Completion
439+
440+
You can quickly reference available context items by typing `#` in the input window. This will show a completion menu with all available context items:
441+
442+
- **Current File** - The currently focused file in the editor
443+
- **Selection** - Currently selected text in visual mode
444+
- **Diagnostics** - LSP diagnostics from the current file
445+
- **Cursor Data** - Current cursor position and line content
446+
- **[filename]** - Files that have been mentioned in the conversation
447+
- **Agents** - Available agents to switch to
448+
- **Selections** - Previously made selections in visual mode
449+
450+
Context items that are not currently available will be shown as disabled in the completion menu.
451+
452+
You should also see the list of files agents and selections in the menu, selecting them in the menu will remove them from the context.
453+
454+
<div align="center">
455+
<img src="https://i.imgur.com/UqQKW33.png" alt="Opencode.nvim context items completion" width="90%" />
456+
</div>
457+
428458
## 🔄 Agents
429459

430460
Opencode provides two built-in agents and supports custom ones:

lua/opencode/api.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ function M.mention()
299299
require('opencode.ui.completion').trigger_completion(char)()
300300
end
301301

302+
function M.context_items()
303+
local config = require('opencode.config')
304+
local char = config.get_key_for_function('input_window', 'context_items')
305+
ui.focus_input({ restore_position = true, start_insert = true })
306+
require('opencode.ui.completion').trigger_completion(char)()
307+
end
308+
302309
function M.slash_commands()
303310
local config = require('opencode.config')
304311
local char = config.get_key_for_function('input_window', 'slash_commands')

lua/opencode/config.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ M.defaults = {
5656
['~'] = { 'mention_file', mode = 'i' },
5757
['@'] = { 'mention', mode = 'i' },
5858
['/'] = { 'slash_commands', mode = 'i' },
59+
['#'] = { 'context_items', mode = 'i' },
5960
['<tab>'] = { 'toggle_pane', mode = { 'n', 'i' } },
6061
['<up>'] = { 'prev_prompt_history', mode = { 'n', 'i' } },
6162
['<down>'] = { 'next_prompt_history', mode = { 'n', 'i' } },
@@ -148,6 +149,7 @@ M.defaults = {
148149
enabled = false,
149150
},
150151
diagnostics = {
152+
enabled = true,
151153
info = false,
152154
warning = true,
153155
error = true,
@@ -163,6 +165,9 @@ M.defaults = {
163165
selection = {
164166
enabled = true,
165167
},
168+
agents = {
169+
enabled = true,
170+
},
166171
},
167172
debug = {
168173
enabled = false,
@@ -300,4 +305,4 @@ return setmetatable(M, {
300305
__tostring = function(_)
301306
return vim.inspect(M.values)
302307
end,
303-
})
308+
}) --[[@as OpencodeConfig & OpencodeConfigModule]]

0 commit comments

Comments
 (0)