@@ -81,23 +81,20 @@ function M.add_file_context(file_path)
8181 -- Create context object
8282 local context = {
8383 type = " file" ,
84- path = file_path ,
85- content = content ,
84+ data = {
85+ path = file_path ,
86+ }
8687 }
8788
88- -- Get current sidebar and add context
89- local sidebar = eca .get ()
90- if not sidebar then
91- Logger .info (" Opening ECA sidebar to add context..." )
92- M .chat ()
93- sidebar = eca .get ()
94- end
89+ local chat = eca .get ()
9590
96- if sidebar then
97- sidebar :add_context (context )
98- else
99- Logger .notify (" Failed to create ECA sidebar" , vim .log .levels .ERROR )
91+ if not chat or not chat .mediator then
92+ Logger .notify (" No active ECA Chat to add context" , vim .log .levels .WARN )
93+ return
10094 end
95+
96+ chat .mediator :add_context (context )
97+ Logger .info (" File context added: " .. vim .inspect (context ))
10198end
10299
103100--- @param directory_path string
@@ -113,12 +110,20 @@ function M.add_directory_context(directory_path)
113110 -- Create context object for directory
114111 local context = {
115112 type = " directory" ,
116- path = directory_path ,
113+ data = {
114+ path = directory_path ,
115+ },
117116 }
118117
119- -- For now, store it for next message
120- -- TODO: Implement context management
121- Logger .debug (" Directory context added: " .. directory_path )
118+ local chat = eca .get ()
119+
120+ if not chat or not chat .mediator then
121+ Logger .notify (" No active ECA Chat to add context" , vim .log .levels .WARN )
122+ return
123+ end
124+
125+ chat .mediator :add_context (context )
126+ Logger .info (" Directory context added: " .. vim .inspect (context ))
122127end
123128
124129function M .add_current_file_context ()
@@ -131,6 +136,9 @@ function M.add_current_file_context()
131136end
132137
133138function M .add_selection_context ()
139+ Logger .info (" Adding selection context ..." )
140+ local eca = require (" eca" )
141+
134142 -- Get visual selection marks (should be set by the command before calling this)
135143 local start_pos = vim .fn .getpos (" '<" )
136144 local end_pos = vim .fn .getpos (" '>" )
@@ -145,97 +153,82 @@ function M.add_selection_context()
145153 local end_line = math.max (start_pos [2 ], end_pos [2 ])
146154
147155 local lines = vim .api .nvim_buf_get_lines (0 , start_line - 1 , end_line , false )
148- if # lines > 0 then
149- local selection_text = table.concat (lines , " \n " )
150- local current_file = vim .api .nvim_buf_get_name (0 )
151- local context_path = current_file .. " :" .. start_line .. " -" .. end_line
152-
153- -- Create context object
154- local context = {
155- type = " file" ,
156+
157+ if # lines <= 0 then
158+ Logger .notify (" No lines found in the selection" , vim .log .levels .WARN )
159+ return
160+ end
161+
162+ local current_file = vim .api .nvim_buf_get_name (0 )
163+
164+ -- Create context object
165+ local context = {
166+ type = " file" ,
167+ data = {
156168 path = current_file ,
157- linesRange = {
158- start = start_line ,
159- [ " end " ] = end_line , -- end is a reserved word in Lua
169+ lines_range = {
170+ line_start = start_line ,
171+ line_end = end_line ,
160172 },
161173 }
174+ }
162175
163- -- Get current sidebar and add context
164- local eca = require (" eca" )
165- local sidebar = eca .get ()
166- if not sidebar then
167- Logger .info (" Opening ECA sidebar to add context..." )
168- M .chat ()
169- sidebar = eca .get ()
170- end
171-
172- if sidebar then
173- sidebar :add_context (context )
174-
175- -- Also set as selected code for visual display
176- local selected_code = {
177- filepath = current_file ,
178- content = selection_text ,
179- start_line = start_line ,
180- end_line = end_line ,
181- filetype = vim .api .nvim_get_option_value (" filetype" , { buf = 0 }),
182- }
183- sidebar :set_selected_code (selected_code )
176+ local chat = eca .get ()
184177
185- Logger .info (" Added selection context (" .. # lines .. " lines from lines " .. start_line .. " -" .. end_line .. " )" )
186- else
187- Logger .notify (" Failed to create ECA sidebar" , vim .log .levels .ERROR )
188- end
189- else
190- Logger .notify (" No lines found in selection" , vim .log .levels .WARN )
178+ if not chat or not chat .mediator then
179+ Logger .notify (" No active ECA Chat to add context" , vim .log .levels .WARN )
180+ return
191181 end
182+
183+ chat .mediator :add_context (context )
184+ Logger .info (" Added selection context: " .. vim .inspect (context ))
192185end
193186
194187function M .list_contexts ()
195188 local eca = require (" eca" )
196- local sidebar = eca .get ()
197- if not sidebar then
189+ local chat = eca .get ()
190+
191+ if not chat or not chat .mediator then
198192 Logger .notify (" No active ECA sidebar" , vim .log .levels .WARN )
199193 return
200194 end
201195
202- local contexts = sidebar : get_contexts ()
196+ local contexts = chat . mediator : contexts ()
203197 if # contexts == 0 then
204198 Logger .notify (" No active contexts" , vim .log .levels .INFO )
205199 return
206200 end
207201
208202 Logger .info (" Active contexts (" .. # contexts .. " ):" )
209203 for i , context in ipairs (contexts ) do
210- local size_info = " "
211- if context .content then
212- local lines = vim .split (context .content , " \n " )
213- size_info = " (" .. # lines .. " lines)"
214- end
215- Logger .info (i .. " . " .. context .type .. " : " .. context .path .. size_info )
204+ Logger .info (i .. " . " .. context .type .. " : " .. vim .inspect (context .data ))
216205 end
217206end
218207
219208function M .clear_contexts ()
220209 local eca = require (" eca" )
221- local sidebar = eca .get ()
222- if not sidebar then
223- Logger .notify (" No active ECA sidebar" , vim .log .levels .WARN )
210+ local chat = eca .get ()
211+
212+ if not chat or not chat .mediator then
213+ Logger .notify (" No active ECA Chat" , vim .log .levels .WARN )
224214 return
225215 end
226216
227- sidebar :clear_contexts ()
217+ chat .mediator :clear_contexts ()
218+ Logger .info (" Cleared all contexts" )
228219end
229220
230221function M .remove_context (path )
231222 local eca = require (" eca" )
232- local sidebar = eca .get ()
233- if not sidebar then
234- Logger .notify (" No active ECA sidebar" , vim .log .levels .WARN )
223+ local chat = eca .get ()
224+
225+ if not chat or not chat .mediator then
226+ Logger .notify (" No active ECA Chat" , vim .log .levels .WARN )
235227 return
236228 end
237229
238- sidebar :remove_context (path )
230+ chat .mediator :remove_context (path )
231+ Logger .info (" Context removed: " .. path )
239232end
240233
241234function M .add_repo_map_context ()
0 commit comments