@@ -75,9 +75,19 @@ function M.add_file_context(file_path)
7575 content = content
7676 }
7777
78- -- For now, store it for next message
79- -- TODO: Implement context management
80- Utils .debug (" File context added: " .. file_path )
78+ -- Get current sidebar and add context
79+ local sidebar = eca .get ()
80+ if not sidebar then
81+ Utils .info (" Opening ECA sidebar to add context..." )
82+ M .chat ()
83+ sidebar = eca .get ()
84+ end
85+
86+ if sidebar then
87+ sidebar :add_context (context )
88+ else
89+ Utils .error (" Failed to create ECA sidebar" )
90+ end
8191end
8292
8393--- @param directory_path string
@@ -123,8 +133,112 @@ function M.add_selection_context()
123133 local lines = vim .api .nvim_buf_get_lines (0 , start_pos [2 ] - 1 , end_pos [2 ], false )
124134 if # lines > 0 then
125135 local selection_text = table.concat (lines , " \n " )
126- Utils .info (" Adding selection context (" .. # lines .. " lines)" )
127- -- TODO: Send selection to ECA server as context
136+ local current_file = vim .api .nvim_buf_get_name (0 )
137+ local context_path = current_file .. " :" .. start_pos [2 ] .. " -" .. end_pos [2 ]
138+
139+ -- Create context object
140+ local context = {
141+ type = " selection" ,
142+ path = context_path ,
143+ content = selection_text ,
144+ source_file = current_file ,
145+ start_line = start_pos [2 ],
146+ end_line = end_pos [2 ]
147+ }
148+
149+ -- Get current sidebar and add context
150+ local eca = require (" eca" )
151+ local sidebar = eca .get ()
152+ if not sidebar then
153+ Utils .info (" Opening ECA sidebar to add context..." )
154+ M .chat ()
155+ sidebar = eca .get ()
156+ end
157+
158+ if sidebar then
159+ sidebar :add_context (context )
160+ Utils .info (" Added selection context (" .. # lines .. " lines)" )
161+ else
162+ Utils .error (" Failed to create ECA sidebar" )
163+ end
164+ end
165+ end
166+
167+ function M .list_contexts ()
168+ local eca = require (" eca" )
169+ local sidebar = eca .get ()
170+ if not sidebar then
171+ Utils .warn (" No active ECA sidebar" )
172+ return
173+ end
174+
175+ local contexts = sidebar :get_contexts ()
176+ if # contexts == 0 then
177+ Utils .info (" No active contexts" )
178+ return
179+ end
180+
181+ Utils .info (" Active contexts (" .. # contexts .. " ):" )
182+ for i , context in ipairs (contexts ) do
183+ local size_info = " "
184+ if context .content then
185+ local lines = vim .split (context .content , " \n " )
186+ size_info = " (" .. # lines .. " lines)"
187+ end
188+ Utils .info (i .. " . " .. context .type .. " : " .. context .path .. size_info )
189+ end
190+ end
191+
192+ function M .clear_contexts ()
193+ local eca = require (" eca" )
194+ local sidebar = eca .get ()
195+ if not sidebar then
196+ Utils .warn (" No active ECA sidebar" )
197+ return
198+ end
199+
200+ sidebar :clear_contexts ()
201+ end
202+
203+ function M .remove_context (path )
204+ local eca = require (" eca" )
205+ local sidebar = eca .get ()
206+ if not sidebar then
207+ Utils .warn (" No active ECA sidebar" )
208+ return
209+ end
210+
211+ sidebar :remove_context (path )
212+ end
213+
214+ function M .add_repo_map_context ()
215+ local eca = require (" eca" )
216+ local sidebar = eca .get ()
217+ if not sidebar then
218+ Utils .info (" Opening ECA sidebar to add repoMap context..." )
219+ M .chat ()
220+ sidebar = eca .get ()
221+ end
222+
223+ if sidebar then
224+ -- Check if repoMap already exists
225+ local contexts = sidebar :get_contexts ()
226+ for _ , context in ipairs (contexts ) do
227+ if context .type == " repoMap" then
228+ Utils .info (" RepoMap context already added" )
229+ return
230+ end
231+ end
232+
233+ -- Add repoMap context
234+ sidebar :add_context ({
235+ type = " repoMap" ,
236+ path = " repoMap" ,
237+ content = " Repository structure and code mapping for better project understanding"
238+ })
239+ Utils .info (" Added repoMap context" )
240+ else
241+ Utils .error (" Failed to create ECA sidebar" )
128242 end
129243end
130244
0 commit comments