|
35 | 35 | ---@return nil |
36 | 36 | CodeCompanion.inline = function(args) |
37 | 37 | 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 |
39 | 42 | end |
40 | 43 |
|
41 | 44 | ---Accept the next word of code completion |
@@ -185,35 +188,37 @@ end |
185 | 188 | CodeCompanion.cmd = function(args) |
186 | 189 | local context = get_context(api.nvim_get_current_buf(), args) |
187 | 190 |
|
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: |
196 | 198 |
|
197 | 199 | - The user is currently working in a %s file |
198 | 200 | - It has %d lines |
199 | 201 | - The user is currently on line %d |
200 | 202 | - 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, |
213 | 210 | }, |
214 | 211 | }, |
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 |
217 | 222 | end |
218 | 223 |
|
219 | 224 | ---Toggle the chat buffer |
|
0 commit comments