Skip to content

Commit dba83b9

Browse files
committed
feat: slash command output is now hidden
1 parent 54b3107 commit dba83b9

File tree

11 files changed

+76
-124
lines changed

11 files changed

+76
-124
lines changed

lua/codecompanion/config.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,6 @@ local defaults = {
204204
callback = "keymaps.change_adapter",
205205
description = "Change adapter",
206206
},
207-
fold_code = {
208-
modes = {
209-
n = "gf",
210-
},
211-
index = 12,
212-
callback = "keymaps.fold_code",
213-
description = "Fold code",
214-
},
215207
debug = {
216208
modes = {
217209
n = "gd",

lua/codecompanion/helpers/slash_commands/buffer.lua

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local config = require("codecompanion.config")
33
local buf = require("codecompanion.utils.buffers")
44
local file_utils = require("codecompanion.utils.files")
55
local log = require("codecompanion.utils.log")
6+
local util = require("codecompanion.utils.util")
67

78
local api = vim.api
89

@@ -34,30 +35,19 @@ local function output(SlashCommand, selected)
3435
end
3536

3637
local Chat = SlashCommand.Chat
37-
if config.opts.visible then
38-
Chat:append_to_buf({
39-
content = "[!"
40-
.. CONSTANTS.NAME
41-
.. ": `"
42-
.. selected[CONSTANTS.DISPLAY]
43-
.. "` / Buf No.: "
44-
.. selected.bufnr
45-
.. "]\n",
46-
})
47-
Chat:append_to_buf({ content = content })
48-
Chat:fold_code()
49-
else
50-
Chat:add_message({
51-
role = "user",
52-
content = string.format(
53-
[[Here is the data from buffer number %d:
38+
Chat:add_message({
39+
role = "user",
40+
content = string.format(
41+
[[Here is the content from %s (which has a buffer number of _%d_ and a filepath of `%s`):
5442
5543
%s]],
56-
selected.bufnr,
57-
content
58-
),
59-
}, { visible = false })
60-
end
44+
selected.name,
45+
selected.bufnr,
46+
selected.path,
47+
content
48+
),
49+
}, { visible = false })
50+
util.notify(string.format("Buffer `%s` content added to the chat", selected.name))
6151
end
6252

6353
local Providers = {

lua/codecompanion/helpers/slash_commands/fetch.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local adapters = require("codecompanion.adapters")
22
local client = require("codecompanion.http")
33

44
local log = require("codecompanion.utils.log")
5+
local util = require("codecompanion.utils.util")
56

67
local fmt = string.format
78

@@ -82,7 +83,7 @@ function SlashCommand:execute()
8283
content = content,
8384
}, { visible = false })
8485

85-
return vim.notify(fmt("Added the data from %s", input), vim.log.levels.INFO, { title = "CodeCompanion" })
86+
return util.notify(fmt("Added the page contents for: %s", input))
8687
end
8788
if chunk.code >= 400 then
8889
return log:error("Error: %s", chunk.body.data)

lua/codecompanion/helpers/slash_commands/file.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local config = require("codecompanion.config")
22

33
local file_utils = require("codecompanion.utils.files")
44
local log = require("codecompanion.utils.log")
5+
local util = require("codecompanion.utils.util")
56

67
CONSTANTS = {
78
NAME = "File",
@@ -26,9 +27,20 @@ local function output(SlashCommand, selected)
2627

2728
local Chat = SlashCommand.Chat
2829
local relative_path = selected.relative_path or selected[1] or selected.path
29-
Chat:append_to_buf({ content = "[!" .. CONSTANTS.NAME .. ": `" .. relative_path .. "`]\n" })
30-
Chat:append_to_buf({ content = "```" .. ft .. "\n" .. content .. "```" })
31-
Chat:fold_code()
30+
Chat:add_message({
31+
role = "user",
32+
content = string.format(
33+
[[Here is the content from the file `%s`:
34+
35+
```%s
36+
%s
37+
```]],
38+
relative_path,
39+
ft,
40+
content
41+
),
42+
}, { visible = false })
43+
util.notify("File data added to chat")
3244
end
3345

3446
local Providers = {

lua/codecompanion/helpers/slash_commands/help.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local config = require("codecompanion.config")
33
local file_utils = require("codecompanion.utils.files")
44
local log = require("codecompanion.utils.log")
55
local tokens_utils = require("codecompanion.utils.tokens")
6+
local util = require("codecompanion.utils.util")
67
local ts = vim.treesitter
78

89
CONSTANTS = {
@@ -85,9 +86,20 @@ local function output(SlashCommand, selected)
8586
end
8687

8788
local Chat = SlashCommand.Chat
88-
Chat:append_to_buf({ content = "[!" .. CONSTANTS.NAME .. ": `" .. selected.tag .. "`]\n" })
89-
Chat:append_to_buf({ content = "```" .. ft .. "\n" .. content .. "\n```" })
90-
Chat:fold_code()
89+
Chat:add_message({
90+
role = "user",
91+
content = string.format(
92+
[[Here is some additional context related to the tag `%s`:
93+
94+
```%s
95+
%s
96+
```]],
97+
selected.tag,
98+
ft,
99+
content
100+
),
101+
}, { visible = false })
102+
util.notify(string.format("%s help file added to chat", selected.tag))
91103
end
92104

93105
local Providers = {

lua/codecompanion/helpers/slash_commands/symbols.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local config = require("codecompanion.config")
22

33
local log = require("codecompanion.utils.log")
4+
local util = require("codecompanion.utils.util")
45

56
---The Tree-sitter queries below are used to extract symbols from the buffer
67
---where the chat was initiated from. If you'd like to add more support
@@ -159,20 +160,24 @@ function SlashCommand:execute()
159160

160161
if #symbols == 0 then
161162
log:info("No symbols found in the buffer")
162-
return vim.notify("No symbols found in the buffer", "info", { title = "CodeCompanion" })
163+
util.notify("No symbols found in the buffer")
163164
end
164165

165166
local content = table.concat(symbols, "\n")
166-
Chat:append_to_buf({ content = "[!Symbols]\n" })
167-
Chat:append_to_buf({
167+
Chat:add_message({
168+
role = "user",
168169
content = string.format(
169-
"```txt\nFilename: %s\nFiletype: %s\n<symbols>\n%s\n</symbols>\n```\n",
170+
[[Here is a symbolic outline of the file `%s` with filetype `%s`:
171+
172+
<symbols>
173+
%s
174+
</symbols>]],
170175
Chat.context.filename,
171176
Chat.context.filetype,
172177
content
173178
),
174-
})
175-
Chat:fold_code()
179+
}, { visible = false })
180+
util.notify("Symbolic outline added to chat")
176181
end
177182

178183
return SlashCommand

lua/codecompanion/helpers/slash_commands/terminal.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local util = require("codecompanion.utils.util")
2+
13
CONSTANTS = {
24
NAME = "Terminal Output",
35
}
@@ -28,20 +30,19 @@ function SlashCommand:execute()
2830
local content = vim.api.nvim_buf_get_lines(terminal_buf, 0, -1, false)
2931

3032
local Chat = self.Chat
31-
32-
Chat:append_to_buf({ content = "[!" .. CONSTANTS.NAME .. "]\n" })
33-
Chat:append_to_buf({
33+
Chat:add_message({
34+
role = "user",
3435
content = string.format(
35-
[[```
36-
Buffer Number: %s
37-
Output:
36+
[[Here is the terminal output for buffer number `%s`:
37+
38+
<terminal>
3839
%s
39-
```]],
40+
</terminal>]],
4041
terminal_buf,
4142
table.concat(content, "\n")
4243
),
43-
})
44-
Chat:fold_code()
44+
}, { visible = false })
45+
util.notify("Terminal output added to chat")
4546
end
4647

4748
return SlashCommand

lua/codecompanion/keymaps.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,6 @@ M.change_adapter = {
362362
end,
363363
}
364364

365-
M.fold_code = {
366-
callback = function(chat)
367-
chat:fold_code()
368-
end,
369-
}
370-
371365
M.debug = {
372366
desc = "Show debug information for the current chat",
373367
callback = function(chat)

lua/codecompanion/strategies/chat.lua

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,71 +1085,6 @@ function Chat:fold_heading(heading)
10851085
return self
10861086
end
10871087

1088-
---Fold code under the user's heading in the chat buffer
1089-
---@return self
1090-
function Chat:fold_code()
1091-
-- NOTE: Folding is super brittle in Neovim
1092-
if not self.has_folded_code then
1093-
api.nvim_create_autocmd("InsertLeave", {
1094-
group = self.aug,
1095-
buffer = self.bufnr,
1096-
desc = "Always fold code when a slash command is used",
1097-
callback = function()
1098-
self:fold_code()
1099-
end,
1100-
})
1101-
self.has_folded_code = true
1102-
end
1103-
1104-
local query = vim.treesitter.query.parse(
1105-
"markdown",
1106-
[[
1107-
(section
1108-
(
1109-
(atx_heading
1110-
(atx_h2_marker)
1111-
heading_content: (_) @role
1112-
)
1113-
([
1114-
(fenced_code_block)
1115-
(indented_code_block)
1116-
] @code (#trim! @code))
1117-
))
1118-
]]
1119-
)
1120-
1121-
local parser = vim.treesitter.get_parser(self.bufnr, "markdown")
1122-
local tree = parser:parse()[1]
1123-
1124-
vim.o.foldmethod = "manual"
1125-
1126-
local role
1127-
for _, matches in query:iter_matches(tree:root(), self.bufnr, nil, nil, { all = false }) do
1128-
local match = {}
1129-
for id, node in pairs(matches) do
1130-
match = vim.tbl_extend("keep", match, {
1131-
[query.captures[id]] = {
1132-
node = node,
1133-
},
1134-
})
1135-
end
1136-
1137-
if match.role then
1138-
role = vim.trim(vim.treesitter.get_node_text(match.role.node, self.bufnr))
1139-
if role:match(user_role) and match.code then
1140-
local start_row, _, end_row, _ = match.code.node:range()
1141-
if start_row < end_row then
1142-
api.nvim_buf_call(self.bufnr, function()
1143-
vim.cmd(string.format("%d,%dfold", start_row, end_row))
1144-
end)
1145-
end
1146-
end
1147-
end
1148-
end
1149-
1150-
return self
1151-
end
1152-
11531088
---CodeCompanion models completion source
11541089
---@param request table
11551090
---@param callback fun(request: table)

lua/codecompanion/strategies/chat/slash_commands.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local config = require("codecompanion").config
21
local log = require("codecompanion.utils.log")
32

43
---Resolve the callback to the correct module

0 commit comments

Comments
 (0)