@@ -2,6 +2,7 @@ local Utils = require("eca.utils")
22
33local M = {}
44
5+ --- Setup ECA commands
56function M .setup ()
67 -- Define ECA commands
78 vim .api .nvim_create_user_command (" EcaChat" , function (opts )
@@ -43,7 +44,7 @@ function M.setup()
4344
4445 vim .api .nvim_create_user_command (" EcaAddSelection" , function ()
4546 -- Force exit visual mode and set marks
46- vim .cmd (' normal! \\ <Esc>' )
47+ vim .cmd (" normal! \\ <Esc>" )
4748 vim .defer_fn (function ()
4849 require (" eca.api" ).add_selection_context ()
4950 end , 50 ) -- Small delay to ensure marks are set
@@ -83,7 +84,7 @@ function M.setup()
8384 })
8485
8586 -- ===== Selected Code Commands =====
86-
87+
8788 vim .api .nvim_create_user_command (" EcaShowSelection" , function ()
8889 require (" eca.api" ).show_selected_code ()
8990 end , {
@@ -97,7 +98,7 @@ function M.setup()
9798 })
9899
99100 -- ===== TODOs Commands =====
100-
101+
101102 vim .api .nvim_create_user_command (" EcaAddTodo" , function (opts )
102103 if opts .args and opts .args ~= " " then
103104 require (" eca.api" ).add_todo (opts .args )
@@ -159,17 +160,17 @@ function M.setup()
159160 local eca = require (" eca" )
160161 local status = eca .server and eca .server :status () or " Not initialized"
161162 local status_icon = " ○"
162-
163+
163164 if status == " Running" then
164165 status_icon = " ✓"
165166 elseif status == " Starting" then
166167 status_icon = " ⋯"
167168 elseif status == " Failed" then
168169 status_icon = " ✗"
169170 end
170-
171+
171172 Utils .info (" ECA Server Status: " .. status .. " " .. status_icon )
172-
173+
173174 -- Also show path info if available
174175 if eca .server and eca .server ._path_finder then
175176 local config = require (" eca.config" )
@@ -183,10 +184,48 @@ function M.setup()
183184 desc = " Show ECA server status with details" ,
184185 })
185186
186- vim .api .nvim_create_user_command (" EcaLogs" , function ()
187- require (" eca.api" ).show_logs ()
187+ vim .api .nvim_create_user_command (" EcaLogs" , function (opts )
188+ local Logger = require (" eca.logger" )
189+ local Api = require (" eca.api" )
190+ local subcommand = opts .args and opts .args :match (" %S+" ) or " show"
191+
192+ if subcommand == " show" then
193+ Api .show_logs ()
194+ elseif subcommand == " log_path" then
195+ local log_path = Logger .get_log_path ()
196+ if log_path then
197+ Utils .info (" ECA log file: " .. log_path , { nofity_only = true })
198+ else
199+ Utils .info (" File logging is disabled" )
200+ end
201+ elseif subcommand == " clear" then
202+ if Logger .clear_log () then
203+ Utils .info (" ECA log file cleared" )
204+ else
205+ Utils .warn (" Failed to clear log file (file logging may be disabled)" )
206+ end
207+ elseif subcommand == " stats" then
208+ local stats = Logger .get_log_stats ()
209+ if stats then
210+ Utils .info (string.format (" Log file: %s" , stats .path ))
211+ Utils .info (string.format (" Size: %.2fMB (%d bytes)" , stats .size_mb , stats .size ))
212+ Utils .info (string.format (" Last modified: %s" , stats .modified ))
213+ else
214+ Utils .info (" No log file stats available (file logging may be disabled)" )
215+ end
216+ else
217+ Utils .warn (" Unknown EcaLogs subcommand: " .. subcommand )
218+ Utils .info (" Available subcommands: show, log_path, clear, stats" )
219+ end
188220 end , {
189- desc = " Open ECA server logs in a new buffer" ,
221+ desc = " ECA logging commands (show, log_path, clear, stats)" ,
222+ nargs = " ?" ,
223+ complete = function (ArgLead , CmdLine , CursorPos )
224+ local subcommands = { " show" , " log_path" , " clear" , " stats" }
225+ return vim .tbl_filter (function (cmd )
226+ return cmd :match (" ^" .. ArgLead )
227+ end , subcommands )
228+ end ,
190229 })
191230
192231 vim .api .nvim_create_user_command (" EcaSend" , function (opts )
@@ -213,23 +252,23 @@ function M.setup()
213252 vim .api .nvim_create_user_command (" EcaRedownload" , function ()
214253 local eca = require (" eca" )
215254 local Utils = require (" eca.utils" )
216-
255+
217256 if eca .server and eca .server :is_running () then
218257 Utils .info (" Stopping server before re-download..." )
219258 eca .server :stop ()
220259 end
221-
260+
222261 -- Remove existing version file to force re-download
223262 local cache_dir = Utils .get_cache_dir ()
224263 local version_file = cache_dir .. " /eca-version"
225264 os.remove (version_file )
226-
265+
227266 -- Remove existing binary
228267 local server_binary = cache_dir .. " /eca"
229268 os.remove (server_binary )
230-
269+
231270 Utils .info (" Removed cached ECA server. Will re-download on next start." )
232-
271+
233272 -- Restart server
234273 vim .defer_fn (function ()
235274 if eca .server then
@@ -243,7 +282,7 @@ function M.setup()
243282 vim .api .nvim_create_user_command (" EcaStopResponse" , function ()
244283 local eca = require (" eca" )
245284 local Utils = require (" eca.utils" )
246-
285+
247286 -- Force stop any ongoing streaming response
248287 if eca .sidebar then
249288 eca .sidebar :_finalize_streaming_response ()
@@ -257,7 +296,7 @@ function M.setup()
257296
258297 vim .api .nvim_create_user_command (" EcaFixTreesitter" , function ()
259298 local Utils = require (" eca.utils" )
260-
299+
261300 -- Emergency treesitter fix for chat buffer
262301 vim .schedule (function ()
263302 local eca = require (" eca" )
@@ -266,15 +305,15 @@ function M.setup()
266305 if bufnr and vim .api .nvim_buf_is_valid (bufnr ) then
267306 -- Disable all highlighting for this buffer
268307 pcall (vim .api .nvim_set_option_value , " syntax" , " off" , { buf = bufnr })
269-
308+
270309 -- Destroy treesitter highlighter if it exists
271310 pcall (function ()
272311 if vim .treesitter .highlighter .active [bufnr ] then
273312 vim .treesitter .highlighter .active [bufnr ]:destroy ()
274313 vim .treesitter .highlighter .active [bufnr ] = nil
275314 end
276315 end )
277-
316+
278317 Utils .info (" Disabled treesitter highlighting for ECA chat buffer" )
279318 Utils .info (" Buffer " .. bufnr .. " highlighting disabled" )
280319 else
0 commit comments