Skip to content

Commit 4c4248e

Browse files
committed
make path replace at sidebar to avoid printing the full path on chat
1 parent 7538816 commit 4c4248e

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

lua/eca/mediator.lua

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,6 @@ function mediator:send(method, params, callback)
124124
params.contexts = contexts
125125
end
126126

127-
if params.message and type(params.message) == "string" then
128-
local message = params.message:gsub("([@#])([%w%._%-%/]+)", function(prefix, path)
129-
-- expand ~
130-
if path:sub(1,1) == "~" then
131-
path = vim.fn.expand(path)
132-
end
133-
return prefix .. vim.fn.fnamemodify(path, ":p")
134-
end)
135-
136-
params.message = message
137-
end
138-
139127
self.server:send_request(method, params, callback)
140128
end
141129

lua/eca/sidebar.lua

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,14 +1038,27 @@ end
10381038

10391039
---@param message string
10401040
function M:_send_message(message)
1041-
Logger.debug("Sending message: " .. message)
1042-
1043-
-- Store the last user message to avoid duplication
1044-
self._last_user_message = message
1041+
if not message or not type(message) == "string" then
1042+
Logger.error("Cannot send empty message")
1043+
return
1044+
end
10451045

10461046
-- Add user message to chat
10471047
self:_add_message("user", message)
10481048

1049+
local replaced = message:gsub("([@#])([%w%._%-%/]+)", function(prefix, path)
1050+
-- expand ~
1051+
if path:sub(1,1) == "~" then
1052+
path = vim.fn.expand(path)
1053+
end
1054+
return prefix .. vim.fn.fnamemodify(path, ":p")
1055+
end)
1056+
1057+
message = replaced
1058+
1059+
-- Store the last user message to avoid duplication
1060+
self._last_user_message = message
1061+
10491062
local contexts = self.mediator:contexts()
10501063
self.mediator:send("chat/prompt", {
10511064
chatId = self.mediator:id(),
@@ -1158,6 +1171,7 @@ function M:_handle_streaming_text(text)
11581171
Logger.debug("Ignoring empty text response")
11591172
return
11601173
end
1174+
11611175
Logger.debug("Received text chunk: '" .. text:sub(1, 50) .. (text:len() > 50 and "..." or "") .. "'")
11621176

11631177
if vim.trim(text) == vim.trim(self._last_user_message) then

0 commit comments

Comments
 (0)