-
-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathconfig.lua
More file actions
121 lines (116 loc) · 4.35 KB
/
Copy pathconfig.lua
File metadata and controls
121 lines (116 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---@class opencode.Opts
---@field server? opencode.server.Opts OpenCode server connection options.
---@field contexts? table<string, fun(context: opencode.context.Context): string?> Context placeholders and their builders.
---@field ask? opencode.ask.Opts Options for `ask()`. Supports [snacks.input](https://github.com/folke/snacks.nvim/blob/main/docs/input.md).
---@field select? opencode.select.Opts Options and items for `select()`. Supports [snacks.picker](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md).
---@field events? opencode.events.Opts Options for handling OpenCode events.
---Your opencode.nvim configuration.
---Passed via global variable for [simpler UX and faster startup](https://mrcjkb.dev/posts/2023-08-22-setup.html).
---
---snacks.nvim note: Neovim does not yet support metatables or mixed integer and string keys in `vim.g` variables, affecting some options.
---In that case you may modify `require("opencode.config").opts` directly.
---See [opencode.nvim #36](https://github.com/nickjvandyke/opencode.nvim/issues/36) and [neovim #12544](https://github.com/neovim/neovim/issues/12544#issuecomment-1116794687).
---@type opencode.Opts?
vim.g.opencode_opts = vim.g.opencode_opts
local M = {}
---@type opencode.Opts
local defaults = {
server = {
url = nil,
username = vim.env.OPENCODE_SERVER_USERNAME or "opencode", -- Same env vars and defaults as OpenCode
password = vim.env.OPENCODE_SERVER_PASSWORD,
start = function()
vim.cmd("vsplit term://opencode --port | wincmd p")
end,
},
contexts = {
["@this"] = require("opencode.context.builtins").this,
["@buffer"] = require("opencode.context.builtins").buffer,
["@buffers"] = require("opencode.context.builtins").buffers,
["@diagnostics"] = require("opencode.context.builtins").diagnostics,
["@marks"] = require("opencode.context.builtins").marks,
["@quickfix"] = require("opencode.context.builtins").quickfix,
["@visible"] = require("opencode.context.builtins").visible_text,
},
ask = {
prompt = "Ask OpenCode: ",
completion = "customlist,v:lua.opencode_completion",
snacks = {
icon = " ",
win = {
title_pos = "left",
relative = "cursor",
row = -3, -- Row above the cursor
col = 0, -- Align with the cursor
keys = {
i_cr = {
desc = "submit",
},
},
b = {
completion = true,
},
bo = {
filetype = "opencode_ask",
},
on_buf = function(win)
-- Make sure your completion plugin has the LSP source enabled,
-- either by default or for the `opencode_ask` filetype!
vim.lsp.start(require("opencode.ui.ask.cmp"), {
bufnr = win.buf,
})
end,
},
},
},
select = {
prompt = "OpenCode: ",
prompts = {
ask = "...",
diagnostics = "Explain @diagnostics",
document = "Add comments documenting @this",
explain = "Explain @this and its context",
fix = "Fix @diagnostics",
implement = "Implement @this",
optimize = "Optimize @this for performance and readability",
review = "Review @this for correctness and readability",
test = "Add tests for @this",
},
commands = {
["agent.cycle"] = "Cycle selected agent",
["prompt.clear"] = "Clear current prompt",
["prompt.submit"] = "Submit current prompt",
["session.compact"] = "Compact current session",
["session.interrupt"] = "Interrupt current session",
["session.new"] = "Start new session",
["session.redo"] = "Redo last undone action in current session",
["session.select"] = "Select session",
["session.undo"] = "Undo last action in current session",
},
server = {
["server.select"] = "Select server",
["server.start"] = "Start configured server",
},
snacks = {
preview = "preview",
layout = {
preset = "vscode",
hidden = {}, -- preview is hidden by default in `vim.ui.select`
},
},
},
events = {
enabled = true,
reload = true,
permissions = {
enabled = true,
edits = {
enabled = true,
},
},
},
}
---Plugin options, lazily merged from `defaults` and `vim.g.opencode_opts`.
---@type opencode.Opts
M.opts = vim.tbl_deep_extend("force", vim.deepcopy(defaults), vim.g.opencode_opts or {})
return M