Skip to content

Commit cd712c5

Browse files
authored
fix(chat): olimorris#783 display settings in chat buffer (olimorris#784)
Co-authored-by: Oli Morris <[email protected]>
1 parent 2fe25b3 commit cd712c5

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

lua/codecompanion/strategies/chat/init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function Chat.new(args)
219219
util.fire("ChatModel", { bufnr = self.bufnr, model = self.adapter.schema.model.default })
220220
util.fire("ChatCreated", { bufnr = self.bufnr, from_prompt_library = self.from_prompt_library })
221221

222-
self:apply_settings(self.opts.settings)
222+
self:apply_settings(schema.get_default(self.adapter.schema, self.opts.settings))
223223

224224
self.ui = require("codecompanion.strategies.chat.ui").new({
225225
adapter = self.adapter,
@@ -365,11 +365,13 @@ function Chat:_get_settings_key(opts)
365365
end
366366

367367
---Apply custom settings to the chat buffer
368-
---@param settings table
368+
---@param settings? table
369369
---@return self
370370
function Chat:apply_settings(settings)
371-
_cached_settings[self.bufnr] = settings
371+
settings = settings or schema.get_default(self.adapter.schema, self.opts.settings)
372+
372373
self.settings = settings
374+
_cached_settings[self.bufnr] = settings
373375

374376
return self
375377
end

tests/helpers.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Helpers.config = {
9999
},
100100
}
101101

102-
Helpers.setup_chat_buffer = function()
102+
Helpers.setup_chat_buffer = function(config)
103103
local codecompanion = require("codecompanion")
104104

105105
local adapter = {
@@ -133,7 +133,7 @@ Helpers.setup_chat_buffer = function()
133133
},
134134
}
135135

136-
codecompanion.setup(Helpers.config)
136+
codecompanion.setup(config or Helpers.config)
137137

138138
local chat = require("codecompanion.strategies.chat").new({
139139
context = { bufnr = 1, filetype = "lua" },
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
local h = require("tests.helpers")
2+
3+
local new_set = MiniTest.new_set
4+
local T = new_set()
5+
6+
local chat, _
7+
8+
T["Settings"] = new_set({
9+
hooks = {
10+
pre_case = function()
11+
chat, _ = h.setup_chat_buffer({
12+
display = {
13+
chat = {
14+
show_settings = true,
15+
},
16+
},
17+
})
18+
end,
19+
post_case = function()
20+
h.teardown_chat_buffer()
21+
end,
22+
},
23+
})
24+
25+
T["Settings"]["Are rendered correctly"] = function()
26+
local buffer = h.get_buf_lines(chat.bufnr)
27+
28+
h.eq("---", buffer[1])
29+
h.eq("model: gpt-3.5-turbo", buffer[2])
30+
h.eq("---", buffer[3])
31+
end
32+
33+
return T

0 commit comments

Comments
 (0)