Skip to content

Commit ce8d473

Browse files
Danilo Verde RibeiroDanilo Verde Ribeiro
authored andcommitted
fix(performace): proper detector and cleaner
1 parent 3ab8e87 commit ce8d473

File tree

6 files changed

+236
-96
lines changed

6 files changed

+236
-96
lines changed

README.md

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ require('opencode').setup({
115115
diff_revert_this_last_prompt = '<leader>ort', -- Revert current file changes since the last opencode prompt
116116
diff_revert_all = '<leader>orA', -- Revert all file changes since the last opencode session
117117
diff_revert_this = '<leader>orT', -- Revert current file changes since the last opencode session
118+
diff_restore_snapshot_file = '<leader>orr', -- Restore file to snapshot
119+
diff_restore_snapshot_all = '<leader>orR', -- Restore all files to snapshot
120+
open_configuration_file = '<leader>oC', -- Open opencode configuration file
118121
swap_position = '<leader>ox', -- Swap Opencode pane left/right
119122
permission_accept = '<leader>opa', -- Accept permission request once
120123
permission_accept_all = '<leader>opA', -- Accept all (for current tool)
@@ -141,6 +144,7 @@ require('opencode').setup({
141144
permission_accept = 'a', -- Accept permission request once (only available when there is a pending permission request)
142145
permission_accept_all = 'A', -- Accept all (for current tool) permission request once (only available when there is a pending permission request)
143146
permission_deny = 'd',-- Accept permission request once (only available when there is a pending permission request)
147+
debug_session = '<leader>ods', -- Debug session info
144148
},
145149
},
146150
ui = {
@@ -153,7 +157,7 @@ require('opencode').setup({
153157
display_cost = true, -- Display cost in the footer
154158
window_highlight = 'Normal:OpencodeBackground,FloatBorder:OpencodeBorder', -- Highlight group for the opencode window
155159
icons = {
156-
preset = 'emoji', -- 'emoji' | 'text'. Choose UI icon style (default: 'emoji')
160+
preset = 'nerdfonts', -- 'emoji' | 'nerdfonts' | 'text'. Choose UI icon style (default: 'nerdfonts')
157161
overrides = {}, -- Optional per-key overrides, see section below
158162
},
159163
output = {
@@ -163,11 +167,12 @@ require('opencode').setup({
163167
},
164168
input = {
165169
text = {
166-
wrap = false, -- Wraps text inside input window
170+
wrap = true, -- Wraps text inside input window
167171
},
168172
},
169173
completion = {
170174
file_sources = {
175+
cache_timeout = 300, -- seconds
171176
enabled = true,
172177
preferred_cli_tool = 'fd', -- 'fd','fdfind','rg','git' if nil, it will use the best available tool
173178
ignore_patterns = {
@@ -203,89 +208,99 @@ require('opencode').setup({
203208
},
204209
context = {
205210
enabled = true, -- Enable automatic context capturing
211+
plugin_versions = {
212+
enabled = false, -- Include plugin versions in context
213+
limit = 20, -- Max number of plugins to include
214+
},
206215
cursor_data = {
207216
enabled = false, -- Include cursor position and line content in the context
208217
},
209218
diagnostics = {
210-
info = false, -- Include diagnostics info in the context (default to false
211-
warn = true, -- Include diagnostics warnings in the context
219+
info = false, -- Include diagnostics info in the context (default to false)
220+
warning = true, -- Include diagnostics warnings in the context
212221
error = true, -- Include diagnostics errors in the context
213222
},
214223
current_file = {
215224
enabled = true, -- Include current file path and content in the context
225+
show_full_path = true, -- Show full file path instead of relative
226+
},
227+
files = {
228+
enabled = true, -- Include mentioned files in context
229+
show_full_path = true, -- Show full file path instead of relative
216230
},
217231
selection = {
218232
enabled = true, -- Include selected text in the context
219233
},
220-
-- Enhanced context options (all disabled by default)
234+
-- Enhanced context options (enabled by default where applicable)
221235
marks = {
222-
enabled = false, -- Include the 10 most recently accessed marks
223-
limit = 10,
236+
enabled = true, -- Include the most recently accessed marks
237+
limit = 5,
224238
},
225239
jumplist = {
226-
enabled = false, -- Include the last 10 jumps
227-
limit = 10,
240+
enabled = true, -- Include the last jumps
241+
limit = 5,
228242
},
229243
recent_buffers = {
230-
enabled = false, -- Include the 10 most recently accessed buffers
231-
limit = 10,
244+
enabled = true, -- Include the most recently accessed buffers
245+
symbols_only = true, -- Include only buffers with symbols (functions, classes, etc.)
246+
limit = 3,
232247
},
233248
undo_history = {
234-
enabled = false, -- Include the last 10 undo branches/changesets
235-
limit = 10,
249+
enabled = true, -- Include the last undo branches/changesets
250+
limit = 3,
236251
},
237252
windows_tabs = {
238-
enabled = false, -- Include active windows and tabs information
253+
enabled = true, -- Include active windows and tabs information
239254
},
240255
highlights = {
241-
enabled = false, -- Include buffer line highlights in current viewport
256+
enabled = true, -- Include buffer line highlights in current viewport
242257
},
243258
session_info = {
244259
enabled = false, -- Include current session name if active
245260
},
246261
registers = {
247-
enabled = false, -- Include contents of specified registers
248-
include = { '"', '/', 'q' }, -- Registers to include
262+
enabled = true, -- Include contents of specified registers
263+
include = { '"', '/', 'q', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '%', '#', '.' }, -- Registers to include
249264
},
250265
command_history = {
251-
enabled = false, -- Include the last 5 executed commands
252-
limit = 5,
266+
enabled = true, -- Include the last executed commands
267+
limit = 3,
253268
},
254269
search_history = {
255-
enabled = false, -- Include the last 5 search patterns
256-
limit = 5,
270+
enabled = true, -- Include the last search patterns
271+
limit = 3,
257272
},
258273
debug_data = {
259-
enabled = false, -- Include active nvim-dap debugging sessions and breakpoints
274+
enabled = true, -- Include active nvim-dap debugging sessions and breakpoints
260275
},
261276
lsp_context = {
262277
enabled = false, -- Include LSP diagnostics and code actions
263278
diagnostics_limit = 10, -- Max diagnostics to include
264279
code_actions = false, -- Include available code actions at cursor
265280
},
266281
git_info = {
267-
enabled = false, -- Include git branch, file diff, and recent changes
282+
enabled = true, -- Include git branch, file diff, and recent changes
268283
diff_limit = 10, -- Max lines of file diff to include
269284
changes_limit = 5, -- Number of recent commits to include
270285
},
271286
fold_info = {
272-
enabled = false, -- Include visible fold information in viewport
287+
enabled = true, -- Include visible fold information in viewport
273288
},
274289
cursor_surrounding = {
275-
enabled = false, -- Include lines around cursor position
276-
lines_above = 3, -- Lines to include above cursor
277-
lines_below = 3, -- Lines to include below cursor
290+
enabled = true, -- Include lines around cursor position
291+
lines_above = 4, -- Lines to include above cursor
292+
lines_below = 4, -- Lines to include below cursor
278293
},
279294
quickfix_loclist = {
280-
enabled = false, -- Include quickfix and location list entries
295+
enabled = true, -- Include quickfix and location list entries
281296
limit = 5,
282297
},
283298
macros = {
284299
enabled = false, -- Include recorded macro content
285300
register = 'q', -- Macro register to include
286301
},
287302
terminal_buffers = {
288-
enabled = false, -- Include most recently used terminal buffer details
303+
enabled = true, -- Include most recently used terminal buffer details
289304
},
290305
session_duration = {
291306
enabled = false, -- Include time spent in current Neovim session
@@ -295,6 +310,7 @@ require('opencode').setup({
295310
enabled = false, -- Enable debug messages in the output window
296311
},
297312
})
313+
298314
```
299315

300316
### UI icons (disable emojis or customize)
@@ -445,39 +461,39 @@ The following editor context is automatically captured and included in your conv
445461

446462
### Core Context (Enabled by Default)
447463

448-
| Context Type | Description | Configuration Key |
449-
| --------------- | ---------------------------------------------------- | ------------------------ |
450-
| Current file | Path to the focused file before entering opencode | `current_file.enabled` |
451-
| Selected text | Text and lines currently selected in visual mode | `selection.enabled` |
452-
| Mentioned files | File info added through [mentions](#file-mentions) | N/A (always available) |
453-
| Diagnostics | Diagnostics from the current file (if any) | `diagnostics` |
454-
| Cursor position | Current cursor position and line content in the file | `cursor_data.enabled` |
464+
| Context Type | Description | Configuration Key |
465+
| --------------- | ---------------------------------------------------- | ---------------------- |
466+
| Current file | Path to the focused file before entering opencode | `current_file.enabled` |
467+
| Selected text | Text and lines currently selected in visual mode | `selection.enabled` |
468+
| Mentioned files | File info added through [mentions](#file-mentions) | N/A (always available) |
469+
| Diagnostics | Diagnostics from the current file (if any) | `diagnostics` |
470+
| Cursor position | Current cursor position and line content in the file | `cursor_data.enabled` |
455471

456472
### Enhanced Context (Disabled by Default)
457473

458474
These additional context types can be enabled to provide even more information to the AI:
459475

460-
| Context Type | Description | Configuration Key |
461-
| ------------------ | ---------------------------------------------------------- | -------------------------- |
462-
| Marks | 10 most recently accessed marks | `marks.enabled` |
463-
| Jumplist | Last 10 jumps in the jump list | `jumplist.enabled` |
464-
| Recent Buffers | 10 most recently accessed buffers | `recent_buffers.enabled` |
465-
| Undo History | Last 10 undo branches or changesets | `undo_history.enabled` |
466-
| Windows & Tabs | Information about active windows and tabs | `windows_tabs.enabled` |
467-
| Highlights | Buffer line highlights in current viewport | `highlights.enabled` |
468-
| Session Info | Current Neovim session name if active | `session_info.enabled` |
469-
| Registers | Contents of specified registers (e.g., `"`, `/`, `q`) | `registers.enabled` |
470-
| Command History | Last 5 executed Vim commands | `command_history.enabled` |
471-
| Search History | Last 5 search patterns | `search_history.enabled` |
472-
| Debug Data | Active nvim-dap debugging sessions and breakpoints | `debug_data.enabled` |
473-
| LSP Context | LSP diagnostics and available code actions | `lsp_context.enabled` |
474-
| Git Info | Current branch, file diff, and recent commits | `git_info.enabled` |
475-
| Fold Info | Visible folds in current viewport | `fold_info.enabled` |
476-
| Cursor Surrounding | Lines above and below cursor position | `cursor_surrounding.enabled`|
477-
| Quickfix/Loclist | Quickfix and location list entries | `quickfix_loclist.enabled` |
478-
| Macros | Recorded macro content from specified register | `macros.enabled` |
479-
| Terminal Buffers | Most recently used terminal buffer details | `terminal_buffers.enabled` |
480-
| Session Duration | Time spent in current Neovim session | `session_duration.enabled` |
476+
| Context Type | Description | Configuration Key |
477+
| ------------------ | ----------------------------------------------------- | ---------------------------- |
478+
| Marks | 10 most recently accessed marks | `marks.enabled` |
479+
| Jumplist | Last 10 jumps in the jump list | `jumplist.enabled` |
480+
| Recent Buffers | 10 most recently accessed buffers | `recent_buffers.enabled` |
481+
| Undo History | Last 10 undo branches or changesets | `undo_history.enabled` |
482+
| Windows & Tabs | Information about active windows and tabs | `windows_tabs.enabled` |
483+
| Highlights | Buffer line highlights in current viewport | `highlights.enabled` |
484+
| Session Info | Current Neovim session name if active | `session_info.enabled` |
485+
| Registers | Contents of specified registers (e.g., `"`, `/`, `q`) | `registers.enabled` |
486+
| Command History | Last 5 executed Vim commands | `command_history.enabled` |
487+
| Search History | Last 5 search patterns | `search_history.enabled` |
488+
| Debug Data | Active nvim-dap debugging sessions and breakpoints | `debug_data.enabled` |
489+
| LSP Context | LSP diagnostics and available code actions | `lsp_context.enabled` |
490+
| Git Info | Current branch, file diff, and recent commits | `git_info.enabled` |
491+
| Fold Info | Visible folds in current viewport | `fold_info.enabled` |
492+
| Cursor Surrounding | Lines above and below cursor position | `cursor_surrounding.enabled` |
493+
| Quickfix/Loclist | Quickfix and location list entries | `quickfix_loclist.enabled` |
494+
| Macros | Recorded macro content from specified register | `macros.enabled` |
495+
| Terminal Buffers | Most recently used terminal buffer details | `terminal_buffers.enabled` |
496+
| Session Duration | Time spent in current Neovim session | `session_duration.enabled` |
481497

482498
To enable any of these enhanced context types, add them to your configuration:
483499

lua/opencode/config.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ M.defaults = {
132132
},
133133
context = {
134134
enabled = true,
135+
-- Idle threshold in milliseconds for automatic context updates
136+
-- Context will be updated after this period of user inactivity
137+
idle_threshold = 10000, -- 10 seconds
138+
-- Cache TTL in milliseconds for expensive context operations
139+
-- Set to 0 to disable caching
140+
cache_ttl = {
141+
git_info = 5000, -- 5 seconds
142+
plugin_versions = 60000, -- 60 seconds
143+
highlights = 2000, -- 2 seconds
144+
lsp_symbols = 10000, -- 10 seconds
145+
},
135146
plugin_versions = {
136147
enabled = false,
137148
limit = 20,
@@ -176,7 +187,7 @@ M.defaults = {
176187
enabled = true,
177188
},
178189
highlights = {
179-
enabled = true,
190+
enabled = false,
180191
},
181192
session_info = {
182193
enabled = false,
@@ -202,8 +213,8 @@ M.defaults = {
202213
code_actions = false,
203214
},
204215
git_info = {
205-
enabled = true,
206-
diff_limit = 10,
216+
enabled = false,
217+
diff_limit = 5,
207218
changes_limit = 5,
208219
},
209220
fold_info = {

0 commit comments

Comments
 (0)