Skip to content

Commit 1ae6d55

Browse files
authored
refactor(adapters): warn users of using acp adapters (#2655)
Co-authored-by: Oli Morris <olimorris@users.noreply.github.com>
1 parent 43aeabc commit 1ae6d55

4 files changed

Lines changed: 39 additions & 28 deletions

File tree

lua/codecompanion/init.lua

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ end
3535
---@return nil
3636
CodeCompanion.inline = function(args)
3737
local context = get_context(api.nvim_get_current_buf(), args)
38-
return require("codecompanion.interactions.inline").new({ buffer_context = context }):prompt(args.args)
38+
local inline = require("codecompanion.interactions.inline").new({ buffer_context = context })
39+
if inline then
40+
inline:prompt(args.args)
41+
end
3942
end
4043

4144
---Accept the next word of code completion
@@ -185,35 +188,37 @@ end
185188
CodeCompanion.cmd = function(args)
186189
local context = get_context(api.nvim_get_current_buf(), args)
187190

188-
return require("codecompanion.interactions.cmd")
189-
.new({
190-
buffer_context = context,
191-
prompts = {
192-
{
193-
role = config.constants.SYSTEM_ROLE,
194-
content = string.format(
195-
[[Some additional context which **may** be useful:
191+
local command = require("codecompanion.interactions.cmd").new({
192+
buffer_context = context,
193+
prompts = {
194+
{
195+
role = config.constants.SYSTEM_ROLE,
196+
content = string.format(
197+
[[Some additional context which **may** be useful:
196198
197199
- The user is currently working in a %s file
198200
- It has %d lines
199201
- The user is currently on line %d
200202
- The file's full path is %s]],
201-
context.filetype,
202-
context.line_count,
203-
context.cursor_pos[1],
204-
context.filename
205-
),
206-
opts = {
207-
visible = false,
208-
},
209-
},
210-
{
211-
role = config.constants.USER_ROLE,
212-
content = args.args,
203+
context.filetype,
204+
context.line_count,
205+
context.cursor_pos[1],
206+
context.filename
207+
),
208+
opts = {
209+
visible = false,
213210
},
214211
},
215-
})
216-
:start(args)
212+
{
213+
role = config.constants.USER_ROLE,
214+
content = args.args,
215+
},
216+
},
217+
})
218+
219+
if command then
220+
command:start(args)
221+
end
217222
end
218223

219224
---Toggle the chat buffer

lua/codecompanion/interactions/background/init.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ function Background.new(args)
5757
end
5858

5959
-- Silence errors
60-
if self.adapter.type ~= "http" then
61-
return log:debug("[background::init] Only HTTP adapters are supported for background interactions")
62-
end
6360
if not self.adapter then
64-
return log:debug("[background::init] No adapter assigned for background interactions")
61+
return log:debug("[Background] No adapter found")
62+
end
63+
if self.adapter.type ~= "http" then
64+
return log:warn("Only HTTP adapters are supported for background interactions")
6565
end
6666

6767
self.settings = schema.get_default(self.adapter, args.settings)

lua/codecompanion/interactions/cmd.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ function Cmd.new(args)
2222

2323
self.adapter = adapters.resolve(config.interactions.cmd.adapter)
2424
if not self.adapter then
25-
return log:error("No adapter found")
25+
return log:error("[Command] No adapter found")
26+
end
27+
if self.adapter.type ~= "http" then
28+
return log:warn("Only HTTP adapters are supported for command interactions")
2629
end
2730

2831
-- Check if the user has manually overridden the adapter

lua/codecompanion/interactions/inline/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ function Inline.new(args)
206206
if not self.adapter then
207207
return log:error("[Inline] No adapter found")
208208
end
209+
if self.adapter.type ~= "http" then
210+
return log:warn("Only HTTP adapters are supported for inline interactions")
211+
end
209212

210213
-- Check if the user has manually overridden the adapter
211214
if vim.g.codecompanion_adapter and self.adapter.name ~= vim.g.codecompanion_adapter then

0 commit comments

Comments
 (0)